pass to \geometry{} options using a macro - keyval error

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.

• 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

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}


is just the same as doing

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

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