Inputenc and fontenc

Your typical LaTeX document imports two packages right at the beginning:

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

What do they do?

fontenc choses an output font for encoding characters. This is important for special characters to have correct hyphenation, ligatures and kerning. Also if you use special characters and want to copy them out of the pdf, when the package is missing you will get wrong results. For example, an “ä” will become “a” plus diacritics instead of just one single letter. Also some other characters may give unexpected results. T1 contains characters for most European languages.

inputenc allows the user to input special characters (like ä, ß, ñ) directly instead of escaping them. This is very nice if you are writing in a language other than English. The value should match the encoding with which the file has been written. If you have a file encoding that’s different from what you specify for inputenc, you will get errors similar to “input character XYZ is not defined”. You should always write all of your documents in UTF-8 nowadays, so that would be the usual value.

It is best to call fontenc first and then inputenc (though I have read conflicting information on that and I haven’t really seen a good reason for it).

This entry was posted in LaTeX and tagged , , by swk. Bookmark the permalink.

About swk

I am a software developr, data scientist, computational linguist, teacher of computer science and above all a huge fan of LaTeX. I use LaTeX for everything, including things you never wanted to do with LaTeX. My latest love is lilypond, aka LaTeX for music. I'll post at irregular intervals about cool stuff, stupid hacks and annoying settings I want to remember for the future.