Debian Codegraph @

texmf-dist/source/latex/koma-script/doc/scrbase-en.tex

raw
1 % ======================================================================
2 % scrbase-en.tex
3 % Copyright (c) Markus Kohm, 2002-2022
4 %
5 % This file is part of the LaTeX2e KOMA-Script bundle.
6 %
7 % This work may be distributed and/or modified under the conditions of
8 % the LaTeX Project Public License, version 1.3c of the license.
9 % The latest version of this license is in
10 % http://www.latex-project.org/lppl.txt
11 % and version 1.3c or later is part of all distributions of LaTeX
12 % version 2005/12/01 or later and of this work.
13 %
14 % This work has the LPPL maintenance status "author-maintained".
15 %
16 % The Current Maintainer and author of this work is Markus Kohm.
17 %
18 % This work consists of all files listed in MANIFEST.md.
19 % ======================================================================
20 %
21 % Package scrbase for Package and Class Authors
22 % Maintained by Markus Kohm
23 %
24 % ======================================================================
25
26 \KOMAProvidesFile{scrbase-en.tex}
27 [$Date: 2022-07-17 11:19:00 +0200 (So, 17. Jul 2022) $
28 KOMA-Script package scrbase]
29 \translator{Markus Kohm\and Melvin Hendrix\and Karl Hagen}
30
31 \chapter{Basic Functions in the \Package{scrbase} Package}
32 \labelbase{scrbase}
33 \BeginIndexGroup
34 \BeginIndex{Package}{scrbase}%
35
36 The \Package{scrbase} package provides basic features intended for use by
37 authors of packages and classes. Its use is not limited merely to wrapper
38 classes which in turn load a \KOMAScript{} class. Authors of classes that
39 otherwise have nothing to do with \KOMAScript{} can also benefit from the
40 functionality of \Package{scrbase}.
41
42 \section{Loading the Package}
43 \seclabel{loadit}
44
45 Whereas users load packages with \Macro{usepackage}, authors of packages or
46 classes should use \Macro{RequirePackage}\IndexCmd{RequirePackage}. Authors of
47 wrapper packages can also use \Macro{RequirePackageWithOptions}. The
48 \Macro{RequirePackage} command has the same optional argument for package
49 options as \Macro{usepackage}. In contrast, \Macro{RequirePackageWithOptions}
50 does not have an optional argument but passes to this package all the options
51 that were previously given when loading the wrapper package or class. See
52 \cite{latex:clsguide} for more information about these commands.
53
54 The \Package{scrbase} package needs the functionality of the
55 \Package{keyval}\IndexPackage{keyval} package internally. This can also be
56 provided by the \Package{xkeyval} package. If needed, \Package{scrbase} itself
57 loads \Package{keyval}.
58
59 The \Package{keyval} package lets you define keys and assign values to them.
60 The options provided by \Package{scrbase} also use \Package{keyval} syntax:
61 \PName{key}\texttt{=}\PName{value}.
62
63
64 \section{Keys as Attributes of Families and Their Members}
65 \seclabel{keyvalue}
66
67 As already mentioned in \autoref{sec:scrbase.loadit}, \Package{scrbase} uses
68 the \Package{keyval} package to set keys and their values. However,
69 \Package{scrbase} extends this functionality. Whereas with \Package{keyval} a
70 key belongs to only one family, \Package{scrbase} also recognizes family
71 members. A key can therefore belong to both a family and one or more family
72 members. Additionally, you can assign a value to the key of a family member,
73 to the key of a family, or to the keys of all family members.
74
75 \begin{Declaration}
76 \Macro{DefineFamily}\Parameter{family}%
77 \Macro{DefineFamilyMember}\OParameter{member}\Parameter{family}%
78 \end{Declaration}
79 \Package{scrbase} needs to know the members of a family for various reasons.
80 Therefore, you must first define a new family using \Macro{DefineFamily},
81 which produces an empty member list. If the family has already been defined,
82 nothing happens. Therefore an existing member list will not be overwritten.
83
84 Next, you can add a new member to the family using \Macro{DefineFamilyMember}.
85 If the family does not exist, this will result in an error message. If the
86 member already exists, nothing happens. If the optional \PName{member} is
87 omitted, the default value
88 ``\texttt{.}\Macro{@currname}\texttt{.}\Macro{@currext}'' is used. While
89 the class or package is being loaded, \Macro{@currname} and \Macro{@currext}
90 together represent the file name of the class or package.
91
92 Theoretically, it is possible, to define a member without a name using an
93 empty optional \PName{member} argument. But this is the same as the family
94 itself. You should use only letters and digits for the \PName{family} name,
95 and the first character of \PName{member} should be something else, preferably
96 a point. Otherwise, it could happen that the members of one family will clash
97 with the members of other families.
98
99 \Package{scrbase} assigns the family ``\PValue{KOMA}'' to itself and adds the
100 member ``\PValue{.scrbase.sty}''. The values ``\PValue{KOMA}'' and
101 ``\PValue{KOMAarg}'' are reserved for \KOMAScript{}. If you are creating a
102 bundle of packages, you should use the name of the bundle as \PName{family}
103 and the name of each package as \PName{member} of that \PName{family}.
104 %
105 \begin{Example}
106 Suppose you are writing a bundle called ``master butcher''. Within that
107 bundle, you have the packages \File{salami.sty}, \File{mettwurst.sty},
108 and \File{kielbasa.sty}. Therefore, you decide to use family name
109 ``\PValue{butcher}'' and you add the lines
110 \begin{lstcode}
111 \DefineFamily{butcher}
112 \DefineFamilyMember{butcher}
113 \end{lstcode}
114 to each of the package files. When loading the three packages, this will
115 add the members ``\PValue{.salami.sty}'', ``\PValue{.mettwurst.sty}'',
116 and ``\PValue{.kielbasa.sty}'' to the family ``\PValue{butcher}''. After
117 loading all three packages, all three members will be defined.
118 \end{Example}
119 %
120 \EndIndexGroup
121
122
123 \begin{Declaration}
124 \Macro{DefineFamilyKey}\OParameter{member}\Parameter{family}%
125 \Parameter{key}%
126 \OParameter{default}\Parameter{action}%
127 \Macro{FamilyKeyState}%
128 \Macro{FamilyKeyStateUnknown}%
129 \Macro{FamilyKeyStateProcessed}%
130 \Macro{FamilyKeyStateUnknownValue}%
131 \Macro{FamilyKeyStateNeedValue}
132 \end{Declaration}
133 The \Macro{DefineFamilyKey} command defines a \PName{key}. If you specify a
134 \PName{member}, the \PName{key} becomes an attribute of that member in the
135 given \PName{family}. If you do not specify a \PName{member}, the member
136 ``\texttt{.}\Macro{@currname}\texttt{.}\Macro{@currext}'' is assumed. If you
137 later assign a value to the \PName{key}, the \PName{action} will be
138 executed and the value made an argument of \PName{action}. Within
139 \PName{action}, ``\lstinline{#1}'' stands for that value. If you omit the value,
140 the \PName{default} is used instead. If you do not specify a \PName{default},
141 the \PName{key} then always requires you to pass an explicit value.
142
143 %\begin{Explain}
144 \phantomsection\label{explain:scrbase.macro.DefineFamilyKey}%
145 Ultimately,
146 \begin{lstcode}[escapeinside=`']
147 \DefineFamilyKey[`\PName{member}']{`\PName{family}'}{`\PName{key}'}
148 [`\PName{default}']{`\PName{action}'}
149 \end{lstcode}
150 results in a call to
151 \begin{lstcode}[moretexcs={define@key},escapeinside=`']
152 \define@key{`\PName{family\,member}'}{`\PName{key}'}
153 [`\PName{default}']{`\PName{extended action}'}
154 \end{lstcode}
155 where \Macro{define@key} is provided by the
156 \Package{keyval}\IndexPackage{keyval} package (see \cite{package:keyval}).
157 However, there are some additional precautions taken with the call to
158 \Macro{define@key}, and the \PName{action} will be extended to include these
159 precautions.
160 %\end{Explain}
161
162 Success\ChangedAt{v3.12}{\Package{scrbase}} or failure in executing the
163 \PName{action} should be reported back to \Package{scrbase} through
164 \Macro{FamilyKeyState} so that the package itself can take further action as
165 needed. This could be, for example, an error message or merely warning of an
166 unknown option. You should not report errors directly!
167
168 The default state of \PName{action} before execution is
169 \Macro{FamilyKeyStateUnknown}. This indicates that it is not known whether or
170 not the key could be processed successfully. If this state remains unchanged
171 after the \PName{action} has been executed, \Package{scrbase} writes a
172 message to the \File{log} file and assumes the that state is
173 \Macro{FamilyKeyStateProcessed}.
174
175 The \Macro{FamilyKeyStateProcessed} state indicates that the key and the value
176 assigned to it have been successfully processed and everything is OK. You can
177 switch to this state by calling \Macro{FamilyKeyStateProcessed} itself.
178
179 The \Macro{FamilyKeyStateUnknownValue} state indicates that the key has been
180 processed but that the value passed to it was either unknown or not allowed.
181 For example, \hyperref[cha:typearea]{\Package{typearea}} reports this
182 condition if you try to set the \DescRef{typearea.option.twoside} option to
183 \PValue{unknown}. You can set this state by simply calling
184 \Macro{FamilyKeyStateUnknownValue}.
185
186 The \Macro{FamilyKeyStateNeedValue} state indicates that the key could not be
187 processed because it expects a value, but it was called without such a value.
188 This state is set automatically if you use a key that does not have a
189 \PName{default} value without assigning a value. Theoretically, you could
190 set this state explicitly with \Macro{FamilyKeyStateNeedValue}, but you should
191 not need to set it yourself.
192
193 In addition, you can define additional error conditions by redefining
194 \Macro{FamilyKeyState} with a short text message. Generally, however, the four
195 predefined states should be sufficient.
196
197 \begin{Example}
198 Suppose each of the three packages from the previous example should have a
199 key named \PValue{coldcuts}. When used, a switch should be set in each of
200 the packages. For the \Package{salami} package, for example, this could look
201 like this:
202 \begin{lstcode}
203 \newif\if@salami@coldcuts
204 \DefineFamilyKey{butcher}%
205 {coldcuts}[true]{%
206 \expandafter\let\expandafter\if@salami@coldcuts
207 \csname if#1\endcsname
208 \FamilyKeyStateProcessed
209 }
210 \end{lstcode}
211 When called, the value will therefore be either \PValue{true} or
212 \PValue{false}. This example does not test for illegal values. Instead,
213 it is always reported that the key was processed completely and correctly.
214 If the key is used later, one of the permitted values, or no value, must be
215 used. In the second case, the default \PName{true} value will be used.
216
217 The definitions for the other packages are nearly identical. Only the string
218 ``\texttt{salami}'' has to be replaced.
219 \end{Example}
220 %
221 \EndIndexGroup
222
223
224 \begin{Declaration}
225 \Macro{RelaxFamilyKey}\OParameter{member}\Parameter{family}%
226 \Parameter{key}
227 \end{Declaration}
228 If\ChangedAt{v3.15}{\Package{scrbase}} a \PName{key} has been previously
229 defined as a \PName{member} of a \PName{family}, that definition will be
230 cancelled. Afterwards the \PName{key} will no longer be defined for this
231 \PName{member} of the \PName{family}. You can use \Macro{RelaxFamilyKey} for a
232 \PName{key} that is not defined for this \PName{member} of the \PName{family}.
233
234 If you do not specify a \PName{member}, then the member
235 ``\texttt{.}\Macro{@currname}\texttt{.}\Macro{@currext}'' is assumed, just as
236 with \DescRef{\LabelBase.cmd.DefineFamilyKey}. However, \Macro{RelaxFamilyKey}
237 is only rarely used while loading a package rather than at runtime. Therefore
238 the \PName{member} should usually be specified explicitly as well.%
239 \EndIndexGroup
240
241
242 \begin{Declaration}
243 \Macro{FamilyProcessOptions}\OParameter{member}\Parameter{family}
244 \end{Declaration}
245 In essence, extending keys from families to both families and family members
246 means that either keys or key-value pairs can be used as normal class or
247 package options. The \Macro{FamilyProcessOptions} command is an extension of
248 \Macro{ProcessOption*} from the \LaTeX{} kernel (see \cite{latex:clsguide},
249 which processes not only options declared with \Macro{DeclareOption}, but also
250 all keys of the given member. If you omit the optional argument
251 \PName{member}, the member
252 ``\texttt{.}\Macro{@currname}\texttt{.}\Macro{@currext}'' is used.
253
254 One feature worth noting is that keys which are attached not to a family
255 member but to a family have an empty family member. Such keys are set before
256 the keys of the members.
257 \begin{Example}
258 If, in the packages from the previous example, you add the line
259 \begin{lstcode}
260 \FamilyProcessOptions{butcher}
261 \end{lstcode}
262 after you define the key, you can specify the \Option{coldcuts} option when
263 loading the package. If you specify the option globally in
264 \Macro{documentclass}, the option will be passed automatically to all three
265 packages if they are loaded later.
266 \end{Example}
267 Note\textnote{Attention!} that packages always process global options
268 before local options. While unknown global options result in an entry in the
269 \File{log} file and the option being otherwise ignored, unknown local
270 options result in an error message.
271
272 You can think of \Macro{FamilyProcessOptions} as an extension of either
273 \Macro{ProcessOption*} or the \PName{key=value} mechanism
274 of \Package{keyval}. Ultimately, with the help of
275 \Macro{FamilyProcessOptions}, \PName{key=value} pairs become options.%
276
277 As with\textnote{Attention!} \Macro{ProcessOptions},
278 \Macro{FamilyProcessOptions} must not be used while executing options code.
279 In particular, you cannot load packages while processing options.%
280 %
281 \EndIndexGroup
282
283
284 \begin{Declaration}
285 \Macro{BeforeFamilyProcessOptions}\OParameter{member}\Parameter{family}%
286 \Parameter{code}%
287 \end{Declaration}
288 Authors\ChangedAt{v3.18}{\Package{scrbase}} of wrapper classes in particular
289 sometimes need a hook to execute \PName{code} before
290 \DescRef{\LabelBase.cmd.FamilyProcessOptions}. The \Package{scrbase} package
291 provides such a hook, and you can add \PName{code} to it with
292 \Macro{BeforeFamilyProcessOptions}. The \PName{member} and \PName{family}
293 parameters are same as those of \DescRef{\LabelBase.cmd.FamilyProcessOptions}.
294 However, you can also add \PName{code} to the hook for families or members
295 that have not yet been defined.
296
297 Note that the hook of a family member is automatically deleted after it is
298 executed. But if you use an empty \PName{member}, this hook\Index{hook} will
299 be executed for every member of the \PName{family} and will not be deleted.
300
301 \begin{Example}
302 You are writing a \Package{smokedsausage} package that loads
303 \Package{mettwurst}. But you do not want to be able to set the
304 \Option{coldcut} option with this package. So you use
305 \Macro{BeforeFamilyProcessOptions} to deactivate that option before you load
306 the package:
307 \begin{lstcode}
308 \RequirePackage{scrbase}
309 \BeforeFamilyProcessOptions[.mettwurst.sty]{butcher}{%
310 \RelaxFamilyKey[.mettwurst.sty]{butcher}{coldcut}%
311 }
312 \RequirePackageWithOptions{mettwurst}
313 \end{lstcode}
314 If a user tries to load your package with the \Option{coldcut} option, the
315 \Package{mettwurst} package will throw an undefined option error. If
316 \Option{coldcut} is used as a global option, the \Package{mettwurst}
317 package will ignore it. But default settings inside \Package{mettwurst},
318 for example using \DescRef{\LabelBase.cmd.FamilyExecuteOptions} before
319 \DescRef{\LabelBase.cmd.FamilyProcessOptions} are not affected. Of course,
320 you can also insert your own default for \Package{smokedsausage} via
321 \Macro{BeforeFamilyProcessOptions} in \Package{mettwurst}.
322 \end{Example}
323 \EndIndexGroup
324
325
326 \begin{Declaration}
327 \Macro{FamilyExecuteOptions}\OParameter{member}\Parameter{family}%
328 \Parameter{options list}
329 \end{Declaration}
330 This command is an extension of \Macro{ExecuteOptions} from the \LaTeX{}
331 kernel (see \cite{latex:clsguide}). The command processes not only options
332 defined with \Macro{DeclareOption} but also all keys of the given
333 \PName{family}. If you omit the optional argument \Macro{member},
334 ``\texttt{.}\Macro{@currname}\texttt{.}\Macro{@currext}'' is used.
335
336 One feature worth noting is that keys which are attached not to a family
337 member but to a family have an empty family member. Such keys are set before
338 the keys of the members.
339 \begin{Example}
340 Suppose the \Option{coldcuts} option should be set by default in the
341 previous examples. In this case only line
342 \begin{lstcode}
343 \FamilyExecuteOptions{butcher}{coldcuts}
344 \end{lstcode}
345 has to be added.
346 \end{Example}
347
348 If\ChangedAt{v3.20}{\Package{scrbase}} you call \Macro{FamilyExecuteOptions}
349 with an unknown option inside the \PName{options list}, you will get an error.
350 An exception to this rule occurs when the \PName{member} has an option called
351 \Option{@else@}. In this case, the \Option{@else@} option will be used instead
352 of the unknown one. The value passed to the \Option{@else@} option is the
353 unknown option with the value specified in the call. \KOMAScript{} itself uses
354 this feature, for example inside the definition of sectioning commands,
355 to evaluate the style option before all other attributes.
356
357 You can also use this command inside the code executed when processing the
358 option.%
359 %
360 \EndIndexGroup
361
362
363 \begin{Declaration}
364 \Macro{FamilyOptions}\Parameter{family}\Parameter{options list}%
365 \end{Declaration}
366 Unlike normal options defined with \Macro{DeclareOption}, the \PName{key}s can
367 also be set after loading a class or package. To do this, you call
368 \Macro{FamilyOptions}. The \PName{options list} has the form
369 \begin{flushleft}\vskip\dp\strutbox\begin{tabular}{l}
370 \PName{key}\texttt{=}\PName{value}\texttt{,}%
371 \PName{key}\texttt{=}\PName{value}\dots
372 \end{tabular}\vskip\dp\strutbox\end{flushleft}
373 after which the value assignment can be omitted for \PName{key}s that have a
374 defined default.
375
376 The statement sets the keys of all members of the specified family. If a
377 \PName{key} also exists as an attribute of the family itself, then the family
378 key is set first, followed by the member keys in the order in which they were
379 defined. If a given \PName{key} does not exist, either for the family or for
380 any member of the family, then \Macro{FamilyOptions} will throw an error. An
381 error also occurs if a \PName{key} exists for some members but each of those
382 members returns an error through \DescRef{\LabelBase.cmd.FamilyKeyState}.
383 \begin{Example}
384 You extend your butcher project with a \Package{sausagesalad} package. If
385 this package has been loaded, all sausage packages should generate cold
386 cuts:
387 \begin{lstcode}
388 \ProvidesPackage{sausagesalad}%
389 [2008/05/06 nonsense package]
390 \DefineFamily{butcher}
391 \DefineFamilyMember{butcher}
392 \FamilyProcessOptions{butcher}\relax
393 \FamilyOptions{butcher}{coldcuts}
394 \end{lstcode}
395 If no sausage package has yet been loaded, the undefined option
396 \Option{coldcuts} leads to an error message. You can avoid this by defining
397 a corresponding key for the package before the last line of the code above:
398 \begin{lstcode}
399 \DefineFamilyKey{butcher}%
400 {coldcuts}[true]{}%
401 \end{lstcode}
402 However, sausage packages loaded after \Package{sausagesalad} still do not
403 produce cold cuts. You can correct this by replacing the previous command
404 with:
405 \begin{lstcode}
406 \AtBeginDocument{%
407 \DefineFamiyKey[.sausagesalad.sty]%
408 {butcher}%
409 {coldcuts}[true]{}%
410 }
411 \DefineFamilyKey{butcher}%
412 {coldcuts}[true]{%
413 \AtBeginDocument{\FamilyOptions{butcher}%
414 {coldcuts=#1}}%
415 }%
416 \end{lstcode}
417 Thus, the option is defined during \Macro{begin}\PParameter{document} so
418 that it no longer functions for the \Package{sausagesalad} package. Because
419 \Macro{@currname} and \Macro{@currext} no longer contain the file name of
420 the package, you must use the optional argument of
421 \DescRef{\LabelBase.cmd.DefineFamilyKey}.
422
423 But until this redefinition is performed, it uses a definition that executes
424 the option again for the family and all its members during
425 \Macro{begin}\PParameter{document}, thus setting it for other sausage
426 packages. The delay in executing \Macro{FamilyOptions} is crucial here. For
427 one thing, it includes only the packages loaded afterwards. For another, it
428 ensures that its own \Option{coldcuts} option has already been redefined.
429 This avoids endless recursion.
430 \end{Example}
431
432 Like\ChangedAt{v3.27}{\Package{scrbase}}
433 \DescRef{\LabelBase.cmd.FamilyExecuteOptions}, \Macro{FamilyOptions} offers
434 special handling for an option named
435 \Option{@else@}\important{\Option{@else@}}. If a family member has such an
436 option, it will be executed whenever an option in the \PName{option list} is
437 unrecognized by the member. If the family itself defines an option
438 \Option{@else@}, it will only be called if neither the family nor any of its
439 members were able to fully process the given option by executing
440 \DescRef{\LabelBase.cmd.FamilyKeyStateProcessed}.%
441 \EndIndexGroup
442
443
444 \begin{Declaration}
445 \Macro{FamilyOption}\Parameter{family}%
446 \Parameter{option}\Parameter{value list}%
447 \end{Declaration}
448 In addition to options that have mutually exclusive values, there may be
449 options that can take multiple values at the same time. To use
450 \DescRef{\LabelBase.cmd.FamilyOptions} for that type of option, it would be
451 necessary to invoke the same option several times with different value
452 assignments. Instead, you can easily assign a whole list of values to a single
453 \PName{option} using \Macro{FamilyOption}. The \PName{value list} is a comma
454 separated list of values, also known as \emph{csv}:
455 %\begin{flushleft}\begin{tabular}{l}
456 \PName{value}\texttt{,}\PName{value}\dots
457 %\end{tabular}\end{flushleft}
458 Note in this context that you can use a comma in a value by putting the value
459 inside braces. This command's other functionality is the same previously
460 described for \DescRef{\LabelBase.cmd.FamilyOptions}.
461 \begin{Example}
462 The \Package{sausagesalad} package should have one more option to add
463 additional ingredients. Each of the ingredients sets a switch, as was done
464 previously for the cold cuts.
465 \begin{lstcode}
466 \newif\if@saladwith@onions
467 \newif\if@saladwith@gherkins
468 \newif\if@saladwith@chillies
469 \DefineFamilyKey{butcher}{ingredient}{%
470 \csname @saladwith@#1true\endcsname
471 }
472 \end{lstcode}
473 Here the three ingredients ``onions'', ``gherkins'', and ``chillies'' have
474 been defined. There is no error message for unknown ingredients.
475
476 For a salad with onions and gherkins, you can use
477 \begin{lstcode}
478 \FamilyOptions{butcher}{%
479 ingredient=onions,ingredient=gherkins}
480 \end{lstcode}
481 or simply
482 \begin{lstcode}
483 \FamilyOption{butcher}
484 {ingredient}{onions,gherkins}
485 \end{lstcode}
486 \end{Example}
487
488 An\ChangedAt{v3.27}{\Package{scrbase}} \Option{@else@} option is processed
489 in the same manner as with \DescRef{\LabelBase.cmd.FamilyOptions}.%
490 \EndIndexGroup
491
492
493 \begin{Declaration}
494 \Macro{AtEndOfFamilyOptions}\Parameter{action}%
495 \Macro{AtEndOfFamilyOptions*}\Parameter{action}%
496 \end{Declaration}
497 Sometimes\ChangedAt{v3.12}{\Package{scrbase}} it is useful to delay the
498 execution of an \PName{action} that is part of a value assignment to a key
499 until all assignments inside one
500 \DescRef{\LabelBase.cmd.FamilyProcessOptions}\IndexCmd{FamilyProcessOptions},
501 \DescRef{\LabelBase.cmd.FamilyExecuteOptions}\IndexCmd{FamilyExecuteOptions},
502 \DescRef{\LabelBase.cmd.FamilyOptions}\IndexCmd{FamilyOptions}, or
503 \DescRef{\LabelBase.cmd.FamilyOption}\IndexCmd{FamilyOptions} is finished.
504 You can do this using \Macro{AtEndOfFamilyOptions} or its starred
505 variant\ChangedAt{v3.23}{\Package{scrbase}} inside an option definition.
506 However, reporting failure states of \PName{action} is not possible with this
507 command, nor should it be used outside an option definition.
508
509 The two variants differ in case there are nested option definitions, when
510 executing an option requires further option calls. In this case all actions
511 specified by \Macro{AtEndOfFamilyOptions} will be executed when the innermost
512 option call returns. In contrast, the actions of \Macro{AtEndOfFamilyOptions*}
513 are not executed until the outermost option call returns.
514 However,\textnote{Attention!} the order of the actions of both commands is
515 emphatically undefined! It is not guaranteed that the action requested first
516 will be executed first, nor the converse.%
517 \EndIndexGroup
518
519
520 \begin{Declaration}
521 \Macro{FamilyBoolKey}\OParameter{member}\Parameter{family}%
522 \Parameter{key}\Parameter{switch name}%
523 \Macro{FamilySetBool}\Parameter{family}%
524 \Parameter{key}\Parameter{switch name}\Parameter{value}
525 \end{Declaration}
526 Boolean switches have been used several times in the previous examples. In the
527 example with \Option{coldcuts} option, the user had to assign either
528 \PValue{true} or \PValue{false} as a value. There was no error message if the
529 user provided the wrong value. Because boolean switches are a common use case,
530 you can easily define them with \Package{scrbase} using \Macro{FamilyBoolKey}.
531 The \PName{member}, \PName{family}, and \PName{key} arguments are the same as
532 those used by \DescRef{\LabelBase.cmd.DefineFamilyKey} (see
533 \DescPageRef{scrbase.cmd.DefineFamilyKey}). The \PName{switch name} is the
534 name of the switch without the prefix \Macro{if}. If a switch with this name
535 does not exist already, \Macro{FamilyBoolKey} will define it and initialize it
536 to \PName{false}. Internally, \Macro{FamilyBooKey} uses \Macro{FamilySetBool}
537 as the \PName{action} of \DescRef{\LabelBase.cmd.DefineFamilyKey}. The
538 \PName{default} for such an option is always \PValue{true}.
539
540 \Macro{FamilySetBool}, on the other hand, accepts \PValue{on} and
541 \PValue{yes}, in addition to \PName{true}, to turn the switch on, and
542 \PName{off} and \PName{no}, in addition to \PName{false}, to turn it off.
543 Unknown values will result in a call to
544 \DescRef{\LabelBase.cmd.FamilyUnknownKeyValue} with the arguments
545 \PName{family}, \PName{key}, and \PName{value}, which sets
546 \DescRef{\LabelBase.cmd.FamilyKeyState} accordingly. As a result, an error
547 message about an unknown value assignment is printed if necessary (see also
548 \DescPageRef{scrbase.cmd.FamilyUnknownKeyValue} and
549 \DescPageRef{scrbase.cmd.FamilyKeyState}).
550 \begin{Example}
551 The key \Option{coldcuts} should be defined more robustly in the sausage
552 packages. Additionally, all sausage packages should use the same key, so
553 that either all sausage packages will produce cold cuts or none will.
554 \begin{lstcode}
555 \FamilyBoolKey{butcher}{coldcuts}%
556 {@coldcuts}
557 \end{lstcode}
558 A test of whether to produce cold cuts would look like this:
559 \begin{lstcode}
560 \if@coldcuts
561 ...
562 \else
563 ...
564 \fi
565 \end{lstcode}
566 This would be the same in all three sausage packages, thereby
567 defining the attribute ``coldcuts'' as a family option:
568 \begin{lstcode}[moretexcs={define@key}]
569 \@ifundefined{if@coldcuts}{%
570 \expandafter\newif\csname if@coldcuts\endcsname
571 }{}%
572 \DefineFamilyKey[]{butcher}{coldcuts}[true]{%
573 \FamilySetBool{butcher}{coldcuts}%
574 {@coldcuts}%
575 {#1}%
576 }
577 \end{lstcode}
578 or shorter:
579 \begin{lstcode}
580 \FamilyBoolKey[]{butcher}{coldcuts}%
581 {@coldcuts}
582 \end{lstcode}
583 taking advantage of the treatment of empty family members as opposed to
584 omitting the optional argument explained on
585 \autopageref{explain:scrbase.macro.DefineFamilyKey}, which applies not only
586 to \DescRef{\LabelBase.cmd.DefineFamilyKey} but also for
587 \Macro{FamilyBoolKey}.
588
589 Since \DescRef{\LabelBase.cmd.FamilyKeyState} is already set by
590 \Macro{FamilySetBool}, you can check its status with the help of
591 \DescRef{\LabelBase.cmd.DefineFamilyKey}. For example, in the first case you
592 could add an equivalence test to \Macro{FamilySetBool} to perform additional
593 actions depending on whether \Macro{FamilySetBool} succeeded or not:
594 \begin{lstcode}
595 \ifx\FamilyKeyState\FamilyKeyStateProcessed
596 ...
597 \else
598 ...
599 \fi
600 \end{lstcode}
601 Note\textnote{Attention!} that it is essential to perform the test with
602 \Macro{ifx} at this point. Fully expanding tests like \Macro{ifstr} should
603 be avoided here. Depending on the current status and the comparison status,
604 they can lead to different error messages as well as incorrect results.
605 \end{Example}%
606 \EndIndexGroup
607
608 \begin{Declaration}
609 \Macro{FamilyInverseBoolKey}\OParameter{member}\Parameter{family}
610 \Parameter{key}\Parameter{switch name}
611 \Macro{FamilySetInverseBool}\Parameter{family}
612 \Parameter{key}\Parameter{switch name}
613 \Parameter{value}
614 \end{Declaration}
615 These\ChangedAt{v3.27}{\Package{scrbase}} two commands differ from
616 \DescRef{\LabelBase.cmd.FamilyBoolKey} and
617 \DescRef{\LabelBase.cmd.FamilySetBool}, respectively, only in that the
618 logic is inverted. This means that the values \PValue{true}, \PValue{yes}, and
619 \PValue{on} set the boolean switch given by \PName{switch name} to
620 \Macro{iffalse} and therefore deactivate it. The values \PValue{false},
621 \PValue{no}, and \PValue{off} set the boolean switch to \Macro{iftrue} and
622 therefore activate it.%
623 \EndIndexGroup
624
625
626 \begin{Declaration}
627 \Macro{FamilyNumericalKey}\OParameter{member}\Parameter{family}%
628 \Parameter{key}%
629 \OParameter{default}\Parameter{command}%
630 \Parameter{value list}%
631 \Macro{FamilySetNumerical}\Parameter{family}\Parameter{key}%
632 \Parameter{command}\Parameter{value list}%
633 \Parameter{value}
634 \end{Declaration}
635 While switches can accept only two values, there are also keys that recognize
636 several values. For example an alignment can be not just left or not-left, but
637 left, centred, or right. Internally, such differentiation is often made using
638 \Macro{ifcase}. This \TeX{} command expects a numerical value. Therefore in
639 \Package{scrbase} the command to define a macro by a \PName{key} has been
640 named \Macro{FamilyNumericalKey}. The \PName{value list} has the form:
641 %\begin{flushleft}\vskip\dp\strutbox\begin{tabular}{l}
642 \Parameter{value}\Parameter{definition}\texttt{,}\linebreak[1]%
643 \Parameter{value}\Parameter{definition}\texttt{,}~\dots
644 %\end{tabular}\vskip\dp\strutbox\end{flushleft}
645 The \PName{value list} defines not just the values permitted for the
646 \PName{key}. For each \PName{value}, the \PName{definition} of the macro
647 \Macro{\PName{command}} also is given. Usually, the \PName{definition} is just
648 a numerical value. Although other content is possible, there is currently a
649 restriction that the \PName{definition} must be fully expandable, and it will
650 be expanded during the assignment.
651 \begin{Example}
652 The sausage for the sausage salad can be cut differently. For example, the
653 cold cuts could simply remain uncut or be cut into thick or thin slices.
654 This information should be stored in the command \Macro{cuthow}.
655 \begin{lstcode}
656 \FamilyNumericalKey{butcher}%
657 {saladcut}{cuthow}{%
658 {none}{none},{no}{none},{not}{none}%
659 {thick}{thick},%
660 {thin}{thin}%
661 }
662 \end{lstcode}
663 Not cutting anything can be selected by
664 \begin{lstcode}
665 \FamilyOptions{butcher}{saladcut=none}
666 \end{lstcode}
667 or
668 \begin{lstcode}
669 \FamilyOptions{butcher}{saladcut=no}
670 \end{lstcode}
671 or
672 \begin{lstcode}
673 \FamilyOptions{butcher}{saladcut=not}
674 \end{lstcode}
675 In all three cases \Macro{cuthow} would be defined with the content
676 \PValue{none}. It can be useful to provide several values for the same
677 result, as shown in this example.
678
679 Now it's very likely that the manner of cutting will not be printed but
680 should be evaluated later. In this case, a textual definition would be
681 rather impractical. If the key is defined like this:
682 \begin{lstcode}
683 \FamilyNumericalKey{butcher}%
684 {saladcut}{cuthow}{%
685 {none}{0},{no}{0},{not}{0}%
686 {thick}{1},%
687 {thin}{2}%
688 }
689 \end{lstcode}
690 then you can use a condition like the following:
691 \begin{lstcode}
692 \ifcase\cuthow
693 % uncut
694 \or
695 % thickly cut
696 \else
697 % thinly cut
698 \fi
699 \end{lstcode}
700 \end{Example}
701 Internally, \Macro{FamilyNumericalKey} uses \Macro{FamilySetNumerical} as the
702 \PName{action} of \DescRef{\LabelBase.cmd.DefineFamilyKey}. If an unknown
703 value is assigned to such a key, \Macro{FamilySetNumerical} will call
704 \DescRef{\LabelBase.cmd.FamilyUnknownKeyValue} with the \PName{family},
705 \PName{key} and \PName{value} arguments. This leads to an error signalled with
706 the \DescRef{\LabelBase.cmd.FamilyKeyStateUnknownValue} status in
707 \DescRef{\LabelBase.cmd.FamilyKeyState}. Similarly, when calling
708 \Macro{FamilySetNumerical} the success is signalled via
709 \DescRef{\LabelBase.cmd.FamilyKeyStateProcessed} in
710 \DescRef{\LabelBase.cmd.FamilyKeyState}.%
711 %
712 \EndIndexGroup
713
714
715 \begin{Declaration}
716 \Macro{FamilyCounterKey}\OParameter{member}\Parameter{family}%
717 \Parameter{key}%
718 \OParameter{default}\Parameter{\LaTeX{} counter}%
719 \Macro{FamilySetCounter}\Parameter{family}%
720 \Parameter{key}\Parameter{\LaTeX{} counter}\Parameter{value}
721 \end{Declaration}
722 While\ChangedAt{v3.12}{\Package{scrbase}}
723 \DescRef{\LabelBase.cmd.FamilyNumericalKey} defines a macro in which a numeric
724 value corresponds to a symbolic value, there are, of course, circumstances
725 when a \PName{key} directly represents a \PName{\LaTeX{} counter} to which a
726 numeric value should be assigned immediately. For this case, you can use
727 \Macro{FamilyCounterKey}, which calls \Macro{FamilySetCounter} internally.
728 There are some basic tests of the \PName{value} argument to determine if the
729 \PName{value} argument appears to be suitable for assignment to a counter. The
730 assignment will only be made if these tests succeed. However, not all errors
731 can be detected here, so an incorrect assignment can also lead to an error
732 message from \TeX{} itself. Errors that are detected, however, are signalled
733 by \DescRef{\LabelBase.cmd.FamilyKeyStateUnknownValue}.
734
735 If\ChangedAt{v3.15}{\Package{scrbase}} the value is omitted, the
736 \PName{default} is used instead. If there is no \PName{default}, the
737 \PName{key} can be used only with an explicit value.%
738 \EndIndexGroup
739
740
741 \begin{Declaration}
742 \Macro{FamilyCounterMacroKey}\OParameter{member}\Parameter{family}%
743 \Parameter{key}%
744 \OParameter{default}\Parameter{macro}%
745 \Macro{FamilySetCounterMacro}\Parameter{family}%
746 \Parameter{key}\Parameter{macro}\Parameter{value}%
747 \end{Declaration}
748 These\ChangedAt{v3.12}{\Package{scrbase}} two commands differ from the
749 previously described \DescRef{\LabelBase.cmd.FamilyCounterKey} and
750 \DescRef{\LabelBase.cmd.FamilySetCounter} only by the fact that they do not
751 assign a \PName{value} to a \LaTeX{} counter, but define a \Macro{macro} with
752 the \PName{value}. This \PName{value} is locally assigned to a counter and
753 then its expanded value is used. Therefore, its value at the time the option
754 is called applies.%
755 \EndIndexGroup
756
757
758 \begin{Declaration}
759 \Macro{FamilyLengthKey}\OParameter{member}\Parameter{family}
760 \Parameter{key}
761 \OParameter{default}\Parameter{length}
762 \Macro{FamilySetLength}\Parameter{family}
763 \Parameter{key}\Parameter{length}\Parameter{value}
764 \Macro{FamilyLengthMacroKey}\OParameter{member}\Parameter{family}
765 \Parameter{key}
766 \OParameter{default}\Parameter{macro}
767 \Macro{FamilySetLengthMacro}\Parameter{family}
768 \Parameter{key}\Parameter{macro}
769 \Parameter{value}
770 \Macro{FamilyUseLengthMacroKey}\OParameter{member}\Parameter{family}
771 \Parameter{key}
772 \OParameter{default}\Parameter{macro}
773 \Macro{FamilySetUseLengthMacro}\Parameter{family}
774 \Parameter{key}\Parameter{macro}
775 \Parameter{value}
776 \end{Declaration}
777 With\ChangedAt{v3.12}{\Package{scrbase}} \Macro{FamilyLengthKey}, you can
778 define a \PName{key} that represents a \PName{length}. It does not matter
779 whether the \PName{length} is a \LaTeX{} length, a \TeX{} skip, or a \TeX{}
780 dimension. Internally the \PName{length} will be set to the \PName{value}
781 using \Macro{FamilySetLength}. There are some basic tests to decide whether
782 this \PName{value} is valid to assign to \PName{length}. The assignment will
783 only take place if these tests succeed. However, not all errors can be
784 detected, so an inaccurate \PName{value} can still result in a \TeX{} error.
785 Errors that are detected, however, are signalled by
786 \DescRef{\LabelBase.cmd.FamilyKeyStateUnknownValue}.
787
788 If\ChangedAt{v3.15}{\Package{scrbase}} the value is omitted, the
789 \PName{default} is used instead. If there is no \PName{default}, the
790 \PName{key} can be used only with an explicit value.
791
792 When you use \Macro{FamilyLengthMacroKey} and \Macro{FamilySetLengthMacroKey},
793 or \Macro{FamilySetLengthMacro} and \Macro{FamilySetUseLengthMacro}, the
794 \PName{value} is stored not in a \PName{length} but in a
795 \PName{macro}. \Macro{FamilyLengthMacroKey} and
796 \Macro{FamilySetLengthMacroKey} define the \PName{macro} to be the
797 \PName{value} as evaluated at the point of definition, similar to
798 \Macro{setlength}. In contrast,
799 \Macro{FamilyUseLengthMacroKey}\ChangedAt{v3.20}{\Package{scrbase}} and
800 \Macro{FamilySetUseLengthMacroKey} store the \PName{value} directly, and
801 so the \PName{value} is reevaluated each time the \PName{macro} is used.%
802 \EndIndexGroup
803
804
805 \begin{Declaration}
806 \Macro{FamilyStringKey}\OParameter{member}\Parameter{family}%
807 \Parameter{key}%
808 \OParameter{default}\Parameter{command}
809 \Macro{FamilyCSKey}\OParameter{member}\Parameter{family}%
810 \Parameter{key}%
811 \OParameter{default}\Parameter{command name}
812 \end{Declaration}
813 This defines\ChangedAt{v3.08}{\Package{scrbase}} a \PName{key} that accepts
814 any value. The value will be stored in the specified \Macro{command}. If there
815 is no optional argument for the \PName{default}, \Macro{FamilyStringKey} is
816 the same as:
817 \begin{lstcode}[escapeinside=`']
818 \DefineFamilyKey[`\PName{member}']{`\PName{family}'}{`\PName{key}'}
819 {\def`\PName{command}'{#1}}
820 \end{lstcode}
821 If you use the optional argument \PName{default}, \Macro{FamilyStringKey}
822 corresponds to:
823 \begin{lstcode}[escapeinside=`']
824 \DefineFamilyKey[`\PName{member}']{`\PName{family}'}{`\PName{key}'}
825 [`\PName{default}']
826 {\def`\PName{command}'{#1}\FamilyKeyStateProcessed}
827 \end{lstcode}
828
829 \begin{Example}
830 By default 250\Unit{g} of sausage salad should be produced. However, the
831 amount should be configurable by an option. To do so, the quantity to be
832 created is stored in the macro \Macro{saladweight}. The option to change
833 the weight should also be called \PValue{saladweight}:
834 \begin{lstcode}
835 \newcommand*{\saladweight}{250g}
836 \FamilyStringKey{butcher}%
837 {saladweight}[250g]{\saladweight}
838 \end{lstcode}
839 To switch back to the default weight after changing it, you can simply
840 call the option without the weight:
841 \begin{lstcode}
842 \FamilyOptions{butcher}{saladweight}
843 \end{lstcode}
844 This is possible because the default quantity was also set as the default
845 value in the definition.
846 \end{Example}
847 In this case, there are no unknown values because all values are simply used
848 for a macro definition. Note, however, that paragraph breaks are not allowed
849 when assigning a value to the key.
850
851 In contrast\ChangedAt{v3.25}{\Package{scrbase}} to \Macro{FamilyStringKey},
852 the \Macro{FamilyCSKey} command expects for the final argument not a macro but
853 only the name of a command, for example \PParameter{saladweight} instead of
854 \PParameter{\Macro{saladweight}}.%
855 %
856 \EndIndexGroup
857
858
859 \begin{Declaration}
860 \Macro{FamilyUnknownKeyValue}\Parameter{family}\Parameter{key}%
861 \Parameter{value}\Parameter{value list}%
862 \end{Declaration}
863 The command \Macro{FamilyUnknownKeyValue} throws an error message due to an
864 unknown or illegal values by means of \DescRef{\LabelBase.cmd.FamilyKeyState}.
865 The \PName{value list} is a comma separated list of permissible values in the
866 form
867 %\begin{flushleft}\vskip\dp\strutbox\begin{tabular}{l}
868 `\PName{value}'\texttt{,} `\PName{value}' \dots
869 %\end{tabular}\vskip\dp\strutbox\end{flushleft}
870 However\ChangedAt{v3.12}{\Package{scrbase}}, the \PName{value list} is
871 currently not evaluated by \Package{scrbase}.
872 \begin{Example}
873 The user should now also be able to select whether the cold cuts should be
874 cut thick or thin. Thick should be the default setting, which should be used
875 even if the user does not specify how to cut the coldcuts.
876 \begin{lstcode}
877 \@ifundefined{if@thincut}{%
878 \expandafter
879 \newif\csname if@thincut\endcsname}{}%
880 \@ifundefined{if@coldcuts}{%
881 \expandafter
882 \newif\csname if@coldcuts\endcsname}{}
883 \DefineFamilyKey{butcher}%
884 {coldcuts}[true]{%
885 \FamilySetBool{butcher}{coldcuts}%
886 {@coldcuts}%
887 {#1}%
888 \ifx\FamilyKeyState\FamilyKeyStateProcessed
889 \@thincutfalse
890 \else
891 \Ifstr{#1}{thin}{%
892 \@coltcutstrue
893 \@finecuttrue
894 \FamilyKeyStateProcessed
895 }{%
896 \FamilyUnknownKeyValue{butcher}%
897 {coldcuts}%
898 {#1}{%
899 `true', `on', `yes',
900 `false`, `off`, `no',
901 `thin'%
902 }%
903 }%
904 \fi
905 }%
906 \end{lstcode}
907 First we try to set the boolean coldcuts switch using
908 \DescRef{\LabelBase.cmd.FamilySetBool}. If this succeeds, i.\,e. if
909 \DescRef{\LabelBase.cmd.FamilyKeyState} corresponds to
910 \DescRef{\LabelBase.cmd.FamilyKeyStateProcessed}, thincut will be
911 deactivated. Otherwise, we check if the value is equal to \PValue{thin}
912 rather than one of the valid values for a boolean switch. In this case, both
913 coldcuts and thincut are activated and the state will be switched to
914 \DescRef{\LabelBase.cmd.FamilyKeyStateProcessed}. If the previous test
915 fails, the error state signalled by \DescRef{\LabelBase.cmd.FamilySetBool}
916 is reset to \DescRef{\LabelBase.cmd.FamilyKeyStateUnknownValue}. The list of
917 the permissible values will be added to it. However, since this list is no
918 longer used, it would have been easy to skip the call to
919 \Macro{FamilyUnknownKeyValue} in the example and thus assume the error
920 status of \DescRef{\LabelBase.cmd.FamilySetBool}.
921
922 The \Macro{ifstr} command used in the test is explained on
923 \DescPageRef{scrbase.cmd.Ifstr} in \autoref{sec:scrbase.if}.
924 \end{Example}
925 %
926 \EndIndexGroup
927
928
929 \section{Conditional Execution}
930 \seclabel{if}
931
932 The \Package{scrbase} package provides several commands for conditional
933 execution. Mostly it does not rely on the \TeX{} syntax of conditionals such
934 as
935 \begin{lstcode}
936 \iftrue
937 ...
938 \else
939 ...
940 \fi
941 \end{lstcode}
942 but uses the \LaTeX{} syntax with arguments similar to those used by \LaTeX{}
943 commands like \Macro{IfFileExists}, \Macro{@ifundefined},
944 \Macro{@ifpackageloaded}, and many others.
945
946 % TODO: Fix translation (note: this text does not really correspond to the
947 % German manual but there is a similar note at the (not free) German book
948 From \KOMAScript~3.28, following a recommendation from \LaTeX{} team members,
949 \Package{scrbase} does not longer use \Macro{if\dots} but \Macro{If\dots} for
950 commands that expect an argument instead of using the \TeX{}
951 syntax. Some commands from prior versions of \KOMAScript{} have been
952 removed. You may use package \Package{iftex} (see \cite{package:iftex}) to
953 replace the functionality. Others have been renamed.
954 % :ODOT
955
956 \begin{Declaration}
957 \Macro{Ifundefinedorrelax}%
958 \Parameter{name}\Parameter{then code}\Parameter{else code}
959 \end{Declaration}
960 This\ChangedAt{v3.28}{\Package{scrbase}} command works like
961 \Macro{@ifundefined} from the \LaTeX{} kernel (see \cite{latex:source2e}). So
962 the \PName{then code} is executed if \PName{name} is the name of a
963 command that is currently either not defined or \Macro{relax}. Otherwise, the
964 \PName{else code} is executed. Unlike \Macro{@ifundefined}, no hash
965 memory is allocated nor is \Macro{\PName{Name}} set to \Macro{relax} if
966 \Macro{\PName{name}} was previously undefined.%
967 \EndIndexGroup
968
969 \begin{Declaration}
970 \Macro{Ifnotundefined}\Parameter{name}%
971 \Parameter{then code}\Parameter{else code}
972 \end{Declaration}
973 If\ChangedAt{v3.28}{\Package{scrbase}} the command with the given name has
974 already been defined, the \PName{then code} is executed. Otherwise, the
975 \PName{else code} is executed. Since \eTeX{} already has a primitive
976 \Macro{ifdefined}, this somewhat unwieldy name, unfortunately, had to be
977 chosen. There is no corresponding internal command.%
978 \EndIndexGroup
979
980
981 \begin{Declaration}
982 \Macro{Ifstr}\Parameter{string 1}\Parameter{string 2}%
983 \Parameter{then code}\Parameter{else code}
984 \end{Declaration}
985 Both\ChangedAt{v3.28}{\Package{scrbase}} \PName{string} arguments are expanded
986 and then compared. If the expansions are the same, the \PName{then code} is
987 executed. Otherwise the \PName{else code} is executed. There is no
988 corresponding internal command.
989 %
990 \EndIndexGroup
991
992
993 \begin{Declaration}
994 \Macro{Ifstrstart}\Parameter{string 1}\Parameter{string 2}%
995 \Parameter{then code}\Parameter{else code}
996 \end{Declaration}
997 Both\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
998 \PName{string} arguments are expanded and then compared. If \PName{string 1},
999 apart from white space, begins with \PName{string 2}, the \PName{then code} is
1000 executed. Otherwise, the \PName{else code} is executed. There is no
1001 corresponding internal command.%
1002 \EndIndexGroup
1003
1004
1005 \begin{Declaration}
1006 \Macro{IfArgIsEmpty}\Parameter{argument}
1007 \Parameter{then code}\Parameter{else code}
1008 \end{Declaration}
1009 If\ChangedAt{v3.19}{\Package{scrbase}} the \PName{argument} is empty, the
1010 \PName{then code} is executed, otherwise the \PName{else code} is
1011 executed. Even one whitespace character is considered non-empty. Since the
1012 \PName{argument} is not expanded, macros that expand to an empty result are
1013 also considered to be a non-empty \PName{argument}. The same applies to
1014 \Macro{relax} or undefined macros.%
1015 \EndIndexGroup
1016
1017
1018 \iffalse % internal
1019 \begin{Declaration}
1020 \Macro{scr@ifluatex}
1021 \Parameter{then code}\Parameter{else code}
1022 \end{Declaration}
1023 If\ChangedAt{v3.21}{\Package{scrbase}} you use lua\TeX{}, the \PName{then
1024 code} will be executed. Otherwise, the \PName{else code} will be executed.
1025 \iftrue% Umbruchkorrekturtext
1026 This test is rarely useful. %
1027 \fi%
1028 As a rule, it is better to test directly for the command you want.
1029 There\textnote{Attention!} is no user equivalent for this instruction. Use the
1030 \Package{ifluatex}\important{\Package{ifluatex}} package instead (see
1031 \cite{package:ifluatex}).%
1032 \EndIndexGroup
1033 \fi
1034
1035
1036 \iffalse% It makes no sense to document this instruction yet
1037 \begin{Declaration}
1038 \Macro{scr@ifpdforluatex}
1039 \Parameter{then code}\Parameter{else code}
1040 \end{Declaration}
1041 Until lua\TeX~0.85, it was mostly irrelevant whether you used pdf\TeX{} or
1042 lua\TeX{}. This command, which executes the \PName{then code} in both cases,
1043 derives from that fact. If neither pdf\TeX{} nor lua\TeX{} is used, the
1044 \PName{else code} will be executed. Since version~0.85, lua\TeX{} has given up
1045 compatibility with many of its commands. Therefore this distinction is no
1046 longer useful in practice and is no longer used by \KOMAScript{} itself. There
1047 is no user equivalent of this statement.%
1048 \EndIndexGroup
1049 \fi
1050
1051 \iffalse % internal
1052 \begin{Declaration}
1053 \Macro{scr@ifpdftex}%
1054 \Parameter{then code}\Parameter{else code}%
1055 \end{Declaration}
1056 If you use pdf\TeX{}, the \PName{then code} will be executed. Otherwise, the
1057 \PName{else code} will be executed. It does not matter whether a PDF-file is
1058 actually generated or not. This test is rarely useful. As a rule, you should
1059 test directly for the command you want instead.%
1060 \EndIndexGroup
1061 \fi
1062
1063 \iffalse % internal
1064 \begin{Declaration}
1065 \Macro{scr@ifVTeX}%
1066 \Parameter{then code}\Parameter{else code}%
1067 \end{Declaration}
1068 If you use V\TeX{}, the \PName{then code} is executed. Otherwise, the
1069 \PName{else code} is executed. This test is seldom useful. As a rule,
1070 you should test directly for the command you want instead.%
1071 %
1072 \EndIndexGroup
1073 \fi
1074
1075
1076 \begin{Declaration}
1077 \Macro{Ifpdfoutput}%
1078 \Parameter{then code}\Parameter{else code}
1079 \end{Declaration}
1080 If\ChangedAt{v3.28}{\Package{scrbase}} a PDF file is generated, the
1081 \PName{then code} is executed. Otherwise, the \PName{else code} is
1082 executed. It does not matter whether PDF file is created using lua\TeX{},
1083 pdf\TeX{}, or V\TeX{}, or \XeTeX{}.%
1084 \EndIndexGroup
1085
1086
1087 \begin{Declaration}
1088 \Macro{Ifpsoutput}%
1089 \Parameter{then code}\Parameter{else code}
1090 \end{Declaration}
1091 If\ChangedAt{v3.28}{\Package{scrbase}} a PostScript file is generated, the
1092 \PName{then code} is executed. Otherwise, the \PName{else code} is
1093 executed. V\TeX{} can generate PostScript directly, which is recognized
1094 here. However, if V\TeX{} is not used but the switch \Macro{if@dvips} has been
1095 defined, the decision depends on that switch. \KOMAScript{} provides
1096 \Macro{if@dvips} in
1097 \hyperref[cha:typearea]{\Package{typearea}}\IndexPackage{typearea}%
1098 \IndexCmd{if@dvips}.
1099 %
1100 \EndIndexGroup
1101
1102
1103 \begin{Declaration}
1104 \Macro{Ifdvioutput}%
1105 \Parameter{then code}\Parameter{else code}
1106 \end{Declaration}
1107 If\ChangedAt{v3.28}{\Package{scrbase}} a DVI-file is generated, the
1108 \PName{then code} is executed. Otherwise, the \PName{else code} is
1109 executed. A DVI file is always assumed to be generated if no direct output of
1110 a PDF file or a PostScript file can be detected.%
1111 \EndIndexGroup
1112
1113
1114 \begin{Declaration}
1115 \Macro{Ifisdimen}\Parameter{expression}%
1116 \Parameter{then code}\Parameter{else code}
1117 \end{Declaration}
1118 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1119 \PName{expression} expands to a \Macro{dimen}, i.\,e. a \TeX{} length
1120 register, the \PName{then code} is executed. Otherwise the \PName{else
1121 code} is executed. The command is not completely expandable, and there
1122 is no corresponding internal command.%
1123 \EndIndexGroup
1124
1125
1126 \begin{Declaration}
1127 \Macro{Ifisdimension}\Parameter{expression}%
1128 \Parameter{then code}\Parameter{else code}
1129 \end{Declaration}
1130 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1131 \PName{expression} expands to something syntactically equivalent to a length,
1132 the \PName{then code} is executed. Otherwise the \PName{else code} is
1133 executed. Note\textnote{Attention!} that unknown units and missing units
1134 cause an error message. The command is not completely expandable, and there is
1135 no corresponding internal command.%
1136 \EndIndexGroup
1137
1138
1139 \begin{Declaration}
1140 \Macro{Ifdimen}\Parameter{string}%
1141 \Parameter{then code}\Parameter{else code}
1142 \end{Declaration}
1143 The \PName{then code}\ChangedAt{v3.28}{\Package{scrbase}} is executed if
1144 the first-order expansion of \PName{string} consists of digits and a valid
1145 length unit. Otherwise, the \PName{else code} is used. There is no
1146 corresponding internal command.%
1147 \EndIndexGroup
1148
1149
1150 \begin{Declaration}
1151 \Macro{Ifisdimexpr}\Parameter{expression}%
1152 \Parameter{then code}\Parameter{else code}
1153 \end{Declaration}
1154 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1155 \PName{expression} expands to an \eTeX{} \Macro{dimexpr}\IndexCmd{dimexpr},
1156 the \PName{then code} is executed. Otherwise, the \PName{else code} is
1157 executed. Note\textnote{Attention!} that illegal expressions result in
1158 error messages. The command is not completely expandable, and there is no
1159 corresponding internal command.%
1160 \EndIndexGroup
1161
1162
1163 \begin{Declaration}
1164 \Macro{Ifisskip}\Parameter{expression}%
1165 \Parameter{then code}\Parameter{else code}
1166 \end{Declaration}
1167 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1168 \PName{expression} expands to a \Macro{skip}, i.\,e. a \TeX{} distance, the
1169 \PName{then code} is executed. Otherwise, the \PName{else code} is
1170 executed. The command is not completely expandable, and there is no
1171 corresponding internal command.%
1172 \EndIndexGroup
1173
1174
1175 \begin{Declaration}
1176 \Macro{Ifisglue}\Parameter{expression}%
1177 \Parameter{then code}\Parameter{else code}
1178 \end{Declaration}
1179 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1180 \PName{expression} expands to something syntactically equivalent of the value
1181 of a skip, the \PName{then code} is executed. Otherwise, the \PName{else code}
1182 is executed. Note\textnote{Attention!} that invalid units and missing units
1183 cause an error message. The command is not completely expandable, and
1184 there is no corresponding internal command.%
1185 \EndIndexGroup
1186
1187
1188 \begin{Declaration}
1189 \Macro{Ifisglueexpr}\Parameter{expression}%
1190 \Parameter{then code}\Parameter{else code}
1191 \end{Declaration}
1192 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1193 \PName{expression} expands to a \Macro{glueexpr}, i.\,e. an \eTeX{} distance
1194 expression, the \PName{then code} is executed. Otherwise, the \PName{else
1195 code} is executed. Note,\textnote{Attention!} that illegal expressions
1196 result in error messages. The command is not completely expandable, and
1197 there is no corresponding internal command.%
1198 \EndIndexGroup
1199
1200
1201 \begin{Declaration}
1202 \Macro{Ifiscounter}\Parameter{counter}%
1203 \Parameter{then code}\Parameter{else code}
1204 \end{Declaration}
1205 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1206 \PName{counter} is defined as a \LaTeX{} counter, the \PName{then code} is
1207 executed. Otherwise, the \PName{else code} is executed. The command is
1208 not completely expandable, and there is no corresponding internal command.%
1209 \EndIndexGroup
1210
1211
1212 \begin{Declaration}
1213 \Macro{Ifiscount}\Parameter{count}%
1214 \Parameter{then code}\Parameter{else code}
1215 \end{Declaration}
1216 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1217 \PName{count} expands to a \Macro{count}, i.\,e. a \TeX{} counter, the
1218 \PName{then code} is executed. Otherwise, the \PName{else code} is
1219 executed. The command is not completely expandable, and there is no
1220 corresponding internal command. For tests of \LaTeX{} counters, see
1221 \DescRef{\LabelBase.cmd.Ifiscounter}.%
1222 \EndIndexGroup
1223
1224
1225 \begin{Declaration}
1226 \Macro{Ifisinteger}\Parameter{expression}%
1227 \Parameter{then code}\Parameter{else code}
1228 \end{Declaration}
1229 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1230 \PName{expression} expands to something syntactically equivalent to of the
1231 value of a counter, i.\,e. a negative or positive integer, the \PName{then
1232 code} is executed. Otherwise, the \PName{else code} is
1233 executed. The command is not completely expandable, and there is no
1234 corresponding internal command.%
1235 \EndIndexGroup
1236
1237
1238 \begin{Declaration}
1239 \Macro{Ifnumber}\Parameter{string}%
1240 \Parameter{then code}\Parameter{else code}
1241 \end{Declaration}
1242 The\ChangedAt{v3.28}{\Package{scrbase}} \PName{then code} is executed if
1243 the first-order expansion of \PName{string} consists only of
1244 digits. Otherwise, the \PName{else code} is used. There is no
1245 corresponding internal command.
1246 %
1247 \EndIndexGroup
1248
1249
1250 \begin{Declaration}
1251 \Macro{Ifisnumexpr}\Parameter{expression}%
1252 \Parameter{then code}\Parameter{else code}
1253 \end{Declaration}
1254 If\ChangedAt{v3.12}{\Package{scrbase}}\ChangedAt{v3.28}{\Package{scrbase}}
1255 \PName{expression} expands to a \Macro{numexpr}, i.\,e. an \eTeX{} number
1256 expression, the \PName{then code} is executed. Otherwise, the \PName{else
1257 code} is executed. Note\textnote{Attention!} that illegal expressions
1258 result in error messages. The command is not completely expandable, and
1259 there is no corresponding internal command.%
1260 \EndIndexGroup
1261
1262
1263 \begin{Declaration}
1264 \Macro{IfActiveMkBoth}\Parameter{then code}\Parameter{else code}
1265 \end{Declaration}
1266 The\ChangedAt{v3.27}{\Package{scrbase}} \LaTeX{} kernel uses
1267 \DescRef{scrlayer.cmd.@mkboth}\important{\Macro{@mkboth}}\IndexCmd{@mkboth} to
1268 distinguish between automatic and manual running heads. Usually, it sets both
1269 marks with automatic running heads. With manual running heads, it does not set
1270 any mark. To determine whether automatic running heads are active, many
1271 packages compare \DescRef{scrlayer.cmd.@mkboth} with either
1272 \DescRef{maincls.cmd.markboth}\IndexCmd{markboth} or \Macro{@gobbletwo}. But
1273 this does not account for all cases in which \DescRef{scrlayer.cmd.@mkboth}
1274 may be redefined. Therefore \Macro{IfActiveMkBoth} tests if
1275 \DescRef{scrlayer.cmd.@mkboth} would actually set a mark, even when
1276 \Macro{marks} appears in the definition of \DescRef{scrlayer.cmd.@mkboth}. If
1277 such an active \DescRef{scrlayer.cmd.@mkboth} is detected, the
1278 \PName{then code} is executed. In all other cases, the \PName{else code} is
1279 used.%
1280 \begin{Example}
1281 For example, suppose you want to set the right mark if and only if
1282 automatic running heads are used, e.\,g., the pagestyle
1283 \PageStyle{headings}\IndexPagestyle{headings}. For a first attempt,
1284 you might use:
1285 \begin{lstcode}
1286 \ifx\@mkboth\markboth \markright{running head}\fi
1287 \end{lstcode}
1288 Later you discover that some package does not use the usual
1289 \begin{lstcode}
1290 \let\@mkboth\markboth
1291 \end{lstcode}
1292 but
1293 \begin{lstcode}
1294 \renewcommand{\@mkboth}{\markboth}
1295 \end{lstcode}
1296 to activate automatic running heads. Because of this, your comparison always
1297 fails and never calls \DescRef{maincls.cmd.markright}. To solve this, you
1298 try the following change:
1299 \begin{lstcode}
1300 \ifx\@mkboth\@gobbletwo\else \markright{running head}\fi
1301 \end{lstcode}
1302 Unfortunately, now \DescRef{maincls.cmd.markright} is also called for
1303 manual running heads, because someone has defined
1304 \begin{lstcode}
1305 \renewcommand{\@mkboth}[2]{%
1306 \typeout{DEBUG: ignoring running head setting}%
1307 }
1308 \end{lstcode}
1309 for this case.
1310
1311 Fortunately, both problems are easy to solve with \Package{scrbase}:
1312 \begin{lstcode}
1313 \IfActiveMkBoth{\markright{Kolumnentitel}}{}
1314 \end{lstcode}%
1315 \end{Example}
1316 By the way, an even simpler solution for the problem in the example
1317 would be to use \DescRef{scrlayer.cmd.@mkright} from package
1318 \hyperref[cha:scrlayer]{\Package{scrlayer}} (see
1319 \autoref{sec:scrlayer.pagestyle.content},
1320 \DescPageRef{scrlayer.cmd.@mkright}).%
1321 \EndIndexGroup
1322
1323
1324 \begin{Declaration}
1325 \Macro{if@atdocument}\ \PName{then code}\ %
1326 \textMacro{else}\ \PName{else code}\ \textMacro{fi}
1327 \end{Declaration}
1328 This conditional command intentionally exists only as an internal command. In
1329 the document preamble, \Macro{if@atdocument} corresponds to \Macro{iffalse}.
1330 After \Macro{begin}\PParameter{document}, it corresponds to \Macro{iftrue}.
1331 Authors of classes and packages may find this command useful if a command
1332 should behave differently depending on whether it is used in the preamble or
1333 inside document body. Note\textnote{Attention!} that this command is a
1334 condition using \TeX{} syntax and not \LaTeX{}
1335 syntax. From\ChangedAt{v3.37}{\Package{scrbase}} \LaTeX{} 2020/10/01
1336 \Package{scrbase} does \Macro{@atdocumentrue} already with the generic
1337 \LaTeX{} hook \texttt{begindocument/before}. Therefore for code with
1338 \Macro{AtBeginDocument} the state of \Macro{if@atdocument} is already
1339 \Macro{iftrue} for all packages and classes. For using \Macro{if@atdocument}
1340 with the generic \LaTeX{} hook \texttt{begindocument/before} you would need an
1341 additional hook rule to have a definite state.%
1342 \EndIndexGroup
1343
1344
1345 \section{Defining Language-Dependent Terms}
1346 \seclabel{languageSupport}
1347 \BeginIndexGroup
1348 \BeginIndex{}{language>definition}
1349 \index{language>dependent terms|see{language definition}}
1350 \index{terms>language-dependent|see{language definition}}
1351
1352 Beginners often find it difficult to change language-dependent terms
1353 \Macro{listfigurename}\IndexCmd{listfigurename}, by default usually ``List of
1354 Figures.'' For example, if these are simply redefined with
1355 \Macro{renewcommand} in the document preamble, they will not survive a later
1356 change of language. If you use \Package{babel}\IndexCmd{babel}, the
1357 redefinition in the preamble is overwritten with
1358 \Macro{begin}\PParameter{document}.
1359
1360 To define or change language-dependent terms, you normally have to redefine
1361 commands like \Macro{captionsenglish} so that the new or redefined terms are
1362 defined in addition to the previous terms. This is made more difficult by the
1363 fact that some packages like \Package{babel}\IndexPackage{babel} or
1364 \Package{polyglossia}\IndexPackage{polyglossia} also redefine those
1365 commands. These definitions, unfortunately, occur in a way that undoes all the
1366 previous changes. For this reason, it makes sense to delay changes until
1367 \Macro{begin}\PParameter{document} by using \Macro{AtBeginDocument}, that is,
1368 after all packages have been loaded. A user can also use
1369 \Macro{AtBeginDocument} or redefine the language-dependent terms not in the
1370 preamble but after \Macro{begin}\PParameter{document}.
1371
1372 Adding further to the difficulty, some packages define additional
1373 language-dependent terms in \Macro{captions\PName{language}}, while others use
1374 \Macro{extras\PName{language}}. So the user must understand the commands very
1375 well in order to use the correct one in the right way.
1376
1377 The \Package{scrbase} package therefore provides additional commands to define
1378 or modify language-dependent terms, relieving the user of many of these
1379 problems. These commands also let you simultaneously define or change the
1380 language-dependent terms of several dialects or forms of a language.
1381
1382 \begin{Declaration}
1383 \Macro{defcaptionname}%
1384 \Parameter{language list}\Parameter{term}\Parameter{definition}%
1385 \Macro{providecaptionname}%
1386 \Parameter{language list}\Parameter{term}\Parameter{definition}%
1387 \Macro{newcaptionname}%
1388 \Parameter{language list}\Parameter{term}\Parameter{definition}%
1389 \Macro{renewcaptionname}%
1390 \Parameter{language list}\Parameter{term}\Parameter{definition}%
1391 \Macro{defcaptionname*}%
1392 \Parameter{language list}\Parameter{term}\Parameter{definition}%
1393 \Macro{providecaptionname*}%
1394 \Parameter{language list}\Parameter{term}\Parameter{definition}%
1395 \Macro{newcaptionname*}%
1396 \Parameter{language list}\Parameter{term}\Parameter{definition}%
1397 \Macro{renewcaptionname*}%
1398 \Parameter{language list}\Parameter{term}\Parameter{definition}
1399 \end{Declaration}
1400 With these four commands and their starred variants, you can assign a
1401 \PName{definition} for a particular language to a \PName{term}. Several
1402 languages can be concatenated with comma in the \PName{language list}.
1403
1404 The \PName{term} is always a macro. The commands differ depending on whether a
1405 given language or a \PName{term} within a given language is already defined at
1406 the time the command is called.
1407
1408 If a language is not defined, \Macro{providecaptionname} does nothing other
1409 than write a message to the log file. This happens only once for each
1410 language. If a language is defined but does not yet contain a corresponding
1411 \PName{term}, it will be defined using \PName{definition}. However, the
1412 \PName{term} will not be redefined if the language already has such a
1413 definition; instead, an appropriate message is written to the log file.
1414
1415 On the other hand, if a language has not yet been defined,
1416 \Macro{newcaptionname} defines a new language command will be created. For the
1417 language \PValue{USenglish}, for example, this would be the language command
1418 \Macro{captionsUSenglish}. This definition will also be noted in the log file.
1419 If \PName{term} is not yet defined in this language, it will be defined using
1420 \PName{definition}. If the \PName{term} already exists in a language, an error
1421 message is issued.
1422
1423 The \Macro{renewcaptionname} command behaves still differently. If a language
1424 is undefined, an error message is issued. If the \PName{term} is not defined
1425 in this language, an error message is also issued. If the \PName{term} is
1426 defined in the language, it will be redefined to \PName{definition}.
1427
1428 The\ChangedAt{v3.12}{\Package{scrbase}} \Macro{defcaptionname} command always
1429 defines the \PName{term}, thus overwriting any previous definition. As with
1430 \Macro{providecaptionname}, the language specified need not be previously
1431 defined.
1432
1433 \KOMAScript{} itself uses \Macro{providecaptionname} to define the commands in
1434 \autoref{sec:scrlttr2-experts.languages}.
1435 \DescPageRef{scrlttr2-experts.cmd.yourrefname}.
1436
1437 \begin{Example}
1438 If you prefer ``fig.'' instead of ``figure'' in \PValue{USenglish}, you can
1439 achieve this using:
1440 \begin{lstcode}
1441 \renewcaptionname{USenglish}{\figurename}{fig.}
1442 \end{lstcode}
1443 If you want the same change not only in \PValue{USenglish} but also in
1444 \PValue{UKenglish}, you do not need an additional:
1445 \begin{lstcode}
1446 \renewcaptionname{UKenglish}{\figurename}{fig.}
1447 \end{lstcode}
1448 but can simply extend the \PName{language list}:
1449 \begin{lstcode}
1450 \renewcaptionname{USenglish,UKenglish}{\figurename}{fig.}
1451 \end{lstcode}
1452 You can extend the \PName{language list} in the same manner with
1453 \PValue{american}, \PValue{australian}, \PValue{british}, \PValue{canadian},
1454 and \PValue{newzealand}.
1455 \end{Example}
1456
1457 Since \KOMAScript~3.12\ChangedAt{v3.12}{\Package{scrbase}}, you no longer need
1458 to delay the definition or redefinition until
1459 \Macro{begin}\PParameter{document} using \Macro{AtBeginDocument} because
1460 \Package{scrbase} does this itself if the commands are called in the
1461 document's preamble. Additionally, \Package{scrbase} now checks if a term
1462 should be redefined in \Macro{extras\PName{language}} instead of
1463 \Macro{captions\PName{language}}. The new starred variants of the commands
1464 always use \Macro{extras\PName{language}}. So redefining language-dependent
1465 terms for packages like \Package{hyperref} that use
1466 \Macro{extras\PName{language}} should work as expected.
1467
1468 Language-dependent terms that are commonly defined by classes and language
1469 packages are described in \autoref{tab:scrbase.commonNames}.
1470
1471 \begin{desclist}
1472 \renewcommand*{\abovecaptionskipcorrection}{-\normalbaselineskip}%
1473 \desccaption[{%
1474 Overview of common language-dependent terms%
1475 }]{%
1476 Overview of language-dependent terms of typical language packages%
1477 \label{tab:scrbase.commonNames}%
1478 }{%
1479 Overview of common language dependent terms
1480 (\emph{continued})%
1481 }%
1482 \entry{\Macro{abstractname}}{%
1483 heading of the abstract%
1484 \IndexCmd{abstractname}%
1485 }%
1486 \entry{\Macro{alsoname}}{%
1487 ``see also'' in additional cross references of the index%
1488 \IndexCmd{alsoname}%
1489 }%
1490 \entry{\Macro{appendixname}}{%
1491 ``appendix'' in the heading of an appendix chapter%
1492 \IndexCmd{appendixname}%
1493 }%
1494 \entry{\Macro{bibname}}{%
1495 heading of the bibliography%
1496 \IndexCmd{bibname}%
1497 }%
1498 \entry{\Macro{ccname}}{%
1499 prefix heading for the distribution list of a letter%
1500 \IndexCmd{ccname}%
1501 }%
1502 \entry{\Macro{chaptername}}{%
1503 ``chapter'' in the heading of a chapter%
1504 \IndexCmd{chaptername}%
1505 }%
1506 \entry{\Macro{contentsname}}{%
1507 heading of the table of contents%
1508 \IndexCmd{contentsname}%
1509 }%
1510 \entry{\Macro{enclname}}{%
1511 prefix heading for the enclosures of a letter%
1512 \IndexCmd{enclname}%
1513 }%
1514 \entry{\Macro{figurename}}{%
1515 prefix heading of figure captions%
1516 \IndexCmd{figurename}%
1517 }%
1518 \entry{\Macro{glossaryname}}{%
1519 heading of the glossary%
1520 \IndexCmd{glossaryname}%
1521 }%
1522 \entry{\Macro{headtoname}}{%
1523 ``to'' in header of letter pages%
1524 \IndexCmd{headtoname}%
1525 }%
1526 \entry{\Macro{indexname}}{%
1527 heading of the index%
1528 \IndexCmd{indexname}%
1529 }%
1530 \entry{\Macro{listfigurename}}{%
1531 heading of the list of figures%
1532 \IndexCmd{listfigurename}%
1533 }%
1534 \entry{\Macro{listtablename}}{%
1535 heading of the list of tables%
1536 \IndexCmd{listtablename}%
1537 }%
1538 \entry{\Macro{pagename}}{%
1539 ``page'' in the pagination of letters%
1540 \IndexCmd{pagename}%
1541 }%
1542 \entry{\Macro{partname}}{%
1543 ``part'' in the heading of a part%
1544 \IndexCmd{partname}%
1545 }%
1546 \entry{\Macro{prefacename}}{%
1547 heading of the preface%
1548 \IndexCmd{prefacename}%
1549 }%
1550 \entry{\Macro{proofname}}{%
1551 prefix heading of mathematical proofs%
1552 \IndexCmd{proofname}%
1553 }%
1554 \entry{\Macro{refname}}{%
1555 heading of the list of references%
1556 \IndexCmd{refname}%
1557 }%
1558 \entry{\Macro{seename}}{%
1559 ``see'' in cross references of the index%
1560 \IndexCmd{seename}%
1561 }%
1562 \entry{\Macro{tablename}}{%
1563 prefix heading at table captions%
1564 \IndexCmd{tablename}%
1565 }%
1566 \end{desclist}
1567 %
1568 \EndIndexGroup
1569 %
1570 \EndIndexGroup
1571
1572
1573 \section{Identifying \KOMAScript}
1574 \seclabel{identify}
1575
1576 Although\,---\,or especially because\,---\,\Package{scrbase} is generally
1577 designed as a package for authors of classes and packages, it is of course
1578 used by the \KOMAScript{} classes and most \KOMAScript{} packages. It
1579 therefore contains a that is present in all \KOMAScript{} classes
1580 and all basic \KOMAScript{} packages.
1581
1582 \begin{Declaration}
1583 \Macro{KOMAScriptVersion}
1584 \end{Declaration}
1585 \KOMAScript{} defines the major version of \KOMAScript{} in this command. It
1586 has the form ``\PName{date} \PName{version} \texttt{KOMA-Script}''. This major
1587 version is same for all \KOMAScript{} classes and all \KOMAScript{} packages
1588 used by the classes. For this reason, it can be queried after you
1589 load \Package{scrbase}, too. For example, this guide was made using
1590 \KOMAScript{} version ``\KOMAScriptVersion''.
1591 %
1592 \EndIndexGroup
1593
1594
1595 \section{Extensions to the \LaTeX{} Kernel}
1596 \seclabel{latexkernel}
1597
1598 Sometimes the \LaTeX{} kernel itself provides commands but lacks other very
1599 similar commands that would often be useful. A few such commands are provided
1600 by \Package{scrbase} for authors of packages and classes.
1601
1602 \begin{Declaration}
1603 \Macro{ClassInfoNoLine}\Parameter{class name}\Parameter{information}%
1604 \Macro{PackageInfoNoLine}\Parameter{package name}\Parameter{information}%
1605 \end{Declaration}%
1606 The \LaTeX{} kernel already provides authors of classes and packages commands
1607 like \Macro{ClassInfo} and \Macro{PackageInfo} to write information, along
1608 with the current line number, to the log file. In addition to
1609 \Macro{PackageWarning} and \Macro{ClassWarning}, which throw warning messages
1610 with line numbers, it also provides \Macro{PackageWarningNoLine} and
1611 \Macro{ClassWarningNoLine} for warning messages without line numbers. However
1612 the obvious commands \Macro{ClassInfoNoLine} and \Macro{PackageInfoNoLine},
1613 for writing information without line numbers into the log file, are missing.
1614 The \Package{scrbase} package provides them.
1615 %
1616 \EndIndexGroup
1617
1618
1619 \begin{Declaration}
1620 \Macro{l@addto@macro}\Parameter{command}\Parameter{extension}%
1621 \end{Declaration}%
1622 The \LaTeX{} kernel provides an internal command \Macro{g@addto@macro} to
1623 extend the definition of macro \Macro{command} globally with
1624 \PName{extension}. This works in this form only for macros that have no
1625 arguments. However, sometimes you may need a command like this that works
1626 locally within the current group. The \Package{scrbase} package provides such
1627 a command with \Macro{l@addto@macro}. An alternative is to use the
1628 \Package{etoolbox}\IndexPackage{etoolbox} or
1629 \Package{xpatch}\IndexPackage{xpatch} package, which offers a whole range of
1630 such commands for different purposes (see \cite{package:etoolbox} or
1631 \cite{package:xpatch}).%
1632 \EndIndexGroup
1633
1634
1635 \section{Extensions to the Mathematical Features of \eTeX}
1636 \seclabel{etex}
1637
1638 \eTeX{}, which is used by \LaTeX{} and loaded by \KOMAScript{}, has extended
1639 capabilities for calculating simple arithmetic with \TeX{} counters and
1640 integers using \Macro{numexpr}\IndexCmd{numexpr}. The four basic arithmetic
1641 operations and parentheses are supported. Division is rounded
1642 correctly. Sometimes additional operators would be useful.
1643
1644 \begin{Declaration}
1645 \Macro{XdivY}\Parameter{dividend}\Parameter{divisor}%
1646 \Macro{XmodY}\Parameter{dividend}\Parameter{divisor}%
1647 \end{Declaration}%
1648 The\ChangedAt{v3.05a}{\Package{scrbase}} \Macro{XdivY} command returns the
1649 value of the integer quotient, with the \Macro{XmodY} command giving the value
1650 of the remainder. This type of of division is defined by the equation
1651 \[
1652 \textit{dividend} = \textit{divisor} \cdot
1653 \textit{integer quotient} + \textit{remainder}
1654 \]
1655 where \textit{dividend}, \textit{divisor}, and \textit{remainder} are
1656 integers, \textit{remainder} is greater or equal to 0 and less than
1657 \textit{divisor}, and \textit{divisor} is a natural number greater than 0.
1658
1659 You can assign the value to a counter or use it directly within an expression
1660 using \Macro{numexpr}. To output the value as an Arabic number, you must
1661 prefix it with \Macro{the}.%
1662 %
1663 \EndIndexGroup
1664
1665
1666 \section[{General Mechanism for Multi-Level Hooks}]
1667 {General Mechanism for Multi-Level
1668 Hooks\ChangedAt[2019/01]{v3.27}{\Package{scrbase}}}
1669 \seclabel{hooks}
1670
1671 \BeginIndexGroup
1672 \BeginIndex{}{Hooks}
1673 The \LaTeX{} kernel provides a few \emph{hooks} in the processing of
1674 a document where additional code can be inserted. Class and package authors
1675 should be very familiar with \Macro{AtBeginDocument} and
1676 \Macro{AtEndDocument}. \KOMAScript{} offers similar features in some places,
1677 for example to hook code into the execution of
1678 \hyperref[sec:maincls.structure]{sectioning commands}. Over the years, there
1679 have been two problems:
1680 \begin{itemize}
1681 \item There are never enough hooks.
1682 \item There is some code that should only be executed once, as if it almost
1683 drops off the hook, as well as code that must be executed each time the
1684 hook is encountered, thus remaining permanently on the hook.
1685 \end{itemize}
1686 Usually, to define a single hook you must define a command that collects the
1687 code for each hook. This code is then stored in another internal macro, which
1688 must be inserted at the point where the collected code is executed. The more
1689 hooks you insert, the more such commands there are. To allow for both
1690 single-use code and permanent code may even require two hooks, and therefore
1691 twice the number of commands to be defined.
1692
1693 The example of sectioning commands shows that the first problem can sometimes
1694 be exacerbated by having only a single point for code execution. One package
1695 author may need only one way to execute the same code for all sectioning
1696 commands. Another package author would prefer to execute different code for
1697 certain sectioning commands only. Meeting both these demands would require a
1698 general hook as well as a hook for each sectioning command. These requirements
1699 are doubled again because of the second problem.
1700
1701 \KOMAScript{} therefore offers a generalized hook mechanism in
1702 \Package{scrbase} that provides multi-level hooks for both single-use and
1703 persistent code. These hooks are named \emph{do-hooks} because of their
1704 implementation. From this also comes the names of the instructions by which
1705 they are controlled.
1706
1707 \begin{Declaration}
1708 \Macro{ExecuteDoHook}\Parameter{specifier}
1709 \end{Declaration}
1710 Hooks\ChangedAt[2019/01]{v3.27}{\Package{scrbase}} are implemented with this
1711 command. The \PName{specifier} determines the name or names of the hook. The
1712 \PName{specifier} is always completely expanded for analysis.
1713
1714 The \PName{specifier} generally consists of strings separated by forward
1715 slashes (``/''). Initially, \Macro{ExecuteDoHook} divides the string at the
1716 first slash. The first part is the name. The remainder (without the slash) is
1717 the argument. Then the code for the hook with this name is executed. Next the
1718 first part of the remaining string is divided again from the remainder,
1719 combined with a slash after the name to form a new name, and the code with
1720 this name is executed. This process continues until the code for the hook with
1721 the name \PName{specifier} has been executed and the argument is empty.
1722
1723 In the simplest case, the \PName{specifier} consists of a single name. In this
1724 case, the persistent code is executed first, with an empty argument, for
1725 exactly one hook specified by this name.
1726
1727 At each stage of execution, single-use code is also executed after the hook's
1728 persistent code, and then the single-use code is globally removed from the
1729 hook.
1730
1731 \begin{Example}
1732 By inserting \DescRef{\LabelBase.cmd.ExecuteDoHook}%
1733 \PParameter{heading/begingroup/\PName{name}} into the execution of each
1734 sectioning command defined with
1735 \DescRef{maincls-experts.cmd.DeclareSectionCommand}, the \KOMAScript{}
1736 classes ultimately have six hooks inserted at that code-point, executed in
1737 this order:
1738 \begin{enumerate}
1739 \item \PValue{heading} with the argument \PValue{begingroup/}\PName{name}
1740 for persistent code,
1741 \item \PValue{heading} with the argument \PValue{begingroup/}\PName{name}
1742 for single-use code,
1743 \item \PValue{heading/begingroup} with the argument \PName{name} for
1744 persistent code,
1745 \item \PValue{heading/begingroup} with the argument \PName{name} for
1746 single-use code,
1747 \item \PValue{heading/begingroup/}\PName{name} with an empty argument for
1748 persistent code,
1749 \item \PValue{heading/begingroup/}\PName{name} with an empty argument for
1750 single-use code.
1751 \end{enumerate}
1752 The \PName{name} is the name of section level specified in
1753 \DescRef{maincls-experts.cmd.DeclareSectionCommand},
1754 \DescRef{maincls-experts.cmd.DeclareNewSectionCommand} or
1755 \DescRef{maincls-experts.cmd.ProvideSectionCommand}, or the sectioning
1756 command specified by it, for example \PValue{chapter} or
1757 \PValue{subparagraph}. Looking at the list above, and considering that there
1758 are various sectioning commands, it becomes clear that the \PValue{heading}
1759 and \PValue{heading/begingroup} hooks will be called multiple times for each
1760 sectioning command.%
1761 \end{Example}%
1762 %
1763 \EndIndexGroup
1764
1765 \begin{Declaration}
1766 \Macro{AddtoDoHook}\Parameter{name}\Parameter{command}
1767 \Macro{AddtoOneTimeDoHook}\Parameter{name}\Parameter{command}
1768 \end{Declaration}
1769 \Macro{AddtoDoHook}\ChangedAt[2019/01]{v3.27}{\Package{scrbase}} appends
1770 persistent code to the hook named \PName{name}. The code to be added is the
1771 \PName{command}, to which the argument mentioned in the description of
1772 \DescRef{\LabelBase.cmd.ExecuteDoHook} is appended as a parameter.
1773 \begin{Example}
1774 Suppose you want to count how many times the \Macro{section} command is
1775 executed. This would be simple, continuing the previous example:
1776 \begin{lstcode}
1777 \newcounter{sectionCounter}
1778 \AddtoDoHook{heading/begingroup/section}
1779 {\stepcounter{sectionCounter}}
1780 \end{lstcode}
1781 However, in reality, \Macro{stepcounter}\PParameter{sectionCounter}%
1782 \PParameter{} would be executed. Remember that an argument is always appended
1783 as a parameter. In the case of the hook named
1784 \PValue{heading/begingroup/section}, this argument is empty. Since an empty
1785 parameter becomes an empty group here, it is better to consume this empty
1786 parameter:
1787 \begin{lstcode}
1788 \newcommand*{\stepcountergobble}[2]{%
1789 \stepcounter{#1}%
1790 }
1791 \AddtoDoHook{heading/begingroup/section}
1792 {\stepcountergobble{sectionCounter}}
1793 \end{lstcode}
1794 Here, the appended, empty parameter of \Macro{stepcountergobble} is read but
1795 not used.
1796
1797 If instead of \Macro{section}, you want to count all sectioning commands, you
1798 only need to change the hook name:
1799 \begin{lstcode}
1800 \AddtoDoHook{heading/begingroup}
1801 {\stepcountergobble{sectionCounter}}
1802 \end{lstcode}
1803 By the way, the appended parameter is not empty in this case but contains the
1804 name of the sectioning level or sectioning command. If you wanted to count
1805 the sectioning commands individually, you could just use this:
1806 \begin{lstcode}
1807 \newcommand*{\stepCounter}[1]{%
1808 \stepcounter{#1Counter}%
1809 }
1810 \AddtoDoHook{heading/begingroup}
1811 {\stepCounter}
1812 \end{lstcode}
1813 Of course, you must also define the counters \Counter{partCounter},
1814 \Counter{chapterCounter} down to \Counter{subparagraphCounter}.
1815 \end{Example}
1816
1817 The \Macro{AddtoOneTimeDoHook} command works similarly but adds the
1818 \PName{command} to the single-use code. This code will be globally removed
1819 after the first execution.%
1820 \EndIndexGroup
1821
1822 \begin{Declaration}
1823 \Macro{ForDoHook}\Parameter{specification}\Parameter{command}
1824 \end{Declaration}
1825 While\ChangedAt[2019/01]{v3.27}{\Package{scrbase}}
1826 \DescRef{\LabelBase.cmd.ExecuteDoHook} executes the commands previously stored
1827 with \DescRef{\LabelBase.cmd.AddtoDoHook} or
1828 \DescRef{\LabelBase.cmd.AddtoOneTimeDoHook} for the hook given by the
1829 \PName{specifier}, this macro executes the \PName{command} immediately. There
1830 are two parameters added to the \PName{command}. The first is the hook's name;
1831 the second, the hook's argument.
1832
1833 This command is a byproduct of the implementation of
1834 \DescRef{\LabelBase.cmd.ExecuteDoHook}. Normally, neither end users nor package
1835 authors should need this command.%
1836 \EndIndexGroup
1837
1838 \begin{Declaration}
1839 \Macro{SplitDoHook}\Parameter{specifier}\Parameter{head macro}
1840 \Parameter{remainder macro}
1841 \end{Declaration}
1842 As\ChangedAt[2019/01]{v3.27}{\Package{scrbase}} can be seen from the preceding
1843 explanations, the parameter of a \PName{command} added with
1844 \DescRef{\LabelBase.cmd.AddtoDoHook} or
1845 \DescRef{\LabelBase.cmd.AddtoOneTimeDoHook} can also be a multi-part
1846 \PName{specifier}. You can use \Macro{SplitDoHook} to divide a
1847 \PName{specifier} into the front element and the remainder. The
1848 \PName{head macro} will be set to the front element. The \PName{remainder
1849 macro} will be set to the rest. If there is no remainder left, the
1850 \PName{remainder macro} is set to empty. If the \PName{specifier} was already
1851 empty, a warning is issued and both the \PName{head macro} and the
1852 \PName{remainder macro} are set to empty.
1853
1854 \begin{Example}
1855 If you want to increase a counter at the start of a group in which a heading
1856 is issued but decrease it at the end, you can do this with two hooks:
1857 \begin{lstcode}
1858 \AddtoDoHook{heading/begingroup}
1859 {\stepCounter}
1860 \newcommand*{\restepCounter}[1]{%
1861 \addtocounter{#1Counter}{-1}%
1862 }
1863 \AddtoDoHook{heading/endgroup}
1864 {\restepCounter}
1865 \end{lstcode}
1866 But you could also use a single hook and split its parameters:
1867 \begin{lstcode}
1868 \newcommand*{\changeCounter}[1]{%
1869 \SplitDoHook{#1}{\Group}{\Level}%
1870 \Ifstr{\Group}{begingroup}{%
1871 \stepcounter{\Level Counter}%
1872 }{%
1873 \Ifstr{\Group}{endgroup}{%
1874 \addtocounter{\Level Counter}{-1}%
1875 }{}%
1876 }%
1877 }
1878 \AddtoDoHook{heading}
1879 {\changeCounter}
1880 \end{lstcode}
1881 As you can see, the first solution is much simpler. In addition, it would
1882 be easy to overlook including the empty group for the second false-case in
1883 the second example. That would be fatal, however, as there make be other
1884 hooks with named \PValue{heading} but with different arguments.
1885 \end{Example}
1886
1887 Strictly speaking, this command is a byproduct of the implementation of
1888 \DescRef{\LabelBase.cmd.ForDoHook}.%
1889 \EndIndexGroup
1890 %
1891 \EndIndexGroup
1892
1893 \section{Obsolete Options and Commands}
1894 \seclabel{obsolete}
1895
1896 % TODO: Fix new translation
1897 Prior release of \Package{scrbase} provided some options and commands that has
1898 been removed or replaced meanwhile. Those are documented in this section only
1899 for completeness but shouldn't be used any longer.
1900 % :ODOT
1901
1902 % \LoadNonFree{scrbase}{0}% not available in English
1903 \begin{Explain}
1904 \begin{Declaration}
1905 \Macro{FamilyElseValues}
1906 \end{Declaration}
1907 Since version 3.12 the command is deprecated. Nevertheless,
1908 \Package{scrbase} detects its use and issues a message requesting that you
1909 update the code accordingly.%
1910 \EndIndexGroup%
1911
1912
1913 \begin{Declaration}
1914 \OptionVName{internalonly}{value}
1915 \end{Declaration}
1916 Since version 3.28 this option is deprecated. For compatibility it is
1917 processed (see \DescRef{\LabelBase.cmd.FamilyKeyStateProcessed}) but
1918 ignored.%
1919 \EndIndexGroup%
1920 \end{Explain}%
1921 %
1922 \EndIndexGroup
1923
1924 \endinput
1925
1926 %%% Local Variables:
1927 %%% mode: latex
1928 %%% TeX-master: "scrguide-en.tex"
1929 %%% coding: utf-8
1930 %%% ispell-local-dictionary: "en_GB"
1931 %%% eval: (flyspell-mode 1)
1932 %%% End: