• No results found

The purpose of this package is to develop commands for extracting any desired solution, for whatever reason, and typesetting it anywhere in the body of the document

N/A
N/A
Protected

Academic year: 2021

Share "The purpose of this package is to develop commands for extracting any desired solution, for whatever reason, and typesetting it anywhere in the body of the document"

Copied!
9
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

mi-solns: Extract solutions from exercises and quizzes

D. P. Story

Email: dpstory@uakron.edu processed January 9, 2019

Contents

1 Introduction 1

2 Preliminaries 2

3 Core commands for this package 2

3.1 Internal macros that expand within a solutions file . . . . 4

3.1.1 For exercises . . . . 4

3.1.2 For short-quizzes . . . . 5

3.1.3 For quizzes . . . . 6

4 User commands for inserting a solution 6 4.1 For exercises . . . . 7

4.2 For quizzes . . . . 7

5 Index 8

1h∗packagei

1 Introduction

The exerquiz package is capable of creating questions and solutions to exercises and quizzes. The purpose of this package is to develop commands for extracting any desired solution, for whatever reason, and typesetting it anywhere in the body of the document. To accomplish this goal, the recent version of exerquiz is required (dated 2018/12/13 or later) and the shellesc package.

While the document is being compiled, the solution files (SOL and QSL) are being written to, so we cannot input them or read them. What we do is to make a copy of the solution files from within the operating system, and input that back into the body of the document when required. Consequently, it is neces- sary to activate the feature of executing an OS script from within the compiling

(2)

operation. To activate the feature, the document needs to be compiled with the --shell-escape switch (for latex, pdflatex, lualatex, and xelatex).

The basic idea is to mark a solution that is to be reproduced elsewhere,

\mrkForIns{hnamei}, just above the solution environment. Then elsewhere in the document, input the solution using the command \insExSoln{hnamei},

\insSqSoln{hnamei}, or \insQzSoln{hnamei}, depending on whether the solu- tion came from the exercise, shortquiz, or quiz environment.

2 Preliminaries

2\RequirePackage{shellesc}

3\ProcessOptions\relax

We require either exerquiz or eqexam with a minimal publish date, \mi@reqChk performs the check, but delays it until \AtBeginDocument.

4\def\mi@reqChk{\begingroup\mifoundfalse

5 \@ifpackageloaded{exerquiz}{\mifoundtrue\def\reqDate{2018/12/13}

6 \@ifpackagelater{exerquiz}{\reqDate}

7 {}{\PackageWarning{mi-solns}{exerquiz dated \reqDate\space

8 or later\MessageBreak required}}%

9 }{}%

10 \@ifpackageloaded{eqexam}{\mifoundtrue

11 \def\reqDate{2018/12/13}\@ifpackagelater{eqexam}{\reqDate}

12 {\mi@solutionsonlyfix}{\PackageWarning{mi-solns}

13 {eqexam dated \reqDate\space or\MessageBreak

14 later required}}%

15 }{}%

16 \ifmifound\else

17 \PackageWarning{mi-solns}{For this package to be

18 effective\MessageBreak you need either exerquiz

19 or eqexam, as appropriate}\fi

20\endgroup}

21\AtBeginDocument{\mi@reqChk}

Beginning with exerquiz/eqexam dated 2018/12/13, we can change the name of the SOL file (from its default of \jobname.sol. If the solutionsonly option of eqexam is being applied, we made some changes so that option works with mi-solns.

22\def\mi@solutionsonlyfix{\ifsolutionsonly

23 \edef\eqExSolFileName{\misolout}\expandafter

24 \global\copySolnsOff\global\notamiopfalse\fi}

3 Core commands for this package

\copyfileCmdEx

\copyfileCmdQz

The commands to copy SOL and QSL files, may be redefined as needed in the operating system.

25\def\declSOLIn#1{\def\misolin{#1}}\def\declSOLOut#1{\def\misolout{#1}}

26\def\misolin{\jobname.sol}\def\misolout{\jobname-cpy.sol}

27\def\declQSLIn#1{\def\miqslin{#1}}\def\declQSLOut#1{\def\miqslout{#1}}

28\def\miqslin{\jobname.qsl}\def\miqslout{\jobname-cpy.qsl}

(3)

29\newcommand*{\copyfileCmdEx}{copy \misolin\space\misolout}

30\newcommand*{\copyfileCmdQz}{copy \miqslin\space\miqslout}

31\def\mi@copysolns{%

32 \ShellEscape{\copyfileCmdEx}\ShellEscape{\copyfileCmdQz}}

\copySolnsOn Making a copy of the solution files is the default.

\copySolnsOff After there are no more changes to the solution files, you can say \copySolnsOff, and each compile will not rebuild ‘cpy-’ solution files.

33\def\copySolnsOn{\let\mi@copySolns\mi@copysolns}

34\def\copySolnsOff{\let\mi@copySolns\relax}

35\@onlypreamble\copySolnsOn

36\@onlypreamble\copySolnsOff

37\copySolnsOn

Copy the solution files. At the end of the document, we make a copy of the solution files, provided \copySolnsOn is in effect.

38\AtEndDocument{\mi@copySolns}

Some utility commands Below, we define a few useful commands.

If \eqterminex has a special definition, perhaps created from the cq environment,

\ignoreterminex

you can pass \ignoreterminex through the optional argument of \insExSoln and the question to the problem does not appear. We also declare \ignoreques as an

\ignoreques

alias for \ignoreterminex.

We define two switches: \ifmifound is set to true when a hnamei we are searching

\ifmifound

for is found; otherwise it remains false. A value of false causes a warning to be issued. \ifnotamiop (not a MI operation) is used to control what is displayed

\ifnotamiop

when one of the \ins... commands are used. See comments just below.

39\newif\ifmifound \mifoundfalse

40\newif\ifnotamiop \notamioptrue

41\newif\ifmi@OKtoRead \mi@OKtoReadtrue

42\def\readSolnsOn{\mi@OKtoReadtrue}

43\def\readSolnsOff{\mi@OKtoReadfalse}

44\newcommand*{\miReadOffMsg}{(\textbf{?? read is off ??})}

The document author can can write to the solution files using \writeToExSolns,

\writeToExSolns

\writeToSolnFile, or . The macros are originally defined in exerquiz and eqexam,

\writeToSolnFile

\writeToQzSolns but we redefine them here so their argument is enclosed in \ifnotamiop.

45\newcommand\mi@wrt@fix[1]{\protect\ifnotamiop^^J%

46 #1^^J\protect\fi}

47\renewcommand\writeToExSolns[1]{\writeT@ExSolns{\mi@wrt@fix{#1}}}

48\renewcommand\writeToQzSolns[1]{\writeT@QzSolns{\mi@wrt@fix{#1}}}

49\@ifpackageloaded{eqexam}

50 {\renewcommand\writeToSolnFile[1]{\writeT@SolnFile{\mi@wrt@fix{#1}}}}

51 {\let\writeToSolnFile\writeToExSolns}

52\def\ignoreterminex{\let\eqterminex\relax\let\decleqterminex\@gobble}

53\let\ignoreques\ignoreterminex

(4)

Some gobbling macros.

54\long\def\gobbleiiterminex#1\eqterminex{}

55\long\def\gobbleiiendinput#1\endinput{\endinput}

56\long\def\gobbleiiendgroup#1\endgroup{}

57\long\def\mi@griii#1#2#3{}

\eqgriii is eventually \let to\mi@griii, while \eqgrii is \let to \@gobbletwo.

\mi@griii

In the data structure of the solution file of an eqexam document. In such a doc- ument, \eqgriii and \eqgrii appears at the top and bottom of the file; for example,

\eqgriii\noindent\begin{eqequestions}

...

\eqgrii\end{eqequestions}

We don’t want the eqequestions environment input as part of the insertion, so we must gobble them up using \eqgriii (\let to \mi@griii) and \eqgrii (\let to \@gobbletwo). These are formatting (a list env), which we don’t want in the body of our document. We are just trying to input the hsolutioni part of the data structure; everything else needs to be ignored.

The next three commands do some internal work. They are each called by

\insExSoln, \insSqSoln, and \insQzSoln, respectively

3.1 Internal macros that expand within a solutions file

There are three macros that are defined and are executed as a solution file is input.

3.1.1 For exercises

Exercises are the more difficult case because they are used not only by exerquiz, but also eqexam; in the latter, there are may more ‘control’ commands that are written to the solution file (SOL) to format how the solutions appear at the end of the document.

Below is a representation of a solution to an exercise. The \insExSoln com- mand, \lets \eqMrkSoln to \eqMrkSolnCpyEx

A representative data structure for an exercise (exerquiz)

\eqMrkSoln{hnamei}\eqEXt{}{}\solnItemMngt

\exerSolnHeader{hargii}{hargiii}{argiii}\eqterminex hsolutioni

\ReturnTo{hargii}{hargiii}\endeqEXt\par{\medskip}%

If a solution to an exercise (or quiz) is not marked by \mrkForInshnamei, then

\eqMrkSoln{hnamei} does not appear in the structure.

A representative data structure for an problem (eforms)

(5)

\decleqterminex{\cqFmtPasteQues{cq-1.cut}}%

\eqMrkSoln{hnamei}\eqEXt{}{}\solnItemMngt

\exerSolnHeader{hargii}{hargiii}{hargiiii}\selectVersion{}{3}\eqterminex hsolutioni

\ReturnTo{hargii}{hargiii}\endeqEXt\par{{}}%

When \selectVersion does not appear prior to the solution environment, then the \declareterminex and \selectVersion (and args) do not appear in the structure.

In general. When \eqMrkSoln is expanded, it tests whether hnamei matches

\eqMrkCpyArg. Referencing the above data structures, \insExSoln pretty much sets \eqEXt, \solnItemMngt, \exerSolnHeader, \ReturnTo to gobble their argu- ment and become noops. \endeqEXt gobbles everything up down to \endinput.

{hnamei} Process a marked solution for an exercise. We hunt for hnamei.

\eqMrkSolnCpyEx

58\def\eqMrkSolnCpyEx#1{\def\eqargi{#1}%

59 \ifx\eqargi\eqMrkCpyArg

60 \mifoundtrue

61 \let\par\par@SAVE

62 \ifmakeExSlLocal

63 \long\def\endeqEXt##1##2##3{##3\gobbleiiendinput}\else

64 \let\endeqEXt\gobbleiiendinput\fi

65 \let\eqEXt\@gobbletwo

66 \let\mi@next\relax

67 \else

68 \long\def\endeqEXt##1##2{}%

69 \let\mi@next\gobbleToEndEXt

70 \fi

71\mi@next}

3.1.2 For short-quizzes

A representative data structure for a short-quiz (exerquiz)

\eqMrkSoln{hnamei}\eqSQt{}\quizSolnHeader{hargii}{hargiii}\eqterminex hsolutioni

\ReturnTo{hargii}{hargiii}\endeqQt\fpAfterSolutionsSkip

As commented above, \eqMrkSoln may not appear in the data structure.

{hnamei} Process a marked solution for an short-quiz (shortquiz env). We hunt for

\eqMrkSolnCpySQ

hnamei.

72\def\eqMrkSolnCpySQ#1{\def\eqargi{#1}%

73 \ifx\eqargi\eqMrkCpyArg

74 \mifoundtrue

75 \let\par\par@SAVE

76 \ifmakeQzSlLocal

77 \long\def\endeqSQt##1##2{##2\gobbleiiendinput}\else

78 \let\endeqSQt\gobbleiiendinput

79 \fi

(6)

80 \let\mi@next\gobbleiiterminex

81 \else

82 \long\def\endeqSQt##1{}%

83 \let\mi@next\gobbleToEndSQt

84 \fi

85\mi@next}

3.1.3 For quizzes

A representative data structure for a quiz (exerquiz)

\eqMrkSoln{hnamei}\eqQt{}\quizSolnHeader{hargii}{hargiii}\eqterminex hsolutioni

\ReturnTo{hargii}{hargiii}\endeqQt\fpAfterSolutionsSkip

As commented above, \eqMrkSoln may not appear in the data structure.

{hnamei} Process a marked solution for an quiz (quiz env). We hunt for hnamei.

\eqMrkSolnCpyQz

86\def\eqMrkSolnCpyQz#1{\def\eqargi{#1}%

87 \ifx\eqargi\eqMrkCpyArg

88 \mifoundtrue

89 \let\par\par@SAVE

90 \ifmakeQzSlLocal

91 \long\def\endeqQt##1##2{##2\gobbleiiendinput}\else

92 \let\endeqQt\gobbleiiendinput

93 \fi

94 \let\mi@next\gobbleiiterminex

95 \else

96 \long\def\endeqQt##1{}%

97 \let\mi@next\gobbleToEndSQt

98 \fi

99\mi@next}

4 User commands for inserting a solution

The main commands are \insExSoln, \insSqSoln, and \insQzSoln.

Preliminary to the definitions, we define a command that is common to all of them. When inputting a solutions file, we cannot any vertical spaces that are not part of the solution, not formatting, not list environments, and so on. The

\mi@nullify is designed to cancel, nullify, or otherwise neutralize anything that

\mi@nullify

is unwanted. I’ve added \addToMINullify for any unforseen things we don’t want

\addToMINullify

to appear or to affect spacing.

100\let\addToMINullify\relax

101\def\mi@nullify{\let\par@SAVE\par\let\par\relax

102 \let\eqgrii\@gobbletwo\let\eqgriii\mi@griii\let\solnItemMngt\relax

103 \def\exerSolnHeader##1##2##3{}\def\ReturnTo##1##2{\unskip}%

104 \let\eqTopOfSolnPage\relax\let\preExamSolnHead\relax

105 \let\eqTopOfQslPage\relax

106 \let\examSolnHeadFmt\@gobble\let\postExamSolnHead\relax

107 \let\btwnExamSkip\relax\def\quizSolnHeader##1##2{}\addToMINullify}

(7)

4.1 For exercises

\insExSoln[hinsertsi]{hnamei} Used for displaying the solution to an exercise that has been marked by \mrkForIns{hnamei}. The optional argument (hinsertsi) is passed (inserted) into the top of the \insExSoln. For exercises, there is a cq command that copies the question to the solution. By default, the question is displayed ; however, by passing \ignoreterminex the question is not displayed.

\ignoreterminex

108\newcommand{\insExSoln}[2][]{\begingroup\withinsoldoctrue#1\relax

109 \notamiopfalse\mi@nullify

110 \let\eqMrkSoln\eqMrkSolnCpyEx

Setting \useExtFilter and \filterFor{@NOMATCH@}; hopefully, no match is ever obtained, which means the already existent function of \useExtFilter will skip over the entries. When \eqMrkSoln does not appear in a data structure, the filter will care of the structure entry.

111 \useEXtFilter\filterFor{@NOMATCH@}\def\eqMrkCpyArg{#2}%

112 \ifmi@OKtoRead\InputIfFileExists{\misolout}{}{}\ifmifound\else

113 \textbf{??}\PackageWarning{mi-solns}{The name ’#2’ defined by

114 \string\mrkForIns\MessageBreak was not found}\fi\else

115 \miReadOffMsg\fi\endgroup}

4.2 For quizzes

The commands \insSqSoln and \insQzSoln are identical, except for two parame- ters: #3 is the internal command (\eqMrkSolnCpySQ or \eqMrkSolnCpyQz); while

#4 is the normal filter (\useSQtFilter or \useQtFilter).

116\newcommand\mi@insSQzSoln[4][]{\begingroup\withinqsldoctrue#1\relax

117 \notamiopfalse\mi@nullify

118 \let\eqMrkSoln#3\relax

119 #4\filterFor{@NOMATCH@}\def\eqMrkCpyArg{#2}%

120 \ifmi@OKtoRead\InputIfFileExists{\miqslout}{}{}\ifmifound\else

121 \textbf{??}\PackageWarning{mi-solns}

122 {The name ’#2’ defined by \string\mrkForIns\MessageBreak

123 was not found}\fi\else\miReadOffMsg\fi\endgroup}

\insSqSoln[hinsertsi]{hnamei} Used for displaying the solution to an short-quiz that has been marked by \mrkForIns{hnamei}. The optional argument (hinsertsi) is passed (inserted) into the top of the \insSqSoln.

124\newcommand{\insSqSoln}[2][]{%

125 \mi@insSQzSoln[#1]{#2}{\eqMrkSolnCpySQ}{\useSQtFilter}}

\insQzSoln[hinsertsi]{hnamei} Used for displaying the solution to an quiz that has been marked by \mrkForIns{hnamei}. The optional argument (hinsertsi) is passed (inserted) into the top of the \insQzSoln.

126\newcommand{\insQzSoln}[2][]{%

127 \mi@insSQzSoln[#1]{#2}{\eqMrkSolnCpyQz}{\useQtFilter}}

128h/packagei

(8)

5 Index

Numbers written in italic refer to the page where the corresponding entry is described; numbers underlined refer to the code line of the definition; numbers in roman refer to the code lines where the entry is used.

Symbols

\@onlypreamble . . . 35, 36 A

\addToMINullify . . . . 6, 100, 107

\AtBeginDocument . . . 21

\AtEndDocument . . . 38

B \btwnExamSkip . . . 107

C \copyfileCmdEx . . . 25

\copyfileCmdQz . . . 25

\copySolnsOff . . . 24, 33 \copySolnsOn . . . 33

D \decleqterminex . . . 52

\declQSLIn . . . 27

\declQSLOut . . . 27

\declSOLIn . . . 25

\declSOLOut . . . 25

E \endeqEXt . . . . 63, 64, 68 \endeqQt . . . . 91, 92, 96 \endeqSQt . . . . 77, 78, 82 \endinput . . . 55

\eqargi . . . . 58, 59, 72, 73, 86, 87 \eqExSolFileName . . . 23

\eqEXt . . . 65

\eqgrii . . . 102

\eqgriii . . . 102

\eqMrkCpyArg . . . . 59, 73, 87, 111, 119 \eqMrkSoln . . . . 110, 118 \eqMrkSolnCpyEx . . . . 5, 58, 110 \eqMrkSolnCpyQz . . . . 6, 86, 127 \eqMrkSolnCpySQ . . . . 5, 72, 125 \eqterminex . . . 52, 54 \eqTopOfQslPage . . . 105

\eqTopOfSolnPage . . . 104

\examSolnHeadFmt . . . 106

\exerSolnHeader . . . 103

F \filterFor . . . . 111, 119 G \gobbleiiendgroup . . . 56

\gobbleiiendinput . . . 55, 63, 64, 77, 78, 91, 92 \gobbleiiterminex . . . . 54, 80, 94 \gobbleToEndEXt . . . 69

\gobbleToEndSQt . . . 83, 97 I \ifmakeExSlLocal . . . 62

\ifmakeQzSlLocal . . . 76, 90 \ifmi@OKtoRead . . . 41, 112, 120 \ifmifound . . . 3, 16, 39, 112, 120 \ifnotamiop . . . . 3, 40, 45 \ifsolutionsonly . . . 22

\ignoreques . . . 3, 53 \ignoreterminex . . . . 3, 7, 52, 53 \InputIfFileExists . . . . 112, 120 \insExSoln . . . 108

\insQzSoln . . . 126

\insSqSoln . . . 124

M \mi@copySolns . . . . 33, 34, 38 \mi@copysolns . . . 31, 33 \mi@griii . . . . 4, 57, 102 \mi@insSQzSoln . . . 116, 125, 127 \mi@next . . . . 66, 69, 71, 80, 83, 85, 94, 97, 99 \mi@nullify . . . 6, 101, 109, 117 \mi@OKtoReadfalse . . . 43

\mi@OKtoReadtrue . . . 41, 42

\mi@reqChk . . . 4, 21

\mi@solutionsonlyfix . . . 12, 22

\mi@wrt@fix . . . 45, 47, 48, 50

\mifoundfalse . . . 4, 39

\mifoundtrue . . . 5, 10, 60, 74, 88

\miqslin . . . . 27, 28, 30

\miqslout . . . 27, 28, 30, 120

\miReadOffMsg . . . 44, 115, 123

\misolin . . . . 25, 26, 29

\misolout . . . . 23, 25, 26, 29, 112

\mrkForIns . . . . 114, 122

(9)

N

\notamiopfalse . . . 24, 109, 117

\notamioptrue . . . 40

P \PackageWarning . . . . 7, 12, 17, 113, 121 \par@SAVE . . . 61, 75, 89, 101 \postExamSolnHead . . . 106

\preExamSolnHead . . . 104

\ProcessOptions . . . 3

Q \quizSolnHeader . . . 107

R \readSolnsOff . . . 43

\readSolnsOn . . . 42

\reqDate . . . . 5–7, 11, 13 \RequirePackage . . . 2

\ReturnTo . . . 103

S \ShellEscape . . . 32

\solnItemMngt . . . 102

T \textbf . . . 44, 113, 121 U \useEXtFilter . . . 111

\useQtFilter . . . 127

\useSQtFilter . . . 125

W \withinqsldoctrue . . . 116

\withinsoldoctrue . . . 108

\writeT@ExSolns . . . 47

\writeT@QzSolns . . . 48

\writeT@SolnFile . . . 50

\writeToExSolns . . . . 3, 47, 51 \writeToQzSolns . . . 3, 48 \writeToSolnFile . . . . 3, 50, 51 6 Change History v0.6 (2018/12/28) General: Change package name from ci-solns to mi-solns; change internal commands to reflect this renaming . . . . 2

Referenties

GERELATEERDE DOCUMENTEN

In her Regeneration trilogy, Pat Barker mimics the methods of the War poets discussed in the previous chapter in terms of using visual imagery, referring to memory

In addition, in this document the terms used have the meaning given to them in Article 2 of the common proposal developed by all Transmission System Operators regarding

Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of

Although the following opportunities actually stem from the Indian macroenvironment, they will be seen as originating from its microenvironment since they influence the potential

3.3.10.a Employees who can submit (a) medical certificate(s) that SU finds acceptable are entitled to a maximum of eight months’ sick leave (taken either continuously or as

A composite manufacturing process for producing Class A finished components..

\requirecommand* (defined in the kernel) with the following difference: if the control sequence is al- ready defined, \requirecommand calls \CheckCommand to make sure that the new

For linguists all language varieties are equal in all respects, but here, due to policies, some dialects are now part of regional languages and thus are under protection, but