| 1 |
%% cloze.sty |
| 2 |
%% Copyright 2015-2025 Josef Friedrich |
| 3 |
% |
| 4 |
% This work may be distributed and/or modified under the |
| 5 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 6 |
% of this license or (at your option) any later version. |
| 7 |
% The latest version of this license is in |
| 8 |
% http://www.latex-project.org/lppl.txt |
| 9 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 10 |
% version 2008/05/04 or later. |
| 11 |
% |
| 12 |
% This work has the LPPL maintenance status `maintained'. |
| 13 |
% |
| 14 |
% The Current Maintainer of this work is Josef Friedrich. |
| 15 |
% |
| 16 |
% This work consists of the files cloze.lua, cloze.tex, |
| 17 |
% and cloze.sty. |
| 18 |
|
| 19 |
\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 20 |
\ProvidesPackage{cloze} |
| 21 |
[2025/07/04 v2.0.0 Package to typeset cloze worksheets or cloze tests] |
| 22 |
% |
| 23 |
% \subsection{The file \tt{cloze.sty}} |
| 24 |
% |
| 25 |
% \begin{macrocode} |
| 26 |
\input{cloze.tex} |
| 27 |
% \end{macrocode} |
| 28 |
% |
| 29 |
% \begin{macrocode} |
| 30 |
\ExplSyntaxOn |
| 31 |
% \end{macrocode} |
| 32 |
% |
| 33 |
% This packages are used to build \emph{cloze}: |
| 34 |
% |
| 35 |
% \subsubsection{Dependencies} |
| 36 |
% |
| 37 |
% The package \href{https://www.ctan.org/pkg/setspace}{setspace} is used |
| 38 |
% by the environment |clozespace|. |
| 39 |
% \begin{macrocode} |
| 40 |
\RequirePackage{setspace} |
| 41 |
% \end{macrocode} |
| 42 |
% |
| 43 |
% \begin{macrocode} |
| 44 |
\DeclareOption*{} % suppresses the error message: ! LaTeX Error: Unknown option |
| 45 |
\ProcessOptions\relax |
| 46 |
\RequirePackage{luakeys} |
| 47 |
\directlua{ |
| 48 |
cloze.parse_global_options('\LuakeysGetPackageOptions', 'global') |
| 49 |
} |
| 50 |
% \end{macrocode} |
| 51 |
% |
| 52 |
% Overwrite the cloze font definition in the plain tex definition to |
| 53 |
% avoid undefined old font command errors. In plain \TeX{} we use \cmd{\it}. |
| 54 |
% \begin{macrocode} |
| 55 |
\def\clozefont{\itshape} |
| 56 |
% \end{macrocode} |
| 57 |
% |
| 58 |
% Load the cloze lua module and put all return values in the variable |
| 59 |
% |cloze|. |
| 60 |
% |
| 61 |
% \subsubsection{Public macros} |
| 62 |
% |
| 63 |
% All public macros are prefixed with |\cloze|. |
| 64 |
% |
| 65 |
% \begin{macro}{\cloze} |
| 66 |
% \begin{macrocode} |
| 67 |
\let\cloze=\undefined |
| 68 |
\NewDocumentCommand{ \cloze }{ O{} m } |
| 69 |
{ |
| 70 |
\Cloze{basic}{\unexpanded{#1}}{#2} |
| 71 |
} |
| 72 |
% \end{macrocode} |
| 73 |
% \end{macro} |
| 74 |
% |
| 75 |
% \begin{macro}{\clozefix} |
| 76 |
% \begin{macrocode} |
| 77 |
\let\clozefix=\undefined |
| 78 |
\NewDocumentCommand{ \clozefix }{ O{} m } |
| 79 |
{ |
| 80 |
\Cloze{fix}{#1}{#2} |
| 81 |
} |
| 82 |
% \end{macrocode} |
| 83 |
% \end{macro} |
| 84 |
% |
| 85 |
% \begin{environment}{clozepar} |
| 86 |
% \begin{macrocode} |
| 87 |
\NewDocumentEnvironment{ clozepar }{ O{} } |
| 88 |
{ |
| 89 |
\par |
| 90 |
\ClozeStartMarker{par}{#1} |
| 91 |
\clozefont\relax |
| 92 |
} |
| 93 |
{ |
| 94 |
\ClozeStopMarker{par} |
| 95 |
\par |
| 96 |
\directlua{cloze.unregister_callback('par')} |
| 97 |
} |
| 98 |
% \end{macrocode} |
| 99 |
% \end{environment} |
| 100 |
% |
| 101 |
% \begin{macro}{\clozeparplain} |
| 102 |
% \begin{macrocode} |
| 103 |
\let\clozeparplain=\undefined |
| 104 |
\NewDocumentCommand{ \clozeparplain }{ O{} m } |
| 105 |
{ |
| 106 |
\ClozePar{#1}{#2} |
| 107 |
} |
| 108 |
% \end{macrocode} |
| 109 |
% \end{macro} |
| 110 |
% |
| 111 |
% \begin{environment}{clozebox} |
| 112 |
% For the box rule a \cmd{\fbox} is used. We store the original rule |
| 113 |
% thickness and restore the dimension after the clozebox is set. |
| 114 |
% The dimension |fboxrule| have to be set before the environment |
| 115 |
% |lrbox|. |
| 116 |
% \begin{macrocode} |
| 117 |
\newsavebox{\ClozeBox} |
| 118 |
\NewDocumentEnvironment{ clozebox }{ s O{} +b } |
| 119 |
{ |
| 120 |
\directlua |
| 121 |
{ |
| 122 |
cloze.print_box('\luaescapestring{\unexpanded{#3}}','\luaescapestring{\unexpanded{#2}}','\luaescapestring{\unexpanded{#1}}') |
| 123 |
} |
| 124 |
} |
| 125 |
{ |
| 126 |
\directlua |
| 127 |
{ |
| 128 |
cloze.restore_fboxrule() |
| 129 |
} |
| 130 |
} |
| 131 |
% \end{macrocode} |
| 132 |
% \end{environment} |
| 133 |
% |
| 134 |
% \begin{environment}{clozespace} |
| 135 |
% TODO: Realization without setspace package. |
| 136 |
% \begin{macrocode} |
| 137 |
\NewDocumentEnvironment { clozespace } { O {} } |
| 138 |
{ |
| 139 |
\directlua{cloze.print_space('#1')} |
| 140 |
} |
| 141 |
{ |
| 142 |
\end{spacing} |
| 143 |
} |
| 144 |
% \end{macrocode} |
| 145 |
% \end{environment} |
| 146 |
% |
| 147 |
% \begin{macro}{\clozeline} |
| 148 |
% \begin{macrocode} |
| 149 |
\let\clozeline=\undefined |
| 150 |
\NewDocumentCommand{ \clozeline }{ O{} } |
| 151 |
{ |
| 152 |
\ClozeLine{#1} |
| 153 |
} |
| 154 |
% \end{macrocode} |
| 155 |
% \end{macro} |
| 156 |
% |
| 157 |
% \begin{macro}{\clozelinefil} |
| 158 |
% \begin{macrocode} |
| 159 |
\let\clozelinefil=\undefined |
| 160 |
\NewDocumentCommand{ \clozelinefil }{ O{} } |
| 161 |
{ |
| 162 |
\ClozeLinefil{#1} |
| 163 |
|
| 164 |
} |
| 165 |
% \end{macrocode} |
| 166 |
% \end{macro} |
| 167 |
% |
| 168 |
% \begin{macro}{\clozefil} |
| 169 |
% \begin{macrocode} |
| 170 |
\let\clozefil=\undefined |
| 171 |
\NewDocumentCommand{ \clozefil} { O{} m } |
| 172 |
{ |
| 173 |
\cloze[#1]{#2}\clozelinefil[#1] |
| 174 |
} |
| 175 |
% \end{macrocode} |
| 176 |
% \end{macro} |
| 177 |
% |
| 178 |
% \begin{macro}{\clozeextend} |
| 179 |
% \begin{macrocode} |
| 180 |
\let\clozeextend=\undefined |
| 181 |
\NewDocumentCommand{ \clozeextend } { O{} } |
| 182 |
{ |
| 183 |
\ClozeExtend{#1} |
| 184 |
} |
| 185 |
% \end{macrocode} |
| 186 |
% \end{macro} |
| 187 |
% |
| 188 |
% \begin{macrocode} |
| 189 |
\ExplSyntaxOff |
| 190 |
% \end{macrocode} |