In XeTeX, a message is printed to the log file if a glyph is not available with the current font. The input
\documentclass{scrartcl}
\begin{document}
α
\end{document}
leads to the following entry in the log:
Missing character: There is no α in font cmr10!
Is there a way to check for a given input if all glyphs required to render it are available, without relying on the log file? Apparently, there is no Command to flush log file, and (in a scenario where I pipe into a running XeLaTeX process) I'd like to know before XeTeX is terminated.
Best Answer
This task was a big issue for me many years ago when I was typesetting and generating preview books of fonts where I needed to know all kind information about the glyphs before actual typesetting. I divided the answer into three small parts each with compilable TeX file.
There is a way in
xelatex
, it is mentioned indirectly on page 8 in the reference manual. We can use the\XeTeXcharglyph
command and check if the output is0
(or.notdef
if checking glyph name). Once any glyph is not defined the zero value is assigned to the character slot.After that step we can use
\ifnum...\else...\fi
statement to decide what to typeset, if anything at all. In the example I am testing four letters,? A \ a
, two are defined, the remaining two are not. I have downloaded and installed RodgauApesInitials from Manfred Klein's collection, http://moorstation.org/typoasis/designers/klein04/deco/rodgau_apes.htmWe run
xelatex mal-kanji1.tex
and terminal says:This is the code:
I needed and I used this strategy when I typesetted a preview book of kanji. I was using many different font faces and I needed to know exactly how many glyphs were going to be typeset. If a glyph or more were missing it was up to me to decide if to typeset that rectangle, or not. I should say that it is normal that a font is missing some CJKV characters, there are so many of them. I enclose a snapshot from the book, it is a preview of a single Japanese character/kanji.
The big disadvantage is that we can use this strategy only with the
xelatex
format and we can check only newer fonts (TTF, OTF), it is not working with PFB. That's a serious limitation in work. Let me show you other approach.One of tools in the TeX distribution is
testfont.tex
file. If we run, e.g.:We are asked about the name of the font, let's use
dmjhira
and hit Enter. There is a list of options when we use\help
and hit Enter. The common option is to write\table\bye
followed by Enter. We are getting thetestfont.pdf
file and this is a preview of it.A problem is that we cannot customize it and we cannot enter TTF and OTF fonts without installing and setting up the fonts. It is worth checking another approach.
The core of TeX is in measuring boxes. It is the approach we are going to use and test. We will test a single glyph, but we could easily measure almost anything. After defining a new box (
\newbox
), we virtually fulfill the box (\setbox
) and we can measure width, height and depth of the box (\wd
,\ht
and\dp
).In the example below we typeset Hiragana, a Japanese syllabary, but we may spot several defects. There is an opening space, lines don't break ideally, spaces are shrinking and stretching, we have no idea how many glyphs were typesetted. But it is a starting point for further explorations.
Worth mentioning is that we can run any major
latex
engine and if we use e.g.fontspec
package, we can test glyphs in the TTF, OTF and some dfont files when runninglualatex
orxelatex
. I enclose the TeX code and a preview of the result.We typeset a glyph only when glyph width is a nonzero value. There are some exceptions in ornament fonts, but it is considered bad fontography. We add a counter (
\newcount
) taking care of a number of typesetted glyphs, we limit spaces to fixed dimension (\fontdimen
3, 4 and 7), we allow line breaks, simply said we are having full control over the output now.I enclose an example and a preview of the PDF file with Katakana, a Japanase syllabary.
There are some limitations of these methods. We cannot test if two glyphs are not just rotated, flipped or scaled, we are also not listing glyphs outside 0-255 region. In case you need something like that, use FontForge, it can be done there as it has own scripting language and a support for Python scripts.
In case you are wondering what was that splash in the very first example in the last letter under the letter: Oh, yes, that's an ape from the great Manfred Klein legendary font creator himself! I enclose a screenshot from FontForge and a preview of his font with 26+26 letters in it.