15

I remember to have read few year ago1 that babel line2 should be placed at the end of the preamble in order to avoid problems with other packages. (I believe hyperref package should also be placed at the end of the preamble for the same reason.)

However, I see, in MWEs, the babel line often just after the \documentclass.

Is there any differences? What is the good practice here?

Addendum

Here is my LaTeX template. Do you see any other misplaced packages calls in general?

\documentclass[12pt,twoside,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{setspace}
\usepackage{todonotes}
\usepackage{graphicx} 
\usepackage{lmodern}
\usepackage{xspace}
\usepackage[style=authoryear-comp,hyperref,backend=biber,isbn=false,doi=false,url=false,date=year]{biblatex}
\AtEveryBibitem{\clearlist{language}}
\renewcommand*{\newunitpunct}{\addcomma\space}
\bibliography{biblio}
\title{}
\author{}
\usepackage[francais,english]{babel}
\usepackage{csquotes}
\usepackage[colorlinks]{hyperref}
\begin{document}
\maketitle
\tableofcontents
\onehalfspacing


\printbibliography
\end{document}

1. I don't remember where... Sorry.

2.\usepackage[dutch,english]{babel}

lockstep
  • 250,273
ppr
  • 8,994

1 Answers1

15

Some packages behave differently, or adapt themselves somehow, if babel has already been loaded or not: for instance biblatex, csquotes, datetime, fmtcount, glossaries, listings microtype, natbib, tikz, to name the most used. So it's best to load babel as soon as possible.

I tend to group package calls by category. First the ones that directly involve the main choices for my document:

\usepackage[T1]{fontenc}    % alphabets to prepare
\usepackage[utf8]{inputenc} % input encoding
\usepackage[italian]{babel} % language(s)

\usepackage{kpfonts}        % or another font package

\usepackage{geometry}       % if needed for page shape
\geometry[<options>]

\usepackage{fancyhdr}       % if needed (it should go after geometry)
<fancyhdr settings>

Then I load the other utility packages in a possibly meaningful order:

\usepackage{amsmath,amssymb,amsthm}

\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{microtype}

\usepackage{csquotes}            % for biblatex, mainly
\usepackage[<options>]{biblatex} % or natbib

and so on. Of course, hyperref should be last, but cleveref should go after it, if loaded.

Note: kpfonts is just by way of example. I'm not generally tied to a particular font.

If etex becomes necessary, it should go first. Other packages to be loaded early are of course ifpdf, ifxetex and ifluatex, when needed.

Command definitions and other settings go after all packages have been loaded.

egreg
  • 1,121,712
  • You can add listings to your package list that should be load after babel. See http://tex.stackexchange.com/questions/100717/code-in-lstlisting-breaks-document-compile-error/100719#comment341860_100719 – quinmars Dec 31 '13 at 00:21
  • @quinmars I did a rather coarse grep for \@ifpackageloaded{babel} and listings didn't show up. I'll add it, because it's very frequently loaded. – egreg Dec 31 '13 at 00:23
  • I actually don't know why changing the order helps, but it seems to be related to the babel shorthands. But I don't know much about how this is handle internally. – quinmars Dec 31 '13 at 00:35
  • Well the "behaves differently" is more like a works or works not for listings. – quinmars Dec 31 '13 at 00:41
  • @quinmars "adapt themselves" applies. – egreg Dec 31 '13 at 00:44