2

I created a switch which is defined iff a new geometry should be twosided. Currently, my code looks like this:

\ifdefined\@TwosideSwitch%
  \typeout{SwitchGiven!}%
  \newgeometry{twoside=true, ...}%
\else%
  \typeout{Undefined!}%
  \newgeometry{twoside=false, ...}%
\fi%

where ... are identical big chunks of options regarding geometry. This works, but for the sake of consistency and beauty, I want it to look more like this:

\someMagicWith{\@TwosideSwitch}%
\newgeometry{\applyTwosideAccordingly, ...}%

I tried:

\ifdefined\@TwosideSwitch%
  \def\@Twoside{true}%
\else%
  \def\@Twoside{false}%
\fi%
\newgeometry{twoside=\@Twoside, ...}%

But apparently geometry hates macros for boolean values. Using the available documentation I discovered a specified "twoside" is implemented as setting two other switches, but that does not work for me either:

\ifdefined\@TwosideSwitch%
  \@twosidetrue\@mparswitchtrue%
\else%
  \@twosidefalse\@mparswitchfalse%
\fi%
\newgeometry{...}%

Any experts here? :)


ANSWER:

Beautiful! As @ChristianHupfer pointed out, J.Wright wrote:

As a result, you need to either store both the key and value and pre-expand:

\def\myvariable{valid-key-name=some-valid-input}
\expandafter\KeySettingCommand\expandafter{\myvariable}

So this boils down to

\ifdefined\@TwosideSwitch%
  \def\@Twoside{twoside=true}%
\else%
  \def\@Twoside{twoside=false}%
\fi%
\expandafter\newgeometry%
  \expandafter{\@Twoside, ...}%

or shorter

\def\@Twoside{twoside=false}%
\ifdefined\@TwosideSwitch%
  \def\@Twoside{twoside=true}%
\fi%
\expandafter\newgeometry\expandafter{\@Twoside, ...}%
4
  • 1
    This could be the same problem as I encountered with boolean keys in conjunction with xkeyval keys, however, geometry uses keyval instead: Perhaps the solution by J. Wright might help: tex.stackexchange.com/questions/152020/… – user31729 Sep 16 '14 at 21:17
  • 1
    Can you please add a full minimal working example so that people can see what packages etc you need to get your code to work (but don't add code that is not needed). This makes it much easier for people to help you. Instead of your switches, i'd use \newif\ifSwitch with \Switchtrue and \Switchfalse for setting your switches. – user30471 Sep 16 '14 at 21:18
  • \gdef\mysides{twoside}, gdef\mysides{oneside}, \newgeometry{\mysides,...}. [Untested as no MWE provided.] – cfr Sep 16 '14 at 22:17
  • @Andrew: As any document including the geometry package suffice as an MWE, i didn't include one explicitly. I'll do so in every future post, though. @Christian Hupfer: This solved my problem, Answer is now added in Question. However I wonder if I should rather answer my own question using that; it seems to me that'd be your part (no metadiscussion intended) – LDericher Sep 16 '14 at 22:49

Your Answer

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

Browse other questions tagged or ask your own question.