summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ximera/src/problem.dtx
blob: 4a8cfaeddbc9622c684a7b3e71431cd3eba8db56 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
% \subsubsection{Problem environments}

% These are problem environment decorations (these should be user invoked, not default).
% The decoration for these environments were inspired by
% \url{http://tex.stackexchange.com/questions/11098/nice-formatting-for-theorems}
%    \begin{macrocode}
%<*classXimera>
%    \end{macrocode}

% \begin{macro}{latexProblemContent}
%    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'.
%    \begin{macrocode}
\providecommand{\latexProblemContent}[1]{#1}
% Iterate count for problem counts.
\Make@Counter{Iteration@probCnt}        
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
\newcommand{\hang}{% top theorem decoration
  \begingroup%
  \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{1pt} \color{black!50}%
      \put(-3,2){\line(1,0){206}}% Top line
      \multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
        \color{black!\iB}%
        \put(-3,\iA){\line(0,-1){1}}% Top left hang
        %\put(203,\iA){\line(0,-1){1}}% Top right hang
      }%
    \end{picture}%
  \endgroup%
}%
\newcommand{\hung}{% bottom theorem decoration
  \nobreak
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{1pt} \color{black!50}%
      \put(60,0){\line(1,0){143}}% Bottom line
      \multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
        \color{black!\iB}%
        %\put(-3,\iA){\line(0,1){1}}% Bottom left hang
        \put(203,\iA){\line(0,1){1}}% Bottom right hang
        \put(\iB,0){\line(60,0){10}}% Left fade out
      }%
    \end{picture}%
  \endgroup%
}%
%    \end{macrocode}
%
% Configure environment configuration commands
%
% The command |\problemNumber| contains all the format code to determine the number (and the format of the number) for any of the problem environments.
% 
%    \begin{macrocode}
\MakeCounter{problem}
\newcommand{\problemNumber}{
% First we determine if we have a counter for this question depth level.
\ifcsname c@depth\Roman{problem@Depth}Count\endcsname% Check to see if counter exists
	%If so, do nothing.
	\else
	%If not, create it.
	\expandafter\newcounter{depth\Roman{problem@Depth}Count}
	\expandafter\setcounter{depth\Roman{problem@Depth}Count}{0}
	\fi

\expandafter\stepcounter{depth\Roman{problem@Depth}Count}
\arabic{depthICount}% The first problem depth, what use to be |\theproblem|.

\forloop{Iteration@probCnt}{2}{\arabic{Iteration@probCnt} < \numexpr \value{problem@Depth} + 1 \relax}{%
    .\expandafter\arabic{depth\Roman{Iteration@probCnt}Count}% Get the problem number of the next depth level and append it with a ".".
}
%\@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).
%\ifhandout % Currently handout mode doesn't allow hints. Putting this code in place in case that changes.
%	\theproblem 
%\else
%	\theproblem 
%\fi
}


%%%%%% Configure various problem environment commands
\Make@Counter{problem@Depth}



%%%% Configure environments start content

\newcommand{\problemEnvironmentStart}[2]{%
% This takes in 2 arguments. 
% The first is optional and is the old optional argument from existing environments. 
%	This is passed down to the associated problem environment name in case you want a global value.
% The second argument is mandatory and is the name of the 'problem' environment, 
%	such as problem, question, exercise, etc. 
% It then configures everything needed at the start of that environment.

\stepcounter{problem@Depth}% Started a problem, so we've sunk another problem layer.
\def\spaceatend{#1}%
\begin{trivlist}%
\item%
  [%
    \hskip\labelsep\sffamily\bfseries
    #2 \problemNumber% Determine the correct number of the problem, and the format of that number.
	]%
\slshape
}



%%%%% Configure environments end content

\newcommand{\problemEnvironmentEnd}{%This configures all the end content for a problem.
%
% First we need to see if we've dropped fully out of a depth level, 
% so we can reset that counter back to zero for the next time we enter that depth level.
\stepcounter{problem@Depth}
\ifcsname c@depth\Roman{problem@Depth}Count\endcsname
	\expandafter\ifnum\expandafter\value{depth\Roman{problem@Depth}Count}>0
		\expandafter\setcounter{depth\Roman{problem@Depth}Count}{0}
	\fi
\fi

\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. 

\par\addvspace{.5ex}\nobreak\noindent\hung %% line at the bottom

\ifhandout
	\ifnewpage
		\newpage
	\fi
\fi 
\end{trivlist}
}



%%%% Now populate the old environment names
%
% Old environments were "problem", "exercise", "exploration", and "question".
% Note that you can add content to the start/end code on top of these base code pieces if you want.


\newenvironment{problem}[1][2in]%
{%Env start code
\problemEnvironmentStart{#1}{Problem}
}
{%Env end code
\problemEnvironmentEnd
}

\newenvironment{exercise}[1][2in]%
{%Env start code
\problemEnvironmentStart{#1}{Exercise}
}
{%Env end code
\problemEnvironmentEnd
}

\newenvironment{exploration}[1][2in]%
{%Env start code
\problemEnvironmentStart{#1}{Exploration}
}
{%Env end code
\problemEnvironmentEnd
}

\newenvironment{question}[1][2in]%
{%Env start code
\problemEnvironmentStart{#1}{Question}
}
{%Env end code
\problemEnvironmentEnd
}
%</classXimera>
%    \end{macrocode}


% Use an ``identification'' counter to assign IDs to the various problem-related DOM elements
%    \begin{macrocode}
%<*htXimera>
\newcounter{identification}
\setcounter{identification}{0}

\newcommand{\ConfigureQuestionEnv}[2]{%
% refstepcounter ensures that labels get updated within these environments
\renewenvironment{#1}{\refstepcounter{problem}}{}%
\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}{}{}%
}

\ConfigureQuestionEnv{problem}{problem}
\ConfigureQuestionEnv{exercise}{exercise}
\ConfigureQuestionEnv{question}{question}
\ConfigureQuestionEnv{exploration}{exploration}
\ConfigureQuestionEnv{hint}{hint}
%%%%\ConfigureQuestionEnv{shuffle}{shuffle}
%</htXimera>
%    \end{macrocode}