Debian Codegraph @

texmf-dist/doc/latex/ximera/src/problem.dtx

raw
1 % \subsubsection{Problem environments}
2
3 % These are problem environment decorations (these should be user invoked, not default).
4 % The decoration for these environments were inspired by
5 % \url{http://tex.stackexchange.com/questions/11098/nice-formatting-for-theorems}
6 % \begin{macrocode}
7 %<*classXimera>
8 % \end{macrocode}
9
10 % \begin{macro}{latexProblemContent}
11 % Added for those that want to use UF problems without using the problem filter code. This command is renewed into something meaningful in the 'ProblemSelector.sty'.
12 % \begin{macrocode}
13 \providecommand{\latexProblemContent}[1]{#1}
14 % Iterate count for problem counts.
15 \Make@Counter{Iteration@probCnt}
16 % \end{macrocode}
17 % \end{macro}
18 % \begin{macrocode}
19 \newcommand{\hang}{% top theorem decoration
20 \begingroup%
21 \setlength{\unitlength}{.005\linewidth}% \linewidth/200
22 \begin{picture}(0,0)(1.5,0)%
23 \linethickness{1pt} \color{black!50}%
24 \put(-3,2){\line(1,0){206}}% Top line
25 \multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
26 \color{black!\iB}%
27 \put(-3,\iA){\line(0,-1){1}}% Top left hang
28 %\put(203,\iA){\line(0,-1){1}}% Top right hang
29 }%
30 \end{picture}%
31 \endgroup%
32 }%
33 \newcommand{\hung}{% bottom theorem decoration
34 \nobreak
35 \begingroup%
36 \setlength{\unitlength}{.005\linewidth}% \linewidth/200
37 \begin{picture}(0,0)(1.5,0)%
38 \linethickness{1pt} \color{black!50}%
39 \put(60,0){\line(1,0){143}}% Bottom line
40 \multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
41 \color{black!\iB}%
42 %\put(-3,\iA){\line(0,1){1}}% Bottom left hang
43 \put(203,\iA){\line(0,1){1}}% Bottom right hang
44 \put(\iB,0){\line(60,0){10}}% Left fade out
45 }%
46 \end{picture}%
47 \endgroup%
48 }%
49 % \end{macrocode}
50 %
51 % Configure environment configuration commands
52 %
53 % The command |\problemNumber| contains all the format code to determine the number (and the format of the number) for any of the problem environments.
54 %
55 % \begin{macrocode}
56 \MakeCounter{problem}
57 \newcommand{\problemNumber}{
58 % First we determine if we have a counter for this question depth level.
59 \ifcsname c@depth\Roman{problem@Depth}Count\endcsname% Check to see if counter exists
60 %If so, do nothing.
61 \else
62 %If not, create it.
63 \expandafter\newcounter{depth\Roman{problem@Depth}Count}
64 \expandafter\setcounter{depth\Roman{problem@Depth}Count}{0}
65 \fi
66
67 \expandafter\stepcounter{depth\Roman{problem@Depth}Count}
68 \arabic{depthICount}% The first problem depth, what use to be |\theproblem|.
69
70 \forloop{Iteration@probCnt}{2}{\arabic{Iteration@probCnt} < \numexpr \value{problem@Depth} + 1 \relax}{%
71 .\expandafter\arabic{depth\Roman{Iteration@probCnt}Count}% Get the problem number of the next depth level and append it with a ".".
72 }
73 %\@ifpackageloaded{shuffle}{<true>}{<false>}% Check if Shuffle has been added. If so, add special numbering to the shuffled "groups". Currently commented out while we decide what that should look like (compared to the normal nested problems).
74 %\ifhandout % Currently handout mode doesn't allow hints. Putting this code in place in case that changes.
75 % \theproblem
76 %\else
77 % \theproblem
78 %\fi
79 }
80
81
82 %%%%%% Configure various problem environment commands
83 \Make@Counter{problem@Depth}
84
85
86
87 %%%% Configure environments start content
88
89 \newcommand{\problemEnvironmentStart}[2]{%
90 % This takes in 2 arguments.
91 % The first is optional and is the old optional argument from existing environments.
92 % This is passed down to the associated problem environment name in case you want a global value.
93 % The second argument is mandatory and is the name of the 'problem' environment,
94 % such as problem, question, exercise, etc.
95 % It then configures everything needed at the start of that environment.
96
97 \stepcounter{problem@Depth}% Started a problem, so we've sunk another problem layer.
98 \def\spaceatend{#1}%
99 \begin{trivlist}%
100 \item%
101 [%
102 \hskip\labelsep\sffamily\bfseries
103 #2 \problemNumber% Determine the correct number of the problem, and the format of that number.
104 ]%
105 \slshape
106 }
107
108
109
110 %%%%% Configure environments end content
111
112 \newcommand{\problemEnvironmentEnd}{%This configures all the end content for a problem.
113 %
114 % First we need to see if we've dropped fully out of a depth level,
115 % so we can reset that counter back to zero for the next time we enter that depth level.
116 \stepcounter{problem@Depth}
117 \ifcsname c@depth\Roman{problem@Depth}Count\endcsname
118 \expandafter\ifnum\expandafter\value{depth\Roman{problem@Depth}Count}>0
119 \expandafter\setcounter{depth\Roman{problem@Depth}Count}{0}
120 \fi
121 \fi
122
123 \addtocounter{problem@Depth}{-2}% Exited a problem so we've exited a problem layer. Need -2 because we steppped once at the start to check for needing a depth-level count reset.
124
125 \par\addvspace{.5ex}\nobreak\noindent\hung %% line at the bottom
126
127 \ifhandout
128 \ifnewpage
129 \newpage
130 \fi
131 \fi
132 \end{trivlist}
133 }
134
135
136
137 %%%% Now populate the old environment names
138 %
139 % Old environments were "problem", "exercise", "exploration", and "question".
140 % Note that you can add content to the start/end code on top of these base code pieces if you want.
141
142
143 \newenvironment{problem}[1][2in]%
144 {%Env start code
145 \problemEnvironmentStart{#1}{Problem}
146 }
147 {%Env end code
148 \problemEnvironmentEnd
149 }
150
151 \newenvironment{exercise}[1][2in]%
152 {%Env start code
153 \problemEnvironmentStart{#1}{Exercise}
154 }
155 {%Env end code
156 \problemEnvironmentEnd
157 }
158
159 \newenvironment{exploration}[1][2in]%
160 {%Env start code
161 \problemEnvironmentStart{#1}{Exploration}
162 }
163 {%Env end code
164 \problemEnvironmentEnd
165 }
166
167 \newenvironment{question}[1][2in]%
168 {%Env start code
169 \problemEnvironmentStart{#1}{Question}
170 }
171 {%Env end code
172 \problemEnvironmentEnd
173 }
174 %</classXimera>
175 % \end{macrocode}
176
177
178 % Use an ``identification'' counter to assign IDs to the various problem-related DOM elements
179 % \begin{macrocode}
180 %<*htXimera>
181 \newcounter{identification}
182 \setcounter{identification}{0}
183
184 \newcommand{\ConfigureQuestionEnv}[2]{%
185 % refstepcounter ensures that labels get updated within these environments
186 \renewenvironment{#1}{\refstepcounter{problem}}{}%
187 \ConfigureEnv{#1}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div role="article" class="problem-environment #2" id="problem\arabic{identification}">}}{\ifvmode \IgnorePar\fi \EndP\HCode{</div>}\IgnoreIndent}{}{}%
188 }
189
190 \ConfigureQuestionEnv{problem}{problem}
191 \ConfigureQuestionEnv{exercise}{exercise}
192 \ConfigureQuestionEnv{question}{question}
193 \ConfigureQuestionEnv{exploration}{exploration}
194 \ConfigureQuestionEnv{hint}{hint}
195 %%%%\ConfigureQuestionEnv{shuffle}{shuffle}
196 %</htXimera>
197 % \end{macrocode}