# Do I really have to specify the font encoding like this?

This input file typesets with no errors, and the PDF is what I wanted, with the three characters:

\documentclass{article}

\usepackage[T5,TS1,T1]{fontenc} % 3 of lmodern's 8 encodings
\usepackage{lmodern}
\usepackage[utf8]{inputenc}

\begin{document}

%Font encoding now is T1, the default set by fontenc above
£   % lmodern character, in T1 encoding

\fontencoding{T5}\selectfont
ỉ   % lmodern character (ihookabove), in T5 encoding

\fontencoding{TS1}\selectfont
€   % lmodern character, in TS1 encoding

\end{document}


But that was work for me, because I had to look up in the documentation what encoding each lmodern character was in, then specify that encoding with \fontencoding {}.

Why doesn't LaTeX look up and set a suitable encoding itself, rather than just giving an error if the character is not in the current encoding? Is there a way that LaTeX can be made to look up the encoding ?

• XeTeX and LuaTeX use UTF8 as the default encoding, so you can use any combination of Unicode characters in your document. – ChrisS Jul 27 '13 at 9:20
• Part of the answer to "why?" is "history"; several of the issues may be found discussed in the documentation for fontenc. Switching to lualatex or xelatex and using the fontspec package removes these problems (and lmodern is the default font). – Andrew Swann Jul 27 '13 at 9:29
• With XeTeX: \documentclass{article}\usepackage{fontspec}\begin{document}€£ỉ\end{document} – Fran Jul 27 '13 at 9:53
• As to the euro symbol (and many others): if you are using T1 you should always load textcomp, too. – Javier Bezos Jul 27 '13 at 11:20

You don't need to, if you're prepared to huge work for supporting all the characters you want to use.

\documentclass{article}

\usepackage[T5,TS1,T1]{fontenc} % 3 of lmodern's 8 encodings
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\DeclareTextAccentDefault{\h}{T5}
\DeclareTextComposite{\h}{T5}{i}{191}
\DeclareUnicodeCharacter{1EC9}{\h\i}

\begin{document}

%Font encoding now is T1, the default set by fontenc above
£   % lmodern character, in T1 encoding

%\fontencoding{T5}\selectfont
ỉ   % lmodern character (ihookabove), in T5 encoding

%\fontencoding{TS1}\selectfont
€   % lmodern character, in TS1 encoding

\end{document}


Notice that the \fontencoding lines are commented out. Actually the method works only with TS1 encoded glyphs. The i is problematic, as you see, because it has to lose the dot.

Why isn't it done by default? There are several reasons, the main one is that overloading LaTeX with definitions of unused characters would slow down the performance. Accents such as \h would make words in which they appear not work with hyphenation, because the letters would be from different fonts. Not a real problem with Vietnamese (that's not hyphenated), but it could be with other languages and accents.

Say you're using Cyrillic. One could add declarations such as

\DeclareTextSymbolDefault{\cyri}{T2A}


but when \"i is found (maybe via the Unicode input Ї), the dieresis would be from the T1 encoded font. Otherwise the \" accent should be defined in a much more complicated way.

You need marking up different languages for hyphenation anyway, so there's not much point in doing really difficult “global” definitions for composite commands.

• Just to add that loading textcomp is enough to ensure that £ € etc. to work even if you switch to e.g. T5 encoding. – cfr Jan 12 '14 at 21:56

You might want to switch to the more modern unicode engines, xelatex or lualatex.

Just use the fontspec package (Latin Modern fonts are the default):

\documentclass{article}

\usepackage{fontspec}

\begin{document}

£   % lmodern character, in T1 encoding
ỉ   % lmodern character (ihookabove), in T5 encoding
€   % lmodern character, in TS1 encoding

\end{document}


compile with xelatex or lualatex.

Result: Replacing inputenc and fontenc with fontspec and using the commands provided by this package instead of font packages is pretty much everything you need to do to switch.

If you need a bibliography you should also (and for pdflatex too) switch to biblatex with the biber backend.

Except $ (for some reason…) you can typeset them directly if you load fontenc with options [TS1,T1], and if you use lmodern, load textcompanion. You also can use \pounds and \texteuro \documentclass[12pt]{article} \usepackage[utf8]{inputenc} \usepackage[TS1, T1]{fontenc} \usepackage{erewhon} \begin{document} \pounds\enspace £\enspace €\enspace \texteuro\enspace \$ \textdollar

\end{document}


• \textdollar ? – cfr Jun 11 '15 at 18:01
• You're right, but I wonder who would type \textdollar, when it's so simple with \\$. But I'll add it :o) – Bernard Jun 11 '15 at 18:05
• Well £ is even simpler (on this keyboard - my laptop is a different matter). And € is easy on both. – cfr Jun 11 '15 at 18:38
• @cfr: I'm sorry to say I don't have direct access to the Vietnamese dong… Maybe someone should create a currencypad, with luminous keys (I'd love to see a luminous dong!) – Bernard Jun 11 '15 at 19:56