Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 ?

share|improve this question
    
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

1 Answer 1

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.

share|improve this answer
    
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 at 21:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.