[Tex/LaTex] Command \texteuro unavailable in encoding T1


I want to know how does LaTeX figures out if the Eurosymbol (€) is a glyph of a given T1 font. I tried \iffontchar but it seems the value is not unique.
AFAIK it's not a standard symbol of the 256 characters, so I'm interested in the algorithm.

Please note: I'm not interested in using the € symbol if my font doesn't has the glyph.
I just want to catch the error and make it relax or redefine if glyph not in font.
I'm also not interested in using opentype font.

Also the answer should work for PDFLaTeX, LuaLaTeX and XeLaTeX.

Here is what I wrote so far when I came across this:

    \input glyphtounicode
        \input glyphtounicode
        \ifXeTeX %XeTeX T1 german special char fix
            \newunicodechar{§}{\textsection}% I think it's okay because standard character... but
            %\newunicodechar{€}{here it should check if eurosymbol in t1 font and if not let him relax (print nothing)}
            \renewcommand{\SS}{\iffontchar\font"1E9E \symbol{"1E9E}\else SS\fi}
Office 0123456789 äüöÄÜÖß \texteuro € \textmu

Using textcomp package works and gets an unfaked glyph from the font. So this is solved.
But I'm still interested in how I should define the %\newunicodechar{€}{} for fonts which don't have the special letters.

Best Answer

With utf8 the Unicode character is mapped to \texteuro, which requires textcomp. The definition of \texteuro is


If the TS1 font for the current family is known not to have the Euro symbol (that is, it belongs to class 5), the glyph is faked by means of \tc@fake@euro. If you want instead to raise an error, just change the definition of this macro:


  \@latex@error{No \noexpand#1in family \f@family}{}%


\fontfamily{put}\selectfont % put belongs to class 5

This will issue

! LaTeX Error: No \texteuro in family put.

and no glyph will be printed. You could define it to use a glyph from another font instead, say


Note that a test based on \iffontchar\font191 will not succeed, because usually fonts built with fontinst have a black square for inexistent characters. Therefore textcomp bases its decision to fake or not a glyph on an internal database.

By the way, \iffontchar\font"1E9E will return false if eight bit TeX fonts are used, so it's a pretty useless test.