Inputenc and fontenc

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


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).