| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% File: expkv-opt.dtx Copyright (C) 2020-2024 Jonathan P. Spratte |
| 4 |
% |
| 5 |
% This work may be distributed and/or modified under the conditions of the |
| 6 |
% LaTeX Project Public License (LPPL), either version 1.3c of this license or |
| 7 |
% (at your option) any later version. The latest version of this license is in |
| 8 |
% the file: |
| 9 |
% |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% ------------------------------------------------------------------------------ |
| 13 |
% |
| 14 |
%<*driver>^^A>>= |
| 15 |
\def\expkvDocNoGenerate{} |
| 16 |
\input expkv-bundle.ins |
| 17 |
\generate{\file{expkv-opt.sty}{\from{expkv-opt.dtx}{pkg}}} |
| 18 |
\endbatchfile |
| 19 |
%</driver>^^A=<< |
| 20 |
% \fi |
| 21 |
% |
| 22 |
% \section{\expkvo} |
| 23 |
% |
| 24 |
% \gobbledocstriptag |
| 25 |
%<*pkg> |
| 26 |
% |
| 27 |
% First we check whether the \LaTeXe\ kernel supports raw options. If it doesn't |
| 28 |
% we check whether a specific version was requested, and if that's not the case |
| 29 |
% we manually run |\pkgcls@parse@date@arg| with the last version that supported |
| 30 |
% non-raw options. |
| 31 |
% \begin{macrocode} |
| 32 |
\IfFormatAtLeastTF{2021/05/01} |
| 33 |
{} |
| 34 |
{% |
| 35 |
\ifx\pkgcls@targetlabel\@empty |
| 36 |
\ifnum\requestedLaTeXdate=\pkgcls@targetdate |
| 37 |
\pkgcls@parse@date@arg{=v0.1}% |
| 38 |
\fi |
| 39 |
\fi |
| 40 |
} |
| 41 |
% \end{macrocode} |
| 42 |
% Then we tell \LaTeXe\ where to find which release so that the package rollback |
| 43 |
% code of \LaTeXe\ can do its thing. |
| 44 |
% \begin{macrocode} |
| 45 |
\DeclareRelease{v0.1}{2020/10/10}{expkv-opt-2020-10-10.sty} |
| 46 |
\DeclareCurrentRelease{v0.2}{2021/04/04} |
| 47 |
% \end{macrocode} |
| 48 |
% |
| 49 |
% Start the package with the typical \LaTeX\ standards. |
| 50 |
% |
| 51 |
% \begin{macro}{\ekvoVersion,\ekvoDate} |
| 52 |
% Store the package's version and date in two macros. |
| 53 |
% \begin{macrocode} |
| 54 |
\newcommand*\ekvoVersion{1.1} |
| 55 |
\newcommand*\ekvoDate{2024-12-16} |
| 56 |
% \end{macrocode} |
| 57 |
% \end{macro} |
| 58 |
% And we report who we are and what we need. |
| 59 |
% \begin{macrocode} |
| 60 |
\ProvidesPackage{expkv-opt} |
| 61 |
[% |
| 62 |
\ekvoDate\space v\ekvoVersion\space |
| 63 |
parse class and package options with expkv% |
| 64 |
] |
| 65 |
\RequirePackage{expkv} |
| 66 |
% \end{macrocode} |
| 67 |
% |
| 68 |
% |
| 69 |
% \subsection{Loop} |
| 70 |
% |
| 71 |
% \begin{macro}[internal] |
| 72 |
% {\ekvo@CurrentOption@loop,\ekvo@CurrentOption@loop@,\ekvo@end@loop} |
| 73 |
% We'll need some loop which can iterate over a comma separated list. The loop |
| 74 |
% is very basic and only works for commas of category~12. First we insert the |
| 75 |
% delimiters for the actual loop. The |\ekv@set@other| is necessary to get a |
| 76 |
% functional |\ekvmorekv| in this loop. |
| 77 |
% \begin{macrocode} |
| 78 |
\protected\long\def\ekvo@CurrentOption@loop#1#2% |
| 79 |
{% |
| 80 |
\ekvo@CurrentOption@loop@#2\ekv@set@other\ekv@mark#1,\ekv@stop,\ekvo@tail |
| 81 |
} |
| 82 |
% \end{macrocode} |
| 83 |
% The actual loop checks whether the final element has been read and if so |
| 84 |
% ends the loop. Else blank elements are ignored, |\CurrentOption| is set and |
| 85 |
% the macro which parses the list elements called. Then call the next |
| 86 |
% iteration. |
| 87 |
% \begin{macrocode} |
| 88 |
\long\def\ekvo@CurrentOption@loop@#1\ekv@set@other#2,% |
| 89 |
{% |
| 90 |
\ekv@gobble@from@mark@to@stop#2\ekvo@end@loop\ekv@stop |
| 91 |
\ekv@ifblank{#2}% |
| 92 |
{}% |
| 93 |
{% |
| 94 |
\edef\CurrentOption{\unexpanded\expandafter{\ekv@gobble@mark#2}}% |
| 95 |
#1{#2}% |
| 96 |
}% |
| 97 |
\ekvo@CurrentOption@loop@#1\ekv@set@other\ekv@mark |
| 98 |
} |
| 99 |
\long\def\ekvo@end@loop#1\ekvo@tail{} |
| 100 |
% \end{macrocode} |
| 101 |
% \end{macro} |
| 102 |
% |
| 103 |
% |
| 104 |
% \subsection{Tests} |
| 105 |
% |
| 106 |
% \begin{macro}[internal]{\ekvo@ifx@TF,\ekvo@ifx@T,\ekvo@ifx@F} |
| 107 |
% We'll need branching |\ifx| tests so that user input containing unbalanced |
| 108 |
% \TeX\ ifs doesn't break (at least not because of us, everything else is the |
| 109 |
% fault of \LaTeXe). |
| 110 |
% \begin{macrocode} |
| 111 |
\def\ekvo@ifx@TF#1#2{\ifx#1#2\ekv@fi@firstoftwo\fi\@secondoftwo} |
| 112 |
\def\ekvo@ifx@T#1#2{\ifx#1#2\ekv@fi@firstofone\fi\@gobble} |
| 113 |
\def\ekvo@ifx@F#1#2{\ifx#1#2\ekv@fi@gobble\fi\@firstofone} |
| 114 |
% \end{macrocode} |
| 115 |
% \end{macro} |
| 116 |
% |
| 117 |
% \begin{macro}[internal]{\ekvo@do@with@set,\ekvo@name,\ekvo@setname} |
| 118 |
% This test checks whether the \set\ is defined. If it is we store it in |
| 119 |
% |\ekvo@setname| and set |\ekvo@name| to a short cut to get the \key's |
| 120 |
% callback name. Next we execute the code in |#2|, if the \set\ isn't defined |
| 121 |
% |#2| is gobbled. |
| 122 |
% \begin{macrocode} |
| 123 |
\protected\def\ekvo@do@with@set#1#2% |
| 124 |
{% |
| 125 |
\ekvifdefinedset{#1}% |
| 126 |
{% |
| 127 |
\expandafter |
| 128 |
\let\expandafter\ekvo@name\csname\ekv@undefined@set{#1}\endcsname |
| 129 |
\def\ekvo@setname{#1}% |
| 130 |
#2% |
| 131 |
}% |
| 132 |
{\ekvo@err@undefined@set{#1}}% |
| 133 |
} |
| 134 |
% \end{macrocode} |
| 135 |
% \end{macro} |
| 136 |
% |
| 137 |
% |
| 138 |
% \subsection{Key handlers} |
| 139 |
% |
| 140 |
% \expkvo\ uses handlers specifying what happens if a parsed \key\ is defined or |
| 141 |
% undefined. |
| 142 |
% |
| 143 |
% \begin{macro}[internal] |
| 144 |
% {\ekvo@handle@undefined@k@pkg,\ekvo@handle@undefined@kv@pkg} |
| 145 |
% The case for undefined keys in a local list of a package is easy, just throw |
| 146 |
% appropriate errors. |
| 147 |
% \begin{macrocode} |
| 148 |
\protected\long\def\ekvo@handle@undefined@k@pkg#1% |
| 149 |
{% |
| 150 |
\ekv@ifdefined{\ekvo@name{#1}}% |
| 151 |
{\ekvo@err@value@required{#1}}% |
| 152 |
{\ekvo@err@undefined@key{#1}}% |
| 153 |
} |
| 154 |
\def\ekvo@handle@undefined@kv@pkg#1#2% |
| 155 |
{% |
| 156 |
\ekv@ifdefined{\ekvo@name{#1}N}% |
| 157 |
{\ekvo@err@value@forbidden{#1}}% |
| 158 |
{\ekvo@err@undefined@key{#1}}% |
| 159 |
} |
| 160 |
% \end{macrocode} |
| 161 |
% \end{macro} |
| 162 |
% |
| 163 |
% \begin{macro}[internal] |
| 164 |
% { |
| 165 |
% \ekvo@addto@unused@one,\ekvo@addto@unused@two, |
| 166 |
% \ekvo@rmfrom@unused@one,\ekvo@rmfrom@unused@two |
| 167 |
% } |
| 168 |
% These macros will add or remove the |\CurrentOption| to or from the list of |
| 169 |
% unused global options. Since |\ekvo@do@unusedoptionlist| will have some |
| 170 |
% overhead before calling the list changing macro in filtering the current |
| 171 |
% option, we use an optimization here in that we check whether the list is |
| 172 |
% empty before calling the |rmfrom| function. |
| 173 |
% \begin{macrocode} |
| 174 |
\long\def\ekvo@addto@unused@one#1{\ekvo@do@unusedoptionlist\ekvo@addnewto@list} |
| 175 |
\long\def\ekvo@addto@unused@two#1#2{\ekvo@do@unusedoptionlist\ekvo@addnewto@list} |
| 176 |
\long\def\ekvo@rmfrom@unused@one#1% |
| 177 |
{% |
| 178 |
\ekvo@ifx@F\@unusedoptionlist\@empty |
| 179 |
{\ekvo@do@unusedoptionlist\ekvo@rmfrom@list}% |
| 180 |
} |
| 181 |
\long\def\ekvo@rmfrom@unused@two#1#2% |
| 182 |
{% |
| 183 |
\ekvo@ifx@F\@unusedoptionlist\@empty |
| 184 |
{\ekvo@do@unusedoptionlist\ekvo@rmfrom@list}% |
| 185 |
} |
| 186 |
% \end{macrocode} |
| 187 |
% \end{macro} |
| 188 |
% |
| 189 |
% \begin{macro}[internal] |
| 190 |
% { |
| 191 |
% \ekvo@do@unusedoptionlist, |
| 192 |
% \ekvo@prepare@unusedoption, |
| 193 |
% \ekvo@prepare@unusedoption@a, |
| 194 |
% \ekvo@prepare@unusedoption@b, |
| 195 |
% \ekvo@prepare@unusedoption@c |
| 196 |
% } |
| 197 |
% The way the new \LaTeXe\ kernel handles the unused option list changed. Now |
| 198 |
% not the entire |\CurrentOption| is listed, but just everything up to the |
| 199 |
% first equals sign, and spaces got zapped, doesn't matter whether the raw |
| 200 |
% option list gets used or not. So we have to zap spaces and remove everything |
| 201 |
% from the first equals sign onwards. The code used here will fail if the |
| 202 |
% current option contains an |\ekv@mark| or |\ekv@stop| before the first |
| 203 |
% equals sign (this seems rather unlikely). |
| 204 |
% \begin{macrocode} |
| 205 |
\protected\def\ekvo@do@unusedoptionlist#1% |
| 206 |
{% |
| 207 |
\let\ekvo@unpreparedCurrentOption\CurrentOption |
| 208 |
\edef\CurrentOption |
| 209 |
{\expandafter\ekvo@prepare@unusedoption\CurrentOption=\ekv@mark}% |
| 210 |
#1\@unusedoptionlist |
| 211 |
\let\CurrentOption\ekvo@unpreparedCurrentOption |
| 212 |
} |
| 213 |
\def\ekvo@prepare@unusedoption{\ekvo@prepare@unusedoption@a\@empty} |
| 214 |
\def\ekvo@prepare@unusedoption@a#1% |
| 215 |
{% |
| 216 |
\long\def\ekvo@prepare@unusedoption@a##1=##2\ekv@mark |
| 217 |
{% |
| 218 |
\ekvo@prepare@unusedoption@b##1\ekv@stop |
| 219 |
\ekv@mark\ekvo@prepare@unusedoption@b |
| 220 |
#1\ekv@mark\ekvo@prepare@unusedoption@c |
| 221 |
}% |
| 222 |
} |
| 223 |
\ekvo@prepare@unusedoption@a{ } |
| 224 |
\long\def\ekvo@prepare@unusedoption@b#1 #2\ekv@mark#3{#3#1#2\ekv@mark#3} |
| 225 |
\long\def\ekvo@prepare@unusedoption@c |
| 226 |
#1\ekv@stop |
| 227 |
\ekv@mark\ekvo@prepare@unusedoption@b\ekv@mark\ekvo@prepare@unusedoption@c |
| 228 |
{\unexpanded\expandafter{#1}} |
| 229 |
% \end{macrocode} |
| 230 |
% \end{macro} |
| 231 |
% |
| 232 |
% \begin{macro}[internal] |
| 233 |
% { |
| 234 |
% \ekvo@set@handlers@local,\ekvo@set@handlers@global, |
| 235 |
% \ekvo@set@handlers@list |
| 236 |
% } |
| 237 |
% These macros are boring. They just set up the handlers to respect the rules |
| 238 |
% documented earlier. |
| 239 |
% \begin{macrocode} |
| 240 |
\protected\def\ekvo@set@handlers@local |
| 241 |
{% |
| 242 |
% \end{macrocode} |
| 243 |
% In case a class has the same option list as the global class, and there are |
| 244 |
% already options in the unused options list, it should remove known keys |
| 245 |
% from the unused options list. |
| 246 |
% \begin{macrocode} |
| 247 |
\ifx\@currext\@clsextension |
| 248 |
\unless\ifx\@classoptionslist\relax |
| 249 |
\expandafter |
| 250 |
\ifx |
| 251 |
\csname @raw@opt@\@currname.\@currext\endcsname |
| 252 |
\@raw@classoptionslist |
| 253 |
\unless\ifx\@unusedoptionlist\@empty |
| 254 |
\let\ekvo@handle@defined@k\ekvo@rmfrom@unused@one |
| 255 |
\let\ekvo@handle@defined@kv\ekvo@rmfrom@unused@two |
| 256 |
\fi |
| 257 |
\fi |
| 258 |
\fi |
| 259 |
\fi |
| 260 |
% \end{macrocode} |
| 261 |
% The normal unused handlers for a class: |
| 262 |
% \begin{macrocode} |
| 263 |
\ekvo@if@need@handlers |
| 264 |
{% |
| 265 |
\ifx\@currext\@clsextension |
| 266 |
\ifx\@classoptionslist\relax |
| 267 |
\let\ekvo@handle@undefined@k\@gobble |
| 268 |
\let\ekvo@handle@undefined@kv\@gobbletwo |
| 269 |
\else |
| 270 |
\expandafter |
| 271 |
\ifx |
| 272 |
\csname @raw@opt@\@currname.\@currext\endcsname |
| 273 |
\@raw@classoptionslist |
| 274 |
\let\ekvo@handle@undefined@k\ekvo@addto@unused@one |
| 275 |
\let\ekvo@handle@undefined@kv\ekvo@addto@unused@two |
| 276 |
\else |
| 277 |
\let\ekvo@handle@undefined@k\@gobble |
| 278 |
\let\ekvo@handle@undefined@kv\@gobbletwo |
| 279 |
\fi |
| 280 |
\fi |
| 281 |
\else |
| 282 |
\let\ekvo@handle@undefined@k\ekvo@handle@undefined@k@pkg |
| 283 |
\let\ekvo@handle@undefined@kv\ekvo@handle@undefined@kv@pkg |
| 284 |
\fi |
| 285 |
}% |
| 286 |
} |
| 287 |
\protected\def\ekvo@set@handlers@global |
| 288 |
{% |
| 289 |
\unless\ifx\@unusedoptionlist\@empty |
| 290 |
\let\ekvo@handle@defined@k\ekvo@rmfrom@unused@one |
| 291 |
\let\ekvo@handle@defined@kv\ekvo@rmfrom@unused@two |
| 292 |
\fi |
| 293 |
\ekvo@if@need@handlers |
| 294 |
{% |
| 295 |
\let\ekvo@handle@undefined@k\@gobble |
| 296 |
\let\ekvo@handle@undefined@kv\@gobbletwo |
| 297 |
}% |
| 298 |
} |
| 299 |
\protected\def\ekvo@set@handlers@list |
| 300 |
{% |
| 301 |
\ekvo@if@need@handlers |
| 302 |
{% |
| 303 |
\let\ekvo@handle@undefined@k\@gobble |
| 304 |
\let\ekvo@handle@undefined@kv\@gobbletwo |
| 305 |
}% |
| 306 |
} |
| 307 |
% \end{macrocode} |
| 308 |
% \end{macro} |
| 309 |
% |
| 310 |
% \begin{macro}[internal]{\ekvo@if@need@handlers,\ekvo@dont@need@handlers} |
| 311 |
% If the user specifies handlers this macro will be let to |
| 312 |
% |\ekvo@dont@need@handlers|, which will act like |\@gobble| and also let it |
| 313 |
% to |\@firstofone| afterwards. |
| 314 |
% \begin{macrocode} |
| 315 |
\let\ekvo@if@need@handlers\@firstofone |
| 316 |
\protected\long\def\ekvo@dont@need@handlers#1% |
| 317 |
{% |
| 318 |
\let\ekvo@if@need@handlers\@firstofone |
| 319 |
}% |
| 320 |
% \end{macrocode} |
| 321 |
% \end{macro} |
| 322 |
% |
| 323 |
% We have to set the default for the handlers of defined keys, because they |
| 324 |
% don't necessarily get defined before a list is parsed. |
| 325 |
% \begin{macrocode} |
| 326 |
\let\ekvo@handle@defined@k\@gobble |
| 327 |
\let\ekvo@handle@defined@kv\@gobbletwo |
| 328 |
% \end{macrocode} |
| 329 |
% |
| 330 |
% |
| 331 |
% \subsection{Processing list elements} |
| 332 |
% |
| 333 |
% \begin{macro}[internal]{\ekvo@process@common} |
| 334 |
% All the key processing frontend macros use the same basic structure. |#1| |
| 335 |
% will be a simple test, deciding whether the list will really be parsed or |
| 336 |
% not, |#3| will be the \set, and |#2| will be the individual code of the |
| 337 |
% frontend macro which should be executed if both the test in |#1| is true and |
| 338 |
% the \set\ is defined. |
| 339 |
% \begin{macrocode} |
| 340 |
\protected\def\ekvo@process@common#1#2#3% |
| 341 |
{% |
| 342 |
#1{\ekvo@do@with@set{#3}{#2}}% |
| 343 |
} |
| 344 |
% \end{macrocode} |
| 345 |
% \end{macro} |
| 346 |
% |
| 347 |
% \begin{macro}[internal]{\ekvo@process@list} |
| 348 |
% This macro only expands the list holding macro and forwards it to the |
| 349 |
% loop macro. |
| 350 |
% \begin{macrocode} |
| 351 |
\protected\def\ekvo@process@list#1% |
| 352 |
{% |
| 353 |
\expandafter\ekvo@CurrentOption@loop\expandafter{#1}\ekvo@parse |
| 354 |
} |
| 355 |
% \end{macrocode} |
| 356 |
% \end{macro} |
| 357 |
% |
| 358 |
% \begin{macro}[internal] |
| 359 |
% { |
| 360 |
% \ekvo@parse, |
| 361 |
% \ekvo@parse@kv,\ekvo@parse@kv@,\ekvo@expansion@kv,\ekvo@expansion@kv@, |
| 362 |
% \ekvo@parse@k, \ekvo@parse@k@, \ekvo@expansion@k, \ekvo@expansion@k@ |
| 363 |
% } |
| 364 |
% This macro calls internals of \expkv\ such that the input is split at an |
| 365 |
% equals sign of category other. |
| 366 |
% \begin{macrocode} |
| 367 |
\long\def\ekvo@parse#1% |
| 368 |
{% |
| 369 |
\ekv@eq@other#1\ekv@nil\ekv@mark\ekvo@parse@kv |
| 370 |
=\ekv@mark\ekvo@parse@k |
| 371 |
} |
| 372 |
% \end{macrocode} |
| 373 |
% If there was an equals sign, this will be called and remove the remainder of |
| 374 |
% the split. Afterwards the \expnotation\ is checked and possibly executed, |
| 375 |
% and the \kv\ pair is set. While reinsertion works via the |Rr| |
| 376 |
% \expansion-rule, it might affect the unused global option list. |
| 377 |
% \begin{macrocode} |
| 378 |
\long\def\ekvo@parse@kv#1\ekv@stop#2\ekv@nil=\ekv@mark\ekvo@parse@k |
| 379 |
{\ekv@strip{#2}{\ekv@strip{#1}\ekvo@parse@kv@}} |
| 380 |
\long\def\ekvo@parse@kv@#1#2% |
| 381 |
{% |
| 382 |
\ekv@ifexp{#1}% |
| 383 |
{\ekvo@expansion@kv{#2}}% |
| 384 |
{\ekvo@set@kv{#1}{#2}}% |
| 385 |
} |
| 386 |
% \end{macrocode} |
| 387 |
% Check for \expansion-rules was true, now we need to execute them, and use |
| 388 |
% the result in |\ekvo@set@kv|. Also we have to handle the key as if it was a |
| 389 |
% defined key if the |\r| \expansion-rule was found (which potentially removes |
| 390 |
% it from the list of global unused options). |
| 391 |
% \begin{macrocode} |
| 392 |
\long\def\ekvo@expansion@kv#1#2#3#4% |
| 393 |
{% |
| 394 |
\ekv@expansion@rule@{#1}#2\ekv@mark\ekv@stop{#3}{}% |
| 395 |
{\ekvo@handle@defined@kv{#3}{#1}\ekvmorekv}% |
| 396 |
\ekvo@expansion@kv@ |
| 397 |
} |
| 398 |
\long\def\ekvo@expansion@kv@#1#2{\ekvo@set@kv{#1}{#2}} |
| 399 |
% \end{macrocode} |
| 400 |
% And basically the same two biggish steps, but for the case that no equals |
| 401 |
% sign is found. |
| 402 |
% \begin{macrocode} |
| 403 |
\long\def\ekvo@parse@k#1\ekv@nil\ekv@mark\ekvo@parse@kv\ekv@stop\ekv@mark |
| 404 |
{\ekv@strip{#1}\ekvo@parse@k@} |
| 405 |
\long\def\ekvo@parse@k@#1% |
| 406 |
{% |
| 407 |
\ekv@ifexp{#1}% |
| 408 |
\ekvo@expansion@k |
| 409 |
{\ekvo@set@k{#1}}% |
| 410 |
} |
| 411 |
\long\def\ekvo@expansion@k#1#2#3% |
| 412 |
{% |
| 413 |
\ekv@expansion@rule@{#2}#1\ekv@mark\ekv@stop{}{}% |
| 414 |
{\ekvo@handle@defined@k{#2}\ekvmorekv}% |
| 415 |
\ekvo@expansion@k@ |
| 416 |
} |
| 417 |
\long\def\ekvo@expansion@k@#1#2{\ekvo@set@k{#2}} |
| 418 |
% \end{macrocode} |
| 419 |
% \end{macro} |
| 420 |
% |
| 421 |
% \begin{macro}[internal]{\ekvo@set@k,\ekvo@set@kv} |
| 422 |
% These two macros check whether the key is defined and if so call the handler |
| 423 |
% for defined keys and execute the key, else the handler for undefined keys is |
| 424 |
% called. |
| 425 |
% \begin{macrocode} |
| 426 |
\protected\def\ekvo@set@k#1% |
| 427 |
{% |
| 428 |
\ekv@ifdefined{\ekvo@name{#1}N}% |
| 429 |
{% |
| 430 |
\ekvo@handle@defined@k{#1}% |
| 431 |
\csname\ekvo@name{#1}N\endcsname |
| 432 |
}% |
| 433 |
{\ekvo@handle@undefined@k{#1}}% |
| 434 |
} |
| 435 |
\protected\def\ekvo@set@kv#1#2% |
| 436 |
{% |
| 437 |
\ekv@ifdefined{\ekvo@name{#1}}% |
| 438 |
{% |
| 439 |
\ekvo@handle@defined@kv{#1}{#2}% |
| 440 |
\csname\ekvo@name{#1}\endcsname{#2}% |
| 441 |
}% |
| 442 |
{\ekvo@handle@undefined@kv{#1}{#2}}% |
| 443 |
} |
| 444 |
% \end{macrocode} |
| 445 |
% \end{macro} |
| 446 |
% |
| 447 |
% |
| 448 |
% \subsection{List variable helpers} |
| 449 |
% |
| 450 |
% \begin{macro}[internal]{\ekvo@addto@list} |
| 451 |
% This macro is rather simple. If the list to which the |\CurrentOption| |
| 452 |
% should be added is empty we can just let the list to the |\CurrentOption|. |
| 453 |
% Else we have to expand the list once and the |\CurrentOption| once. |
| 454 |
% \begin{macrocode} |
| 455 |
\protected\def\ekvo@addto@list#1% |
| 456 |
{% |
| 457 |
\ekvo@ifx@TF#1\@empty |
| 458 |
{\let#1\CurrentOption}% |
| 459 |
{% |
| 460 |
\edef#1% |
| 461 |
{% |
| 462 |
\unexpanded\expandafter{#1},% |
| 463 |
\unexpanded\expandafter{\CurrentOption}% |
| 464 |
}% |
| 465 |
}% |
| 466 |
} |
| 467 |
% \end{macrocode} |
| 468 |
% \end{macro} |
| 469 |
% |
| 470 |
% \begin{macro}[internal]{\ekvo@addnewto@list} |
| 471 |
% This works just like |\ekvo@addto@list|, but it only adds elements which are |
| 472 |
% not yet part of the list, hence we check if the option is already in the |
| 473 |
% list. |
| 474 |
% \begin{macrocode} |
| 475 |
\protected\def\ekvo@addnewto@list#1% |
| 476 |
{% |
| 477 |
\ekvo@ifx@TF#1\@empty |
| 478 |
{\let#1\CurrentOption}% |
| 479 |
{% |
| 480 |
\ekvo@if@in@list#1% |
| 481 |
{}% |
| 482 |
{% |
| 483 |
\edef#1% |
| 484 |
{% |
| 485 |
\unexpanded\expandafter{#1},% |
| 486 |
\unexpanded\expandafter{\CurrentOption}% |
| 487 |
}% |
| 488 |
}% |
| 489 |
}% |
| 490 |
} |
| 491 |
% \end{macrocode} |
| 492 |
% \end{macro} |
| 493 |
% |
| 494 |
% \begin{macro}[internal] |
| 495 |
% {\ekvo@if@in@list,\ekvo@if@in@list@,\ekvo@if@in@list@result} |
| 496 |
% This is a slow but robust test whether some option is already contained in a |
| 497 |
% list. Using argument gobbling logic would be faster, but that way wouldn't |
| 498 |
% be robust for elements containing |{|, |}|, or |#|. Just loop over the code |
| 499 |
% and compare each element, end early if a match is found. |
| 500 |
% \begin{macrocode} |
| 501 |
\protected\def\ekvo@if@in@list#1% |
| 502 |
{% |
| 503 |
\ekvo@ifx@TF#1\@empty |
| 504 |
\@secondoftwo |
| 505 |
{% |
| 506 |
\let\ekvo@curropt\CurrentOption |
| 507 |
\let\ekvo@if@in@list@result\@secondoftwo |
| 508 |
\expandafter\ekvo@CurrentOption@loop\expandafter{#1}\ekvo@if@in@list@ |
| 509 |
\let\CurrentOption\ekvo@curropt |
| 510 |
\ekvo@if@in@list@result |
| 511 |
}% |
| 512 |
} |
| 513 |
\protected\long\def\ekvo@if@in@list@#1% |
| 514 |
{% |
| 515 |
\ekvo@ifx@T\ekvo@curropt\CurrentOption |
| 516 |
{% |
| 517 |
\let\ekvo@if@in@list@result\@firstoftwo |
| 518 |
\ekvo@end@loop |
| 519 |
}% |
| 520 |
} |
| 521 |
% \end{macrocode} |
| 522 |
% \end{macro} |
| 523 |
% |
| 524 |
% \begin{macro}[internal]{\ekvo@rmfrom@list,\ekvo@rmfrom@list@} |
| 525 |
% This works by looping over every list item and comparing it to |
| 526 |
% |\ekvo@curropt| which stores the real |\CurrentOption|. This is |
| 527 |
% comparatively slow, but works for items containing braces unlike what |
| 528 |
% \LaTeXe\ does. We could be faster for items not containing braces, though. |
| 529 |
% \begin{macrocode} |
| 530 |
\protected\def\ekvo@rmfrom@list#1% |
| 531 |
{% |
| 532 |
\ekvo@ifx@F#1\@empty |
| 533 |
{% |
| 534 |
\let\ekvo@tmp@list\@empty |
| 535 |
\let\ekvo@curropt\CurrentOption |
| 536 |
\expandafter\ekvo@CurrentOption@loop\expandafter{#1}\ekvo@rmfrom@list@ |
| 537 |
\let\CurrentOption\ekvo@curropt |
| 538 |
\let#1\ekvo@tmp@list |
| 539 |
}% |
| 540 |
} |
| 541 |
\protected\long\def\ekvo@rmfrom@list@#1% |
| 542 |
{% |
| 543 |
\ekvo@ifx@F\CurrentOption\ekvo@curropt |
| 544 |
{\ekvo@addto@list\ekvo@tmp@list}% |
| 545 |
} |
| 546 |
% \end{macrocode} |
| 547 |
% \end{macro} |
| 548 |
% |
| 549 |
% |
| 550 |
% \subsection{Errors} |
| 551 |
% |
| 552 |
% \begin{macro}[internal] |
| 553 |
% { |
| 554 |
% \ekvo@err@undefined@key,\ekvo@err@value@required, |
| 555 |
% \ekvo@err@value@forbidden,\ekvo@err@undefined@set |
| 556 |
% } |
| 557 |
% Just some macros to throw errors in the few cases an error has to be thrown. |
| 558 |
% \begin{macrocode} |
| 559 |
\protected\def\ekvo@err@undefined@key#1% |
| 560 |
{% |
| 561 |
\ekvo@pkg@cls@error |
| 562 |
{Undefined option `\detokenize{#1}'}% |
| 563 |
{The used option was not defined. Perhaps you misspelled it?}% |
| 564 |
} |
| 565 |
\protected\def\ekvo@err@value@required#1% |
| 566 |
{% |
| 567 |
\ekvo@pkg@cls@error |
| 568 |
{Missing value for option `\detokenize{#1}'}% |
| 569 |
{The used option requires a value or you misspelled its name.}% |
| 570 |
} |
| 571 |
\protected\def\ekvo@err@value@forbidden#1% |
| 572 |
{% |
| 573 |
\ekvo@pkg@cls@error |
| 574 |
{Unwanted value for option `\detokenize{#1}'}% |
| 575 |
{The used option doesn't support a value or you misspelled its name.}% |
| 576 |
} |
| 577 |
\protected\def\ekvo@err@undefined@set#1% |
| 578 |
{% |
| 579 |
\PackageError{expkv-opt}% |
| 580 |
{Undefined set `#1'}% |
| 581 |
{The set for which you try to parse options isn't defined in expkv.}% |
| 582 |
} |
| 583 |
\protected\def\ekvo@pkg@cls@error |
| 584 |
{% |
| 585 |
\ekvo@ifx@TF\@currext\@clsextension |
| 586 |
\ClassError |
| 587 |
\PackageError |
| 588 |
\@currname |
| 589 |
} |
| 590 |
% \end{macrocode} |
| 591 |
% \end{macro} |
| 592 |
% |
| 593 |
% |
| 594 |
% \subsection{User Interface} |
| 595 |
% |
| 596 |
% The user interface macros just put together the bits and pieces. |
| 597 |
% |
| 598 |
% \begin{macro}{\ekvoProcessOptions} |
| 599 |
% First we check if user-defined handlers were used. If that's the case we |
| 600 |
% need to store them and restore them for each list processor. Else just call |
| 601 |
% them sequentially. |
| 602 |
% \begin{macrocode} |
| 603 |
\protected\def\ekvoProcessOptions#1% |
| 604 |
{% |
| 605 |
\ekvo@if@need@handlers |
| 606 |
{% |
| 607 |
\ekvoProcessGlobalOptions{#1}% |
| 608 |
\ekvoProcessLocalOptions {#1}% |
| 609 |
\ekvoProcessFutureOptions{#1}% |
| 610 |
\@gobbletwo |
| 611 |
}% |
| 612 |
\@firstofone |
| 613 |
{% |
| 614 |
\let\ekvo@tmpa\ekvo@handle@undefined@k |
| 615 |
\let\ekvo@tmpb\ekvo@handle@undefined@kv |
| 616 |
\ekvoUseUnknownHandlers\ekvo@tmpa\ekvo@tmpb |
| 617 |
\ekvoProcessGlobalOptions{#1}% |
| 618 |
\ekvoUseUnknownHandlers\ekvo@tmpa\ekvo@tmpb |
| 619 |
\ekvoProcessLocalOptions {#1}% |
| 620 |
\ekvoUseUnknownHandlers\ekvo@tmpa\ekvo@tmpb |
| 621 |
\ekvoProcessFutureOptions{#1}% |
| 622 |
\let\ekvo@tmpa\ekvo@undefined |
| 623 |
\let\ekvo@tmpb\ekvo@undefined |
| 624 |
}% |
| 625 |
} |
| 626 |
% \end{macrocode} |
| 627 |
% \end{macro} |
| 628 |
% |
| 629 |
% \begin{macro}{\ekvoProcessLocalOptions} |
| 630 |
% \begin{macrocode} |
| 631 |
\protected\def\ekvoProcessLocalOptions |
| 632 |
{% |
| 633 |
\ekvo@process@common |
| 634 |
{\ekv@ifdefined{@raw@opt@\@currname.\@currext}\@firstofone\@gobble}% |
| 635 |
{% |
| 636 |
\ekvo@set@handlers@local |
| 637 |
\expandafter |
| 638 |
\ekvo@process@list\csname @raw@opt@\@currname.\@currext\endcsname |
| 639 |
\AtEndOfPackage{\let\@unprocessedoptions\relax}% |
| 640 |
}% |
| 641 |
} |
| 642 |
% \end{macrocode} |
| 643 |
% \end{macro} |
| 644 |
% |
| 645 |
% \begin{macro}{\ekvoProcessGlobalOptions} |
| 646 |
% \begin{macrocode} |
| 647 |
\protected\def\ekvoProcessGlobalOptions |
| 648 |
{% |
| 649 |
\ekvo@process@common{\ekvo@ifx@F\@classoptionslist\relax}% |
| 650 |
{% |
| 651 |
\ekvo@set@handlers@global |
| 652 |
\ekvo@process@list\@raw@classoptionslist |
| 653 |
\let\ekvo@handle@defined@k\@gobble |
| 654 |
\let\ekvo@handle@defined@kv\@gobbletwo |
| 655 |
}% |
| 656 |
} |
| 657 |
% \end{macrocode} |
| 658 |
% \end{macro} |
| 659 |
% |
| 660 |
% \begin{macro}{\ekvoProcessFutureOptions} |
| 661 |
% Parsing future options (without patching kernel internals) is only possible |
| 662 |
% with kernel versions after 2022-11-01. |
| 663 |
% The user macro needs to store the user-set handlers for later if |
| 664 |
% |\ekvoUseUnknownHandlers| was used. Then it stores the correct code to |
| 665 |
% process future options in the |opt@handler@| variable. |
| 666 |
% \begin{macrocode} |
| 667 |
\IfFormatAtLeastTF{2022/11/01} |
| 668 |
{% |
| 669 |
\protected\def\ekvoProcessFutureOptions#1% |
| 670 |
{% |
| 671 |
\ekvo@if@need@handlers\@gobbletwo |
| 672 |
\@firstofone |
| 673 |
{% |
| 674 |
\expandafter\let |
| 675 |
\csname ekvo@future@undefined@k@\@currname.\@currext\endcsname |
| 676 |
\ekvo@handle@undefined@k |
| 677 |
\expandafter\let |
| 678 |
\csname ekvo@future@undefined@kv@\@currname.\@currext\endcsname |
| 679 |
\ekvo@handle@undefined@kv |
| 680 |
}% |
| 681 |
\protected\expandafter |
| 682 |
\xdef\csname opt@handler@\@currname.\@currext\endcsname |
| 683 |
{\ekv@unexpanded{\ekvo@future{#1}}}% |
| 684 |
} |
| 685 |
% \end{macrocode} |
| 686 |
% \begin{macro}[internal]{\ekvo@future,\ekvo@set@handlers@future} |
| 687 |
% Key parsing is pretty similar to |\ekvoProcessLocalOptions|, only the |
| 688 |
% handlers are defined differently, namely it is checked whether they are |
| 689 |
% user-specified, if not we reuse the undefined handlers for packages (which |
| 690 |
% will throw an error if an unknown key is found). |
| 691 |
% \begin{macrocode} |
| 692 |
\protected\def\ekvo@future |
| 693 |
{% |
| 694 |
\ekvo@process@common |
| 695 |
{\ekv@ifdefined{@raw@opt@\@currname.\@currext}\@firstofone\@gobble}% |
| 696 |
{% |
| 697 |
\ekvo@set@handlers@future |
| 698 |
\expandafter\ekvo@process@list |
| 699 |
\csname @raw@opt@\@currname.\@currext\endcsname |
| 700 |
\AtEndOfPackage{\let\@unprocessedoptions\relax}% |
| 701 |
}% |
| 702 |
} |
| 703 |
\protected\def\ekvo@set@handlers@future |
| 704 |
{% |
| 705 |
\expandafter\let\expandafter |
| 706 |
\ekvo@handle@undefined@k |
| 707 |
\csname |
| 708 |
\ekv@ifdefined{ekvo@future@undefined@k@\@currname.\@currext}% |
| 709 |
{ekvo@future@undefined@k@\@currname.\@currext}% |
| 710 |
{ekvo@handle@undefined@k@pkg}% |
| 711 |
\endcsname |
| 712 |
\expandafter\let\expandafter |
| 713 |
\ekvo@handle@undefined@kv |
| 714 |
\csname |
| 715 |
\ekv@ifdefined{ekvo@future@undefined@kv@\@currname.\@currext}% |
| 716 |
{ekvo@future@undefined@kv@\@currname.\@currext}% |
| 717 |
{ekvo@handle@undefined@kv@pkg}% |
| 718 |
\endcsname |
| 719 |
} |
| 720 |
% \end{macrocode} |
| 721 |
% \end{macro} |
| 722 |
% \begin{macrocode} |
| 723 |
} |
| 724 |
{% |
| 725 |
\protected\def\ekvoProcessFutureOptions#1% |
| 726 |
{% |
| 727 |
\PackageWarning{expkv-opt}% |
| 728 |
{LaTeX-kernel is too old to process future options.\@gobbletwo}% |
| 729 |
\protected\gdef\ekvoProcessFutureOptions##1{}% |
| 730 |
}% |
| 731 |
} |
| 732 |
% \end{macrocode} |
| 733 |
% \end{macro} |
| 734 |
% |
| 735 |
% \begin{macro}{\ekvoProcessOptionsList} |
| 736 |
% \begin{macrocode} |
| 737 |
\protected\def\ekvoProcessOptionsList#1% |
| 738 |
{% |
| 739 |
\ekvo@process@common{\ekvo@ifx@F#1\@empty}% |
| 740 |
{% |
| 741 |
\ekvo@set@handlers@list |
| 742 |
\ekvo@process@list#1% |
| 743 |
}% |
| 744 |
} |
| 745 |
% \end{macrocode} |
| 746 |
% \end{macro} |
| 747 |
% |
| 748 |
% \begin{macro}{\ekvoUseUnknownHandlers} |
| 749 |
% \begin{macro}[internal]{\ekvoUseUnknownHandlers@n,\ekvoUseUnknownHandlers@s} |
| 750 |
% \begin{macrocode} |
| 751 |
\protected\def\ekvoUseUnknownHandlers |
| 752 |
{% |
| 753 |
\let\ekvo@if@need@handlers\ekvo@dont@need@handlers |
| 754 |
\@ifstar\ekvoUseUnknownHandlers@s\ekvoUseUnknownHandlers@n |
| 755 |
} |
| 756 |
\protected\def\ekvoUseUnknownHandlers@s |
| 757 |
{% |
| 758 |
\long\def\ekvo@handle@undefined@k##1% |
| 759 |
{% |
| 760 |
\ekv@ifdefined{\ekvo@name{}uN}% |
| 761 |
{% |
| 762 |
\csname\ekvo@name{}uN\expandafter\endcsname\expandafter |
| 763 |
{\detokenize{##1}}{##1}% |
| 764 |
}% |
| 765 |
{}% |
| 766 |
}% |
| 767 |
\long\def\ekvo@handle@undefined@kv##1##2% |
| 768 |
{% |
| 769 |
\ekv@ifdefined{\ekvo@name{}u}% |
| 770 |
{% |
| 771 |
\csname\ekvo@name{}u\ekv@expanded{\endcsname |
| 772 |
{\ekv@unexpanded{##2}}{\detokenize{##1}}}{##1}% |
| 773 |
}% |
| 774 |
{}% |
| 775 |
}% |
| 776 |
} |
| 777 |
\protected\def\ekvoUseUnknownHandlers@n#1#2% |
| 778 |
{% |
| 779 |
\let\ekvo@handle@undefined@k#1\relax |
| 780 |
\let\ekvo@handle@undefined@kv#2\relax |
| 781 |
} |
| 782 |
% \end{macrocode} |
| 783 |
% \end{macro} |
| 784 |
% \end{macro} |
| 785 |
% |
| 786 |
% All user interface macros should be only used in the preamble. |
| 787 |
% \begin{macrocode} |
| 788 |
\@onlypreamble\ekvoProcessOptions |
| 789 |
\@onlypreamble\ekvoProcessLocalOptions |
| 790 |
\@onlypreamble\ekvoProcessGlobalOptions |
| 791 |
\@onlypreamble\ekvoProcessFutureOptions |
| 792 |
\@onlypreamble\ekvoProcessOptionsList |
| 793 |
\@onlypreamble\ekvoUseUnknownHandlers |
| 794 |
% \end{macrocode} |
| 795 |
% |
| 796 |
% \gobbledocstriptag |
| 797 |
%</pkg> |