tags:

views:

52

answers:

2

When I declare an option containing a space, LaTeX/XeLaTeX eats it.

In the main .tex, I have :

\usepackage[test font]{test}

In my .sty file I have :

\DeclareOption*{\newfontfamily\testfont[Scale=1]{\CurrentOption}}
\ProcessOptions

But the Tex engine passes to the package testfont option and not test font.

So the question is how to pass the option containing the space to the package.

A: 

Try


\catcode`\ =11
\usepackage[test font]{test}
\catcode`\ =10

This is quite likely to fail, but the failure might be progress on what we have so far.

Charles Stewart
Yes this will fail, but with a little change it will compile without error :in the .tex file\catcode`\ =11\usepackage[test font]{test}and in the .sty file\DeclareOption*{\typeout{What's \CurrentOption}}\ProcessOptions\catcode`\ =10The problem being that moving the first catcode in the .sty file doesn't work.
anno
+3  A: 

Protect it with braces

\usepackage[{test font}]{test}
Joseph Wright
Doesn't work and not an acceptable solution.
anno
I was forgetting that you'd actually need two sets of braces here:\documentclass{article}\begin{filecontents}{test.sty}\def\Options{}\DeclareOption*{% \edef\Options{\Options,\CurrentOption} \AtBeginDocument{\Options}}\ProcessOptions\end{filecontents}\usepackage[{{option here}}]{test}\begin{document}\end{document}Unfortunately, the kernel does the space stripping before your package gets at anything. The usual alternative is not to take the data at package loading but have a set up macro that processes things after loading. That avoids loosing spaces.
Joseph Wright
Yes with 2 braces it works, but I can't ask the user to do this.
anno
Hence my suggestion of not taking the options at load time, and instead having a preamble-only macro which does the same thing.
Joseph Wright