[Tex/LaTex] In which order should I load inputenc and fontenc


When I’m using pdfLaTeX, my preamble usually contains




Should these two be loaded in any particular order? What problems could arise if they’re loaded in the “wrong” order?

On a related topic, I know that fontenc should come after font packages, as described in Should the fontenc package be loaded before or after font packages?, so I’d move font packages along with inputenc – unless there’s a catch as well, which would indicate something like
1) font package(s) 2) inputenc 3) fontenc?

Best Answer

No the order doesn't matter as inputenc contains some code to avoid "order problems".

Some background: inputenc with option utf8 doesn't set up definitions for every unicode character as everyone knows who got once the message ! Package inputenc Error: Unicode char \u8:... not set up for use with LaTeX.

Instead it loads a .dfu for each font encoding declared by fontenc (naturally only if the dfu exists) so that there exist input definitions for the chars that can be printed with this font encodings.

fontenc puts all the font encodings it has been called with or which have been loaded by default in a list \cdp@list. inputenc process this list and loads the corresponding .dfu (e.g. T1.dfu) and then redefines \DeclareFontEncoding@ so that from now on every \DeclareFontEncoding will load the .dfu directly.