blob: 317e8096ebbda28febc34393d88e11ed36632484 [file] [log] [blame]
%%
%% 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.
%%
%% Copyright (C) IBM Corporation, 2008
%% Copyright (C) Paolo Bonzini, 2015
%% Copyright (C) Akira Yokosawa, 2016, 2017
%%
%% Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
%% Paolo Bonzini <pbonzini@redhat.com> # cross-link questions and answers
%% Akira Yokosawa <akiyks@gmail.com> # improvement of cross-link
\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{\QuickQuizChapter}[2]{
\chapter{#2}
\label{#1}
}
\newcommand{\QuickQuiz}[1]{
\refstepcounter{quickquizctr}
\QuickQHeading{QQ}{QQA}{\thechapter.\thequickquizctr}}
\newcommand{\QuickQuizAnswer}[1]{%
\refstepcounter{quickquizctrE}%
\hyperref[QQA.\thechapter.\thequickquizctr]{\rule{7pt}{7pt}}%
\label{QQE.\thechapter.\thequickquizctrE}}
\newcommand{\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}%
}
\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 2ex}
\input{qqz}
\setlength{\parskip}{0.0pt plus 1.0pt}% return to default
}
%% Internal interfaces generated by scripts.
\newcommand{\QuickQAC}[2]{
\edef\QuickQuizAnswerChapter{\getrefnumber{#1}}
\section{#2}}
\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.5\baselineskip plus .5ex minus .3ex}
\noindent\textbf{Answer:} \\ }
\newcommand{\QuickE}{%
\hyperref[QQE.\QuickQuizAnswerChapter.\thequickquizctrC]{\ding{113}}
\vspace{1.0\baselineskip plus 2ex minus .5ex}
}