TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a document class that has draft and final versions. The final version has a front page generated by \maketitle, but in draft mode \maketitle is \let to \relax. I decided to insert a test to ensure that \maketitle is present in final mode. The simplest method seemed to be to use \AtEndDocument.

\ProvidesClass{myexam}[2013/03/08 \space (v1.0) \space\space Ian Thompson]

\newif\iffinal %Option for final or draft mode                                                                                                          
\finalfalse %Default to draft mode                                                                                                                      


  \typeout{FINAL MODE}
  \AtEndDocument{\ifmaketitle\relax\else \ClassError{myexam}{Final version requires maketitle}{}\fi}
  \renewcommand\maketitle{THIS IS THE TITLE\newpage\maketitletrue}
  \typeout{DRAFT MODE}

However, attempting to typeset this simple example file

The quick brown fox jumps over the lazy dog.

results in the error

! Class myexam Error: Final version requires maketitle

despite the fact that the example uses draft mode. Everything worked until I inserted \AtEndDocument. What is going on here?

share|improve this question
changed tag [tex-core] to [latex-kernel]. still not sure if this is best choice, but [tex-core] would have been appropriate only if \bye were the trigger for the problem. – barbara beeton Mar 13 '13 at 13:20
up vote 11 down vote accepted

You need:



You need to always declare the new if otherwise the scanning of your \iffinal block goes wrong as \ifmaketitle is not an if but the else and \fi are (so terminate the \iffinal.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.