8

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?

Canageek
  • 17,935

2 Answers2

14

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.

David Carlisle
  • 757,742
  • May I misunderstood that Joseph Wright advised to use \RequirePackage{fixltx2e} before \documentclass... ? – jotagah Dec 30 '14 at 01:01
  • @jotagah no as I say here it is best to use fixltx2e before \documentclass. – David Carlisle Dec 30 '14 at 01:44
  • @DavidCarlisle Shouldn't any sane document class load it before anything else anyway? – jub0bs Dec 30 '14 at 01:57
  • 4
    @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 02:10
2

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}
Fran
  • 80,769