1

I can't seem to figure out why this isn't working. I'd like to set up an option for this package to allow for a preprint version (with no page range marked) and a final version with the page range included. The \@firstpage and \@lastpage commands are defined elsewhere.

From what I understand of TeX conditionals, I define a new choice, \@final, define it by default to be true. When the user invokes \documentstyle[preprint]{package} it should set \@final to false, and then later on define \thepagerange to be some text. If the preprint option is not used or is set to final, then \@final should be true (the default) and \thepagerange should be defined as shown.

The problem is that this does not seem to work. Regardless of whether I pass preprint or final, the compiler tosses out the errors:

./package.cls:388: Undefined control sequence.
l.388 \if@finaltrue

./package.cls:393: Extra \fi.
l.393 \fi

./package.cls:394: Undefined control sequence.
l.394 \if@finalfalse

./package.cls:396: Extra \fi.
l.396 \fi

Troublesome MWE here:

\newif\if@final
\@finaltrue

\DeclareOption{final}{\@finaltrue}
\DeclareOption{preprint}{\@finalfalse}

\ProcessOptions

\if@finaltrue
\def\thepagerange{%                                   
   \ifnum\@lastpage =0 {\ \bf ???} \else
   \ifnum\@lastpage = \@firstpage \ \thefirstpage\else
   \thefirstpage--\thelastpage \fi\fi}
\fi
\if@finalfalse
\def\thepagerange{xx--xx}
\fi
  • This is no MWE so far. It is incomplete class code and no document that loads this class – user31729 Oct 30 '17 at 0:57
  • Your code isn't compilable. But the conditional is \if@final <true part> \else <false part> \fi not \if@finaltrue .... Also \bf is a deprecated command and you shouldn't use it. Use \bfseries instead. – Alan Munn Oct 30 '17 at 0:57
2

When you define a conditional using \newif\if@final the conditional itself is simply \if@final. You set the conditional by using either \@finaltrue or \@finalfalse.

If you want to use the conditional then the syntax is:

\if@final
   <true part code>
\else
   <false part code>
\fi

You are trying to use \if@finaltrue (and later \if@finalfalse) and since those macros do not exist, you predictably get an "Undefined control sequence" errors (as your error shows.)

You also shouldn't use \bf, which is a deprecated command. Use \bfseries instead.

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.