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.

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.

share|improve this question
    
add comment

2 Answers

up vote 5 down vote accepted

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.

share|improve this answer
add comment

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}
share|improve this answer
    
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? –  Yiannis Lazarides Apr 26 '12 at 15:59
    
Edited the answer. –  Simurgh12 Apr 26 '12 at 16:24
    
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. –  Khaled Hosny Apr 26 '12 at 16:26
    
EDited my answer. –  Simurgh12 Apr 26 '12 at 17:11
add comment

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.