Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When I’m using pdfLaTeX, my preamble usually contains

\usepackage[utf8]{inputenc}

and

\usepackage[T1]{fontenc}

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

Before trying to answer the question I would like to make a general statement that font encoding and keyboard mappings is an area which is still in a mess. This is not only with LaTeX but also with the web. How many pages still come up with funny characters? The nearest thing to a solution is the use of UTF-8. For the TeX/LaTeX family the answer is XeLaTeX or LuaLaTeX.

For texts that their language is predominantly English, I would stick with the extended ASCII encoding at the cost of typing a few commands for accented letters here and there. This in my opinion is a safer way and ensures that journal archives have an easier time in the longer run.

As to the question, I would place \inputenc first as shown in the below minimal.

\documentclass{article}
\usepackage[utf8]{inputenc} 
\def\testa{Umlauts: äöüß}   
%\usepackage[T1]{fontenc}    
%\usepackage{textcomp}
%\usepackage{lmodern}
%\usepackage[utf8]{inputenc} 
\begin{document}

\testa

äöüß 

\end{document}

Reasoning, defensive programming means I want to catch errors as soon as possible. Contrary to what one would expect, this works with and without \fontenc. (Since LaTeX loads both the T1 and OT1 encoding files on its own).

share|improve this answer
1  
T1 is not loaded automatically. –  egreg Feb 7 '13 at 23:39
2  
pdflatex can use UTF-8... –  Paul Gaborit Feb 8 '13 at 0:07
2  
I use UTF-8 exclusively (except for BIBTeX files...), and write mostly in Spanish (ASCII with a few accented characters, my text has occasional "weird characters" thrown in, mostly names in Hungarian or German). pdflatex handles that just fine, and has for a long time now. Even hyphenation seems to work OK (TeX hyphenates so little it is hard to be sure...). –  vonbrand Feb 8 '13 at 2:44
4  
@YiannisLazarides The fact that T1 is known to the format doesn't mean that it is used for typesetting characters: you have to request it explicitly (or some package has to); for instance, Ð will throw Command \DH unavailable in encoding OT1 without a \usepackage[T1]{fontenc} call. This is what I mean by "T1 is not loaded automatically". –  egreg Feb 8 '13 at 6:39
2  
@YiannisLazarides: font encodings are a bit like babel languages: You can load more than one and you can switch between them but only one is active at some point. At the begin of the document the last fontenc option (again similar to babel) is active (or the default OT1). –  Ulrike Fischer Feb 8 '13 at 9:04
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.