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.
\NeedsTeXFormat{LaTeX2e}
\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
\DeclareOption{final}{\finaltrue}
\DeclareOption{draft}{\finalfalse}
\ProcessOptions\relax
\LoadClass[12pt]{article}
\iffinal
\typeout{FINAL MODE}
\newif\ifmaketitle
\maketitlefalse
\AtEndDocument{\ifmaketitle\relax\else \ClassError{myexam}{Final version requires maketitle}{}\fi}
\renewcommand\maketitle{THIS IS THE TITLE\newpage\maketitletrue}
\else
\typeout{DRAFT MODE}
\let\maketitle\relax
\fi
However, attempting to typeset this simple example file
\documentclass[draft]{myexam}
\begin{document}
\maketitle
The quick brown fox jumps over the lazy dog.
\end{document}
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?
\byewere the trigger for the problem. – barbara beeton Mar 13 '13 at 13:20