summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/webquiz/latex/webquiz.cfg
blob: 571fecd2fa7947e05b3a75dd4b003d2e7edf2091 (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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
% -----------------------------------------------------------------------
%   webquiz.cfg | webquiz TeX4ht configuration file
% -----------------------------------------------------------------------
%
%   Copyright (C) Andrew Mathas and Don Taylor, University of Sydney
%
%   Distributed under the terms of the GNU General Public License (GPL)
%               http://www.gnu.org/licenses/
%
%   This file is part of the WebQuiz system.
%
%   <Andrew.Mathas@sydney.edu.au>
% ----------------------------------------------------------------------

\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\ProvidesFile{webquiz.cfg}[\webquiz{release date} v\webquiz{version} WebQuiz tex4ht configuration]

\makeatletter% quite surprisingly, this is needed!

% shortcut for inserting newlines into xml ifle
\newcommand\HNewLine{\HCode{\Hnewline}}

% Generate HTML5 + MathML code
\Preamble{xhtml,mathml,html5,NoFonts,charset="utf-8",ext=xml,svg}

% Don't output xml version tag
\Configure{VERSION}{}

% Output a WebQuiz doctype instead of the default for HTML5
\Configure{DOCTYPE}{\HCode{<?xml version="1.0" encoding="UTF-8" ?>\Hnewline
<!DOCTYPE webquiz>}}

\ifWQ@Debugging\def\WQ@debugging{true}\else\def\WQ@debugging{false}\fi

% store the quiz specifications as attributes to <quiz>
\Configure{HTML}{%
  \HNewLine%
  \Tg<webquiz debugging="\WQ@debugging"
                 hide_side_menu="\WQ@ClassOption{hidesidemenu value}"
                 language="\WQ@ClassOption{language}"
                 one_page="\WQ@ClassOption{onepage value}"
                 pst2pdf="\WQ@ClassOption{pst2pdf value}"
                 random_order="\WQ@ClassOption{randomorder value}"
                 src="\jobname.tex"
                 theme="\WQ@ClassOption{theme}">
  \HNewLine%
  \Tg<title>\@title\Tg</title>%
  \HNewLine%
  \Tg<breadcrumb breadcrumbs="\WQ@breadcrumbs">\WQ@breadcrumb\Tg</breadcrumb>%
  \HNewLine%
  \Tg<unit_name url="\uos@url" quizzes_url="\WQ@quizzesUrl">\uos@name\Tg</unit_name>%
  \HNewLine%
  \Tg<unit_code>\uos@code\Tg</unit_code>%
  \HNewLine%
  \Tg<department url="\WQ@departmentURL">\WQ@department\Tg</department>%
  \HNewLine%
  \Tg<institution url="\WQ@institutionURL">\WQ@institution\Tg</institution>%
  \HNewLine%
}{\Tg</webquiz>}

% reset all configurations
\Configure{HEAD}{}{}
\Configure{BODY}{}{}
\Configure{TITLE}{}{}
\Configure{TITLE+}{}
\Configure{thanks author date and}{}{}{}{}{}{}{}{}
\renewcommand{\maketitle}{}

% convert pictures to svg
\Configure{Picture}{.svg}
%\Configure{Picture*}{.svg}

%\Configure{textit}{\HCode{<span class="textit">}\NoFonts}{\EndNoFonts\HCode{</span>}}
%\Configure{textsf}{\HCode{<span class="textsf">}\NoFonts}{\EndNoFonts\HCode{</span>}} 

% The webquiz macros and environments need to write opening and closing tags to
% the xml file. Opening these tags is easy. To close them we use \WQ@closeXXX
% and \WQ@@closeXXX macros. Each time a tag is opened we \let the \WQ@closeTag
% macro to the corresponding \WQ@@close macro. The \WQ@@close macro closes the
% tag and then \let's the \WQ@closeTag macro to \relax. This allows us to use
% the \WQ@close macros at the start of the tag routines below, which results in
% fairly transparent and readable code.

% make the @close tags \relax initially
\let\WQ@closeTag\relax % closes \correct, \incorrect, \feedback, \whenRight and \whenWrong
\let\WQ@closeText\relax   % closes text

% text tags - everything in wrapped inside <text>...</text> tags
\def\WQ@openText{\Tg<text>\HtmlParOff\HCode{<![CDATA[}\let\WQ@closeText\WQ@@closeText}
\def\WQ@@closeText{\HCode{]]>}\HtmlParOn\Tg</text>\HNewLine\global\let\WQ@closeText\relax}

% -----------------------------------------------------------------------
% discussion environment
% -----------------------------------------------------------------------

% discussion environments are number -1, -2, ... in the webquiz.js
\renewcommand\thediscussion{-\arabic{discussion}}

% inside a discussion environment any label defines two labels, the second of 
% which is a label to the short-title for the discussion item. Of there are many
% labels this is slightly in efficient but, because of tex4ht magic, it proved 
% too painful to extract the discussion number from the label.
\let\WQ@reallabel=\label
\newcommand\WQ@discussionLabel[1]{%
  \WQ@reallabel{#1}%
  \bgroup\let\@currentlabel\WQ@shortDiscussionTitle%
  \WQ@reallabel{discussion-title-#1}%
  \egroup%
}

% discussion environments
\RenewDocumentEnvironment{discussion}{O{Discussion}O{#1}}{%
    \WQ@DiscussionStart%
    \HNewLine%
    \Tg<discussion>\HNewLine
    \Tg<short_heading>#1\Tg</short_heading>\HNewLine
    \Tg<heading>#2\Tg</heading>\HNewLine
    \Tg<text>\HCode{<![CDATA[}% don't use \WQ@openText as we want paragraphs
    \def\WQ@shortDiscussionTitle{#1}%
    \let\label\WQ@discussionLabel%
}{\EndP\HCode{]]>}\Tg</text>\HNewLine\Tg</discussion>\HNewLine\WQ@DiscussionEnd}

% ---------------------------------------------------------------------------
% Cross referencing question and discussion environments
% ---------------------------------------------------------------------------

% tex4ht redefines the \ref internals so that r@<label> uses \rEfLiNK,
% so we temporarily redefine \rEfLiNK to access the question/discussion
% number
\def\WQ@rEfLiNK#1#2{#2}
% \WQ@Ref[optional *][optional text]{mandatory label}
\RenewDocumentCommand\WQ@ref{ m s o m }{%
  \HNewLine%
  \bgroup%
  \let\rEfLiNK\WQ@rEfLiNK%
  \IfBooleanTF{#2}{% link
    \HCode{<a onClick="gotoQuestion(}\ref{#4}\HCode{);">}%
    \IfNoValueTF{#3}{\ref{#1#4}}{#3}%
    \HCode{</a>}%
  }{% button
    \HCode{<span class="button blank" onClick="gotoQuestion(}\ref{#4}%
    \HCode{);">}%
    \IfNoValueTF{#3}{\ref{#1#4}}{#3}%
    \HCode{</span>}%
  }%
  \egroup%
}

\renewcommand\dref{\WQ@ref{discussion-title-}}
\renewcommand\qref{\WQ@ref{}}
\RenewDocumentCommand\Qref{ s O{#3} m }{%
  \HNewLine%
  \IfBooleanTF{#1}{% link
    \HCode{<a onClick="gotoQuestion(#3);">}#2\HCode{</a>}%
  }{% button
    \HCode{<span class="button blank" onClick="gotoQuestion(#3);">}#2\HCode{</span>}%
  }%
}

% -----------------------------------------------------------------------
% question environments
% -----------------------------------------------------------------------

\renewenvironment{question}{%
  \WQ@QuestionStart%
  \IgnorePar\HCode{\Hnewline<question>}% open the question tag
  \WQ@openText% start some text
}{\WQ@QuestionEnd\WQ@closeText\WQ@closeTag\Tg</question>\HNewLine}

% -----------------------------------------------------------------------
% choice environment, \correct and \incorrect choices and \feedback
% -----------------------------------------------------------------------

\RenewDocumentEnvironment{choice}{O{}}{%
  \WQ@ChoiceStart{#1}%
  \WQ@closeText% close any open text tags and then insert tex4ht code
  \IgnorePar%
  \Tg<choice type="\pgfkeysvalueof{/webquiz checker/mode}"
             columns="\pgfkeysvalueof{/webquiz checker/columns value}">%
  \let\WQ@closeTag\relax%
}{\WQ@ChoiceEnd\WQ@closeTag\Tg</choice>}

% correct and incorrect items
\def\WQ@@closeItem{\WQ@closeText\Tg</item>\HNewLine\let\WQ@closeTag\relax}
\def\WQ@Item#1{%
  \WQ@ItemStart%
  \WQ@closeTag%
  \Tg<item correct="#1" symbol="\thechoice">\WQ@openText%
  \let\WQ@closeTag\WQ@@closeItem%
}
\def\correct{\WQ@Item{true}}
\def\incorrect{\WQ@Item{false}}

% feedback
\def\WQ@@closeFeedback{\WQ@closeText\Tg</feedback>\HNewLine\let\WQ@closeTag\relax}
\def\feedback{%
  \WQ@FeedbackStart%
  \WQ@closeTag\Tg<feedback>\WQ@openText\let\WQ@closeTag\WQ@@closeFeedback%
}

% -----------------------------------------------------------------------
% The \answer macro and \whenRight, \whenWrong
% -----------------------------------------------------------------------

\RenewDocumentCommand\answer {sO{string}m}{%
  \WQ@AnswerStart{#2}%
  \WQ@closeText%
  \IfBooleanTF{#1}{\def\WQ@prompt{false}}{\def\WQ@prompt{true}}%
  \Tg<answer prompt="\WQ@prompt" comparison="#2">\HNewLine%
  \WQ@openText#3\WQ@closeText%
  \Tg</answer>%
  \HNewLine%
  \let\WQ@closeTag\relax%
  \WQ@openText%
}

% whenRight and whenWrong
\def\WQ@closeWhen{\Tg</when>\HNewLine\let\WQ@closeTag\relax}
\def\WQ@When#1{%
  \WQ@WhenStart{#1}%
  \WQ@closeText\WQ@closeTag%
  \IgnorePar\Tg<when type="#1">\WQ@openText%
  \let\WQ@closeTag\WQ@closeWhen%
}
\def\whenRight{\WQ@When{right}}
\def\whenWrong{\WQ@When{wrong}}

% -----------------------------------------------------------------------
% the quizindex environment and \quiz macro
% -----------------------------------------------------------------------

% quizindex environment and \quiz
\ConfigureEnv{quizindex}{\Tg<quizindex>\HNewLine}{\Tg</quizindex>\HNewLine}{}{}
\RenewDocumentCommand\quiz{som}{\refstepcounter{quiz}%
  \WQ@QuizStart%
  \IfBooleanTF{#1}{\def\WQ@prompt{false}}{\def\WQ@prompt{true}}%
  \IfNoValueTF{#2}{\def\WQ@url{quiz\thequiz.html}}{\def\WQ@url{#2}}%
  \Tg<index_item prompt="\WQ@prompt" url="\WQ@url">\WQ@openText #3 \WQ@closeText\Tg</index_item>\HNewLine%
}

% -----------------------------------------------------------------------
% making listing environment work with colour I
% - this code appears to break \color and \textcolor in the online manual
% -----------------------------------------------------------------------


% from https://tex.stackexchange.com/questions/225554/syntax-highlighting-in-an-html-presentation
% extract current color as hexadecimal value
\makeatletter
\ifdefined\lst@version
\newcommand\tsf@getColor[1][.]{%
      % colorname `.` holds current color
      \extractcolorspec{.}{\tsf@color}
      \expandafter\convertcolorspec\tsf@color{HTML}\tsf@color
      %\tmpcolor
  }

  % write css color for given css selector
  \newcommand\CssColor[1]{%on-l
      % save current color
      \tsf@getColor%
      \Css{#1{color:\#\tsf@color;}}%
  }
\fi

% Do not set indent and noindent classes on paragraphs
\Configure{HtmlPar}
    {\EndP\Tg<p>}
    {\EndP\Tg<p>}
    {\HCode{</p>\Hnewline}}
    {\HCode{</p>\Hnewline}}

\renewcommand\DisplayAsImage[2][]{%
  \csletcs{real:#2}{#2}%
  \NewConfigure{#2}{2}
  \csdef{#2}##1{\Picture+[#1]{}\csuse{real:#2}{##1}\EndPicture}
  \Configure{#2}{\Picture+[#1]{}}{\EndPicture}
}

\begin{document}

% disable \title after \begin{document}
\def\title{\WQ@Error{\@backslashchar title can only be used in the preamble}\@ehc}

% -----------------------------------------------------------------------
% making listing environment work with colour II
% - this code appears to break \color and \textcolor in the online manual
% -----------------------------------------------------------------------

%% this code is for processing the listing environments in the online manual
\ifdefined\lst@version
  % from https://www.mail-archive.com/tex4ht@tug.org/msg00116.html
  \let\savecolor\color
  \NewConfigure{color}[2]{\def\a@color{#1}\def\b@color{#2}}
  \def\color@@tmp#1{\a@color#1\b@color\savecolor{#1}\aftergroup\endspan}
  \let\color\color@@tmp
  \def\endspan{\Tg</span>}
  \Configure{color}{\HCode{<span style="color:}}{\HCode{">}}

  \ConfigureEnv{lstlisting}
     {\let\color\savecolor
      \ifvmode \IgnorePar\fi \EndP
      \gHAdvance\listingN by 1
      \HCode{<!--l. \the\inputlineno-->}%
      \gdef\start:LstLn{\HCode{<div class="lstlisting" id="listing-\listingN">}%
        \gdef\start:LstLn{\leavevmode\special{t4ht@+\string&{35}x00A0{59}}x%
      \HCode{<br/>}}}
      \bgroup
         \Configure{listings}
           {{\everypar{}\leavevmode}}
           {{\everypar{}\leavevmode}}
           {\start:LstLn \HCode{<span class="label">}}
           {\HCode{</span>}}%
     }
     {\egroup
      \ifvmode \IgnorePar\fi \EndP \HCode{</div>}\par}
     {}{}

  % for listings in webquiz-manual
  % from https://tex.stackexchange.com/questions/225554/syntax-highlighting-in-an-html-presentation
  \newcommand\LstCss[2]{%
      \bgroup%
          \csname lst@#2\endcsname%
          \CssColor{#1}%
      \egroup%
  }

  \LstCss{div.lstlisting .ecbx-1000}{keywordstyle}
  \LstCss{div.lstlisting .ecss-1000}{commentstyle}
  \LstCss{div.lstlisting .ectt-1000}{basicstyle}
\fi

\makeatother

\EndPreamble

% bug fix for \mathbf from http://tex.stackexchange.com/questions/362178
%\Configure{mathbf}{\HCode{<mi mathvariant="bold">}\PauseMathClass}{\EndPauseMathClass\HCode{</mi>}}

\endinput
%%
%% End of file `webquiz.cfg'.