# I'm supposed to load some packages BEFORE the document class?

So I was reading Fixing LaTeX2e and it has several examples of the form

\RequirePackage{fixltx2e}
\documentclass...


What? I thought documentclass always went right at the top. Are there other situations I should require a package before documentclass?

• I don't think this will be a very "big list"... :-D Not that I'm an expert, but I can't think of any others besides nag and hyphsubst. – Paul Gessler Dec 29 '14 at 23:03
• @PaulGessler Isn't fix-cm one? – cfr Dec 29 '14 at 23:34
• @cfr could be; I've never used it. I only listed the ones I knew of. – Paul Gessler Dec 29 '14 at 23:52
• @PaulGessler I had no idea what to tag it, sorry about that. I expected someone to edit it to the right one. Best Practices perhaps? – Canageek Jan 1 '15 at 4:27

Generally the use for package loading is with \usepackage after \documentclass but fixltx2e is essentially a list of unrelated fixes that should really be in the format and so potentially could include commands that a document class file wants to use, so ought to be fixed before that are used. Actually given the current set of fixes in fixltx2e and the typical commands used in a class file, using it at the start of the preamble with \usepackage is usually safe enough.

As noted in comments fix-cm (which is actually generated from the same source file) is similar in that it changes the font settings for the standard OT1 cm fonts and so ought to be loaded before the document class if that class does any typesetting (including trial typesetting in box registers to measure things) so not just visible typeset output.

• May I misunderstood that Joseph Wright advised to use \RequirePackage{fixltx2e} before \documentclass... ? – jotagah Dec 30 '14 at 1:01
• @jotagah no as I say here it is best to use fixltx2e before \documentclass. – David Carlisle Dec 30 '14 at 1:44
• @DavidCarlisle Shouldn't any sane document class load it before anything else anyway? – jubobs Dec 30 '14 at 1:57
• @Jubobs no that removes choice from the end user. the (current) design is that the fixes are not put in the format so that by default existing documents are not changed. For the same reason none of the standard classes load it by default. – David Carlisle Dec 30 '14 at 2:10

Only a too long comment about:

I thought \documentclass always went right at the top.

Not necessarily, beside \RequirePackage{}, that could be needed to load the package before the macros contained in the .cls file, many (not all) commands works above \documentclass. For example (It is a proof of concept, not a recommendation!) this is a functional code:

\def\mymacro{Some macro make this text. }
\newcommand\thistoo{This too. }
\title{My title}
\author{Me}
\date{\today}

\documentclass{article}
\begin{document}
\maketitle
Hello, Word. \mymacro
\thistoo
\end{document}


In fact, you can have a working main.tex file without a \documentclass, as this can be loaded from a subdocument:

\input{pre-preamble}
\begin{document}
\TEST
\lipsum[1-10]
\end{document}


Where pre-preamble.tex could be some like:

% pre-preamble.tex
\def\TEST{A test. }
\documentclass[twocolumn]{article}
\usepackage{lipsum}