[Tex/LaTex] Do I need fontenc and inputenc

font-encodingsinput-encodings

My question feels like a duplicate of: fontenc vs inputenc, but in that question the OP uses German and non-ascii characters.

I speak and write in English exclusively. My keyboard is the standard en-GB layout making typing non-ascii characters difficult. I use latex and not xetex. My LateX files are 100% ascii. Every once in a while a citation I download into my .bib file contains a non-ascii character, but I have never had an issues "fixing" these. Do I need, or would I benefit from using, the fontenc and inputenc packages?

Best Answer

Font encoding

Because of deficiencies of the OT1 encoding I also recommend T1 font encoding:

\usepackage[T1]{fontenc}

For example OT1 contains inconsistencies in the encoding for different families, typewriter is different, … Also

\usepackage{textcomp}

is useful for getting other symbols (Euro, …). Instead of Computer Modern/EC I would use the new Latin Modern fonts that are a further development of the former:

\usepackage{lmodern}

Input encoding

Of course there are advantages using plain ASCII for the texts and using commands for the other characters. This way the text is quite independent from the encoding and can be more easily be used in different environments with different encodings.

But sometimes characters outside of ASCII might slip through. In case of OT1 the file compiles fine, but the characters are missing:

\documentclass{article}
% Default font encoding: OT1
\begin{document}
Umlauts via LICR: \"a\"o\"u\ss

Umlauts directly: äöüß
\end{document}

Missing non-ASCII characters in output

There is no warning or error, only the .log file says:

Missing character: There is no ä in font cmr10!
Missing character: There is no ö in font cmr10!
Missing character: There is no ü in font cmr10!
Missing character: There is no ß in font cmr10!

Switching to T1 encoding helps to make more characters available. However I do not know an editor that supports T1 encoding. Some positions match the slots in latin1, for example. But other characters are different or have other positions. The following example uses the ^^-notation to avoid problems with editing and copy&pasting, because the example uses two different encodings at the same time:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{lmodern}

\begin{document}

% Umlauts/Euro: äöüß/€

Umlauts/Euro via LICR: \"a\"o\"u\ss/\texteuro

Umlauts/Euro directly (latin9): ^^e4^^f6^^fc^^df/^^a4

Umlauts/Euro directly (UTF-8): ^^c3^^a4^^c3^^b6^^c3^^bc^^c3^^9f/^^e2^^82^^ac
\end{document}

Unexpected result with non-ASCII characters

This time, there is no hint even in the .log file.

Therefore I recommend using package inputenc with encoding ascii:

\usepackage[ascii]{inputenc}

Then non-ASCII input characters generate errors:

! Package inputenc Error: Keyboard character used is undefined
(inputenc)                in inputencoding `ascii'.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.10 Umlauts/Euro directly (latin9): ä
                                      öüß/€

After fixing the input lines this helps to ensure that the file is indeed ASCII.