• No results found

Index of /CTAN/macros/latex/contrib/kvoptions

N/A
N/A
Protected

Academic year: 2022

Share "Index of /CTAN/macros/latex/contrib/kvoptions"

Copied!
45
0
0

Full text

(1)

The kvoptions package

Heiko Oberdiek

2022-06-15 v3.15

Abstract

This package is intended for package authors who want to use options in key value format for their package options.

Contents

1 Introduction 3

1.1 The beginning. . . 3

1.2 Overview . . . 3

2 Usage 3 2.1 Process options . . . 3

2.1.1 \ProcessKeyvalOptions . . . 3

2.1.2 \ProcessLocalKeyvalOptions . . . 4

2.1.3 \SetupKeyvalOptions . . . 4

2.2 Option declarations. . . 4

2.2.1 \DeclareStringOption . . . 5

2.2.2 \DeclareBoolOption . . . 5

2.2.3 \DeclareComplementaryOption . . . 6

2.2.4 \DeclareVoidOption . . . 6

2.2.5 \DeclareDefaultOption . . . 6

2.2.6 Local options . . . 7

2.2.7 Dynamic options . . . 7

2.2.8 \DisableKeyvalOption . . . 7

2.2.9 \AddToKeyvalOption . . . 8

2.3 Global vs. local options . . . 8

2.4 Summary of internal macros. . . 9

2.5 plain TEX . . . 9

3 Example 9 4 Package options 11 4.1 Packagekvoptions-patch . . . 11

4.2 Optiondebugshow . . . 12

5 Limitations 13 5.1 Compatibility . . . 13

5.1.1 Packagekvoptions-patchvs. packagexkvltxp . . . 13

5.2 Limitations . . . 13

5.2.1 Option comparisons . . . 13

5.2.2 Option list parsing with packagekvoptions-patch . . . 13

Please report any issues athttps://github.com/ho-tex/kvoptions/issues

(2)

6 Implementation 14

6.1 Disabling the patches for newer LaTeX. . . 14

6.2 Preamble . . . 14

6.3 Option declaration macros. . . 17

6.3.1 \SetupKeyvalOptions . . . 17

6.3.2 \DeclareBoolOption . . . 18

6.3.3 \DeclareStringOption . . . 20

6.3.4 \DeclareVoidOption . . . 21

6.3.5 \DeclareDefaultOption . . . 22

6.3.6 \DeclareLocalOptions . . . 22

6.4 Dynamic options . . . 22

6.4.1 \DisableKeyvalOption . . . 22

6.5 Change option code . . . 24

6.5.1 \AddToKeyvalOption . . . 24

6.6 Process options . . . 25

6.6.1 Get global options . . . 25

6.6.2 \ProcessKeyvalOptions . . . 25

6.6.3 \ProcessLocalKeyvalOptions . . . 28

6.6.4 Helper macros . . . 29

6.7 plain TEX . . . 30

6.8 Packagekvoptions-patch . . . 30

7 Installation 38 7.1 Download . . . 38

7.2 Package installation . . . 38

7.3 Refresh file name databases . . . 38

7.4 Some details for the interested . . . 38

8 References 39 9 History 39 [0000/00/00 v0.0]. . . 39

[2004/02/22 v1.0]. . . 39

[2006/02/16 v2.0]. . . 39

[2006/02/20 v2.1]. . . 40

[2006/06/01 v2.2]. . . 40

[2006/08/17 v2.3]. . . 40

[2006/08/22 v2.4]. . . 40

[2007/04/11 v2.5]. . . 40

[2007/05/06 v2.6]. . . 40

[2007/06/11 v2.7]. . . 40

[2007/10/02 v2.8]. . . 40

[2007/10/11 v2.9]. . . 40

[2007/10/18 v3.0]. . . 40

[2009/04/10 v3.1]. . . 40

[2009/07/17 v3.2]. . . 40

[2009/07/21 v3.3]. . . 41

[2009/08/13 v3.4]. . . 41

[2009/12/04 v3.5]. . . 41

[2009/12/08 v3.6]. . . 41

[2010/02/22 v3.7]. . . 41

[2010/07/23 v3.8]. . . 41

[2010/12/02 v3.9]. . . 41

[2010/12/23 v3.10] . . . 41

[2011/06/30 v3.11] . . . 41

[2016/05/16 v3.12] . . . 41

[2019/11/29 v3.13] . . . 41

[2020-10-07 v3.14] . . . 41

(3)

[2022-06-15 v3.15] . . . 41

10 Index 42

1 Introduction

First I want to recommend the very good review article “A guide to key-value methods” by Joseph Wright [1]. It introduces the different key-value packages and compares them.

1.1 The beginning

This packagekvoptionsaddresses class or package writers that want to allow their users to specify options as key value pairs, e.g.:

\documentclass[verbose=false,name=me]{myclass}

\usepackage[format=print]{mylayout}

Prominent example is packagehyperref, probably the first package that offers this service. It’s\ProcessOptionsWithKVis often copied und used in other packages, e.g. packagehelvetthat uses this interface for its optionscaled.

However copying code is not the most modern software development technique.

And hyperref’s code for \ProcessOptionsWithKV was changed to fix bugs. The version used in other packages depends on the time of copying and the awareness of hyperref’s changes. Now the code is sourced out into this package and available for other package or class writers.

1.2 Overview

Packagekvoptionsconnects packagekeyvalwith LATEX’s package and classoptions:

Packagekeyval Package kvoptions LATEX kernel

\define@key \DeclareVoidOption

\DeclareStringOption

\DeclareBoolOption

\DeclareComplementaryOption

\DisableKeyvalOption

\DeclareOption

\DeclareDefaultOption \DeclareOption*

\ProcessKeyvalOptions \ProcessOptions*

Optionpatch Class/package

option system

\SetupKeyvalOptions

2 Usage

2.1 Process options

2.1.1 \ProcessKeyvalOptions

\ProcessKeyvalOptions{⟨family⟩}

\ProcessKeyvalOptions *

This command evaluates the global or local options of the package that are defined withkeyval’s interface within the family⟨family⟩. It acts the same way as LATEX’s

\ProcessOptions*. In a package unknown global options are ignored, in a class

(4)

they are added to the unknown option list. The known global options and all local options are passed tokeyval’s\setkeyscommand for executing the options.

Unknown options are reported to the user by an error.

If the family name happens to be the same as the name of the package or class where \ProcessKeyvalOptions is used or the family name has previously been setup by\SetupKeyvalOptions, then\ProcessKeyvalOptionsknows the family name already and you can use the star form without mandatory argument.

2.1.2 \ProcessLocalKeyvalOptions

\ProcessLocalKeyvalOptions{⟨family⟩}

\ProcessLocalKeyvalOptions *

This macro has the same syntax and works similar as \ProcessKeyvalOptions.

However it ignores global options and only processes the local package options.

Therefore it only can be used inside a package. An error is thrown, if it is used inside a class.

Neither of the following macros are necessary for\ProcessKeyvalOptions{}.

They just help the package/class author in common tasks.

2.1.3 \SetupKeyvalOptions

\SetupKeyvalOptions{ family =⟨family⟩, prefix =⟨prefix⟩

setkeys =⟨setkeys command⟩ }

This command allows to configure the default assumptions that are based on the current package or class name. LATEX remembers this name in\@currname. The syntax description of the default looks a little weird, therefor an example is given for a package or class named foobar.

Key Default (example) Used by

family ⟨\@currname⟩ (foobar) \ProcessKeyvalOptions*

\DeclareBoolOption

\DeclareStringOption prefix ⟨\@currname⟩@ (foobar@) \DeclareBoolOption

\DeclareStringOption

\DeclareVoidOption setkeys \setkeys (\kvsetkeys) \ProcessKeyvalOptions

\ProcessLocalKeyvalOptions Keysetkeyswas added in version 3.9. The original\setkeysof packagekeyvalis not reentrant. If an option is processed by this\setkeys, then the option should not call \setkeys again with a different family. Otherwise the next options of the first \setkeys call are processed with the wrong family. With key setkeys the macro\kvsetkeys can be set that does not have the problem of the original

\setkeysof package keyval.

Probably \setkeysof package xkeyval is safe in this respect. But I haven’t made a full analysis. At least it does not have the problem of the original\setkeys.

2.2 Option declarations

The options for \ProcessKeyvalOptions are defined by keyval’s \define@key.

Common purposes of such keys are boolean switches, they enable or disable some- thing. Or they store a name or some kind of string in a macro. The following

(5)

commands help the user. He declares what he wants and kvoptions take care of the key definition, resource allocation and initialization.

In order to avoid name clashes of macro names, internal commands are prefixed.

Both the prefix and the family name for the defined keys can be configured by

\SetupKeyvalOptions.

2.2.1 \DeclareStringOption

\DeclareStringOption [⟨init⟩]{⟨key⟩}[⟨default⟩]

A macro is created that remembers the value of the key⟨key⟩. The name of the macro consists of the option name⟨key⟩that is prefixed by the prefix (see2.1.3).

The initial contents of the macro can be given by the first optional argument

⟨init⟩. The default is empty.

The the option⟨key⟩ is defined. The option code just stores its value in the macro. If the optional argument at the end of \DeclareStringOption is given, then option⟨key⟩is defined with the default⟨default⟩.

Example for a package with the following two lines:

\ProvidesPackage{foobar}

\DeclareStringOption[me]{name}

Then\DeclareStringOptiondefines the macro with contentme, note LATEX com- plains if the name of the macro already exists:

\newcommand*{\foobar@name}{me}

The option definition is similar to:

\define@key{foobar}{name}{%

\renewcommand*{\foobar@name}{#1}%

}

2.2.2 \DeclareBoolOption

\DeclareBoolOption [⟨init⟩]{⟨key⟩}

A boolean switch is generated, initialized by value⟨init⟩and the corresponding key

⟨key⟩is defined. If the initialization value is not given,falseis used as default.

The internal actions of \DeclareBoolOption are shown below. The example is given for a package author who has the following two lines in his package/class:

\ProvidesPackage{foobar}

\DeclareBoolOption{verbose}

First a new switch is created:

\newif\iffoobar@verbose and initialized:

\foobar@verbosefalse Finally the key is defined:

\define@key{foobar}{verbose}[true]{. . .}

The option code configures the boolean option in the following way: If the author specifies true or falsethen the switch is turned on or off respectivly. Also the option can be given without explicit value. Then the switch is enabled. Other values are reported as errors.

Now the switch is ready to use in the package/class, e.g.:

(6)

\iffoobar@verbose

% print verbose message

\else

% be quiet

\fi

Users of package\ifthencan use the switch as boolean:

\boolean{foobar@verbose}

2.2.3 \DeclareComplementaryOption

\DeclareComplementaryOption{⟨key⟩} {⟨parent⟩}

Sometimes contrasting names are used to characterize the two states of a boolean switch, for example draft vs. final. Both options behave like boolean options but they do not need two different switches, they should share one.

\DeclareComplementaryOption allows this. The option⟨key⟩shares the switch of option⟨parent⟩. Example:

\DeclareBoolOption{draft}

\DeclareComplementaryOption{final}{draft}

Thenfinalsets the switch of draftto false, andfinal=falseenables thedraft switch.

2.2.4 \DeclareVoidOption

\DeclareVoidOption{⟨key⟩} {⟨code⟩}

\ProcessKeyvalOptionscan be extended to recognize options that are declared in traditional way by \DeclareOption. But in case of the error that the user specifies a value, then this option would not recognized as key value option because of \DeclareOption and not detected as traditional option because of the value part. The user would get an unknown option error, difficult to understand.

\DeclareVoidOption solves this problem. It defines the option ⟨key⟩as key value option. If the user specifies a value, a warning is given and the value is ignored.

The code part⟨code⟩is stored in a macro. The name of the macro consists of the option name⟨key⟩that is prefixed by the prefix (see2.1.3). If the option is set, the macro will be executed. During the execution \CurrentOption is available with the current key name.

2.2.5 \DeclareDefaultOption

\DeclareDefaultOption{⟨code⟩}

This command does not define a specific key, it is the equivalent to LATEX’s \DeclareOption*. It allows the specification of a default action

⟨code⟩ that is invoked if an unknown option is found. While ⟨code⟩ is called, macro \CurrentOption contains the current option string. In addition

\CurrentOptionValue contains the value part if the option string is parsable as key value pair, otherwise it is \relax. \CurrentOptionKey contains the key of the key value pair, or the whole option string, if it misses the equal sign.

Inside packages typical default actions are to pass unknown options to another package. Or an error message can be thrown by \@unknownoptionerror. This is the original error message that LATEX gives for unkown package options. This error

(7)

message is easier to understand for the user as the error message from package keyvalthat is given otherwise.

A Class ignores unknown options and puts them on the unused option list. Let LATEX do the job and just call\OptionNotUsed. Or the options can be passed to another class that is later loaded.

2.2.6 Local options

\DeclareLocalOption{⟨option⟩}

\DeclareLocalOptions{⟨option list⟩}

Both macros mark package options as local options. That means that they are ignored by \ProcessKeyvalOptions if they are given as global options.

\DeclareLocalOptions takes one option, \DeclareLocalOptions expects a comma separated list of options.

2.2.7 Dynamic options

Options of LATEX’s package/class system are cleared in \ProcessOptions. They modify the static model of a package. For example, depending on optionbookmarks packagehyperref loads differently.

Options, however, defined bykeyval’s\define@key remain defined, if the op- tions are processed by \setkeys. Therefore these options can also be used to model the dynamic behaviour of a package. For example, in hyperref the link colors can be changed everywhere until the end in\end{document}.

However packagecolorthat adds color support is necessary and it cannot be loaded after\begin{document}. Optioncolorlinksthat loadscolorshould be active until\begin{document}and die in some way if it is too late for loading packages.

With\DisableKeyvalOptionthe package/class author can specify and configure the death of an option and controls the life period of the option.

2.2.8 \DisableKeyvalOption

\DisableKeyvalOption [⟨options⟩]{⟨family⟩} {⟨key⟩}

⟨options⟩:

action = undef,warning,error, orignore default: undef

globalorlocal default: global

packageorclass =⟨name⟩

\DisableKeyvalOption can be called to mark the end when the option⟨key⟩ is no longer useful. The behaviour of an option after its death can be configured by action:

undef: The option will be undefined, If it is called, \setkeys reports an error because of unknown key.

error orwarning: Use of the option will cause an error or warning message. Also these actions require that exclusivly either the package or class name is given in optionspackageorclass.

ignore: The use of the option will silently be ignored.

The option’s death can be limited to the end of the current group, if optionlocal is given. Default isglobal.

The package/class author can wish the end of the option already during the package loading, then he will have static behaviour. In case of dynamic options

\DisableKeyvalOption can be executed everywhere, also outside the package.

Therefore the family name and the package/class name is usually unknown for

(8)

\DisableKeyvalOption. Therefore the argument for the family name is manda- tory and for some actions the package/class name must be provided.

Usually a macro would configure the option death, Example:

\ProvidesPackage{foobar}

\DeclareBoolOption{color}

\DeclareStringOption[red]{emphcolor}

\ProcessKeyvalOptions*

\newcommand*{\foobar@DisableOption}[2]{%

\DisableKeyvalueOption[

action={#1}, package=foobar ]{foobar}{#2}%

}

\iffoobar@color

\RequirePackage{color}

\renewcommand*{\emph}[1]{\textcolor{\foobar@emphcolor}{#1}}

\else

% Option emphcolor is not wrong, if we have color support.

% otherwise the option has no effect, but we don’t want to

% remove it. Therefore action ’ignore’ is the best choice:

\foobar@DisableOption{ignore}{emphcolor}

\fi

% No we don’t need the option ’color’.

\foobar@DisableOption{warning}{color}

% With color support option ’emphcolor’ will dynamically

% change the color of \emph statements.

2.2.9 \AddToKeyvalOption

\AddToKeyvalOption{⟨family⟩} {⟨key⟩} {⟨code⟩}

\AddToKeyvalOption *{⟨key⟩} {⟨code⟩}

The code for an existing key⟨key⟩of family⟨family⟩is extended by code⟨code⟩. In the starred form the current family setting is used, see\ProcessKeyvalOptions*.

2.3 Global vs. local options

Options that are given for \documentclass are called global options. They are known to the class and all packages. A package may make use of a global option and marks it as used. The advantage for the user is the freedom to specify options both in the \documentclassor \usepackagecommands.

However global options are shared with the class options and options of all other packages. Thus there can be the same option with different semantics for different packages and classes. As example, packagebookmarkknows option open that specifies whether the bookmarks are opened or closed initially. It’s values are trueorfalse. Since KOMA-Script version 3.00 the KOMA classes also introduces optionopenwith valuesrightandanyand a complete different meaning.

Such conflicts can be resolved by marking all or part of options as local by

\DeclareLocalOption or \DeclareLocalOptions. Then the packages ignores global occurences of these options. Packagekvoptionsprovides two methods:

• \ProcessLocalKeyvalOptions automatically uses all options as local op- tions. It ignores all global options.

• \DeclareLocalOption or \DeclareLocalOptions marks options as local options. \ProcessKeyvalOptions will then ignore global occurences for these local options.

(9)

Since version 1.5 packagebookmarkuses the latter method. It checks global and local option places for driver options and limits all other options as local options.

Thus the class option openof KOMA-Script is not misread as option for package bookmark.

2.4 Summary of internal macros

The \Declare...Option commands define macros, additionally to the macros generated by the key definition. These macros can be used by the package/class author. The name of the macros starts with the prefix⟨prefix⟩ that can be con- figured by\SetupKeyvalOptions.

Declare⟨key⟩ Defined macro Description

\DeclareStringOption \⟨prefix⟩⟨key⟩ holds the string

\DeclareBoolOption \if⟨prefix⟩⟨key⟩ boolean switch

\⟨prefix⟩⟨key⟩false disable switch

\⟨prefix⟩⟨key⟩true enable switch

\DeclareComplementaryOption \⟨prefix⟩⟨key⟩false enable parent switch

\⟨prefix⟩⟨key⟩true disable parent switch

\DeclareVoidOption \⟨prefix⟩⟨key⟩ holds the action

2.5 plain TEX

Packagekeyvalis also usable in plain TEX with the help of fileminiltx.tex. Some features of this packagekvoptionsmight also be useful for plain TEX. If LATEX is not found, \ProcessKeyvalOptionsand optionpatchare disabled. Before using the option declaration commands \Declare...Option, \SetupKeyvalOptions must be used.

3 Example

The following example defined a package that serves some private color manage- ment. A boolean optionprintenables print mode without colors. An optionemph redefines \emph to print in the given color. And the driver can be specified by optiondriver.

1⟨∗example⟩

2 % Package identification

3 % ---

4\NeedsTeXFormat{LaTeX2e}

5\ProvidesPackage{example-mycolorsetup}[2019/11/29 Managing my colors]

6

7\RequirePackage{iftex}

8\RequirePackage{kvoptions}

9

10 % Option declarations

11 % ---

12

13\SetupKeyvalOptions{

14 family=MCS,

15 prefix=MCS@

16}

17 % Use a shorter family name and prefix

18

19 % Option print

20\DeclareBoolOption{print}

21 % is the same as

22 % \DeclareBoolOption[false]{print}

23

(10)

24 % Option driver

25\ifpdf

26 \DeclareStringOption[pdftex]{driver}

27\else

28 \DeclareStringOption[dvips]{driver}

29\fi

30

31 % Alternative interface for driver options

32\DeclareVoidOption{dvips}{\SetupDriver}

33\DeclareVoidOption{dvipdfm}{\SetupDriver}

34\DeclareVoidOption{pdftex}{\SetupDriver}

35 % In \SetupDriver we take the current option \CurrentOption

36 % and pass it to the driver option.

37 % The \expandafter commands expand \CurrentOption at the

38 % time, when \SetupDriver is executed and \CurrentOption

39 % has the correct meaning.

40\newcommand*{\SetupDriver}{%

41 \expandafter\@SetupDriver\expandafter{\CurrentOption}%

42}

43\newcommand*{\@SetupDriver}[1]{%

44 \setkeys{MCS}{driver={#1}}%

45}

46

47 % Option emph

48 % An empty value means, we want to have no color for \emph.

49 % If the user specifies option emph without value, the red is used.

50\DeclareStringOption{emph}[red]

51 % is the same as

52 % \DeclareStringOption[]{emph}[red]

53

54 % Default option rule

55\DeclareDefaultOption{%

56 \ifx\CurrentOptionValue\relax

57 \PackageWarningNoLine{\@currname}{%

58 Unknown option ‘\CurrentOption’\MessageBreak

59 is passed to package ‘color’%

60 }%

61 % Pass the option to package color.

62 % Again it is better to expand \CurrentOption.

63 \expandafter\PassOptionsToPackage

64 \expandafter{\CurrentOption}{color}%

65 \else

66 % Package color does not take options with values.

67 % We provide the standard LaTeX error.

68 \@unknownoptionerror

69 \fi

70}

71

72 % Process options

73 % ---

74\ProcessKeyvalOptions*

75

76 % Implementation depending on option values

77 % ---

78 % Code for print mode

79\ifMCS@print

80 \PassOptionsToPackage{monochrome}{color}

81 % tells package color to use black and white

82\fi

83

84\RequirePackage[\MCS@driver]{color}

85 % load package color with the correct driver

(11)

86

87 % \emph setup

88\ifx\MCS@emph\@empty

89 % \@empty is a predefined macro with empty contents.

90 % the option value of option emph is empty, thus

91 % we do not want a redefinition of \emph.

92\else

93 \renewcommand*{\emph}[1]{%

94 \textcolor{\MCS@emph}{#1}%

95 }

96\fi

97⟨/example⟩

4 Package options

The packagekvoptions knows two package optionspatchanddebugshow. The op- tions of packagekvoptionsare intended for authors, not for package/class writers.

Inside a package it is too late for optionpatchanddebugshowenables some mes- sages that are perhaps useful for the debugging phase. Also LATEX is unhappy if a package is loaded later again with options that are previously not given. Thus package and class authors, stay with\RequirePackage{kvoptions}without op- tions.

Optionpatchloads packagekvoptions-patch.

4.1 Package kvoptions-patch

Change in version v3.14: kvoptions-patchis not compatible with a LATEX 2020- 10-01 or newer and will abort loading if it detects it!

LATEX’s system of package/class options has some severe limitations that espe- cially affects the value part if options are used as pair of key and value.

• Spaces are removed, regardless where:

\documentclass[box=0 0 400 600]{article}

Now each package will seebox=00400600as global option.

• In the previous case also braces would not help:

\documentclass[box={0 0 400 600}]{article}

The result is an error message:

! LaTeX Error: Missing \begin{document}.

As local option, however, it works if the package knows about key value options (By using this package, for example).

• The requirements on robustness are extremly high. LATEX expands the op- tion. All that will not work as environment name will break also as option.

Even a\relax will generate an error message:

! Missing \endcsname inserted.

Of course, LATEX does not use its protecting mechanisms. On contrary

\protectitself will cause errors.

• The options are expanded. But perhaps the package will do that, because it has to setup some things before? Examplehyperref:

\usepackage[pdfauthor=M\"uller]{hyperref}

(12)

Package hyperref does not see M\"uller but its expansion and it does not like it, you get many warnings

Token not allowed in a PDFDocEncoded string

And the title becomes: Mu127uller. Therefore such options must usually be given after package hyperref is loaded:

\usepackage{hyperref}

\hypersetup{pdfauthor=Fran\c coise M\"uller}

As package option it will even break with Fran\c coise because of the cedilla\c c, it is not robust enough.

For users that do not want with this limitations the package offers package kvoptions-patch. It patches LATEX’s option system and tries to teach it also to handle options that are given as pairs of key and value and to prevent expansion.

It can already be used at the very beginning, before\documentclass:

\RequirePackage{kvoptions-patch}

\documentclass[pdfauthor=Fran\c coise M\"uller]{article}

\usepackage{hyperref}

The latest time is before the package where you want to use problematic values:

\usepackage{kvoptions-patch}

\usepackage[Fran\c coise M\"uller]{hyperref}

Some remarks:

• The patch requires ε-TEX, its\unexpanded feature is much too nice. It is possible to work around using token registers. But the code becomes longer, slower, more difficult to read and maintain. The package without option patchworks and will work withoutε-TEX.

• The code for the patch is quite long, there are many test cases. Thus the probability for bugs is probably not too small.

• Since 2008/10/18 v3.0 package kvoptions-patch is available. Before option patch of package kvoptions must be used instead. I think, the solution as standalone package kvoptions-patchis cleaner and avoids option clashes.

4.2 Option debugshow

The name of this option follows the convention of packages multicol, tabularx, and tracefnt. Currently it prints the setting of boolean options, declared by

\DeclareBoolOption in the .log file, if that boolean option is used. You can activate the option by

• \PassOptionsToPackage{debugshow}{kvoptions}

Put this somewhere before package kvoptions is loaded first, e.g. before

\documentclass.

• \RequirePackage[debugshow]{kvoptions}

Before \documentclass even an author has to use \RequirePackage.

\usepackage only works after\documentclass.

The preferred method is \PassOptionsToPackage, because it does not force the package loading and does not disturb, if the package is not loaded later at all.

(13)

5 Limitations

5.1 Compatibility

5.1.1 Packagekvoptions-patch vs. package xkvltxp

Packagexkvltxpfrom the xkeyvalproject has the same goal as packagekvoptions- patch and to patch LATEX’s kernel commands in order to get better support for key value options. Of course they cannot be used both. The user must decide, which method he prefers. Packagekvoptions-patchaborts itself, if it detects that xkvltxpis already loaded.

However packagexkvltxpandkvoptionscan be used together, example:

\usepackage{xkvltxp}

\usepackage[...]{foobar} % foobar using kvoptions The other way should work, too.

Packagekvoptions-patchtries to catch more situations and to be more robust.

For example, during the comparison of options it normalizes them by removing spaces around=and the value. Thus the following is not reported as option clash:

\RequirePackage{kvoptions-patch}

\documentclass{article}

\usepackage[scaled=0.7]{helvet}

\usepackage[scaled = 0.7]{helvet}

\begin{document}

\end{document}

5.2 Limitations

5.2.1 Option comparisons

In some situations LATEX compares option lists, e.g. option clash check,

\@ifpackagewith, or \@ifclasswith. Apart from catcode and sanitizing prob- lems of option patch, there is another problem. LATEX does not know about the type and default values of options in key value style. Thus an option clash is reported, even if the key value has the same meaning:

\usepackage[scaled]{helvet} %default is .95

\usepackage[.95]{helvet}

\usepackage[0.95]{helvet}

5.2.2 Option list parsing with packagekvoptions-patch

With package kvoptions-patch the range of possible values in key value specifi- cations is much large, for example the comma can be used, if enclosed in curly braces.

Other packages, especially the packages that uses their own process option code can be surprised to find tokens inside options that they do not expect and errors would be the consequence. To avoid errors the options, especially the unused option list is sanitized. That means the list will only contain tokens with catcode 12 (other) and perhaps spaces (catcode 10). This allows a safe parsing for other packages. But a comma in the value part is no longer protected by curly braces because they have lost their special meaning. This is the price for compatibility.

Example:

\RequirePackage{kvoptions-patch}

\documentclass[a={a,b,c},b]{article}

\begin{document}

\end{document}

(14)

Result:

LaTeX Warning: Unused global option(s):

[a={a,c},b].

6 Implementation

6.1 Disabling the patches for newer LaTeX

kvoptions-patchis not compatible with LATEX 2020-10-01 and newer so it is disabled and issues a warning.

98⟨∗patch⟩

99\providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}

100\IfFormatAtLeastTF{2020/10/01}{\PackageWarning{kvoptions-patch}%

101 {kvoptions-patch is not compatible with \MessageBreak

102 LaTeX \fmtversion\MessageBreak Loading is aborted}{}}{}

103\IfFormatAtLeastTF{2020/10/01}{\endinput}{}

104⟨/patch⟩

6.2 Preamble

105⟨∗package⟩

Reload check and identification. Reload check, especially if the package is not used with LATEX.

106\begingroup\catcode61\catcode48\catcode32=10\relax%

107 \catcode13=5 % ^^M

108 \endlinechar=13 %

109 \catcode35=6 % #

110 \catcode39=12 % ’

111 \catcode44=12 % ,

112 \catcode45=12 % -

113 \catcode46=12 % .

114 \catcode58=12 % :

115 \catcode64=11 % @

116 \catcode123=1 % {

117 \catcode125=2 % }

118 \expandafter\let\expandafter\x\csname [email protected]\endcsname

119 \ifx\x\relax % plain-TeX, first loading

120 \else

121 \def\empty{}%

122 \ifx\x\empty % LaTeX, first loading,

123 % variable is initialized, but \ProvidesPackage not yet seen

124 \else

125 \expandafter\ifx\csname PackageInfo\endcsname\relax

126 \def\x#1#2{%

127 \immediate\write-1{Package #1 Info: #2.}%

128 }%

129 \else

130 \def\x#1#2{\PackageInfo{#1}{#2, stopped}}%

131 \fi

132 \x{kvoptions}{The package is already loaded}%

133 \aftergroup\endinput

134 \fi

135 \fi

136\endgroup%

Package identification:

137\begingroup\catcode61\catcode48\catcode32=10\relax%

138 \catcode13=5 % ^^M

139 \endlinechar=13 %

140 \catcode35=6 % #

(15)

141 \catcode39=12 % ’

142 \catcode40=12 % (

143 \catcode41=12 % )

144 \catcode44=12 % ,

145 \catcode45=12 % -

146 \catcode46=12 % .

147 \catcode47=12 % /

148 \catcode58=12 % :

149 \catcode64=11 % @

150 \catcode91=12 % [

151 \catcode93=12 % ]

152 \catcode123=1 % {

153 \catcode125=2 % }

154 \expandafter\ifx\csname ProvidesPackage\endcsname\relax

155 \def\x#1#2#3[#4]{\endgroup

156 \immediate\write-1{Package: #3 #4}%

157 \xdef#1{#4}%

158 }%

159 \else

160 \def\x#1#2[#3]{\endgroup

161 #2[{#3}]%

162 \ifx#1\@undefined

163 \xdef#1{#3}%

164 \fi

165 \ifx#1\relax

166 \xdef#1{#3}%

167 \fi

168 }%

169 \fi

170\expandafter\x\csname [email protected]\endcsname

171\ProvidesPackage{kvoptions}%

172 [2022-06-15 v3.15 Key value format for package options (HO)]%

Catcodes

173\begingroup\catcode61\catcode48\catcode32=10\relax%

174 \catcode13=5 % ^^M

175 \endlinechar=13 %

176 \catcode123=1 % {

177 \catcode125=2 % }

178 \catcode64=11 % @

179 \def\x{\endgroup

180 \expandafter\edef\csname KVO@AtEnd\endcsname{%

181 \endlinechar=\the\endlinechar\relax

182 \catcode13=\the\catcode13\relax

183 \catcode32=\the\catcode32\relax

184 \catcode35=\the\catcode35\relax

185 \catcode61=\the\catcode61\relax

186 \catcode64=\the\catcode64\relax

187 \catcode123=\the\catcode123\relax

188 \catcode125=\the\catcode125\relax

189 }%

190 }%

191\x\catcode61\catcode48\catcode32=10\relax%

192\catcode13=5 % ^^M

193\endlinechar=13 %

194\catcode35=6 % #

195\catcode64=11 % @

196\catcode123=1 % {

197\catcode125=2 % }

198\def\TMP@EnsureCode#1#2{%

199 \edef\KVO@AtEnd{%

200 \KVO@AtEnd

(16)

201 \catcode#1=\the\catcode#1\relax

202 }%

203 \catcode#1=#2\relax

204}

205\TMP@EnsureCode{1}{14}% ^^A (comment)

206\TMP@EnsureCode{2}{14}% ^^A (comment)

207\TMP@EnsureCode{33}{12}% !

208\TMP@EnsureCode{39}{12}% ’

209\TMP@EnsureCode{40}{12}% (

210\TMP@EnsureCode{41}{12}% )

211\TMP@EnsureCode{42}{12}% *

212\TMP@EnsureCode{44}{12}% ,

213\TMP@EnsureCode{45}{12}% -

214\TMP@EnsureCode{46}{12}% .

215\TMP@EnsureCode{47}{12}% /

216\TMP@EnsureCode{58}{12}% :

217\TMP@EnsureCode{62}{12}% >

218\TMP@EnsureCode{91}{12}% [

219\TMP@EnsureCode{93}{12}% ]

220\TMP@EnsureCode{94}{7}% ^ (superscript)

221\TMP@EnsureCode{96}{12}% ‘

222\edef\KVO@AtEnd{\KVO@AtEnd\noexpand\endinput}

External resources. The package extends the support for key value pairs of package\keyvalto package options. Thus the package needs to be loaded anyway.

and we use it for \SetupKeyvalOptions. AFAIK this does not disturb users of xkeyval.

223\@ifundefined{define@key}{%

224 \RequirePackage{keyval}\relax

225}{}

Macro \DeclareLocalOptions parses a comma separated key list and uses

\comma@parseof packagekvsetkeys, version 1.3.

226\RequirePackage{ltxcmds}[2010/12/02]

227\RequirePackage{kvsetkeys}[2007/09/29]

Provide macros for plain TEX.

228\@ifundefined{@x@protect}{%

229 \def\@x@protect#1\fi#2#3{%

230 \fi\protect#1%

231 }%

232 \let\@typeset@protect\relax

233}{}

234\@ifundefined{@currname}{%

235 \def\@currname{}%

236}{}

237\@ifundefined{@currext}{%

238 \def\@currext{}%

239}{}

Options Optiondebugshowenables additional lines of code that prints informa- tion into the.logfile.

240\DeclareOption{debugshow}{\catcode\@ne=9 }

241\DeclareOption{patch}{%

242 \AtEndOfPackage{%

243 \RequirePackage{kvoptions-patch}[2019/11/29]%

244 }%

245}

Optionen auswerten:

246\ProcessOptions\relax

(17)

6.3 Option declaration macros

6.3.1 \SetupKeyvalOptions

The family for the key value pairs can be setup once and is remembered later.

The package name seems a reasonable default for the family key, if it is not set by the package author.

\KVO@family We cannot store the family setting in one macro, because the package should be usable for many other packages, too. Thus we remember the family setting in a macro, whose name contains the package name with extension, a key in LATEX’s class/package system.

247\define@key{KVO}{family}{%

248 \expandafter\edef\csname KVO@family@%

249 \@currname.\@currext\endcsname{#1}%

250}

251\def\KVO@family{%

252 \@ifundefined{KVO@family@\@currname.\@currext}{%

253 \@currname

254 }{%

255 \csname KVO@family@\@currname.\@currext\endcsname

256 }%

257}

\KVO@prefix The value settings of options that are declared by \DeclareBoolOption and

\DeclareStringOption need to be saved in macros. in the first case this is a switch\if⟨prefix⟩⟨key⟩, in the latter case a macro\⟨prefix⟩⟨key⟩. The prefix can be configured, by prefix that is declared here. The default is the package name with@appended.

258\define@key{KVO}{prefix}{%

259 \expandafter\edef\csname KVO@prefix@%

260 \@currname.\@currext\endcsname{#1}%

261}

262\def\KVO@prefix{%

263 \ltx@ifundefined{KVO@prefix@\@currname.\@currext}{%

264 \@currname @%

265 }{%

266 \csname KVO@prefix@\@currname.\@currext\endcsname

267 }%

268}

269\define@key{KVO}{setkeys}{%

270 \expandafter\def\csname KVO@setkeys@%

271 \@currname.\@currext\endcsname{#1}%

272}

\KVO@setkeys

273\def\KVO@setkeys{%

274 \ltx@IfUndefined{KVO@setkeys@\@currname.\@currext}{%

275 \setkeys

276 }{%

277 \csname KVO@setkeys@\@currname.\@currext\endcsname

278 }%

279}

\SetupKeyvalOptions The argument of \SetupKeyvalOptionsexpects a key value list, known keys are familyandprefix.

280\newcommand*{\SetupKeyvalOptions}{%

281 \kvsetkeys{KVO}%

282}

(18)

6.3.2 \DeclareBoolOption

\DeclareBoolOption Usually options of boolean type can be given by the user without value and this means a setting totrue. We follow this convention here. Also it simplifies the user interface.

The switch is created and initialized withfalse. The default setting can be overwritten by the optional argument.

LATEX’s \newif does not check for already defined macros, therefore we add this check here to prevent the user from accidently redefining of TEX’s primitives and other macros.

283\newcommand*{\DeclareBoolOption}[2][false]{%

284 \KVO@ifdefinable{if\KVO@prefix#2}{%

285 \KVO@ifdefinable{\KVO@prefix#2true}{%

286 \KVO@ifdefinable{\KVO@prefix#2false}{%

287 \csname newif\expandafter\endcsname

288 \csname if\KVO@prefix#2\endcsname

289 \@ifundefined{\KVO@prefix#2#1}{%

290 \PackageWarning{kvoptions}{%

291 Initialization of option ‘#2’ failed,\MessageBreak

292 cannot set boolean option to ‘#1’,\MessageBreak

293 use ‘true’ or ‘false’, now using ‘false’%

294 }%

295 }{%

296 \csname\KVO@prefix#2#1\endcsname

297 }%

298 \begingroup

299 \edef\x{\endgroup

300 \noexpand\define@key{\KVO@family}{#2}[true]{%

301 \noexpand\KVO@boolkey{\@currname}%

302 \ifx\@currext\@clsextension

303 \noexpand\@clsextension

304 \else

305 \noexpand\@pkgextension

306 \fi

307 {\KVO@prefix}{#2}{####1}%

308 }%

309 }%

310 \x

311 }%

312 }%

313 }%

314}

\DeclareComplementaryOption The first argument is the key name, the second the key that must be a boolean option with the same current family and prefix. A new switch is not created for the new key, we have already a switch. Instead we define switch setting commands to work on the parent switch.

315\newcommand*{\DeclareComplementaryOption}[2]{%

316 \@ifundefined{if\KVO@prefix#2}{%

317 \PackageError{kvoptions}{%

318 Cannot generate option code for ‘#1’,\MessageBreak

319 parent switch ‘#2’ does not exist%

320 }{%

321 You are inside %

322 \ifx\@currext\@clsextension class\else package\fi\space

323 ‘\@currname.\@currext’.\MessageBreak

324 ‘\KVO@family’ is used as familiy %

325 for the keyval options.\MessageBreak

326 ‘\KVO@prefix’ serves as prefix %

327 for internal switch macros.\MessageBreak

328 \MessageBreak

329 \@ehc

(19)

330 }%

331 }{%

332 \KVO@ifdefinable{\KVO@prefix#1true}{%

333 \KVO@ifdefinable{\KVO@prefix#1false}{%

334 \expandafter\let\csname\KVO@prefix#1false\expandafter\endcsname

335 \csname\KVO@prefix#2true\endcsname

336 \expandafter\let\csname\KVO@prefix#1true\expandafter\endcsname

337 \csname\KVO@prefix#2false\endcsname

The same code part as in\DeclareBoolOptioncan now be used.

338 \begingroup

339 \edef\x{\endgroup

340 \noexpand\define@key{\KVO@family}{#1}[true]{%

341 \noexpand\KVO@boolkey{\@currname}%

342 \ifx\@currext\@clsextension

343 \noexpand\@clsextension

344 \else

345 \noexpand\@pkgextension

346 \fi

347 {\KVO@prefix}{#1}{####1}%

348 }%

349 }%

350 \x

351 }%

352 }%

353 }%

354}

\KVO@ifdefinable Generate the command token LaTeX’s\@ifdefinableexpects.

355\def\KVO@ifdefinable#1{%

356 \expandafter\@ifdefinable\csname #1\endcsname

357}

\KVO@boolkey We check explicitly fortrueandfalseto prevent the user from accidently calling other macros.

#1 package/class name

#2 \@pkgextension/\@clsextension

#3 prefix

#4 key name

#5 new value

358\def\KVO@boolkey#1#2#3#4#5{%

359 \edef\KVO@param{#5}%

360 \ltx@onelevel@sanitize\KVO@param

361 \ifx\KVO@param\KVO@true

362 \expandafter\@firstofone

363 \else

364 \ifx\KVO@param\KVO@false

365 \expandafter\expandafter\expandafter\@firstofone

366 \else

367 \ifx#2\@clsextension

368 \expandafter\ClassWarning

369 \else

370 \expandafter\PackageWarning

371 \fi

372 {#1}{%

373 Value ‘\KVO@param’ is not supported by\MessageBreak

374 option ‘#4’%

375 }%

376 \expandafter\expandafter\expandafter\@gobble

377 \fi

378 \fi

(20)

379 {%

380 ^^A\ifx#2\@clsextension

381 ^^A \expandafter\ClassInfo

382 ^^A\else

383 ^^A \expandafter\PackageInfo

384 ^^A\fi

385 ^^A{#1}{[option] #4=\KVO@param}%

386 \csname#3#4\KVO@param\endcsname

387 }%

388}

\KVO@true

\KVO@false

The macros \KVO@trueand \KVO@false are used for string comparisons. After

\ltx@onelevel@sanitizewe have only tokens with catcode 12 (other).

389\def\KVO@true{true}

390\def\KVO@false{false}

391\ltx@onelevel@sanitize\KVO@true

392\ltx@onelevel@sanitize\KVO@false 6.3.3 \DeclareStringOption

\DeclareStringOption

393\newcommand*{\DeclareStringOption}[2][]{%

394 \@ifnextchar[{%

395 \KVO@DeclareStringOption{#1}{#2}@%

396 }{%

397 \KVO@DeclareStringOption{#1}{#2}{}[]%

398 }%

399}

\KVO@DeclareStringOption

400\def\KVO@DeclareStringOption#1#2#3[#4]{%

401 \KVO@ifdefinable{\KVO@prefix#2}{%

402 \@namedef{\KVO@prefix#2}{#1}%

403 \begingroup

404 \ifx\\#3\\%

405 \toks@{}%

406 \else

407 \toks@{[{#4}]}%

408 \fi

409 \edef\x{\endgroup

410 \noexpand\define@key{\KVO@family}{#2}\the\toks@{%

411 ^^A\begingroup

412 ^^A \toks@{####1}%

413 ^^A \ifx\@currext\@clsextension

414 ^^A \noexpand\ClassInfo

415 ^^A \else

416 ^^A \noexpand\PackageInfo

417 ^^A \fi

418 ^^A {\@currname}{%

419 ^^A [option] #2={\noexpand\the\toks@}%

420 ^^A }%

421 ^^A\endgroup

422 \noexpand\def

423 \expandafter\noexpand\csname\KVO@prefix#2\endcsname{####1}%

424 }%

425 }%

426 \x

427 }%

428}

(21)

6.3.4 \DeclareVoidOption

\DeclareVoidOption

429\newcommand*{\DeclareVoidOption}[2]{%

430 \begingroup

431 \let\next\@gobbletwo

432 \KVO@ifdefinable{\KVO@prefix#1}{%

433 \let\next\@firstofone

434 }%

435 \expandafter\endgroup

436 \next{%

437 \begingroup

438 \edef\x{\endgroup

439 \noexpand\define@key{\KVO@family}{#1}[\KVO@VOID@]{%

440 \noexpand\KVO@voidkey{\@currname}%

441 \ifx\@currext\@clsextension

442 \noexpand\@clsextension

443 \else

444 \noexpand\@pkgextension

445 \fi

446 {#1}%

447 {####1}%

448 \expandafter\noexpand\csname\KVO@prefix#1\endcsname

449 }%

450 }%

451 \x

452 \begingroup

453 \toks@{#2}%

454 \expandafter\endgroup

455 \expandafter\def

456 \csname\KVO@prefix#1\expandafter\endcsname

457 \expandafter{\the\toks@}%

458 }%

459}

460\def\KVO@VOID@{@VOID@}

\KVO@voidkey

#1 package/class name

#2 \@pkgextension/\@clsextension

#3 key name

#4 default (@VOID@)

#5 macro with option code

461\def\KVO@voidkey#1#2#3#4{%

462 \def\CurrentOption{#3}%

463 \begingroup

464 \def\x{#4}%

465 \expandafter\endgroup

466 \ifx\x\KVO@VOID@

467 \else

468 \ifx#2\@clsextension

469 \expandafter\ClassWarning

470 \else

471 \expandafter\PackageWarning

472 \fi

473 {#1}{%

474 Unexpected value for option ‘#3’\MessageBreak

475 is ignored%

476 }%

477 \fi

478 ^^A\ifx#2\@clsextension

479 ^^A \expandafter\ClassInfo

480 ^^A\else

481 ^^A \expandafter\PackageInfo

482 ^^A\fi

(22)

483 ^^A{#1}{[option] #3}%

484}

6.3.5 \DeclareDefaultOption

\DeclareDefaultOption

485\newcommand*{\DeclareDefaultOption}{%

486 \@namedef{KVO@default@\@currname.\@currext}%

487}

6.3.6 \DeclareLocalOptions

\DeclareLocalOptions

488\newcommand*{\DeclareLocalOptions}[1]{%

489 \comma@parse{#1}\KVO@DeclareLocalOption

490}

\KVO@DeclareLocalOption

491\def\KVO@DeclareLocalOption#1{%

492 \expandafter\def\csname KVO@local@\KVO@family @#1\endcsname{}%

493}

6.4 Dynamic options

6.4.1 \DisableKeyvalOption

494\SetupKeyvalOptions{%

495 family=KVOdyn,%

496 prefix=KVOdyn@%

497}

498\DeclareBoolOption[true]{global}

499\DeclareComplementaryOption{local}{global}

500\DeclareStringOption[undef]{action}

501\let\KVOdyn@name\relax

502\let\KVOdyn@ext\@empty

503\define@key{KVOdyn}{class}{%

504 \def\KVOdyn@name{#1}%

505 \let\KVOdyn@ext\@clsextension

506}

507\define@key{KVOdyn}{package}{%

508 \def\KVOdyn@name{#1}%

509 \let\KVOdyn@ext\@pkgextension

510}

511\newcommand*{\DisableKeyvalOption}[3][]{%

512 \begingroup

513 \kvsetkeys{KVOdyn}{#1}%

514 \def\x{\endgroup}%

515 \@ifundefined{KVO@action@\KVOdyn@action}{%

516 \PackageError{kvoptions}{%

517 Unknown disable action %

518 ‘\expandafter\strip@prefix\meaning\KVOdyn@action’\MessageBreak

519 for option ‘#3’ in keyval family ’#2’%

520 }\@ehc

521 }{%

522 \csname KVO@action@\KVOdyn@action\endcsname{#2}{#3}%

523 }%

524 \x

525}

526\def\KVO@action@undef#1#2{%

527 \edef\x{\endgroup

528 \ifKVOdyn@global\global\fi

529 \let

(23)

530 \expandafter\noexpand\csname KV@#1@#2\endcsname

531 \relax

532 \ifKVOdyn@global\global\fi

533 \let

534 \expandafter\noexpand\csname KV@#1@#2@default\endcsname

535 \relax

536 }%

537 ^^A\PackageInfo{kvoptions}{%

538 ^^A [option] key ‘#2’ of family ‘#1’\MessageBreak

539 ^^A is disabled (undef, \ifKVOdyn@global global\else local\fi)%

540 ^^A}%

541}

542\def\KVO@action@ignore#1#2{%

543 \edef\x{\endgroup

544 \ifKVOdyn@global\global\fi

545 \let

546 \expandafter\noexpand\csname KV@#1@#2\endcsname

547 \noexpand\@gobble

548 \ifKVOdyn@global\global\fi

549 \let

550 \expandafter\noexpand\csname KV@#1@#2@default\endcsname

551 \noexpand\@empty

552 }%

553 ^^A\PackageInfo{kvoptions}{%

554 ^^A [option] key ‘#2’ of family ‘#1’\MessageBreak

555 ^^A is disabled (ignore, \ifKVOdyn@global global\else local\fi)%

556 ^^A}%

557}

558\def\KVO@action@error{%

559 \KVO@do@action{error}%

560}

561\def\KVO@action@warning{%

562 \KVO@do@action{warning}%

563}

#1 errororwarning

#2 ⟨family⟩

#3 ⟨key⟩

564\def\KVO@do@action#1#2#3{%

565 \ifx\KVOdyn@name\relax

566 \PackageError{kvoptions}{%

567 Action type ‘#1’ needs package/class name\MessageBreak

568 for key ‘#3’ in family ‘#2’%

569 }\@ehc

570 \else

571 \edef\x{\endgroup

572 \noexpand\define@key{#2}{#3}[]{%

573 \expandafter\noexpand\csname KVO@disable@#1\endcsname

574 {\KVOdyn@name}\noexpand\KVOdyn@ext{#3}%

575 }%

576 \ifKVOdyn@global

577 \global\let

578 \expandafter\noexpand\csname KV@#2@#3\endcsname

579 \expandafter\noexpand\csname KV@#2@#3\endcsname

580 \global\let

581 \expandafter\noexpand\csname KV@#2@#3@default\endcsname

582 \expandafter\noexpand\csname KV@#2@#3@default\endcsname

583 \fi

584 }%

585 ^^A\ifx\KVOdyn@ext\@clsextension

586 ^^A \expandafter\ClassInfo

587 ^^A\else

588 ^^A \expandafter\PackageInfo

(24)

589 ^^A\fi

590 ^^A{\KVOdyn@name}{%

591 ^^A [option] key ‘#3’ of family ‘#2’\MessageBreak

592 ^^A is disabled (#1, \ifKVOdyn@global global\else local\fi)%

593 ^^A}%

594 \fi

595}

596\def\KVO@disable@error#1#2#3{%

597 \ifx#2\@clsextension

598 \expandafter\ClassError

599 \else

600 \expandafter\PackageError

601 \fi

602 {#1}{%

603 Option ‘#3’ is given too late,\MessageBreak

604 now the option is ignored%

605 }\@ehc

606}

607\def\KVO@disable@warning#1#2#3{%

608 \ifx#2\@clsextension

609 \expandafter\ClassWarning

610 \else

611 \expandafter\PackageWarning

612 \fi

613 {#1}{%

614 Option ‘#3’ is already consumed\MessageBreak

615 and has no effect%

616 }%

617}

6.5 Change option code

6.5.1 \AddToKeyvalOption

\AddToKeyvalOption

618\newcommand*{\AddToKeyvalOption}{%

619 \@ifstar{%

620 \begingroup

621 \edef\x{\endgroup

622 \noexpand\KVO@AddToKeyvalOption{\KVO@family}%

623 }%

624 \x

625 }%

626 \KVO@AddToKeyvalOption

627}

\KVO@AddToKeyvalOption

628\def\KVO@AddToKeyvalOption#1#2{%

629 \@ifundefined{KV@#1@#2}{%

630 \PackageWarning{kvoptions}{%

631 Key ‘#2’ of family ‘#1’ does not exist.\MessageBreak

632 Ignoring \string\AddToKeyvalOption

633 }%

634 \@gobble

635 }{%

636 \edef\KVO@next{%

637 \noexpand\KVO@@AddToKeyvalOption

638 \expandafter\noexpand\csname KV@#1@#2\endcsname

639 }%

640 \afterassignment\KVO@next

641 \def\KVO@temp##1%

642 }%

643}

(25)

\KVO@@AddToKeyvalOption

644\def\KVO@@AddToKeyvalOption#1{%

645 \begingroup

646 \toks@\expandafter{#1{##1}}%

647 \toks@\expandafter{\the\expandafter\toks@\KVO@temp{##1}}%

648 \edef\x{\endgroup

649 \noexpand\def\noexpand#1####1{\the\toks@}%

650 }%

651 \x

652}

6.6 Process options

6.6.1 Get global options

Package xkeyval removes options with equal signs from the global options (\@classoptionslist). The effect is that other packages and classes will not see these global options anymore. A bug-report was answered that this behaviour is “by design”. Thus I call it a design bug. Now getting the global options require an algorithm instead of a simple macro call.

653⟨/package⟩

654⟨∗package|patch⟩

\KVO@IfDefThen Call#2if command#1is defined and not\relax. (Packagekvoptions-patchdoes not load packageltxcmds.)

655\def\KVO@IfDefThen#1#2{%

656 \ifx#1\ltx@undefined

657 \else

658 \ifx#1\relax

659 \else

660 #2%

661 \fi

662 \fi

663}%

\KVO@GetClassOptionsList

664\def\KVO@GetClassOptionsList{%

665 \let\KVO@classoptionslist\@classoptionslist

666 \KVO@IfDefThen\@classoptionslist{%

667 \KVO@IfDefThen\XKV@documentclass{%

668 \ifx\XKV@documentclass\ltx@empty

669 \else

670 \KVO@IfDefThen\XKV@classoptionslist{%

671 \ifx\XKV@classoptionslist\ltx@empty

672 \else

673 \let\KVO@classoptionslist\XKV@classoptionslist

674 \fi

675 }%

676 \fi

677 }%

678 }%

679}%

680⟨/package|patch⟩

681⟨∗package⟩

6.6.2 \ProcessKeyvalOptions

\ProcessKeyvalOptions If the optional star is given, we get the family name and expand it for safety.

682\newcommand*{\ProcessKeyvalOptions}{%

683 \@ifstar{%

(26)

684 \begingroup

685 \edef\x{\endgroup

686 \noexpand\KVO@ProcessKeyvalOptions{\KVO@family}%

687 }%

688 \x

689 }%

690 \KVO@ProcessKeyvalOptions

691}

692\def\KVO@ProcessKeyvalOptions#1{%

693 \let\@tempc\relax

694 \let\KVO@temp\@empty

Add any global options that are known to KV to the start of the list being built in

\KVO@tempand mark them used (by removing them from the unused option list).

695 \ifx\@currext\@clsextension

696 \else

697 \KVO@GetClassOptionsList

698 \ifx\KVO@classoptionslist\relax

699 \else

700 \@for\KVO@CurrentOption:=\KVO@classoptionslist\do{%

701 \@ifundefined{KV@#1@\expandafter\KVO@getkey

702 \KVO@CurrentOption=\@nil}{%

703 }{%

704 \@ifundefined{KVO@local@#1@\expandafter\KVO@getkey

705 \KVO@CurrentOption=\@nil}{%

706 \ifx\KVO@Patch Y%

707 \edef\KVO@temp{%

708 \etex@unexpanded\expandafter{%

709 \KVO@temp

710 }%

711 ,%

712 \etex@unexpanded\expandafter{%

713 \KVO@CurrentOption

714 }%

715 ,%

716 }%

717 \ltx@onelevel@sanitize\KVO@CurrentOption

718 \else

719 \edef\KVO@temp{%

720 \KVO@temp

721 ,%

722 \KVO@CurrentOption

723 ,%

724 }%

725 \fi

726 \@expandtwoargs\@removeelement{\expandafter\@remove@eq@value\KVO@CurrentOption=\@nil}%

727 \@unusedoptionlist\@unusedoptionlist

728 }{}%

729 }%

730 }%

731 \fi

732 \fi

Now stick the package options at the end of the list and wrap in a call to\setkeys.

A class ignores unknown global options, we must remove them to prevent error messages from\setkeys.

733 \begingroup

734 \toks\tw@{}%

735 \@ifundefined{opt@\@currname.\@currext}{%

736 \toks@\expandafter{\KVO@temp}%

737 }{%

738 \toks@\expandafter\expandafter\expandafter{%

(27)

739 \csname opt@\@currname.\@currext\endcsname

740 }%

741 \ifx\@currext\@clsextension

742 \edef\CurrentOption{\the\toks@}%

743 \toks@\expandafter{\KVO@temp}%

744 \@for\CurrentOption:=\CurrentOption\do{%

745 \@ifundefined{%

746 KV@#1@\expandafter\KVO@getkey\CurrentOption=\@nil

747 }{%

A class puts not used options in the unused option list unless there is a default handler.

748 \@ifundefined{KVO@default@\@currname.\@currext}{%

749 \ifx\KVO@Patch Y%

750 \ltx@onelevel@sanitize\CurrentOption

751 \fi

752 \ifx\@unusedoptionlist\@empty

753 \global\let\@unusedoptionlist\CurrentOption

754 \else

755 \expandafter\expandafter\expandafter\gdef

756 \expandafter\expandafter\expandafter\@unusedoptionlist

757 \expandafter\expandafter\expandafter{%

758 \expandafter\@unusedoptionlist

759 \expandafter,\CurrentOption

760 }%

761 \fi

762 }{%

763 \toks\tw@\expandafter{%

764 \the\toks\expandafter\tw@\expandafter,\CurrentOption

765 }%

766 }%

767 }{%

768 \toks@\expandafter{%

769 \the\expandafter\toks@\expandafter,\CurrentOption

770 }%

771 }%

772 }%

773 \else

Without default action we pass all options to \setkeys. Otherwise we have to check which options are known. These are passed to \setkeys. For the others the default action is performed.

774 \@ifundefined{KVO@default@\@currname.\@currext}{%

775 \toks@\expandafter\expandafter\expandafter{%

776 \expandafter\KVO@temp\the\toks@

777 }%

778 }{%

779 \edef\CurrentOption{\the\toks@}%

780 \toks@\expandafter{\KVO@temp}%

781 \@for\CurrentOption:=\CurrentOption\do{%

782 \@ifundefined{%

783 KV@#1@\expandafter\KVO@getkey\CurrentOption=\@nil

784 }{%

785 \toks\tw@\expandafter{%

786 \the\toks\expandafter\tw@\expandafter,\CurrentOption

787 }%

788 }{%

789 \toks@\expandafter{%

790 \the\expandafter\toks@\expandafter,\CurrentOption

791 }%

792 }%

793 }%

794 }%

(28)

795 \fi

796 }%

797 \edef\KVO@temp{\endgroup

798 \noexpand\KVO@calldefault{\the\toks\tw@}%

799 \noexpand\KVO@setkeys{#1}{\the\toks@}%

800 }%

801 \KVO@temp

Some cleanup of \ProcessOptions.

802 \let\CurrentOption\@empty

803 \AtEndOfPackage{\let\@unprocessedoptions\relax}%

804}

6.6.3 \ProcessLocalKeyvalOptions

\ProcessLocalKeyvalOptions If the optional star is given, we get the family name and expand it for safety.

805\newcommand*{\ProcessLocalKeyvalOptions}{%

806 \@ifstar{%

807 \begingroup

808 \edef\x{\endgroup

809 \noexpand\KVO@ProcessLocalKeyvalOptions{\KVO@family}%

810 }%

811 \x

812 }%

813 \KVO@ProcessLocalKeyvalOptions

814}

815\def\KVO@ProcessLocalKeyvalOptions#1{%

816 \let\@tempc\relax

817 \let\KVO@temp\@empty

Check if \ProcessLocalKeyvalOptionsis called inside a package.

818 \ifx\@currext\@pkgextension

819 \else

820 \PackageError{kvoptions}{%

821 \string\ProcessLocalKeyvalOptions\space is intended for packages only%

822 }\@ehc

823 \fi

The package options are put into toks register\toks@.

824 \begingroup

825 \toks\tw@{}%

826 \@ifundefined{opt@\@currname.\@currext}{%

827 \toks@\expandafter{\KVO@temp}%

828 }{%

829 \toks@\expandafter\expandafter\expandafter{%

830 \csname opt@\@currname.\@currext\endcsname

831 }%

Without default action we pass all options to \setkeys. Otherwise we have to check which options are known. These are passed to \setkeys. For the others the default action is performed.

832 \@ifundefined{KVO@default@\@currname.\@currext}{%

833 \toks@\expandafter\expandafter\expandafter{%

834 \expandafter\KVO@temp\the\toks@

835 }%

836 }{%

837 \edef\CurrentOption{\the\toks@}%

838 \toks@\expandafter{\KVO@temp}%

839 \@for\CurrentOption:=\CurrentOption\do{%

840 \@ifundefined{%

841 KV@#1@\expandafter\KVO@getkey\CurrentOption=\@nil

842 }{%

843 \toks\tw@\expandafter{%

References

Related documents

They are defined using the \Available. These macros define a symbolic name to be used as an option to the package, and take the name of the NFSS font family as a second argument..

With the spbmark option, the altsubsup package use the \sub and \super macros of the spbmark package to handle subscripts and superscripts in place of the standard _ and ^

The transition field in our \BibSpec example is a dummy field to be used when punctuation or other material must be added at a certain point in the bibliography without regard to

For example, suppose you are using the indextools package and you want a general index and a scripture index, you can do something

Exception: Driver options, option atend and options draft/final cannot be changed after the package is loaded.... 1.2.1 Options draft

The bundle provides source code environments that also print the output and defines quite a lot of macros for formatting of control sequence names, package names, package options and

This package provides macros which collect the cell content of a tab- ular and provide it to a macro as argument.. It was inspired

The package has three options: braces (default) colors the braces and pairs of matching macros (\if. -.. \fi); contents colors what’s inside these delimiters; numbers (also

You can change the useregional setting either through datetime2 ’s package options or using \DTMsetup however it will only have an effect during the module loading (when the value

After processing the options (in case of the kvoptions’ string options that means a macro has been defined holding the key value) we check if they are empty and, if not so, redefine

drawstack is a LaTeX package to easily draw execution stack (typically to illustrate assembly language notions), written on top of TikZ.. This file serves as an example of usage

The return addresses are printed on the envelopes if the package option New feature Version 1.1 printreturnaddress (default) is chosen. Alternatively, the

v Applies the package option to the current figure, and if no package option is specified, it forces the current floating figure to be typset to the right in a paragraph if

When using the package option verbose the fnbreak package writes a message for every footnote, even if it is completely on one

1.1 Basic use and requirements The package is invoked by writing the following in the preamble of your document nusepackage [ style ] ffancychaptersg If the option, style , is

defaults Define the defaults option which deactivates the paper and font options and prevents the change of the class defaults by this package.

The hep-text package extends L A TEX lists using the enumitem package and provides some text macros... The package can be loaded by

The hep-title package extends the title macros of the standard classes with macros for a preprint, affiliation, editors, and endorsers.. To use the hep-title package include it

Package xcolor provides macros for extracting color values and converting color data to other color models.. If this package is loaded, the full range of color specifications

Index: The main part of this package deals with index links in order to support the kind of index that package doc provides.... Thumbnails: Package thumbpdf may additionally be

If your image is made up of L A TEX code (for example, commands provided by the pgf package) you can include it using \includeteximage (defined by the jmlr class).. This can be

The keycommand package requires and is based on the package xkeyval by Hendri Adriaens, and uses the \kv@normalize macro of kvsetkeys (Heiko Oberdiek) for robustness, as shown in

Package xkeyval also knows a star form of \setkeys that stores unknown keys in an internal macro for further processing with \setrmkeys and similar macros.. This feature is covered