2

I would like to make condition inside the geometry options

 \geometry
 { headsep    =   \baselineskip
  , textwidth  = 42\baselineskip
  , textheight = 60\baselineskip
  , hmarginratio = 2:3
  , vmarginratio = 2:3
  , bindingoffset = 0cm
  , onecolumn
 }

I try the code bellow, but that does not work.

\newif\ifPDF \PDFtrue
\geometry
 { headsep    =   \baselineskip
 , textwidth  = 42\baselineskip
 , textheight = 60\baselineskip
 \ifPDF
 , hmarginratio = 1:1
 \else
 , hmarginratio = 2:3
 \fi
 , vmarginratio = 2:3
 , bindingoffset = 0cm
 , onecolumn
 }

1 Answer 1

4

You can't use conditionals inside the options in that way. However you can exploit the fact that \geometry can appear as many times as you want.

\newif\ifscreen
\screentrue % comment out for printable version

\geometry{
  headsep=\baselineskip,
  textwidth=42\baselineskip,
  textheight=60\baselineskip,
  heightrounded,
  vmarginratio=2:3,
  onecolumn,
}
\ifscreen
  \geometry{
    hmarginratio=1:1,
  }
\else
  \geometry{
    hmarginratio=2:3,
  }
\fi

I think you can do

hmarginratio=\ifscreen 1:1\else 2:3\fi,

but I don't think it's even worth trying.

3
  • Please can you explain why the second (shorter) answer is not worth trying? It works :)
    – chejnik
    Nov 3, 2015 at 15:23
  • 1
    @chejnik Yes, I suspected it works ;-), but I think it's unreadable and difficult to maintain if the option is buried in the middle of several others.
    – egreg
    Nov 3, 2015 at 15:25
  • I see, thank you for explanation and the answer.
    – chejnik
    Nov 3, 2015 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .