4

After reading basics about catcode I started to use conditionals to autoset the preamble. Surprisingly when sandwiching the command I do get the error Undefined control sequence. \if@oneside, also there is @ within the command:

\makeatletter % ??? why does it only work without catcode sandwich
\if@oneside\newcommand{\onetwoside}{oneside} \else\newcommand{\onetwoside}{twoside}\fi  % Autoset var for later according to choosen layout
\makeatother

Using the if directly works fine. Where to read up on this?

  • I know \if@twoside; never heard of \if@oneside. – campa Apr 11 '16 at 14:24
  • 1
    Without \makeatletter the conditional is always false because it tests (with \if) if @ and o are the same. With \makeatletter you get notified that \if@oneside is not defined. – cgnieder Apr 11 '16 at 14:29
5

As you say, if you do not use \makeatletter...\makeatother everything "works" (so to say...). And if you call \onetwoside you will get "twoside" (try!).

What is going on? Without \makeatletter...\makeatother the @ is not a letter and thus not part of a command. What the human eye reads as \if@oneside is for TeX the token list

\if @ o n e s i d e and so on.

\if starts reading and compares the two following tokens: the @ (category code 12) and o (category code 11). They are definitely not the same, the \if conditional evaluates to false, skips the remaining tokens (neside and so on) and jumps to the \else branch.

If you use \makeatletter and \makeatother, TeX tries to evaluate \if@oneside, which does not exist (LaTeX defines \if@twoside), and you get the error.

| improve this answer | |
  • Where is the o (category code 11) sign from? If \makeatletter is missing what does it evaluate the @ against? Maybe the starting-letter o from oneside? – qrtLs Apr 11 '16 at 14:52
  • @ItsmeJulian see edit – campa Apr 11 '16 at 14:57

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.