| 1 |
%% cloze.tex |
| 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 |
% \subsection{The file \tt{cloze.tex}} |
| 20 |
% |
| 21 |
% The cloze package uses following naming conventions: Internal / private |
| 22 |
% macros / commands / envirnoments are written in PascalCase, public |
| 23 |
% ones are written in lowercase. Earlier versions of this package used |
| 24 |
% @ characters for private macros. The lower level / private macros |
| 25 |
% are now defined in the plain Lua\TeX{} version of the package and |
| 26 |
% used to set cloze text in plain Lua\TeX{}. |
| 27 |
% |
| 28 |
% \begin{macrocode} |
| 29 |
\directlua{ |
| 30 |
cloze = require('cloze') |
| 31 |
cloze.register_functions() |
| 32 |
} |
| 33 |
% \end{macrocode} |
| 34 |
% |
| 35 |
% \begin{macrocode} |
| 36 |
\input farbe.tex |
| 37 |
% \end{macrocode} |
| 38 |
% |
| 39 |
% \subsubsection{Internal macros} |
| 40 |
% |
| 41 |
% \begin{macro}{\ClozeGetOption} |
| 42 |
% This macro is used in the documentation to show the default values |
| 43 |
% of some options. |
| 44 |
% \begin{macrocode} |
| 45 |
\def\ClozeGetOption#1{% |
| 46 |
\directlua{ |
| 47 |
tex.print(cloze.get_option('#1')) |
| 48 |
}% |
| 49 |
} |
| 50 |
% \end{macrocode} |
| 51 |
% \end{macro} |
| 52 |
% |
| 53 |
% \begin{macro}{\ClozeStartMarker} |
| 54 |
% At the begining |\ClozeStartMarker| registers the required Lua |
| 55 |
% callbacks. Then it inserts a whatsit marker which marks the begin of a |
| 56 |
% gap. |
| 57 |
% \begin{macrocode} |
| 58 |
\def\ClozeStartMarker#1#2{% |
| 59 |
\strut\directlua{ |
| 60 |
cloze.initialize_cloze('#1', '\luaescapestring{#2}') |
| 61 |
}% |
| 62 |
} |
| 63 |
% \end{macrocode} |
| 64 |
% \end{macro} |
| 65 |
% |
| 66 |
% \begin{macro}{\ClozeStopMarker} |
| 67 |
% \cmd{\ClozeStopMarker} inserts a whatsit marker that marks the end |
| 68 |
% of gap. |
| 69 |
% \begin{macrocode} |
| 70 |
\def\ClozeStopMarker#1{% |
| 71 |
\strut\directlua{ |
| 72 |
cloze.write_marker('#1', 'stop') |
| 73 |
}% |
| 74 |
} |
| 75 |
% \end{macrocode} |
| 76 |
% \end{macro} |
| 77 |
% |
| 78 |
% \begin{macro}{\ClozeWrapWithFont} |
| 79 |
% \cmd{\ClozeWrapWithFont} wraps the text with the font definition. |
| 80 |
% \begin{macrocode} |
| 81 |
\def\ClozeWrapWithFont#1{% |
| 82 |
{% |
| 83 |
\directlua{cloze.print_font()}\relax% |
| 84 |
#1% |
| 85 |
}% |
| 86 |
}% |
| 87 |
% \end{macrocode} |
| 88 |
% \end{macro} |
| 89 |
% |
| 90 |
% \begin{macro}{\ClozeMargin} |
| 91 |
% \cmd{\ClozeMargin} surrounds a text in a gap with two |kerns|. |
| 92 |
% \begin{macrocode} |
| 93 |
\def\ClozeMargin#1{% |
| 94 |
\directlua{cloze.write_margin_node()}% |
| 95 |
#1% |
| 96 |
\directlua{cloze.write_margin_node()}% |
| 97 |
} |
| 98 |
% \end{macrocode} |
| 99 |
% \end{macro} |
| 100 |
% |
| 101 |
% \subsubsection{Public plain \TeX{} macros} |
| 102 |
% |
| 103 |
% \begin{macro}{\clozeset} |
| 104 |
% \begin{macrocode} |
| 105 |
\def\clozeset#1{% |
| 106 |
\directlua |
| 107 |
{ |
| 108 |
cloze.parse_global_options('\luaescapestring{\unexpanded{#1}}') |
| 109 |
}% |
| 110 |
} |
| 111 |
% \end{macrocode} |
| 112 |
% \end{macro} |
| 113 |
% |
| 114 |
% |
| 115 |
% \begin{macro}{\clozereset} |
| 116 |
% \begin{macrocode} |
| 117 |
\def\clozereset{% |
| 118 |
\directlua{cloze.reset()}% |
| 119 |
} |
| 120 |
% \end{macrocode} |
| 121 |
% \end{macro} |
| 122 |
% |
| 123 |
% \begin{macro}{\clozeshow} |
| 124 |
% \begin{macrocode} |
| 125 |
\def\clozeshow{% |
| 126 |
\clozeset{show}% |
| 127 |
} |
| 128 |
% \end{macrocode} |
| 129 |
% \end{macro} |
| 130 |
% |
| 131 |
% \begin{macro}{\clozehide} |
| 132 |
% \begin{macrocode} |
| 133 |
\def\clozehide{% |
| 134 |
\clozeset{hide}% |
| 135 |
} |
| 136 |
% \end{macrocode} |
| 137 |
% \end{macro} |
| 138 |
% |
| 139 |
% \begin{macro}{\clozefont} |
| 140 |
% \begin{macrocode} |
| 141 |
\def\clozefont{\it} |
| 142 |
% \end{macrocode} |
| 143 |
% \end{macro} |
| 144 |
% |
| 145 |
% \begin{macro}{\clozesetfont} |
| 146 |
% \begin{macrocode} |
| 147 |
\def\clozesetfont#1{% |
| 148 |
\def\clozefont{% |
| 149 |
#1% |
| 150 |
}% |
| 151 |
} |
| 152 |
% \end{macrocode} |
| 153 |
% \end{macro} |
| 154 |
% |
| 155 |
% \begin{macro}{\Cloze} |
| 156 |
% \cmd{\Cloze}\marg{cloze-type}\marg{kv-string}\marg{text} |
| 157 |
% \begin{macrocode} |
| 158 |
\def\Cloze#1#2#3{% |
| 159 |
\ClozeStartMarker{#1}{#2}% |
| 160 |
\ClozeWrapWithFont{% |
| 161 |
\ClozeMargin{#3}% |
| 162 |
}% |
| 163 |
\ClozeStopMarker{#1}% |
| 164 |
} |
| 165 |
% \end{macrocode} |
| 166 |
% \end{macro} |
| 167 |
% |
| 168 |
% \begin{macro}{\ClozeLine} |
| 169 |
% This is the plain Lua\TeX-Version of the macro \cmd{\clozeline}. |
| 170 |
% \begin{macrocode} |
| 171 |
\def\ClozeLine#1{% |
| 172 |
\directlua{ |
| 173 |
cloze.parse_local_options('\luaescapestring{#1}') |
| 174 |
cloze.write_line_nodes() |
| 175 |
}% |
| 176 |
} |
| 177 |
% \end{macrocode} |
| 178 |
% \end{macro} |
| 179 |
% |
| 180 |
% \begin{macro}{\ClozeLinefil} |
| 181 |
% This is the plain Lua\TeX-Version of the macro \cmd{\clozelinefil}. |
| 182 |
% \begin{macrocode} |
| 183 |
\def\ClozeLinefil#1{% |
| 184 |
\strut% |
| 185 |
\directlua{ |
| 186 |
cloze.parse_local_options('\luaescapestring{#1}') |
| 187 |
cloze.write_linefil_nodes() |
| 188 |
}% |
| 189 |
\strut% |
| 190 |
} |
| 191 |
% \end{macrocode} |
| 192 |
% \end{macro} |
| 193 |
% |
| 194 |
% \begin{macro}{\ClozeFil} |
| 195 |
% This is the plain Lua\TeX-Version of the macro \cmd{\clozefil}. |
| 196 |
% \begin{macrocode} |
| 197 |
\def\ClozeFil#1#2{% |
| 198 |
\Cloze{basic}{#1}{#2}\ClozeLinefil{#1}% |
| 199 |
} |
| 200 |
% \end{macrocode} |
| 201 |
% \end{macro} |
| 202 |
% |
| 203 |
% \begin{macro}{\ClozeStrike} |
| 204 |
% \begin{macrocode} |
| 205 |
\def\ClozeStrike#1#2#3{% |
| 206 |
\ClozeStartMarker{strike}{#1}% |
| 207 |
\vbox{\hbox{\kern0pt\ClozeWrapWithFont{#3}}\hbox{#2}}% |
| 208 |
\ClozeStopMarker{strike}% |
| 209 |
} |
| 210 |
% \end{macrocode} |
| 211 |
% \end{macro} |
| 212 |
% |
| 213 |
% \begin{macro}{\ClozePar} |
| 214 |
% \cmd{\ClozePar}\marg{kv-string}\marg{text} |
| 215 |
% \begin{macrocode} |
| 216 |
\def\ClozePar#1#2{% |
| 217 |
\par% |
| 218 |
\ClozeStartMarker{par}{#1}% |
| 219 |
\ClozeWrapWithFont{#2}% |
| 220 |
\ClozeStopMarker{par}% |
| 221 |
\par% |
| 222 |
\directlua{cloze.unregister_callback('par')}% |
| 223 |
} |
| 224 |
% \end{macrocode} |
| 225 |
% \end{macro} |
| 226 |
% |
| 227 |
% \begin{macro}{\clozeparcapture} |
| 228 |
% \begin{macrocode} |
| 229 |
\def\clozeparcapture#1\par {% |
| 230 |
\ClozePar{}{#1}% |
| 231 |
} |
| 232 |
\let\clozeparcmd=\clozeparcapture |
| 233 |
% \end{macrocode} |
| 234 |
% \end{macro} |
| 235 |
|
| 236 |
% \begin{macro}{\ClozeExtend} |
| 237 |
% TODO: Use node library to create kern nodes. |
| 238 |
% \begin{macrocode} |
| 239 |
\def\ClozeExtend#1{% |
| 240 |
\directlua |
| 241 |
{ |
| 242 |
cloze.print_extension('\luaescapestring{#1}') |
| 243 |
}% |
| 244 |
} |
| 245 |
% \end{macrocode} |
| 246 |
% \end{macro} |