-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise.sty
56 lines (48 loc) · 1.96 KB
/
exercise.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{exercise}[2025-03-26 Typeset exercises]
\RequirePackage{xkeyval}
\RequirePackage{ifthen}
\makeatletter
% declare exercise styles
\define@key{ex@style}{headfont}{\def\currentHeadFont{#1}}
\define@key{ex@style}{bodyfont}{\def\currentBodyFont{#1}}
\setkeys{ex@style}{headfont=\sffamily\bfseries, bodyfont=\normalfont}
\newcommand{\NewExerciseStyle}[2]{
\setkeys{ex@style}{#2}
\def\styleName{#1}
\expandafter\def\csname \styleName.headfont\endcsname{\currentHeadFont}
\expandafter\def\csname \styleName.bodyfont\endcsname{\currentBodyFont}
}
% default exercise style
\NewExerciseStyle{ex@style@default}{headfont=\sffamily\bfseries, bodyfont=\normalfont}
% declare exercise environments
\define@key{ex@definition}{style}{\def\currentStyle{#1}}
\define@key{ex@definition}{numbered}{\def\currentNumbered{#1}}
\define@key{ex@definition}{numberWithin}{\def\currentNumberWithin{#1}}
\setkeys{ex@definition}{style=ex@style@default, numbered=false, numberWithin=none}
\newcommand{\NewExerciseDefinition}[3][style=ex@style@default]{%
\setkeys{ex@definition}{#1}%
\ifthenelse{\equal{\currentNumbered}{true}}{%
\@ifundefined{ex@counter@#3}{%
\ifthenelse{\equal{\currentNumberWithin}{none}}{%
\newcounter{ex@counter@#3}%
}{%
\newcounter{ex@counter@#3}[\currentNumberWithin]%
\expandafter\renewcommand\csname theex@counter@#3\endcsname{\csname the\currentNumberWithin\endcsname.\arabic{ex@counter@#3}}%
}%
}{}%
\setcounter{ex@counter@#3}{0}%
}{}%
\newenvironment{#3}{%
\par\noindent%
{%
\csname \currentStyle.headfont\endcsname #2%
\ifthenelse{\equal{\currentNumbered}{true}}{%
\refstepcounter{ex@counter@#3}%
~\csname theex@counter@#3\endcsname.%
}{}%
}%
\csname \currentStyle.bodyfont\endcsname%
}{\normalfont\par}%
}
\makeatother