6

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
    You can use the standard trick: \begingroup\edef\x{\endgroup\noexpand\geometry{\GeomOpts}}\x – Marco Daniel Dec 10 '13 at 19:40
  • Worked! Thanks. Can't be written without defining a new command \x? Why \begingroup and \endgroup in these places? – Emilio Lazo Dec 10 '13 at 20:49
  • The encapsulation is needed to define \x local and to use the power \edef. – Marco Daniel Dec 10 '13 at 20:53
3

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.

  • 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! – Emilio Lazo Dec 11 '13 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.