2

The following produces error! The error is solved if no space exists between text= and {5in,8in}. This is really weird! Why is this happening with LaTeX?

\documentclass[a4paper,10pt,onecolumn,oneside, portrait]{article}

\usepackage[text= {5in,8in},centering]{geometry}

\begin{document}





\section{What Endogenous uncertainty is:}
 yes

\subsection{Type as it is : Stochastic and determ! }
on

\subsubsection{Well there is more than it}
Yes  

\end{document}
SGNL
  • 21

1 Answers1

3

Answering your question in the comment: no this is not a bug in geometry. In fact, if you do something similar with other packages, it also doesn't work:

\usepackage[pdfborder= {0 0 0}]{hyperref}

the error is different:

Package hyperref Warning: Invalid value `000'
(hyperref)                for option `pdfborder'.

but the cause is the same.

This behaviour is implemented in the LaTeX kernel by design. This is the reason that this:

\documentclass[12 pt]{article}

behaves exactly as:

\documentclass[12pt]{article}

But what exactly is happening? You ask. LaTeX's package and class loader, has a \@pass@ptions macro that, at some point, uses a construct like

\zap@space#2 \@empty

where \zap@space is defined as:

\def\zap@space#1 #2{%
  #1%
  \ifx#2\@empty\else
    \expandafter\zap@space
  \fi
  #2}

which clears spaces from option lists. But it also has some interesting consequences (one of which causes your error with geometry). Suppose you have the option list text= {5in,8in}.

The first call to \zap@space is \zap@space text= {5in,8in} \@empty. The first argument is delimited by a space token, so #1 is text=.

The second argument goes by TeX's argument grabbing rules: either a single token or a brace delimited group. In the latter case, which is the the one for our example, TeX removes the enclosing braces, so #2 is 5in,8in.

The second call to \zap@space is then \zap@space text=5in,8in \@empty. Here #1 is text=5in,8in and #2 is \@empty, which causes \zap@space to exit with text=5in,8in!

If you look closely, now you have two options for geometry: text=5in, and 8in. The latter is not a valid option, thus the error:

! Package keyval Error: 8in undefined.

See the keyval package documentation for explanation.
Type  H <return>  for immediate help.

The same happens to the example with hyperref, except that there are four iterations of \zap@space to remove the spaces between the zeros and the final options list is pdfborder=000.

But how do I fix this?

Well, the obvious fix is to remove the space, so that the first call to \zap@space is \zap@space text={5in,8in} \@empty, then #1 is text={5in,8in} and all goes well.

The second, less obvious, but sometimes very useful option, is to load Heiko Oberdiek's kvoptions-patch package, whose manual even states:

LaTeX's system of package/class options has some severe limitations that especially 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 see box=00400600 as global option.