I always place all my packages immediately following the document class, followed by setting information (\hypersetup for example) and customization to my documents (header and footer customization for example), and macros for use in the document.

Is there any case were you would want to load code before you load a package?

This answers points out that for clarity you might want to have setting information immediately following the package, to reduce the amount of documentation you have to do (For example, I should move \hypersetup to be right after \usepackage{hyperref}, but before any packages that follow it, achemso or cleverref or whatever)

I thought all packages had to be loaded first, but it seems that in some cases you need code before them, for example you need to set \author, \title, and \date before you load the titling package.

So, are there cases where it is technically better (or required) to write some code before loading a package? By technically better I mean, makes a difference to the compiler, not just someone reading the code later.


2 Answers 2


One situation in which you need some code before loading a package is to prevent name clashes. A little example: suppose you are using one of the AMS document classes and you want to use some command from the dingbat package, say \leftpointright; you then try





and receive the following error

! LaTeX Error: Command \checkmark already defined.
               Or name \end... illegal, see p.192 of the manual.

The problem is that the package amsfonts internally loaded by the AMS classes, defines \checkmark and the dingbat package also defined this command, producing a name clash. One possible solution is to use the savesym package, rename the conflicting symbol, and then load the dingbat package: \savesymbol{XXX} renames a symbol from \XXX to \origXXX thus preventing the name clash:





enter image description here

This techniques was used extensively by Scott Pakin to build the The Comprehensive LaTeX Symbol List.

As a curiosity, the file associated to the savesym package is savesym.sty but the package says

\ProvidesPackage{savesymbol}[2003/06/01v1.1 Saves and restores symbols]

so you will get a (harmless) warning when using the package:

LaTeX Warning: You have requested package `savesym',
               but the package provides `savesymbol'.

The biblatex package uses \parindent to initialize the \bibhang length which controls the hanging indentation of bibliography entries. If you want \parindent and \bibhang to match, any changes to \parindent should be carried out before loading biblatex.




\newcommand*{\sometext}{Lorem ipsum dolor sit amet, consectetuer
    adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
    adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
    libero, nonummy eget, consectetuer id, vulputate a, magna.}


  author = {Author, A.},
  year = {2001},
  title = {Alpha},
  addendum ={\sometext}







enter image description here

  • Seems like a bug in the package: The code for initializing \bibhang should be executed with \AtBeginDocument to remove that dependency on code order. Sep 23, 2012 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .