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

Writing accents and quotes that look like accents and quotes in LaTeX

I had a very strange problem. In my slides for teaching LaTeX I wanted to tell people that they have to write ``test'' to get “test” (in correct quotes). But if you write ` in LaTeX, you get… a single quote sign! So I tried verbatim, \verb|`| and \texttt{`} – which all gives something that looks like a LaTeX quote sign.

After quite some frustration I found the following:

\`{} gives ` (grave accent)
\'{} curiously gives ´ (acute accent)

The straight quote is the hardest, after reading about many creative ways at stackexchange, I chose the easiest: Include package textcomp. Then

\textquotesingle gives ' (single straight quote)

What a mess!