I use the "variables" in my header and would like to shorten the code by combining \ifdefined\@@author and \ifdefined\@group. Searching the repository for "ifdefined multiple arguments" etc. didn't give a useful result. I experimented with ||, as from different programming languages, but you can imagine... :)

Is there no easier way to do that?

            , %


Edit (MWE):

\title{Work Hygiene and Safety}


            , %
  • I can't see what logic changes would make this shorter: could you write out in pseudo-code what flow you are after? – Joseph Wright Sep 2 '18 at 8:44
  • I just want the learn "whats's possible". I thought there must be a solution like \ifdefined\THIS&&THAT ... – Steffen Sep 2 '18 at 8:48
  • @Steffen there are no boolean and and or connectives although of course any logical combination can be made with suitable \if combinations. – David Carlisle Sep 2 '18 at 8:55
  • unrelated but you have % at the ends of exactly the wrong lines, you need one after \rhead{ but the ones after command names like \group% do nothing as white space is ignored after a command name. – David Carlisle Sep 2 '18 at 8:59
  • 1
    I would guess you intended \newcommand\group[1]{\def\group{#1}} to be \newcommand\group[1]{\def\@group{#1}} – David Carlisle Sep 2 '18 at 9:02

The logic of all TeX primitive conditionals is the same: they are 'one shot' tests with no combining logic. There are a variety of 'wrappers' which provide such logic, most notable in etoolbox and expl3, which use a more 'LaTeX-like' syntax. At the primitive level, one can create combinations by using \ifnum or \ifodd, for example

  \ifdefined\@@author 1\fi
  \ifdefined\@group 1\fi
  >0 %
  % Code for 'at least one is true' case
  % Code for 'neither is true' case

This uses the fact that TeX keeps expanding material in the number test until it finds a non-numeral, in particular a comparator here. So the two \ifdefined tests get converted into either a value or nothing at all.

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.