8

MWE:

\documentclass{article}
\usepackage{geometry}
\newcommand{\GeomOpts}{a4paper,vmargin={3cm,3cm}}
\geometry{\GeomOpts}
\begin{document}
\end{document}

Because of the braces in \GeomOpts its expansion fails when inserted as parameter to \geometry. I did read [1] and [2] but I didn't find a way to adapt this to my simpler \geometry case.

I did try with \expandafter before \geometry and before its braces. Also I did try with xparse's commands intented to define macros/command without success.

[1] Keyval Error with \includegraphics: options undefined

[2] Strip one level of braces for using keyval-value within nested keyval

3
  • 3
    You can use the standard trick: \begingroup\edef\x{\endgroup\noexpand\geometry{\GeomOpts}}\x Commented Dec 10, 2013 at 19:40
  • Worked! Thanks. Can't be written without defining a new command \x? Why \begingroup and \endgroup in these places? Commented Dec 10, 2013 at 20:49
  • The encapsulation is needed to define \x local and to use the power \edef. Commented Dec 10, 2013 at 20:53

1 Answer 1

4

You don't need this type of tricks. Options passed to the \geometry command are cumulative. So you can simply say

\geometry{a4paper,vmargin={3cm,3cm}

(which I think is your standard) and then add whatever adjustment you like in another \geometry command.

So, saying

\geometry{a4paper,vmargin={3cm,3cm}
\geometry{headheight=14.5pt}

is just the same as doing

\newcommand{\GeomOpts}{a4paper,vmargin={3cm,3cm}}
\expandafter\geometry\expandafter{\GeomOpts,headheight=14.5pt}

which I think was your aim. I don't see how

\newcommand{\GeomOpts}{a4paper,vmargin={3cm,3cm}}
\expandafter\geometry\expandafter{\GeomOpts}

is clearer than my suggestion above.

1
  • I don't know what happened. I wrote my post because I thought I had tried with exactly this syntax, that was my first guess after keyval error. Now it worked; I don't know what happened before. :-) Thanks egreg and Marco Daniel! Commented Dec 11, 2013 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .