-
Notifications
You must be signed in to change notification settings - Fork 0
/
qqz.sty
286 lines (269 loc) · 8.75 KB
/
qqz.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
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
%%
%% This is file `qqz.sty'. It handles the latex portions of extracting
%% Quick Quizzes. Other pieces of the puzzle may be found
%% in the Makefile and the utilities directory.
%%
%% \QuickQuizChapter{chp:label} -- to introduce a chapter with quick quizzes.
%% \QuickQuiz{
%% Question goes here.
%% }\QuickQuizAnswer{
%% Answer goes here.
%% }\QuickQuizEnd
%% \QuickQuizAnswers -- to dump out all questions and answers in new section.
%%
%% For consecutive Quick Quizzes, use the following construct:
%%
%% \QuickQuizSeries{%
%% \QuickQuizB{
%% Question 1
%% }\QuickQuizAnswerB{
%% Answer 1
%% }\QuickQuizEndB
%% %
%% \QuickQuizM{
%% Question 2
%% }\QuickQuizAnswerM{
%% Answer 2
%% }\QuickQuizEndM
%% %
%% \QuickQuizE{
%% Question 3
%% }\QuickQuizAnswerE{
%% Answer 3
%% }\QuickQuizEndE
%% } % End of \QuickQuizSeries
%%
%% To keep quizzes essential to the discussion in "noqq" build,
%% use the following:
%%
%% \EQuickQuiz{
%% Question
%% }\EQuickQuizAnswer{
%% Answer
%% }\EQuickQuizEnd
%%
%% Copyright (C) IBM Corporation, 2008-2019
%% Copyright (C) Facebook, 2019
%% Copyright (C) Paolo Bonzini, 2015
%% Copyright (C) Akira Yokosawa, 2016, 2017, 2020
%%
%% Authors: Paul E. McKenney <[email protected]>
%% Paolo Bonzini <[email protected]> # cross-link questions and answers
%% Akira Yokosawa <[email protected]> # improvement of cross-link
\tcbset{enhanced,colback=black!5,boxrule=0.5pt,top=1pt,bottom=1pt,left=0pt,right=0pt}
\newcounter{quickquizctr}[chapter]
\newcounter{quickquizctrC}[section]
\newcounter{quickquizctrP}[chapter] % for noqqz build page anchor
\newcommand*{\theHNum}{\arabic{chapter}.\arabic{quickquizctr}}
\newcommand{\QuickQuizAnswerChapter}{\textbf{Unknown QuickQAC!!!}}
\newcommand{\QuickQHeading}[3]{\hyperref[#2.#3]{\textbf{Quick Quiz #3:}}\label{#1.#3}}
\IfNoQqz{
\newcommand{\QuickQHeadingPage}[3]{\hyperref[#2.#3]{\textbf{Quick Quiz #3:}}\label{#1.#3}%
\hfill\raisebox{0.5ex}{\footnotesize\fbox{p.\pageref{QQP.#3}}}}
}{\IfQqzBg{
\newcommand{\QuickQHeadingPage}[3]{\hyperref[#2.#3]{\textbf{Quick Quiz #3:}}\label{#1.#3}%
\hfill\raisebox{0.5ex}{\footnotesize\fbox{p.\pageref{QQ.#3}}}}
}{% draft build
\newcommand{\QuickQHeadingPage}[3]{\hyperref[#2.#3]{\textbf{Quick Quiz #3:}}\label{#1.#3}%
\hfill{\footnotesize{[p.\pageref{QQ.#3}]}}}
}}
\newcommand{\QuickQHeadingLight}[3]{\scriptsize QQ~\hyperref[#2.#3]{#3}\label{#1.#3}}
\newcommand{\QuickQHeadingBegin}[3]{\scriptsize QQ~\hyperref[#2.#3]{#3}\label{#1.#3},}
\newcommand{\QuickQHeadingMiddle}[3]{\scriptsize\hyperref[#2.#3]{{ #3}}\label{#1.#3},}
\newcommand{\QuickQHeadingEnd}[3]{\scriptsize\hyperref[#2.#3]{{ #3}}\label{#1.#3}}
\newcommand{\QuickQuizChapter}[3]{
\chapter{#2}
\label{#1}
}
\IfNoQqz{
\newcommand{\QuickQuizSeries}[1]{%
\vspace{-1pt}\hfill\fbox{#1}\vspace{1pt}}
\newcommand{\QuickQuiz}[1]{%
\vspace{-1pt}%
\hfill\fbox{\refstepcounter{quickquizctrP}%
\QuickQHeadingLight{QQP}{QQ}{\thechapter.\thequickquizctrP}}%
\vspace{1pt}}
\newcommand{\QuickQuizB}[1]{%
\refstepcounter{quickquizctrP}%
\QuickQHeadingBegin{QQP}{QQ}{\thechapter.\thequickquizctrP}}
\newcommand{\QuickQuizM}[1]{%
\refstepcounter{quickquizctrP}%
\QuickQHeadingMiddle{QQP}{QQ}{\thechapter.\thequickquizctrP}}
\newcommand{\QuickQuizE}[1]{%
\refstepcounter{quickquizctrP}%
\QuickQHeadingEnd{QQP}{QQ}{\thechapter.\thequickquizctrP}}
\newcommand{\EQuickQuiz}[1]{%
\begin{tcolorbox}[breakable]
\leavevmode\refstepcounter{quickquizctrP}%
\small\QuickQHeading{QQP}{QQA}{\thechapter.\thequickquizctrP}%
{#1}
}
\newcommand{\QuickQuizAnswer}[1]{\label{QQE.\thechapter.\thequickquizctrP}}
\newcommand{\QuickQuizAnswerB}[1]{\QuickQuizAnswer{#1}}
\newcommand{\QuickQuizAnswerM}[1]{\QuickQuizAnswer{#1}}
\newcommand{\QuickQuizAnswerE}[1]{\QuickQuizAnswer{#1}}
\newcommand{\EQuickQuizAnswer}[1]{%
\hyperref[QQA.\thechapter.\thequickquizctrP]{\rule{7pt}{7pt}}%
\phantomsection\label{QQE.\thechapter.\thequickquizctrP}%
\end{tcolorbox}
}
\newcommand{\QuickQuizEnd}{\goodbreak}
\newcommand{\QuickQuizEndB}{}
\newcommand{\QuickQuizEndM}{}
\newcommand{\QuickQuizEndE}{\goodbreak}
\newcommand{\EQuickQuizEnd}{}
}{
\newcommand{\QuickQuizSeries}[1]{#1}
\IfQqzBg{
\newcommand{\QuickQuiz}[1]{
\begin{tcolorbox}[breakable]
\leavevmode\refstepcounter{quickquizctr}%
\small\QuickQHeading{QQ}{QQA}{\thechapter.\thequickquizctr}
{#1}
}
\newcommand{\QuickQuizAnswer}[1]{%
\hyperref[QQA.\thechapter.\thequickquizctr]{\rule{7pt}{7pt}}%
\phantomsection\label{QQE.\thechapter.\thequickquizctr}
\end{tcolorbox}
}
\newcommand{\QuickQuizEnd}{}
}{
\newcommand{\QuickQuiz}[1]{
\goodbreak\refstepcounter{quickquizctr}%
\QuickQHeading{QQ}{QQA}{\thechapter.\thequickquizctr}
{#1}}
\newcommand{\QuickQuizAnswer}[1]{%
\hyperref[QQA.\thechapter.\thequickquizctr]{\rule{7pt}{7pt}}%
\phantomsection\label{QQE.\thechapter.\thequickquizctr}}
\newcommand{\QuickQuizEnd}{\goodbreak}
}
\newcommand{\QuickQuizB}[1]{\QuickQuiz{#1}}
\newcommand{\QuickQuizM}[1]{\QuickQuiz{#1}}
\newcommand{\QuickQuizE}[1]{\QuickQuiz{#1}}
\newcommand{\EQuickQuiz}[1]{\QuickQuiz{#1}}
\newcommand{\QuickQuizAnswerB}[1]{\QuickQuizAnswer{#1}}
\newcommand{\QuickQuizAnswerM}[1]{\QuickQuizAnswer{#1}}
\newcommand{\QuickQuizAnswerE}[1]{\QuickQuizAnswer{#1}}
\newcommand{\EQuickQuizAnswer}[1]{\QuickQuizAnswer{#1}}
\newcommand{\QuickQuizEndB}{\QuickQuizEnd}
\newcommand{\QuickQuizEndM}{\QuickQuizEnd}
\newcommand{\QuickQuizEndE}{\QuickQuizEnd}
\newcommand{\EQuickQuizEnd}{\QuickQuizEnd}
}
% To create a macro referencing the previously defined quick quiz:
% \QuickQuizLabel{\QQname}
%
% When labeling a QQz inside \QuickQuizSeries{}, use
% \QuickQuizLabelRel{\QQname}{rel}
% in front of the series.
%
% To reference the macro in the text:
% \QuickQuizRef{\QQname}
% To reference the answer of the macro in the text:
% \QuickQuizARef{\QQname}
% The reference also generates a hyperlink.
\IfNoQqz{
\newcommand{\QuickQuizLabel}[1]{
\edef#1{\thechapter.\thequickquizctrP}
}
\newcommand{\QuickQuizLabelRel}[2]{
\addtocounter{quickquizctrP}{#2}
\QuickQuizLabel{#1}
\addtocounter{quickquizctrP}{-#2}
}
\newcommand{\QuickQuizRef}[1]{%
\hyperref[QQ.#1]{Quick Quiz~#1}%
}
\newcommand{\QuickQuizARef}[1]{%
\hyperref[QQA.#1]{Quick Quiz~#1}%
}
}{
\newcommand{\QuickQuizLabel}[1]{
\edef#1{\thechapter.\thequickquizctr}
}
\newcommand{\QuickQuizLabelRel}[2]{
\addtocounter{quickquizctr}{#2}
\QuickQuizLabel{#1}
\addtocounter{quickquizctr}{-#2}
}
\newcommand{\QuickQuizRef}[1]{%
\hyperref[QQ.#1]{Quick Quiz~#1}%
}
\newcommand{\QuickQuizARef}[1]{%
\hyperref[QQA.#1]{Quick Quiz~#1}%
}
}
\newcommand{\QuickQuizAnswers}{%
\renewcommand*{\theHNum}{\arabic{section}.\arabic{quickquizctrC}}
\chapter{Answers to Quick Quizzes}
\label{chp:app:Answers to Quick Quizzes}
\Epigraph{The Answer to the Ultimate Question of Life, The Universe,
and Everything.}
{\emph{The Hitchhikers Guide to the Galaxy}, Douglas~Adams}
\setlength{\parskip}{0.0pt plus 1ex}
\input{qqz}
\setlength{\parskip}{0.0pt plus 1.0pt}% return to default
}
\IfNoQqz{
\newcommand{\QuickQuizAnswersChp}[1]{
\setlength{\parskip}{0.0pt plus 1ex}
\input{#1}
\setlength{\parskip}{0.0pt plus 1.0pt}% return to default
}}{
\newcommand{\QuickQuizAnswersChp}[1]{}
}
%% Internal interfaces generated by scripts.
\newcommand{\QuickQAC}[3]{
\pagebreak[3]
\edef\QuickQuizAnswerChapter{\getrefnumber{#1}}
\section{#2}\nopagebreak}
\IfNoQqz{
\newcommand{\QuickQQC}[3]{
\edef\QuickQuizAnswerChapter{\getrefnumber{#1}}
\section{Quick Quizzes}
\label{sec:#3:Quick Quizzes}}
}{}
\IfQqzBg{
\newcommand{\QuickQ}[1]{
\begin{tcolorbox}[breakable]
\leavevmode\refstepcounter{quickquizctrC}%
\QuickQHeadingPage{QQA}{QQ}{\QuickQuizAnswerChapter.\thequickquizctrC} \\
}
\newcommand{\QuickA}[1]{%
\hyperref[QQ.\QuickQuizAnswerChapter.\thequickquizctrC]{\rule{7pt}{7pt}}
\end{tcolorbox}
\noindent\textbf{Answer:} \\ }
}{\IfNoQqz{
\newcommand{\QuickQQ}[1]{
\begin{tcolorbox}[breakable]
\leavevmode\refstepcounter{quickquizctr}%
\QuickQHeadingPage{QQ}{QQA}{\thechapter.\thequickquizctr}\\
}
\newcommand{\QuickQE}[1]{%
\hyperref[QQA.\thechapter.\thequickquizctr]{\rule{7pt}{7pt}}%
\end{tcolorbox}
}
\newcommand{\QuickQ}[1]{
\begin{tcolorbox}[breakable]
\leavevmode\refstepcounter{quickquizctrC}%
\QuickQHeadingPage{QQA}{QQ}{\QuickQuizAnswerChapter.\thequickquizctrC}\\
}
\newcommand{\QuickA}[1]{%
\hyperref[QQ.\QuickQuizAnswerChapter.\thequickquizctrC]{\rule{7pt}{7pt}}
\end{tcolorbox}
\noindent\textbf{Answer:} \\ }
}{
\newcommand{\QuickQ}[1]{
\par
\refstepcounter{quickquizctrC}%
\noindent
\QuickQHeadingPage{QQA}{QQ}{\QuickQuizAnswerChapter.\thequickquizctrC}\\}
\newcommand{\QuickA}[1]{%
\hyperref[QQ.\QuickQuizAnswerChapter.\thequickquizctrC]{\rule{7pt}{7pt}}
\par\vspace{0.2\baselineskip plus .2ex minus .1ex}
\noindent\textbf{Answer:} \\ }
}}
\newcommand{\QuickE}{%
\hyperref[QQE.\QuickQuizAnswerChapter.\thequickquizctrC]{\ding{113}}
\goodbreak\vspace{0.7\baselineskip plus .5ex minus .2ex}
}