7

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.

anno
  • 5,970
  • 4
  • 28
  • 37

2 Answers2

7

Protect it with braces

\usepackage[{test font}]{test}
Joseph Wright
  • 2,857
  • 22
  • 32
  • 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 Apr 21 '10 at 05:49
  • 1
    Yes with 2 braces it works, but I can't ask the user to do this. – anno Apr 22 '10 at 00:06
  • 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 Apr 22 '10 at 06:01
1

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
  • 11,661
  • 4
  • 46
  • 85
  • 1
    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`\ =10 The problem being that moving the first catcode in the .sty file doesn't work. – anno Apr 20 '10 at 21:07