4

I have defined the following variable storing my margin settings:

\def \geometryTitlepage {
    left=25mm,
    right=25mm,
    top=25mm,
    bottom=25mm
}

Then in the titlepage I want to set \newgeometry

\begin{titlepage}
    \newgeometry{
        \geometryTitlepage
    }
    \begin{center}
        *
        *
        *
    \end{center}
    \restoregeometry
\end{titlepage}

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?

Werner
  • 603,163
Humberd
  • 143

1 Answers1

3

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.

Werner
  • 603,163