I have defined the following variable storing my margin settings:

\def \geometryTitlepage {

Then in the titlepage I want to set \newgeometry


But the compiler throws an error:

!Package keyval Error: left=25mm, right=25mm, top=25mm, bottom=25mm undefined. 

When I put the values by hand everything is ok. But when I use variable it seems to add undefined at the end of the string. What am I doing wrong?

  • \expandafter\newgeometry\expandafter{\geometryTitlepage} – egreg Dec 22 '16 at 23:29

Key-values are not expanded by default, so combining multiple keys into a single command requires expansion first before the separate keys can be interpreted. There are a number of ways of achieving this:

  • \expandafter\geometry\expandafter{\geometryTitlepage}

  • \edef\x{\noexpand\geometry{\geometryTitlepage}}\x

The latter option should be used inside a group to prevent \x (or whatever you choose) from "leaking" elsewhere (although not critical). This is already the case since you're using it inside the titlepage environment, thereby limiting its scope. For this reason, some use it also in this context

  • \begingroup\edef\x{\endgroup\noexpand\geometry{\geometryTitlepage}}\x

which "destroys" \x after using it.

  • Whoa, thanks. I don't understand any of the code you provided, but it works. – Humberd Dec 23 '16 at 1:58

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.