-
Notifications
You must be signed in to change notification settings - Fork 4
/
qqz.sty
247 lines (234 loc) · 7.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
%%
%% 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{quickquizctrE}[chapter]
\newcounter{quickquizctrC}[section]
\newcommand*{\theHNum}{\arabic{chapter}.\arabic{quickquizctr}}
\newcommand{\QuickQuizAnswerChapter}{\textbf{Unknown QuickQAC!!!}}
\newcommand{\QuickQHeading}[3]{\hyperref[#2.#3]{\textbf{Quick Quiz #3:}}\label{#1.#3}}
\newcommand{\QuickQHeadingPage}[3]{\hyperref[#2.#3]{\textbf{Quick Quiz #3:}}\label{#1.#3}%
\hfill\raisebox{0.5ex}{\footnotesize\fbox{p.\pageref{#2.#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{quickquizctr}%
\QuickQHeadingLight{QQ}{QQA}{\thechapter.\thequickquizctr}}%
\vspace{1pt}}
\newcommand{\QuickQuizB}[1]{%
\refstepcounter{quickquizctr}%
\QuickQHeadingBegin{QQ}{QQA}{\thechapter.\thequickquizctr}}
\newcommand{\QuickQuizM}[1]{%
\refstepcounter{quickquizctr}%
\QuickQHeadingMiddle{QQ}{QQA}{\thechapter.\thequickquizctr}}
\newcommand{\QuickQuizE}[1]{%
\refstepcounter{quickquizctr}%
\QuickQHeadingEnd{QQ}{QQA}{\thechapter.\thequickquizctr}}
\newcommand{\EQuickQuiz}[1]{
\refstepcounter{quickquizctr}
\begin{tcolorbox}[breakable]
\small\QuickQHeading{QQ}{QQA}{\thechapter.\thequickquizctr}
{#1}
}
\newcommand{\QuickQuizAnswer}[1]{%
\refstepcounter{quickquizctrE}%
\hyperref[QQA.\thechapter.\thequickquizctr]{}%
\label{QQE.\thechapter.\thequickquizctrE}}
\newcommand{\QuickQuizAnswerB}[1]{\QuickQuizAnswer{#1}}
\newcommand{\QuickQuizAnswerM}[1]{\QuickQuizAnswer{#1}}
\newcommand{\QuickQuizAnswerE}[1]{\QuickQuizAnswer{#1}}
\newcommand{\EQuickQuizAnswer}[1]{%
\refstepcounter{quickquizctrE}%
\hyperref[QQA.\thechapter.\thequickquizctr]{\rule{7pt}{7pt}}%
\label{QQE.\thechapter.\thequickquizctrE}
\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]
\refstepcounter{quickquizctr}
\small\QuickQHeading{QQ}{QQA}{\thechapter.\thequickquizctr}
{#1}
}
\newcommand{\QuickQuizAnswer}[1]{%
\refstepcounter{quickquizctrE}%
\hyperref[QQA.\thechapter.\thequickquizctr]{\rule{7pt}{7pt}}%
\label{QQE.\thechapter.\thequickquizctrE}
\end{tcolorbox}
}
\newcommand{\QuickQuizEnd}{}
}{
\newcommand{\QuickQuiz}[1]{
\goodbreak\refstepcounter{quickquizctr}%
\QuickQHeading{QQ}{QQA}{\thechapter.\thequickquizctr}
{#1}}
\newcommand{\QuickQuizAnswer}[1]{%
\refstepcounter{quickquizctrE}%
\hyperref[QQA.\thechapter.\thequickquizctr]{\rule{7pt}{7pt}}%
\label{QQE.\thechapter.\thequickquizctrE}}
\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}
% 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.
\newcommand{\QuickQuizLabel}[1]{
\edef#1{\thechapter.\thequickquizctr}
}
\newcommand{\QuickQuizRef}[1]{%
\hyperref[QQ.#1]{Quick Quiz~#1}%
}
\newcommand{\QuickQuizARef}[1]{%
\hyperref[QQA.#1]{Quick Quiz~#1}%
}
\IfQqzChpEnd{
\newcommand{\QuickQuizAnswers}{}
\newcommand{\QuickQuizAnswersChp}[1]{
% \renewcommand*{\theHNum}{\arabic{section}.\arabic{quickquizctrC}}
% \label{sec:#1:Answers to Quick Quizzes}
\setlength{\parskip}{0.0pt plus 1ex}
\input{#1}
\setlength{\parskip}{0.0pt plus 1.0pt}% return to default
}}{
\newcommand{\QuickQuizAnswers}{
\renewcommand*{\theHNum}{\arabic{section}.\arabic{quickquizctrC}}
\chapter{Answers to Quick Quizzes}
\label{chp: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
}
\newcommand{\QuickQuizAnswersChp}[1]{}
}
%% Internal interfaces generated by scripts.
\IfQqzChpEnd{
\newcommand{\QuickQAC}[3]{
\edef\QuickQuizAnswerChapter{\getrefnumber{#1}}
\section{Answers to Quick Quizzes}
\label{sec:#3:Answers to Quick Quizzes}}
}{
\newcommand{\QuickQAC}[3]{
\edef\QuickQuizAnswerChapter{\getrefnumber{#1}}
\section{#2}}
}
\IfQqzBg{
\newcommand{\QuickQ}[1]{
\begin{tcolorbox}[breakable]
\refstepcounter{quickquizctrC}
\QuickQHeading{QQA}{QQ}{\QuickQuizAnswerChapter.\thequickquizctrC} \\
}
\newcommand{\QuickA}[1]{%
\hyperref[QQ.\QuickQuizAnswerChapter.\thequickquizctrC]{\rule{7pt}{7pt}}
\end{tcolorbox}
\noindent\textbf{Answer:} \\ }
}{\IfNoQqz{
\newcommand{\QuickQ}[1]{
\begin{tcolorbox}[breakable]
\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
\QuickQHeading{QQA}{QQ}{\QuickQuizAnswerChapter.\thequickquizctrC} #1 ~ \\ }
\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}
}