# class file option: switch endnote to footnote

I'm working on a class file where notes are endnotes by default but can be converted to footnotes through a class option (this is because some prominent journals in my field require that submissions come with endnotes; this is ostensibly to make life easier for their typesetters, but given that endnotes are a pain to read, the first thing everybody does before uploading papers to a repository is change the endnotes to the footnotes). A minimal class file looks as follows

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mwe}[18/05/2015, MWE]

\PassOptionsToClass{12pt}{article}

\RequirePackage{endnotes}

\DeclareOption{endnotes}{\let\footnote=\endnote}
\DeclareOption{footnotes}{}

\ExecuteOptions{endnotes}
\ProcessOptions


And the MWE .tex file

\documentclass{mwe}

\usepackage{lipsum}

\begin{document}

\lipsum\footnote{First footnote}
\lipsum\footnote{Second footnote}

\theendnotes

\end{document}


Compiling mwe.tex without a class option or with the endnotes option produces two endnotes, as expected. However, compiling it with the footnote option eliminates all notes, even if I also delete the \theendnotes line.

What is the best way of implementing this option?

• Make the endnotes option load the endnotes package, and otherwise not, might be a better way. – Alan Munn Jun 18 '15 at 20:09

You could conditionally load the endnotes package

mwe.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mwe}[18/05/2015, MWE]

\PassOptionsToClass{12pt}{article}

\newif\if@endnotes

\DeclareOption{endnotes}{\@endnotestrue}
\DeclareOption{footnotes}{\@endnotesfalse}

\ExecuteOptions{endnotes}
\ProcessOptions

\if@endnotes
\RequirePackage{endnotes}
\let\footnote=\endnote
\fi

\providecommand\theendnotes\relax


You can create a conditional to keep track of the which type of notes are to be used

\newif\if@endnotes


Then after processing the options you conditionally load the endnotes package:

\if@endnotes
\RequirePackage{endnotes}
\let\footnote=\endnote
\fi


You can't just load the package inside the option because packages can't be loaded at that point in a class file.

Finally, so you can leave \theendnotes in your document even when using footnotes, make the class define it if it isn't already defined:

\providecommand\theendnotes\relax