I am trying to set parameters of the geometry package via macros. For example


However the above command, nor \expandafter\geometry{twoside=\xxx} seem to work; I also tried \expandafter\geometry\expandafter{twoside=\xxx} as suggested by pass to \geometry{} options using a macro - keyval error . Is there a way to make this work? (Preferably an expl3 way)


Your sequence of \expandafter's only reaches t.

There may be better ways, but without further details on your document class and where \xxx is set, this can work

\def\xxx{false} % or true


If you don't trust your users to have a recent TeX distribution that supports \expanded, you can do

\def\xxx{false} % or true


A more generic way could be


so you can call


and any other option can be used.

For expl3 keys, you can define a choice key:



  \keys_set:nn { jason/class } { #1 }

\keys_define:nn { jason/class }
  twoside .choices:nn = { true, false } { \geometry{twoside=#1} },
  twoside .default:n = true,




\chapter{Test chapter}

\section{Test section}


  • I am actually try to set this from a l3keys boolean value. I have twosided .bool_set:N = \l__twosided, and I was trying \gemetry{twoside=\bool_if:nTF \l__twosided {true} {false}}. Maybe there's a better way to extract the boolean? – Jason Siefken Jun 12 '20 at 16:58
  • @JasonSiefken Use a choice key – egreg Jun 12 '20 at 17:29
  • That's a nice solution :-). Can you have .choices:nn and .set_bool:N? – Jason Siefken Jun 12 '20 at 20:51
  • @JasonSiefken You can use any code inside the second part, together with \geometry{twoside=#1}, for instance \bool_gset:Nn \g_jason_twoside_bool { \use:c { c_#1_bool } } – egreg Jun 12 '20 at 21:46

In \geometry{twoside=\xxx}, what you need is to expand \xxx first, then \geometry. In \expandafter\geometry\expandafter{twoside=\xxx}, t is expanded first, then \geometry.

Here is a solution, to use a macro to collect the key-value list, then pass it to \geometry{...}.



% now \geo@options == "twoside="

% now \geo@options == "twoside=false"


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.