-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathximera.4ht
292 lines (231 loc) · 13.6 KB
/
ximera.4ht
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ximera.4ht
% Copyright (C) 2014
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is
% in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This Current Maintainer of this work
% is Jim Fowler.
%
% If you modify this program your changing its signature
% with a directive of the following form will be
% appreciated.
% \message{signature}
%
% fowler@math.osu.edu
% http://kisonecat.com/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\immediate\write-1{version 2014-01-26-09:44}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% disable ligatures in HTML
\usepackage{microtype}
\DisableLigatures{encoding = *, family = * }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% pgf sometimes causes trouble, but we simply don't care in tex4ht mode
\newcommand{\pgfsyspdfmark}[3]{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use an "identification" counter to assign IDs to the various problem-related DOM elements
\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 class="problem-environment #2" id="problem\arabic{identification}">}}{\HCode{</div>}\IgnoreIndent}{}{}%
}
\ConfigureQuestionEnv{problem}{problem}
\ConfigureQuestionEnv{exercise}{exercise}
\ConfigureQuestionEnv{question}{question}
\ConfigureQuestionEnv{exploration}{exploration}
\ConfigureQuestionEnv{xarmaBoost}{xarma-boost}
\ConfigureQuestionEnv{hint}{hint}
\renewenvironment{freeResponse}{\refstepcounter{problem}}{}%
\ConfigureEnv{freeResponse}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div class="free-response" id="problem\arabic{identification}">}}{\HCode{</div>}\IgnoreIndent}{}{}%
\ConfigureQuestionEnv{shuffle}{shuffle}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% respondables
\renewcommand{\answer}[2][false]{\HCode{<span class="answer respondable">}#2\HCode{</span>}}
\renewcommand{\graph}[2][]{\HCode{<div class="graph" data-options="#1">}#2\HCode{</div>}}
%% correct answers for multiple choice
%\newboolean{correct}
%\setboolean{correct}{true}
\newcounter{choiceId}
\renewcommand{\choice}[2][]{%
\setkeys{choice}{correct=false}%
\setkeys{choice}{#1}%
\stepcounter{choiceId}\ifvmode \IgnorePar\fi \EndP%
\HCode{<span class="choice }%
\ifthenelse{\boolean{\choice@correct}}{\HCode{correct}}{}
\HCode{" }
\ifthenelse{\equal{\choice@value}{}}{}{\HCode{data-value="\choice@value" }}
\HCode{id="choice\arabic{choiceId}">}%
#2\HCode{</span>}}
% You might expect a \setcounter{choiceId}{0} here --- that would be
% wrong, because then the generated IDs would no longer be unique.
%
% You might also expect these to be "problem environments" but they aren't -- they're respondables
\renewenvironment{multipleChoice}{}{}%\refstepcounter{problem}}{}%
\renewenvironment{multipleChoice}[1][]
{\setkeys{multipleChoice}{#1}%
\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div class="multiple-choice" }%
\ifthenelse{\equal{\mc@id}{}}{}{\HCode{data-id="\mc@id" }}%
\HCode{id="problem\arabic{identification}">}%
}{\HCode{</div>}\IgnoreIndent}
\ConfigureEnv{multipleChoice}{}{}{}{}
% This is actually just word choice
\renewenvironment{multipleChoice*}{\refstepcounter{problem}}{}%
\ConfigureEnv{multipleChoice*}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<span class="word-choice" id="word-choice\arabic{identification}">}}{\HCode{</span>}\IgnoreIndent}{}{}
\renewenvironment{selectAll}{\refstepcounter{problem}}{}%
\ConfigureEnv{selectAll}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div class="select-all" id="problem\arabic{identification}">}}{\HCode{</div>}\IgnoreIndent}{}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% refstepcounter ensures that labels get updated within these environments
%\makeatletter
\newcommand{\ConfigureTheoremEnv}[1]{%
\renewenvironment{#1}[1][]{\refstepcounter{problem}%
\ifthenelse{\equal{##1}{}}{}{%
\HCode{<span class="theorem-like-title">}##1\HCode{</span>}%
}}{}
\ConfigureEnv{#1}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div class="theorem-like problem-environment #1" id="problem\arabic{identification}">}}{\HCode{</div>}\IgnoreIndent}{}{}%
}
%\makeatother
\ConfigureTheoremEnv{theorem}
\ConfigureTheoremEnv{acknowledgement}
\ConfigureTheoremEnv{algorithm}
\ConfigureTheoremEnv{axiom}
\ConfigureTheoremEnv{claim}
\ConfigureTheoremEnv{conclusion}
\ConfigureTheoremEnv{condition}
\ConfigureTheoremEnv{conjecture}
\ConfigureTheoremEnv{corollary}
\ConfigureTheoremEnv{criterion}
\ConfigureTheoremEnv{definition}
\ConfigureTheoremEnv{example}
\ConfigureTheoremEnv{explanation}
\ConfigureTheoremEnv{lemma}
\ConfigureTheoremEnv{notation}
\ConfigureTheoremEnv{proposition}
\ConfigureTheoremEnv{remark}
\ConfigureTheoremEnv{summary}
\ConfigureTheoremEnv{paradox}
\ConfigureTheoremEnv{warning}
\ConfigureTheoremEnv{observation}
\ConfigureTheoremEnv{template}
\ConfigureTheoremEnv{idea}
\ConfigureTheoremEnv{fact}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Eliminate some formatting that we'll handle later with CSS
\renewcommand{\maketitle}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dialogue environment
\renewenvironment{dialogue}{\begin{description}}{\end{description}}
\ConfigureList{dialogue}%
{\EndP\HCode{<dl \a:LRdir class="dialogue">}%
\PushMacro\end:itm
\global\let\end:itm=\empty}
{\PopMacro\end:itm \global\let\end:itm \end:itm
\EndP\HCode{</dd></dl>}\ShowPar}
{\end:itm \global\def\end:itm{\EndP\Tg</dd>}\HCode{<dt
class="actor">}\bgroup \bf}
{\egroup\EndP\HCode{</dt><dd\Hnewline class="speech">}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% foldable elements -- these could be HTML5 details and summary.
\renewenvironment{foldable}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div id="foldable\arabic{identification}" class="foldable">}}{\HCode{</div>}\IgnoreIndent}
\renewenvironment{expandable}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div data-original="expandable" id="foldable\arabic{identification}" class="foldable">}
}{\HCode{</div>}\IgnoreIndent}
\renewcommand{\unfoldable}[1]{\HCode{<span class="unfoldable">}#1\HCode{</span>}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% video environments
% Youtube command. Requires id.
\renewcommand{\youtube}[1]{\ifvmode \IgnorePar\fi \EndP\HCode{<div class="video youtube-player" data-youtube="#1">_</div>}}
% Image environment doesn't actually work in tex4ht as defined with
% NewEnviron; so this renewenvironment is needed. image-environment
% also gets formatted in a well, and when the user clicks on the
% image, it zooms in.
\renewenvironment{image}[1][]{\ifvmode \IgnorePar\fi \EndP\HCode{<div class="image-environment">}}{\HCode{</div>}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewenvironment{leash}[1]{\ifvmode \IgnorePar\fi \EndP\HCode{<div style="overflow: auto; height: #1px">}}{\HCode{</div>}\IgnoreIndent}
\renewcommand{\xkcd}[1]{\ifvmode \IgnorePar\fi \EndP\HCode{<img src="https://imgs.xkcd.com/comics/#1.png">}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sage Cells
\renewenvironment{sageCell}{\NoFonts}{\EndNoFonts}
\ScriptEnv{sageCell}{\ifvmode \IgnorePar\fi \EndP\HCode{<div class="sage"><script type="text/x-sage">}\HtmlParOff}{\HtmlParOn\HCode{\Hnewline</script></div>}}
\renewenvironment{sageOutput}{\NoFonts}{\EndNoFonts}
\ScriptEnv{sageOutput}{\ifvmode \IgnorePar\fi \EndP\HCode{<div class="sageOutput"><script type="text/x-sage">}}{\HCode{\Hnewline</script></div>}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% interactives
% Geogebra command. Requires id, width, and height as arguments.
%defining keys for answer geogebra key=value pairs
\define@key{geogebra}{rc}[true]{\def\geo@rc{#1}}
\define@key{geogebra}{sdz}[true]{\def\geo@sdz{#1}}
\define@key{geogebra}{smb}[true]{\def\geo@smb{#1}}
\define@key{geogebra}{stb}[true]{\def\geo@stb{#1}}
\define@key{geogebra}{stbh}[true]{\def\geo@stbh{#1}}
\define@key{geogebra}{ld}[true]{\def\geo@ld{#1}}
\define@key{geogebra}{sri}[true]{\def\geo@sri{#1}}
%set default key values
\setkeys{geogebra}{rc=false,sdz=false,smb=false,stb=false,stbh=false,ld=false,sri=false}
%command definition
\renewcommand{\geogebra}[4][]{%
\setkeys{geogebra}{#1}% Set new keys
\HCode{<iframe scrolling="no" src="https://tube.geogebra.org/material/iframe/id/#2/width/#3/height/#4/border/888888/rc/\geo@rc/ai/false/sdz/\geo@sdz/smb/\geo@smb/stb/\geo@stb/stbh/\geo@stbh/ld/\geo@ld/sri/\geo@sri/at/auto" width="#3px" height="#4px" style="border:0px;"> </iframe>}}
% Desmos command. Requires id, width, and height as arguments.
\renewcommand{\desmos}[3]{\HCode{<a title="View with the Desmos Graphing Calculator" href="https://www.desmos.com/calculator/#1" target="_blank"> <img src="https://s3.amazonaws.com/calc_thumbs/production/#1.png"" width="#2px" height="#3px" style="border:1px solid \#ccc; border-radius:5px"/></a>}}
% googleSheet command. Requires id, width, and height as arguments.
% optional arguments are gid for sheet ID and range for cell range.
%command definition
\renewcommand{\googleSheet}[5]{%
\ifthenelse{\equal{#4}{}}%
{\HCode{<iframe width="#2px" height="#3px" src="https://docs.google.com/spreadsheets/d/#1/htmlembed?widget=true">This browser does not support embedded elements.</iframe>}}%
{\ifthenelse{\equal{#5}{}}%
{\HCode{<iframe width="#2px" height="#3px" src="https://docs.google.com/spreadsheets/d/#1/htmlembed?single=true&gid=#4&widget=false">This browser does not support embedded elements.</iframe>}}%
{\HCode{<iframe width="#2px" height="#3px" src="https://docs.google.com/spreadsheets/d/#1/htmlembed?single=true&gid=#4&range=#5&widget=false">This browser does not support embedded elements.</iframe>}}%
}%
}%
% HTML environment.
%\renewcommand{\html}[1]{\HCode{#1}}
\RenewEnviron{html}{\HCode{\BODY}}
% This is the "usual" hyperref command
\renewcommand{\href}[2]{\HCode{<a href="#1">}#2\HCode{</a>}}
% This is a command that Ximera used initially; in Jim's opinion it should be deprecated for \href
\renewcommand*{\link}[2][]{%
\ifthenelse{\equal{#1}{}}%
{\HCode{<a href="#2">}LINK\HCode{</a>}}
{\HCode{<a href="#2">}#1\HCode{</a>}}}
% This connects back to ximera.cls code which makes lim into display math
% \newcommand{\prelim}{\lim}
% Interactive element
\renewcommand{\includeinteractive}[2][]{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div id="interactive\arabic{identification}" class="interactive"> </div>}\HCode{<script src="#2" data-argument="#1" data-target="interactive\arabic{identification}"> </script>}\IgnoreIndent}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand{\label}[1]{\HCode{<a class="ximera-label" id="#1"></a>}}
\renewcommand{\ref}[1]{\HCode{<a class="reference" href="\##1">#1</a>}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewenvironment{javascript}{\NoFonts}{\EndNoFonts}
\ScriptEnv{javascript}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div class="javascript" id="javascript\arabic{identification}"><script type="text/javascript">\Hnewline//<![CDATA[\Hnewline}\HtmlParOff}{\HtmlParOn\HCode{\Hnewline//]]>\Hnewline</script></div>}}
\def\js#1{\stepcounter{identification}\HCode{<span class="inline-javascript" id="javascript\arabic{identification}"><script type="text/javascript">\Hnewline//<![CDATA[\Hnewline function javascript\arabic{identification}() }\{\HCode{ return \detokenize{#1}; }\}\HCode{\Hnewline //]]>\Hnewline</script></span>}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% validator
\def\validator[#1]{\stepcounter{identification}\HCode{<div class="validator" id="validator\arabic{identification}"><script type="text/javascript">\Hnewline//<![CDATA[\Hnewline function validator\arabic{identification}() }\{\HCode{ return \detokenize{#1}; }\}\HCode{\Hnewline //]]>\Hnewline</script>}}
\def\endvalidator{\HCode{</div>}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Feedback environments take an optional parameter (which describes
% when the feedback is to be provided)
\def\feedback{\@ifnextchar[{\@feedbackcode}{\@feedbackattempt}}
\def\@feedbackattempt{\@feedbackcode[attempt]}
\def\@feedbackcode[#1]{\stepcounter{identification}%
\ifvmode \IgnorePar\fi \EndP%
\ifthenelse{\equal{#1}{attempt}}{\HCode{<div class="feedback" data-feedback="attempt" id="feedback\arabic{identification}">}}%
{\ifthenelse{\equal{#1}{correct}}{\HCode{<div class="feedback" data-feedback="correct" id="feedback\arabic{identification}">}}%
{\HCode{<div class="feedback" data-feedback="script" id="feedback\arabic{identification}"><script type="text/javascript">\Hnewline//<![CDATA[\Hnewline function feedback\arabic{identification}() }\{\HCode{ return \detokenize{#1}; }\}\HCode{\Hnewline //]]>\Hnewline</script>}}}}
\def\endfeedback{\HCode{</div>}\IgnoreIndent}
% Include author name in meta tags
\Configure{@HEAD}{\HCode{<meta name="author" content="}\@author\HCode{" />\Hnewline}}
% the \and command would emit tabular environments which really should not appear in a meta tag
\def\and{ and }
\Hinput{ximera}
\endinput