| %% |
| %% 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 <paulmck@kernel.org> |
| %% Paolo Bonzini <pbonzini@redhat.com> # cross-link questions and answers |
| %% Akira Yokosawa <akiyks@gmail.com> # 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} |
| } |