Because I began to use many Unicode characters (Japanese, some unusual diacritics, etc.) I switched from LaTeX to XeLaTeX to render my documents. Unfortunately, if a font is missing, the letters are simply left out (for example, when I had forgotten to specify the font for Japanese) without any error (and I can't seem to spot a warning either). I will read the result, but I prefer to get some early warning if some character isn't available. Is there any way to get a warning about characters that have not been rendered? An error would be even better.
-
Related: http://tex.stackexchange.com/questions/41130/getting-xelatex-to-display-accents-and-characters-not-included-with-the-font – Mechanical snail Oct 21 '12 at 05:54
2 Answers
The log should list all missing characters in the form of:
Missing character: There is no <char> in font <font>
Where <char> and <font> is real character and TeX font name respectively. I usually use a simple grep call to check for such messages in the log.
- 22,859
-
I’m afraid the fonts I need to care about (e.g. CMU Serif Italic and Latin Modern Roman Demi) seem to have lots of characters defined to be, respectively, a boxed x and a blank. Nothing shows up in the log, though a visual review will show problems in the former. – Flash Sheridan Aug 14 '20 at 20:13
-
1@FlashSheridan https://tex.stackexchange.com/questions/23863/generating-a-table-of-glyphs-with-xetex/23868#23868 may help. CMU Classical Serif Italic (
cmunci.otf) has large coverage, 1561 glyphs, but lots of gaps: for example, it has left angle bracket (〈) in slot #9001, but nothing in slot #9000 (keyboard = ⌨). And so on. It has nonot.defglyph either, so presumably display of non-existing glyphs falls back to the font renderer rather than the font. – Cicada May 03 '21 at 08:24
It is easy. Just try:
\documentclass{article}
\usepackage{fontspec}
\newfontfamily\testfont[ExternalLocation]{persian-modern-regular}
\begin{document}
\setbox0=\hbox{\testfont A}
\ifdim\ht0=0pt Character A does not exist in font \else Character A exits in the font\fi
\end{document}
In the example above I used Persian Modern font which does not have Latin Characters so I get a box of height 0pt for character A.
Another one:
\documentclass{article}
\usepackage{fontspec}
% font spec loads "LAtin Modern" font which does not contain Persian characters
\begin{document}
\setbox0=\hbox{و}
\ifdim\ht0=0pt Character Vav does not exist in font \else Character Vav exits in the font\fi
\end{document}
Edit1: Based on Khaled comments "If there is a missing glyph in the font XeTeX will show the .notdef glyph, most fonts have a .notdef glyph with non zero height and width". So we can perform a furthur test with characters from a script that is unlikely to be found in every font. Say, Avestan (an ancient Iranian script). Being a Zoroastrian myself, there are only few unicode fonts that contain Avestan chracters. So let's try (although there may be a better approach):
\documentclass{article}
\usepackage{fontspec}
\newfontfamily\testfont[ExternalLocation]{amiri-regular}
\begin{document}
\setbox0=\hbox{\testfont A}
\setbox1=\hbox{\testfont \char"10B00} % this is Avestan character A
\ifvoid0
Font does not have character A
\else
\ifdim\dp0=\dp1
\ifdim\ht0=\ht1
\ifdim\wd0=\wd1
Font does not have character A
\fi\fi\else
Font has character A
\fi\fi
\end{document}
Edit2: It seems that my previous answers was not needed because etex provides \iffontchar primitive which has the following syntax:
\iffontchar ⟨font⟩ ⟨code⟩ ⟨true text⟩ \else ⟨false text⟩ \fi
The primitive \iffontchar can be used to check whether a certain glyph exists in a font. For this purpose it takes a font and the code of a character and performs the test. If the character exists the then branch is expanded otherwise the else branch.
An example would be:
\documentclass{article}
\usepackage{fontspec} % this loads Latin Modern font
\begin{document}
Font \iffontchar\font`ج has Persian character Jim\else does not have Persian character Jim\fi
\end{document}
- 853
-
Normally when a character does not exist you get the little blank square or a question mark, wouldn't this have a width? Can you provide a full MWE? – yannisl Apr 26 '12 at 15:59
-
-
If there is a missing glyph in the font XeTeX will show the
.notdefglyph, most fonts have a.notdefglyph with non zero height and width. – خالد حسني Apr 26 '12 at 16:26 -
-
1"Most fonts" - that's true. But mostly common (default one) Latin Modern does not! All U+01C4-U+01CC are missing, and all of them have positive width, height and depth. See: https://github.com/reutenauer/polyglossia/issues/216. Therefore, I find the
\iffontcharapproach the best (it also fits the WYSIWYM paradigm). Kind regards, Ivan – ivankokan Aug 01 '19 at 22:52