Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

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

1 Answer 1

up vote 10 down vote accepted

You need:

  \newif\ifmaketitle

 \iffinal

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

 
discard

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.