Is there a simple way to allow spaces in the options of a package using pgfopts to process them, which is local to that package i.e. I don't have to include some package in the main document before \documentclass. What I'm trying to do is pass font names to fontspec inside the package using pgfopts.
- 259,911
- 34
- 706
- 1,036
- 417
2 Answers
Basically, the answer here is 'no'. Space-stripping from class (and package) options is carried out by the LaTeX2e kernel before anything is passed to pgfopts or any other keyval-processing package. The two patches which exist for this (xkvltxp and kvoptions-patch) both have to be loaded before any options they 'protect' are used, which means before \documentclass for class options.
You can protect options from space stripping using braces, for example
\documentclass[foo={bar baz}]{mycls}
but this can cause issues as the kernel may choke on these when doing 'duplicate removal'. So in general it's best not to use options containing spaces when loading a package or class: set the options afterwards.
- 223,288
- 259,911
- 34
- 706
- 1,036
11 years have passed and things changed.
Recent versions of the LaTeX kernel provide the option list once as the processed list with spaces removed, and once as a raw list in which no such changes were made.
Unfortunately, most packages don't support processing those raw options in which spaces haven't been zapped. The solutions I'm currently aware of are:
the LaTeX kernel itself supports key=value options by using
\DeclareKeys[<module>]{<key-definitions>}to define the keys,\SetKeys[<module>]{<key=val-list>}to set keys to values, and\ProcessKeyOptions[<module>]to process options for the current package or class file. In all those<module>defaults to the current file name (with the file extension stripped).the package
expkv-opt(part of theexpkv-bundle), to get a key-defining frontend comparable topgfkeysor\DeclareKeysyou'll have to also loadexpkv-def, then you get\ekvdefinekeys{<set>}{<key-definitions>}to define keys,\ekvset{<set>}{<key=val-list>}to set keys to values, and\ekvoProcessOptions{<set>}to process options for the current package or class file.
With both of these solutions you can just use
\documentclass[foo=bar baz]{mycls}
and things work.
Here a very small example for both solutions:
Document file
This file works for both class files below.
\documentclass[foo=bar baz]{mycls}
\begin{document}
The value was \texttt{\myfoo}.
\end{document}
Class file for expkv-opt
\ProvidesClass{mycls}[adhoc class for an example]
\LoadClass{article}
\RequirePackage{expkv-opt,expkv-def}
\ekvdefinekeys{mycls}{store foo = \myfoo}
\ekvoProcessOptions{mycls}
Class file to use LaTeX's built in mechanism
\ProvidesClass{mycls}[adhoc class for an example]
\LoadClass{article}
\DeclareKeys{foo .store = \myfoo}
\ProcessKeyOptions\relax
In both cases the output looks like this:
- 60,462
