| 1 |
% \iffalse |
| 2 |
%<*copyright> |
| 3 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4 |
%% mi-solns package %% |
| 5 |
%% Copyright (C) 2018 D. P. Story %% |
| 6 |
%% [email protected] %% |
| 7 |
%% %% |
| 8 |
%% This program can redistributed and/or modified under %% |
| 9 |
%% the terms of the LaTeX Project Public License %% |
| 10 |
%% Distributed from CTAN archives in directory %% |
| 11 |
%% macros/latex/base/lppl.txt; either version 1.2 of the %% |
| 12 |
%% License, or (at your option) any later version. %% |
| 13 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 14 |
%</copyright> |
| 15 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 16 |
%<package>\ProvidesPackage{mi-solns} |
| 17 |
%<package> [2018/12/28 v0.6 extract solutions from exerquiz (dps)] |
| 18 |
%<*driver> |
| 19 |
\documentclass{ltxdoc} |
| 20 |
\usepackage[colorlinks,hyperindex=false]{hyperref} |
| 21 |
\OnlyDescription % comment out for implementation details |
| 22 |
\EnableCrossrefs |
| 23 |
\CodelineIndex |
| 24 |
\RecordChanges |
| 25 |
\InputIfFileExists{aebdocfmt.def}{\PackageInfo{web}{Inputting aebdocfmt.def}} |
| 26 |
{\def\IndexOpt{\DescribeMacro}\def\IndexKey{\DescribeMacro}\let\setupFullwidth\relax |
| 27 |
\PackageInfo{web}{aebdocfmt.def cannot be found}} |
| 28 |
\makeatletter |
| 29 |
\let\@latex@warning\@gobble |
| 30 |
\makeatother |
| 31 |
\begin{document} |
| 32 |
\def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}} |
| 33 |
\def\meta#1{\textsl{\texttt{#1}}} |
| 34 |
\def\darg#1{{\ttfamily\char123\relax#1\char125\relax}} |
| 35 |
\def\CMD#1{\textbackslash#1} |
| 36 |
\let\pkg\textsf |
| 37 |
\let\app\textsf |
| 38 |
\let\opt\texttt |
| 39 |
\let\env\texttt |
| 40 |
\GetFileInfo{mi-solns.sty} |
| 41 |
\title{\textsf{mi-solns}: Extract solutions from exercises and quizzes} |
| 42 |
\author{D. P. Story\\ |
| 43 |
Email: \texttt{[email protected]}} |
| 44 |
\date{processed \today} |
| 45 |
\maketitle |
| 46 |
\tableofcontents |
| 47 |
\DocInput{mi-solns.dtx} |
| 48 |
\IfFileExists{\jobname.ind}{\newpage\setupFullwidth\par\PrintIndex}{\paragraph*{Index} The index goes here. Execute |
| 49 |
\begin{quote}\texttt{makeindex -s gind.ist -o\\\null\quad mi-solns.ind mi-solns.idx}\end{quote} on the command line and recompile |
| 50 |
\texttt{mi-solns.dtx}.} |
| 51 |
\IfFileExists{\jobname.gls}{\PrintChanges}{\paragraph*{Change History} The list of changes goes here. Execute |
| 52 |
\begin{quote}\texttt{makeindex -s gglo.ist -o\\\null\quad mi-solns.gls mi-solns.glo}\end{quote} on the command line and recompile |
| 53 |
\texttt{mi-solns.dtx}.} |
| 54 |
\makeatletter |
| 55 |
\let\@latex@warning\@gobble |
| 56 |
\makeatother |
| 57 |
\end{document} |
| 58 |
%</driver> |
| 59 |
% \fi |
| 60 |
% |
| 61 |
% \MakeShortVerb{|} |
| 62 |
% \DoNotIndex{\w,\x,\y,\z} |
| 63 |
% \InputIfFileExists{aebdonotindex.def}{\PackageInfo{web}{Inputting aebdonotindex.def}} |
| 64 |
% {\PackageInfo{web}{cannot find aebdonotindex.def}} |
| 65 |
% |
| 66 |
% \begin{macrocode} |
| 67 |
%<*package> |
| 68 |
% \end{macrocode} |
| 69 |
% \section{Introduction} |
| 70 |
% The \pkg{exerquiz} package is capable of creating questions and solutions to exercises and quizzes. |
| 71 |
% The purpose of this package is to develop commands for extracting any desired solution, for whatever |
| 72 |
% reason, and typesetting it anywhere in the body of the document. To accomplish this goal, the |
| 73 |
% recent version of \pkg{exerquiz} is required (dated 2018/12/13 or later) and the \pkg{shellesc} package. |
| 74 |
% |
| 75 |
% While the document is being compiled, the solution files (SOL and QSL) are being written to, so we cannot |
| 76 |
% input them or read them. What we do is to make a copy of the solution files from within the operating system, |
| 77 |
% and input that back into the body of the document when required. Consequently, it is necessary to activate |
| 78 |
% the feature of executing an OS script from within the compiling operation. To activate the feature, the document |
| 79 |
% needs to be compiled with the \texttt{--shell-escape} switch (for \app{latex}, \app{pdflatex}, \app{lualatex}, and \app{xelatex}). |
| 80 |
% |
| 81 |
% The basic idea is to mark a solution that is to be reproduced elsewhere, \cs{mrkForIns\darg{\ameta{name}}}, just above |
| 82 |
% the \env{solution} environment. Then elsewhere in the document, input the solution using the command \cs{insExSoln\darg{\ameta{name}}}, |
| 83 |
% \cs{insSqSoln\darg{\ameta{name}}}, or \cs{insQzSoln\darg{\ameta{name}}}, depending on whether the solution came from |
| 84 |
% the \env{exercise}, \env{shortquiz}, or \env{quiz} environment. |
| 85 |
% \changes{v0.6}{2018/12/28}{Change package name from \string\pkg{ci-solns} to \string\pkg{mi-solns}; change internal commands |
| 86 |
% to reflect this renaming} |
| 87 |
% \section{Preliminaries} |
| 88 |
% \begin{macrocode} |
| 89 |
\RequirePackage{shellesc} |
| 90 |
\ProcessOptions\relax |
| 91 |
% \end{macrocode} |
| 92 |
% We require either \pkg{exerquiz} or \pkg{eqexam} with a minimal publish date, \cs{mi@reqChk} performs the |
| 93 |
% check, but delays it until \cs{AtBeginDocument}. |
| 94 |
% \begin{macrocode} |
| 95 |
\def\mi@reqChk{\begingroup\mifoundfalse |
| 96 |
\@ifpackageloaded{exerquiz}{\mifoundtrue\def\reqDate{2018/12/13} |
| 97 |
\@ifpackagelater{exerquiz}{\reqDate} |
| 98 |
{}{\PackageWarning{mi-solns}{exerquiz dated \reqDate\space |
| 99 |
or later\MessageBreak required}}% |
| 100 |
}{}% |
| 101 |
\@ifpackageloaded{eqexam}{\mifoundtrue |
| 102 |
\def\reqDate{2018/12/13}\@ifpackagelater{eqexam}{\reqDate} |
| 103 |
{\mi@solutionsonlyfix}{\PackageWarning{mi-solns} |
| 104 |
{eqexam dated \reqDate\space or\MessageBreak |
| 105 |
later required}}% |
| 106 |
}{}% |
| 107 |
\ifmifound\else |
| 108 |
\PackageWarning{mi-solns}{For this package to be |
| 109 |
effective\MessageBreak you need either exerquiz |
| 110 |
or eqexam, as appropriate}\fi |
| 111 |
\endgroup} |
| 112 |
\AtBeginDocument{\mi@reqChk} |
| 113 |
% \end{macrocode} |
| 114 |
% Beginning with \pkg{exerquiz/eqexam} dated 2018/12/13, we can change the name of the |
| 115 |
% SOL file (from its default of \cs{jobname.sol}. If the \opt{solutionsonly} option of |
| 116 |
% \pkg{eqexam} is being applied, we made some changes so that option works with |
| 117 |
% \pkg{mi-solns}. |
| 118 |
% \begin{macrocode} |
| 119 |
\def\mi@solutionsonlyfix{\ifsolutionsonly |
| 120 |
\edef\eqExSolFileName{\misolout}\expandafter |
| 121 |
\global\copySolnsOff\global\notamiopfalse\fi} |
| 122 |
% \end{macrocode} |
| 123 |
% \section{Core commands for this package} |
| 124 |
% \begin{macro}{\copyfileCmdEx} |
| 125 |
% \begin{macro}{\copyfileCmdQz} |
| 126 |
% The commands to copy SOL and QSL files, may be redefined as needed in the operating system. |
| 127 |
% \begin{macrocode} |
| 128 |
\def\declSOLIn#1{\def\misolin{#1}}\def\declSOLOut#1{\def\misolout{#1}} |
| 129 |
\def\misolin{\jobname.sol}\def\misolout{\jobname-cpy.sol} |
| 130 |
\def\declQSLIn#1{\def\miqslin{#1}}\def\declQSLOut#1{\def\miqslout{#1}} |
| 131 |
\def\miqslin{\jobname.qsl}\def\miqslout{\jobname-cpy.qsl} |
| 132 |
\newcommand*{\copyfileCmdEx}{copy \misolin\space\misolout} |
| 133 |
\newcommand*{\copyfileCmdQz}{copy \miqslin\space\miqslout} |
| 134 |
\def\mi@copysolns{% |
| 135 |
\ShellEscape{\copyfileCmdEx}\ShellEscape{\copyfileCmdQz}} |
| 136 |
% \end{macrocode} |
| 137 |
% \end{macro} |
| 138 |
% \end{macro} |
| 139 |
% \begin{macro}{\copySolnsOn} |
| 140 |
% Making a copy of the solution files is the default. |
| 141 |
% \begin{macro}{\copySolnsOff} |
| 142 |
% After there are no more changes to the solution files, you can say |
| 143 |
% \cs{copySolnsOff}, and each compile will not rebuild `\texttt{cpy-}' solution |
| 144 |
% files. |
| 145 |
% \begin{macrocode} |
| 146 |
\def\copySolnsOn{\let\mi@copySolns\mi@copysolns} |
| 147 |
\def\copySolnsOff{\let\mi@copySolns\relax} |
| 148 |
\@onlypreamble\copySolnsOn |
| 149 |
\@onlypreamble\copySolnsOff |
| 150 |
\copySolnsOn |
| 151 |
% \end{macrocode} |
| 152 |
% \textbf{Copy the solution files.} At the end of the document, we make a copy of the solution files, provided |
| 153 |
% \cs{copySolnsOn} is in effect. |
| 154 |
% \begin{macrocode} |
| 155 |
\AtEndDocument{\mi@copySolns} |
| 156 |
% \end{macrocode} |
| 157 |
% \end{macro} |
| 158 |
% \end{macro} |
| 159 |
% \textbf{Some utility commands} |
| 160 |
% Below, we define a few useful commands.\medskip\par |
| 161 |
% \noindent\DescribeMacro\ignoreterminex If \cs{eqterminex} has a special definition, |
| 162 |
% perhaps created from the \env{cq} environment, you can pass \cs{ignoreterminex} through |
| 163 |
% the optional argument of \cs{insExSoln} and the question to the problem does not appear. |
| 164 |
% We also declare \DescribeMacro\ignoreques\cs{ignoreques} as an alias for \cs{ignoreterminex}.\medskip |
| 165 |
% |
| 166 |
% \noindent We define two switches: \DescribeMacro\ifmifound\cs{ifmifound} is set to true when |
| 167 |
% a \ameta{name} we are searching for is found; otherwise it remains false. A value of false causes |
| 168 |
% a warning to be issued. \DescribeMacro\ifnotamiop\cs{ifnotamiop} (not a MI operation) is used to control what is displayed |
| 169 |
% when one of the \cs{ins...} commands are used. See comments just below. |
| 170 |
% \begin{macrocode} |
| 171 |
\newif\ifmifound \mifoundfalse |
| 172 |
\newif\ifnotamiop \notamioptrue |
| 173 |
\newif\ifmi@OKtoRead \mi@OKtoReadtrue |
| 174 |
\def\readSolnsOn{\mi@OKtoReadtrue} |
| 175 |
\def\readSolnsOff{\mi@OKtoReadfalse} |
| 176 |
\newcommand*{\miReadOffMsg}{(\textbf{?? read is off ??})} |
| 177 |
% \end{macrocode} |
| 178 |
% The document author can can write to the solution files using |
| 179 |
% \DescribeMacro\writeToExSolns\cs{writeToExSolns}, \DescribeMacro\writeToSolnFile\cs{writeToSolnFile}, |
| 180 |
% or \DescribeMacro\writeToQzSolns. The macros are originally defined in \pkg{exerquiz} and |
| 181 |
% \pkg{eqexam}, but we redefine them here so their argument is enclosed in |
| 182 |
% \cs{ifnotamiop}. |
| 183 |
% \begin{macrocode} |
| 184 |
\newcommand\mi@wrt@fix[1]{\protect\ifnotamiop^^J% |
| 185 |
#1^^J\protect\fi} |
| 186 |
\renewcommand\writeToExSolns[1]{\writeT@ExSolns{\mi@wrt@fix{#1}}} |
| 187 |
\renewcommand\writeToQzSolns[1]{\writeT@QzSolns{\mi@wrt@fix{#1}}} |
| 188 |
\@ifpackageloaded{eqexam} |
| 189 |
{\renewcommand\writeToSolnFile[1]{\writeT@SolnFile{\mi@wrt@fix{#1}}}} |
| 190 |
{\let\writeToSolnFile\writeToExSolns} |
| 191 |
\def\ignoreterminex{\let\eqterminex\relax\let\decleqterminex\@gobble} |
| 192 |
\let\ignoreques\ignoreterminex |
| 193 |
% \end{macrocode} |
| 194 |
% Some gobbling macros. |
| 195 |
% \begin{macrocode} |
| 196 |
\long\def\gobbleiiterminex#1\eqterminex{} |
| 197 |
\long\def\gobbleiiendinput#1\endinput{\endinput} |
| 198 |
\long\def\gobbleiiendgroup#1\endgroup{} |
| 199 |
\long\def\mi@griii#1#2#3{} |
| 200 |
% \end{macrocode} |
| 201 |
% \cs{eqgriii} is eventually \cs{let} to\DescribeMacro{\mi@griii}\cs{mi@griii}, while \cs{eqgrii} is |
| 202 |
% \cs{let} to \cs{@gobbletwo}. In the data structure of |
| 203 |
% the solution file of an \pkg{eqexam} document. In such a document, \cs{eqgriii} and \cs{eqgrii} appears at the top |
| 204 |
% and bottom of the file; for example, |
| 205 |
% \begin{flushleft}\ttfamily\small\let\s\string\let\b\darg\let\t\quad |
| 206 |
% \t\s\eqgriii\s\noindent\s\begin\b{eqequestions}\\ |
| 207 |
% \t\dots\\ |
| 208 |
% \t\s\eqgrii\s\end\b{eqequestions} |
| 209 |
% \end{flushleft} |
| 210 |
% We don't want the \env{eqequestions} environment input as part of the insertion, so we must gobble |
| 211 |
% them up using \cs{eqgriii} (\cs{let} to \cs{mi@griii}) and \cs{eqgrii} (\cs{let} to \cs{@gobbletwo}). |
| 212 |
% These are formatting (a list env), which we don't want in the body of our document. We are |
| 213 |
% just trying to input the \ameta{solution} part of the data structure; everything else needs to be |
| 214 |
% ignored. |
| 215 |
% \begin{macrocode} |
| 216 |
% \end{macrocode} |
| 217 |
% The next three commands do some internal |
| 218 |
% work. They are each called by \cs{insExSoln}, \cs{insSqSoln}, and \cs{insQzSoln}, respectively\medskip |
| 219 |
% |
| 220 |
% \subsection{Internal macros that expand within a solutions file} |
| 221 |
% There are three macros that are defined and are executed as a solution file is input. |
| 222 |
% |
| 223 |
% \subsubsection{For exercises} |
| 224 |
% Exercises are the more difficult case because they are used not only by \pkg{exerquiz}, |
| 225 |
% but also \pkg{eqexam}; in the latter, there are may more `control' commands that are written |
| 226 |
% to the solution file (SOL) to format how the solutions appear at the end of the document. |
| 227 |
% |
| 228 |
% Below is a representation of a solution to an exercise. The \cs{insExSoln} command, \cs{let}s |
| 229 |
% \cs{eqMrkSoln} to \cs{eqMrkSolnCpyEx}\par\medskip\noindent |
| 230 |
% \textbf{A representative data structure for an exercise (\pkg{exerquiz})}\vadjust{\kern-6pt} |
| 231 |
% \begin{flushleft}\ttfamily\small\let\s\string\let\b\darg\let\t\quad |
| 232 |
% \t\s\eqMrkSoln\b{\ameta{name}}\s\eqEXt\b{}\b{}\s\solnItemMngt\\ |
| 233 |
% \t\s\exerSolnHeader\b{\ameta{argi}}\b{\ameta{argii}}{\b{argiii}}\s\eqterminex\\ |
| 234 |
% \t\t\t\ameta{solution}\\ |
| 235 |
% \t\s\ReturnTo\b{\ameta{argi}}\b{\ameta{argii}}\s\endeqEXt\s\par\b{\s\medskip}\% |
| 236 |
% \end{flushleft} |
| 237 |
% If a solution to an exercise (or quiz) is \emph{not marked} by \cs{mrkForIns{\ameta{name}}}, then |
| 238 |
% \cs{eqMrkSoln\darg{\ameta{name}}} \emph{does not appear} in the structure.\par\medskip\noindent |
| 239 |
% \textbf{A representative data structure for an problem (\pkg{eforms})}\vadjust{\kern-6pt} |
| 240 |
% \begin{flushleft}\ttfamily\small\let\s\string\let\b\darg\let\t\quad |
| 241 |
% \t\s\decleqterminex\b{\s\cqFmtPasteQues\b{cq-1.cut}}\%\\ |
| 242 |
% \t\s\eqMrkSoln\b{\ameta{name}}\s\eqEXt\b{}\b{}\s\solnItemMngt\\ |
| 243 |
% \t\s\exerSolnHeader\b{\ameta{argi}}\b{\ameta{argii}}\b{\ameta{argiii}}\s\selectVersion\b{}\b{3}\s\eqterminex\\ |
| 244 |
% \t\t\t\ameta{solution}\\ |
| 245 |
% \t\s\ReturnTo\b{\ameta{argi}}\b{\ameta{argii}}\s\endeqEXt\s\par\b{\b{}}\% |
| 246 |
% \end{flushleft} |
| 247 |
% When \cs{selectVersion} \emph{does not appear} prior to the \env{solution} environment, then the \cs{declareterminex} |
| 248 |
% and \cs{selectVersion} (and args) \emph{do not appear} in the structure.\par\medskip\noindent |
| 249 |
% \textbf{In general.} When \cs{eqMrkSoln} is expanded, it tests whether |
| 250 |
% \ameta{name} matches \cs{eqMrkCpyArg}. Referencing the above data structures, \cs{insExSoln} pretty |
| 251 |
% much sets \cs{eqEXt}, \cs{solnItemMngt}, \cs{exerSolnHeader}, \cs{ReturnTo} to gobble their argument and become noops. |
| 252 |
% \cs{endeqEXt} gobbles everything up down to \cs{endinput}.\medskip |
| 253 |
% |
| 254 |
% \noindent\DescribeMacro{\eqMrkSolnCpyEx}\hskip-\marginparsep\texttt{\darg{\ameta{name}}} Process |
| 255 |
% a marked solution for an exercise. We hunt for \ameta{name}. |
| 256 |
% \begin{macrocode} |
| 257 |
\def\eqMrkSolnCpyEx#1{\def\eqargi{#1}% |
| 258 |
\ifx\eqargi\eqMrkCpyArg |
| 259 |
\mifoundtrue |
| 260 |
\let\par\par@SAVE |
| 261 |
\ifmakeExSlLocal |
| 262 |
\long\def\endeqEXt##1##2##3{##3\gobbleiiendinput}\else |
| 263 |
\let\endeqEXt\gobbleiiendinput\fi |
| 264 |
\let\eqEXt\@gobbletwo |
| 265 |
\let\mi@next\relax |
| 266 |
\else |
| 267 |
\long\def\endeqEXt##1##2{}% |
| 268 |
\let\mi@next\gobbleToEndEXt |
| 269 |
\fi |
| 270 |
\mi@next} |
| 271 |
% \end{macrocode} |
| 272 |
% \subsubsection{For short-quizzes} |
| 273 |
% \textbf{A representative data structure for a short-quiz (\pkg{exerquiz})}\vadjust{\kern-6pt} |
| 274 |
% \begin{flushleft}\ttfamily\small\let\s\string\let\b\darg\let\t\quad |
| 275 |
% \t\s\eqMrkSoln\b{\ameta{name}}\s\eqSQt\b{}\s\quizSolnHeader\b{\ameta{argi}}\b{\ameta{argii}}\s\eqterminex\\ |
| 276 |
% \t\t\t\ameta{solution}\\ |
| 277 |
% \t\s\ReturnTo\b{\ameta{argi}}\b{\ameta{argii}}\s\endeqQt\s\fpAfterSolutionsSkip |
| 278 |
% \end{flushleft} |
| 279 |
% As commented above, \cs{eqMrkSoln} may not appear in the data structure.\medskip |
| 280 |
% |
| 281 |
% \noindent\DescribeMacro{\eqMrkSolnCpySQ}\hskip-\marginparsep\texttt{\darg{\ameta{name}}} Process |
| 282 |
% a marked solution for an short-quiz (\env{shortquiz} env). We hunt for \ameta{name}. |
| 283 |
% \begin{macrocode} |
| 284 |
\def\eqMrkSolnCpySQ#1{\def\eqargi{#1}% |
| 285 |
\ifx\eqargi\eqMrkCpyArg |
| 286 |
\mifoundtrue |
| 287 |
\let\par\par@SAVE |
| 288 |
\ifmakeQzSlLocal |
| 289 |
\long\def\endeqSQt##1##2{##2\gobbleiiendinput}\else |
| 290 |
\let\endeqSQt\gobbleiiendinput |
| 291 |
\fi |
| 292 |
\let\mi@next\gobbleiiterminex |
| 293 |
\else |
| 294 |
\long\def\endeqSQt##1{}% |
| 295 |
\let\mi@next\gobbleToEndSQt |
| 296 |
\fi |
| 297 |
\mi@next} |
| 298 |
% \end{macrocode} |
| 299 |
% \subsubsection{For quizzes} |
| 300 |
% \textbf{A representative data structure for a quiz (\pkg{exerquiz})}\vadjust{\kern-6pt} |
| 301 |
% \begin{flushleft}\ttfamily\small\let\s\string\let\b\darg\let\t\quad |
| 302 |
% \t\s\eqMrkSoln\b{\ameta{name}}\s\eqQt\b{}\s\quizSolnHeader\b{\ameta{argi}}\b{\ameta{argii}}\s\eqterminex\\ |
| 303 |
% \t\t\t\ameta{solution}\\ |
| 304 |
% \t\s\ReturnTo\b{\ameta{argi}}\b{\ameta{argii}}\s\endeqQt\s\fpAfterSolutionsSkip |
| 305 |
% \end{flushleft} |
| 306 |
% As commented above, \cs{eqMrkSoln} may not appear in the data structure.\medskip |
| 307 |
% |
| 308 |
% \noindent\DescribeMacro{\eqMrkSolnCpyQz}\hskip-\marginparsep\texttt{\darg{\ameta{name}}} Process |
| 309 |
% a marked solution for an quiz (\env{quiz} env). We hunt for \ameta{name}. |
| 310 |
% \begin{macrocode} |
| 311 |
\def\eqMrkSolnCpyQz#1{\def\eqargi{#1}% |
| 312 |
\ifx\eqargi\eqMrkCpyArg |
| 313 |
\mifoundtrue |
| 314 |
\let\par\par@SAVE |
| 315 |
\ifmakeQzSlLocal |
| 316 |
\long\def\endeqQt##1##2{##2\gobbleiiendinput}\else |
| 317 |
\let\endeqQt\gobbleiiendinput |
| 318 |
\fi |
| 319 |
\let\mi@next\gobbleiiterminex |
| 320 |
\else |
| 321 |
\long\def\endeqQt##1{}% |
| 322 |
\let\mi@next\gobbleToEndSQt |
| 323 |
\fi |
| 324 |
\mi@next} |
| 325 |
% \end{macrocode} |
| 326 |
|
| 327 |
% \section{User commands for inserting a solution} |
| 328 |
% The main commands are \cs{insExSoln}, \cs{insSqSoln}, and \cs{insQzSoln}. |
| 329 |
% |
| 330 |
% Preliminary to the definitions, we define a command that is common to all of them. |
| 331 |
% When inputting a solutions file, we cannot any vertical spaces that are not part of |
| 332 |
% the solution, not formatting, not list environments, and so on. The |
| 333 |
% \DescribeMacro\mi@nullify\cs{mi@nullify} is designed to cancel, nullify, or otherwise |
| 334 |
% neutralize anything that is unwanted. I've added \DescribeMacro\addToMINullify\cs{addToMINullify} |
| 335 |
% for any unforseen things we don't want to appear or to affect spacing. |
| 336 |
% |
| 337 |
% \begin{macrocode} |
| 338 |
\let\addToMINullify\relax |
| 339 |
\def\mi@nullify{\let\par@SAVE\par\let\par\relax |
| 340 |
\let\eqgrii\@gobbletwo\let\eqgriii\mi@griii\let\solnItemMngt\relax |
| 341 |
\def\exerSolnHeader##1##2##3{}\def\ReturnTo##1##2{\unskip}% |
| 342 |
\let\eqTopOfSolnPage\relax\let\preExamSolnHead\relax |
| 343 |
\let\eqTopOfQslPage\relax |
| 344 |
\let\examSolnHeadFmt\@gobble\let\postExamSolnHead\relax |
| 345 |
\let\btwnExamSkip\relax\def\quizSolnHeader##1##2{}\addToMINullify} |
| 346 |
% \end{macrocode} |
| 347 |
% |
| 348 |
% \subsection{For exercises} |
| 349 |
% |
| 350 |
% \begin{macro}{\insExSoln}\hskip-\marginparsep\texttt{[\ameta{inserts}]\darg{\ameta{name}}} |
| 351 |
% Used for displaying the solution to an exercise that has been marked by |
| 352 |
% \cs{mrkForIns\darg{\ameta{name}}}. The optional argument (\ameta{inserts}) is passed (inserted) into the top of the |
| 353 |
% \cs{insExSoln}. For exercises, there is a \env{cq} command that copies the question |
| 354 |
% to the solution. By default, the question \emph{is displayed}; however, by passing |
| 355 |
% \DescribeMacro{\ignoreterminex}\cs{ignoreterminex} the question \emph{is not displayed}. |
| 356 |
% \begin{macrocode} |
| 357 |
\newcommand{\insExSoln}[2][]{\begingroup\withinsoldoctrue#1\relax |
| 358 |
\notamiopfalse\mi@nullify |
| 359 |
\let\eqMrkSoln\eqMrkSolnCpyEx |
| 360 |
% \end{macrocode} |
| 361 |
% Setting \cs{useExtFilter} and \cs{filterFor\darg{@NOMATCH@}}; hopefully, no match is ever obtained, which |
| 362 |
% means the already existent function of \cs{useExtFilter} will skip over the entries. |
| 363 |
% When \cs{eqMrkSoln} does not appear in a data structure, the filter will care of the structure entry. |
| 364 |
% \begin{macrocode} |
| 365 |
\useEXtFilter\filterFor{@NOMATCH@}\def\eqMrkCpyArg{#2}% |
| 366 |
\ifmi@OKtoRead\InputIfFileExists{\misolout}{}{}\ifmifound\else |
| 367 |
\textbf{??}\PackageWarning{mi-solns}{The name '#2' defined by |
| 368 |
\string\mrkForIns\MessageBreak was not found}\fi\else |
| 369 |
\miReadOffMsg\fi\endgroup} |
| 370 |
% \end{macrocode} |
| 371 |
% \end{macro} |
| 372 |
% |
| 373 |
% \subsection{For quizzes} |
| 374 |
% The commands \cs{insSqSoln} and \cs{insQzSoln} are identical, except for |
| 375 |
% two parameters: \texttt{\#3} is the internal command (\cs{eqMrkSolnCpySQ} |
| 376 |
% or \cs{eqMrkSolnCpyQz}); while \texttt{\#4} is the normal filter |
| 377 |
% (\cs{useSQtFilter} or \cs{useQtFilter}). |
| 378 |
% \begin{macrocode} |
| 379 |
\newcommand\mi@insSQzSoln[4][]{\begingroup\withinqsldoctrue#1\relax |
| 380 |
\notamiopfalse\mi@nullify |
| 381 |
\let\eqMrkSoln#3\relax |
| 382 |
#4\filterFor{@NOMATCH@}\def\eqMrkCpyArg{#2}% |
| 383 |
\ifmi@OKtoRead\InputIfFileExists{\miqslout}{}{}\ifmifound\else |
| 384 |
\textbf{??}\PackageWarning{mi-solns} |
| 385 |
{The name '#2' defined by \string\mrkForIns\MessageBreak |
| 386 |
was not found}\fi\else\miReadOffMsg\fi\endgroup} |
| 387 |
% \end{macrocode} |
| 388 |
% \begin{macro}{\insSqSoln}\hskip-\marginparsep\texttt{[\ameta{inserts}]\darg{\ameta{name}}} |
| 389 |
% Used for displaying the solution to an short-quiz that has been marked by |
| 390 |
% \cs{mrkForIns\darg{\ameta{name}}}. The optional argument (\ameta{inserts}) is passed (inserted) into the top of the |
| 391 |
% \cs{insSqSoln}. |
| 392 |
% \begin{macrocode} |
| 393 |
\newcommand{\insSqSoln}[2][]{% |
| 394 |
\mi@insSQzSoln[#1]{#2}{\eqMrkSolnCpySQ}{\useSQtFilter}} |
| 395 |
% \end{macrocode} |
| 396 |
% \end{macro} |
| 397 |
% |
| 398 |
% \begin{macro}{\insQzSoln}\hskip-\marginparsep\texttt{[\ameta{inserts}]\darg{\ameta{name}}} |
| 399 |
% Used for displaying the solution to an quiz that has been marked by |
| 400 |
% \cs{mrkForIns\darg{\ameta{name}}}. The optional argument (\ameta{inserts}) is passed (inserted) into the top of the |
| 401 |
% \cs{insQzSoln}. |
| 402 |
% \begin{macrocode} |
| 403 |
\newcommand{\insQzSoln}[2][]{% |
| 404 |
\mi@insSQzSoln[#1]{#2}{\eqMrkSolnCpyQz}{\useQtFilter}} |
| 405 |
% \end{macrocode} |
| 406 |
% \end{macro} |
| 407 |
% \begin{macrocode} |
| 408 |
%</package> |
| 409 |
% \end{macrocode} |
| 410 |
% \Finale |
| 411 |
\endinput |