Part II.
KOMA-Script for Advanced Users and Experts
In this part information for the authors of LaTeX packages and classes can be found. This
applies not only instructions that are useful for implementation of new packages and classes,
but also interfaces to allow further intervention in KOMA-Script. Moreover, in this part, in-
formation on obsolete options and instructions are provided as well as background information
on the implementation of KOMAScript.
This part is intended to supplement the information for authors of articles, reports, books
and letters in
part I
. More information and examples for those users can be found in that
part.
Chapter 12: Basic Functions of Package scrbase
308
Basic Functions of Package scrbase
The package scrbase provides basic features designed and implemented for use by authors
of packages and classes. However, scrbase cannot only by used for wrapper classes related
to KOMA-Script class. Authors of classes that have nothing to do with KOMA-Script can
benefit from scrbase functionality.
12.1. Loading the Package
Whereas users load packages using \usepackage, authors of packages or classes should use
\RequirePackage
. Authors of wrapper packages may also use \RequirePackageWithOptions.
Command \RequirePackage has the same optional argument for package options like
\usepackage
. In contrast, \RequirePackageWithOptions does not have an optional argu-
ment but passes all options given when loading the wrapper package to the required package.
See [
Tea06
] for more information about these commands.
The package scrbase needs the functionality of package keyval internally. This may be
provided by package xkeyval alternatively. Package scrbase loads keyval as needed.
The package keyval provides definition of keys and assignment of values to these keys. The
options provided by scrbase also use keyval syntax: key =value .
internalonly=value
Package scrbase provides some commands for conditional execution. The primary names
for these are builds like \scr@name , which are internal commands. KOMA-Script only uses
these internal commands internally. Authors of packages and classes may use these internal
commands, too, but should not redefine them. Because some of these commands are useful for
users, too, they are provided as \name normally. But eventually, other packages may provide
commands with the same name but different syntax or different functionality. As this would
result in an conflict, scrbase can suppress the definition of the user commands \name . Using
option internalonly without value will define only the internal commands and suppress
definition of all the user commands for conditional execution. Alternatively, the user may give
all the commands that should not be defined as value , but replaces “\” by “/”.
Authors of packages and classes normally should not use this option.
Users may
use it with or without value either as a global option with \documentclass or using
\PassOptionsToPackage
.
Example: The user does not want scrbase to define commands \ifVTeX and
\ifundefinedorrelax
. Because of this, to load the class, the user writes:
\documentclass%
[internalonly=/ifVTeX/ifundefinedorrelax]%
{foo}
Chapter 12: Basic Functions of Package scrbase
309
Class name foo is, therefore, an placeholder for any class in this example. The
meanings of commands \ifVTeX and
\ifundefinedorrelax
and many more com-
mands for conditional execution is located in
section 12.3
.
12.2. Keys as Attributes of Families and their Members
As already mentioned in
section 12.1
, scrbase uses package keyval for keys and values of keys.
Nevertheless scrbase extends the functionality of keyval. Whereas only one family owns all
keys of keyval, scrbase recognises also family members. Therefore, a key may be owned by a
family or by one or more family members. Additionally, a value may be assigned to the key
of a family member, to the key of a family, or to the keys of all family members.
\DefineFamily{family }
\DefineFamilyMember[family member ]{family }
scrbase needs to know the members of a family for different reasons. First, you have to define
a new family using \DefineFamily, which produces an empty member list. If the family has
already been defined nothing would happen. Nothing also means that an already existing
member list would not be overwritten.
Next, a new member can be added to the family using \DefineFamilyMember. If the family
does not exist, this would result in an error message. If the member already exists, nothing hap-
pens. If the optional family member is omitted, the default value “.\@currname.\@currext”
is used. During class or package loading \@currname and \@currext together represent the
file name of the class or package.
Theoretically, it is possible, to define a member without a name using an empty optional
family member
argument. But this is the same as the family itself. It is recommended that
only letters and digits be used for family and the first character of family member should
not be a letter or digit. Otherwise, it could happen that members of one family are the same
as members of another family.
scrbase assigns family “KOMA” to itself and adds member “.scrbase.sty” to it. Family
“KOMA” is reserved to KOMA-Script. For your own packages, use the name of the bundle as
family
and the name of the package as family member of that family .
Example: Assume you are writing a bundle called “master butcher”. Within that bundle you
have packages salami.sty, liversausage.sty, and kielbasa.sty. Therefore,
you decide to use family name “butcher” and,to each of the package file, you add
the lines
\DefineFamily{butcher}
\DefineFamilyMember{butcher}
Chapter 12: Basic Functions of Package scrbase
310
When loading the three packages, this will add the members “.salami.sty”,
“.liversausage.sty”, and “.kielbasa.sty” to the family “butcher”. After
loading all three packages, all three member will be defined.
\DefineFamilyKey[family member ]{family }{key }[default ]{action }
\FamilyKeyState
\FamilyKeyStateUnknown
\FamilyKeyStateProcessed
\FamilyKeyStateUnknownValue
\FamilyKeyStateNeedValue
The command \DefineFamilyKey defines a key . If a family member is given, the key be-
comes an attribute of that member in the given family . If a family member is not given,
the member “.\@currname.\@currext” is assumed. If, later, a value is assigned to the key ,
the action will be executed and the value made an argument of action . So inside action
“#1” would be that value. If the value is omitted, the default is used instead. If there is no
default
, the key can be used only with a value being defined.
At least
\DefineFamilyKey[member ]{family }{key }
[default ]{action }
will result in a call of
\define@key{family member }{key }
[default ]{extended action }
with \define@key provided by package keyval (see [
Car99a
]). However, the call of \define@key
and the action is, in fact, extended by additional arrangements.
Success
v3.12
or failure of the execution of the action should be reported back to scrbase by
\FamilyKeyState
. The package itself will take care of additional procedures if needed.
You should not report errors by yourself! The default state before execution of action is
\FamilyKeyStateUnknown
. This signals that it is not known whether or not the execution
is successful. If this state does not change until end of execution of the action , scrbase will
write a message into the log file and assumes state \FamilyKeyStateProcessed during the
further procedure.
State \FamilyKeyStateProcessed signals that the option and the value assignment to
the option are completely and successfully finished. You may switch to this state by using
\FamilyKeyStateProcessed
itself.
State \FamilyKeyStateUnknownValue indicates that the option was handled, but the
value, that should be assigned to the key, was unknown or not allowed. You should use
\FamilyKeyStateUnknownValue
to switch to this state.
State \FamilyKeyStateNeedValue signals that the option could not be set because it needs
a value, but no value was assigned to the key. This state is used automatically, whenever an
Chapter 12: Basic Functions of Package scrbase
311
option has been defined without default value and is used without value assignment. You
should not set the state using \FamilyKeyStateNeedValue yourself.
Last but not least you may switch to additional failure states, simply re-defining
\FamilyKeyState
with a very short text message. Generally, the four predefined states should
be sufficient.
Example: Assume each of the three packages from the previous example should get a key
named coldcuts. When used, a switch is set at each of the packages. For package
salami this may be:
\newif\if@Salami@Aufschnitt
\DefineFamilyKey{butcher}%
{coldcuts}[true]{%
\expandafter\let\expandafter\if@salami@coldcuts
\csname if#1\endcsname
\FamilyKeyStateProcessed
}
Available values for the key are true or false in this case. Instead of testing
on inappropriate values, success will be signalled for any case in this example.
If the key is used later, it is executed with one of the allowed values or without
assignment. In the second case, the default true will be used.
The definitions in the other packages are similar. Only “salami” has to be replaced
by the corresponding names.
\RelaxFamilyKey[family member ]{family }{key }
If
v3.15
the key of the family member of family has been defined before, that definition will be
cancelled. Afterwards the key will not be defined for the family member of family any
longer. Usage of \RelaxFamilyKey for a not yet defined key of the family member of the
family
is also allowed.
\FamilyProcessOptions[family member ]{family }
Generally the extension of keys of families to keys of families and family members, as men-
tioned earlier, uses keys or key-value settings as class or package options. The command
\FamilyProcessOptions
is an extension of \ProcessOption* from L
A
TEX kernel (see [
Tea06
],
which processes not only options that has been declared using \DeclareOption, it processes
all keys of the given family member. If the optional argument family member is omitted,
family member “.\@currname.\@currext” is used.
Somehow special are keys that are not attached to a family member, but to a family. These
are keys with an empty family member. Such keys are set before the keys of the family
members.
Chapter 12: Basic Functions of Package scrbase
312
Example: If a package in the previous example would be extended by the line
\FamilyProcessOptions{butcher}
then the user may select the option coldcuts when loading the package. If the
option is used globally, this means at the optional argument of \documentclass,
then the option would be passed automatically to all three packages, if all three
packages are loaded later.
Please note that packages always process global options before local options. When processing
unknown options initiate an entry in the log-file and the option is otherwise ignored. By
contrast, unknown options assigned to the package locally leads to an error message.
\FamilyProcessOptions
may be interpreted either as an extension of \ProcessOption*
or as an extension of the key=value mechanism of keyval. Ultimately, with the help of
\FamilyProcessOptions
, key=value pairs become options.
\BeforeFamilyProcessOptions[member ]{family }{code }
Especially
v3.18
authors of wrapper classes or wrapper packages sometimes need a hook to execute
code
just before
\FamilyProcessOptions
. The package scrbase provides such a hook and
you can add code to it using \BeforeFamilyProcessOptions. The parameters member and
family
are same to
\FamilyProcessOptions
. In difference to
\FamilyProcessOptions
you
can add code also to the hook of not yet defined family or member .
Note, the hook of a family member will be cleaned after execution. But if you use an empty
member
the code will be executed before the
\FamilyProcessOptions
of every member of
the family and will never be deleted.
Example: Now, you are writing a package that loads liversausage. But you do not provide
option coldcut with this package. So you use \BeforeFamilyProcessOptions to
deactivate that option before loading the package:
\RequirePackage{scrbase}
\BeforeFamilyProcessOptions[.liversausage.sty]{butcher}{%
\RelaxFamilyKey[.liversausage.sty]{butcher}{coldcut}%
}
\RequirePackageWithOptions{liversausage}
If after this a user tries to load your package with option coldcut, package
liversausage will throw an undefined option error. If coldcut is used as a global
option, package liversausage will ignore it. But default settings inside liversausage,
e. g., using
\FamilyExecuteOptions
before
\FamilyProcessOptions
are not ef-
fected.
Chapter 12: Basic Functions of Package scrbase
313
\FamilyExecuteOptions[family member ]{family }{options list }
This command is an extension of \ExecuteOptions from the L
A
TEX kernel (see [
Tea06
]).
The command processes not only options that are defined using \DeclareOption, but also
processes all keys of the given family member . If the optional argument \family member is
omitted, then “.\@currname.\@currext” is used.
Somehow special are keys of empty family members, which are not attached to a family
member, but to a family. Such keys are set before the keys of family members.
Example: Assume option coldcuts should be set by default in the previous example. In this
case only line
\FamilyExecuteOptions{butcher}{coldcuts}
has to be added.
If
v3.20
you call \FamilyExecuteOptions with an unknown option inside the options list , you
will get an error. But you will not get an error, if the family member has an option @else@.
In this case option @else@ will be used instead of the unknown option. KOMA-Script itself
uses this feature, e. g., inside the definition of section like commands to prior the style attribute
above all other attributes.
Usage of the command inside the execution of an option is provided.
\FamilyOptions{family }{options list }
Hence options list is like:
key = value , key = value
. . .
after which the value assignment may be omitted for key s that have a defined default.
In contrast to average options that are defined using \DeclareOption, the key s also may be
set after loading a class or package. For this, the user calls \FamilyOptions. Thereafter, the
key
s of all members of the specified family are set. If a key also exists as a family attribute,
then the family key is set first. After this, the member keys follow in the order in which the
members have been defined. If a given key does not exist, either for the family or for any
member of the family, then \FamilyOptions will result in an error. Package scrbase reports
an error also if there are members with key key , but all those members signal failure via
\FamilyKeyState
.
Example: You extend your butcher project by a package sausagesalad. If this package has
been loaded, all sausage package should generate cold cuts:
\ProvidesPackage{sausagesalad}%
[2008/05/06 nonsense package]
\DefineFamily{butcher}
\DefineFamilyMember{butcher}
Chapter 12: Basic Functions of Package scrbase
314
\FamilyProcessOptions{butcher}\relax
\FamilyOptions{butcher}{coldcuts}
If currently none of the sausage packages are loaded, the undefined option
coldcuts
leads to an error message. This is avoided by adding before the last
line of the code above:
\DefineFamilyKey{butcher}%
{coldcuts}[true]{}%
However, sausage packages loaded after sausagesalad still do not produce cold cuts.
This may be corrected by editing the last line of the code again to:
\AtBeginDocument{%
\DefineFamiyKey[.sausagesalad.sty]%
{butcher}%
{coldcuts}[true]{}%
}
\DefineFamilyKey{butcher}%
{coldcuts}[true]{ %
\AtBeginDocument{\FamilyOptions{butcher}%
{coldcuts=#1}}%
}%
This code does following: First the option will be defined while \begin{document}
to do nothing for package sausagesalad. Because \@currname and \@currext are
not longer valid at this time, the optional argument on
\DefineFamilyKey
has to
be used. But until this re-definition of the option, a second definition is made,
that calls the option again while \begin{document} for the whole family and so
also for other sausage salad packages.
\FamilyOption{family }{option }{values list }
Besides options that have concurrently excluding values, there may be options that produce
several values at the same time. Using
\FamilyOptions
for that type of option would result
in using the same option several times with different value assignments. Instead of this,
\FamilyOption
may be used to assign a whole values list to the same option . The
values list
is a comma separated list of values, also known as csv:
value , value
. . .
By the way, please note that usage of a comma inside a value may be done only if the value
is put inside braces. The general functionality of this command is the same as that of the
previous command
\FamilyOptions
.
Example: Package sausagesalad should have one mire option, to add additional ingredients.
Each of the ingredients sets a switch as was done previously for the cold cuts.
Chapter 12: Basic Functions of Package scrbase
315
\newif\if@saladwith@onions
\newif\if@saladwith@gherkins
\newif\if@saladwith@chillies
\DefineFamilyKey{butcher}{ingredient}{%
\csname @saladwith@#1true\endcsname
}
Here the three ingredients “onions”, “gherkins”, and “chillies” have been defined.
An error message for “not defined” ingredients does not exist.
For a salad with onions and gherkins the user may use
\FamilyOptions{butcher}{%
ingredient=onions,ingredient=gherkins}
or shorter
\FamilyOption{butcher}
{ingredient}{onions,gherkins}
\AtEndOfFamilyOptions{action }
Sometimes
v3.12
it is useful to delay the execution of an action that is part of a
value assignment to a key until all assignments inside one
\FamilyProcessOptions
,
\FamilyExecuteOptions
,
\FamilyOptions
, or
\FamilyOption
is finished. This may be done
using \AtEndOfFamilyOptions inside an option definition. Reporting failure states of action
is not possible in this case. Furthermore, the command should not be used outside an option
definition.
\FamilyBoolKey[family member ]{family }{key }{switch name }
\FamilySetBool{family }{key }{switch name }{value }
In the previous examples, boolean switches often have been used. In the example with option
coldcuts
, it is necessary that the user assigns either value true or value false. There
is no error message for wrong value assignment. Because of this, boolean switches are a
necessary feature. Package scrbase provides \FamilyBoolKey for definition of such options.
Therefore, the arguments family member , family , and key are the same as that used by
\DefineFamilyKey
(see
page 310
). Argument switch name is the name of the switch without
the prefix \if. If a switch with this name does not exist already, \FamilyBoolKey will define
it and initialize it to false . Internally \FamilyBooKey uses \FamilySetBool as action of
\DefineFamilyKey
. The default for those options is always true.
On the other hand, \FamilySetBool understands value on and yes beside true for switch-
ing on and off and no beside false for switching off. Unknown values will result in a call
of
\FamilyUnknownKeyValue
with the arguments family , key , and value , which results in
setting of
\FamilyKeyState
. Depending on the command used and other family members,
|