14

In the kvoptions package the following macro is defined:

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

Following is the related documentation:

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 (see 2.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⟩.

I fail to understand what is the difference between the default value and the init one. Can someone please explain?

14

In common with many keyval methods, the default value is the one which will be used if only the key name is given at point of use. Thus with

\DeclareStringOption{foo}[bar]

giving foo with no value/= sign in the option list is equivalent to giving foo = bar.

In contrast, the initial value is used to ensure that some value has been stored before option processing. Thus

\ProvidesPackage{mypkg}
\DeclareStringOption[baz]{foo}

will store the value baz for key foo 'now'. This is equivalent to giving

\ProvidesPackage{mypkg}
\DeclareStringOption{foo}
\newcommand*{\mypkg@foo}{baz}

If the user then sets the foo option, the initial value will be 'thrown away' and has no more influence on the outcome. In contrast, the default value is still important as in the case

\ProvidesPackage{mypkg}
\DeclareStringOption[baz]{foo}[bar]

If the user does not give the foo option, then \mypkg@foo will have value baz. If the user gives the foo option with no value, the default is used and \mypkg@foo will have value bar. Finally, if the user gives foo = <some value> then of course \mypkg@foo will contain <some value>.

3
  • Just to make sure: \DeclareStringOption{foo} defines a macro \mypkg@foo that will expand to bar given the call \usepackage[foo=bar]{mypkg}. Is that correct? – Dror Jan 23 '14 at 12:22
  • Another point: Is it correct to think of the initial value as the default one (in the sense that it is the one that will be if the user provided nothing)? – Dror Jan 23 '14 at 12:23
  • 1
    @Dror Yes, \DeclareStringOption{foo} defines \mypkg@foo, initially to be empty unless you give the [<init>] optional argument. The initial value is used if the user doesn't use the key at all. – Joseph Wright Jan 24 '14 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.