This question "has been answered before", but not directly to the question. My question pertains only to LuaLaTeX, only to OpenType fonts using UTF-8 encoding, only to text mode (not math), only to the regular main font (which has already been selected). Also, no shell escape.

I seek a true/false test, regarding whether the current font (main font) has the glyph for a specific Unicode character. It it does, I use it. If not, there is another character that certainly exists in the font, so I will use that character instead.

The specific situation: U+2015 HORIZONTAL BAR is often used to indicate the beginning of quote or dialog in some languages. Not all fonts have this character. If not, then I can substitute U+2014 EM DASH from the same font. Pseudo-code example:

\usepackage{fontspec} % Compile only with lualatex
\setmainfont{EB Garamond} % Or any OpenType font.
% begin pseudo-code:
% end pseudo-code
They were speaking:\par
\myowndash Hello, Harry.\par
\myowndash Hello, Sue.\par
It was a brief conversation.\par

Yes, I did look at the fontspec documentation. Near the end, it looks like there is some sort of Lua aux macro that may address this, but I do not know how to use it.

Searched before asking, but the results either used a different compiler, or not UTF-8, or involved substituting the font (rather than different character from same font).

EDIT: My above example is linguistically incorrect. An English-language resource said that the French use U+2015 where possible. But several French-language resources (I can read French) said that U+2014 (EM DASH) is used, not U+2015.

EDIT2 (Actually 3, thanks to Ingmar): The local university library had a copy of Les Travailleurs de la Mer by Victor Hugo, reprinted in Paris, 1980 (thus, not confused by Internet). I can see that the quotation dashes (les tirets) are longer than I would expect an em dash to be. They are indented as with any paragraph, and separated from the text by a full space. So, despite what I wrote in the first edit, it seems that U+2015 would be correct for printed works; U+2014 is used on the Internet. Actually, once it is printed to paper, it is the appearance that matters, not the character code.

  • as in pdftex \iffontchar\font "2015 Commented May 3, 2023 at 16:26

1 Answer 1


you can use \iffontchar as in other engines

% !tex lualatex

\iffontchar\font "2015 yes \else no \fi [^^^^2015]

\iffontchar\font "2212 yes \else no \fi [^^^^2212]


enter image description here

  • Thanks! So simple. I had seen that macro before, but all questions pertained to T1 encoding, or XeTeX, or something else. And, in the usual fashion, the accompanying MWE was not very minimal. Note: I had initially comment that it did not work, but removed that comment (typo on my part, during test).
    – user287367
    Commented May 3, 2023 at 16:42
  • 3
    n.b.: If the current font has fallback fonts configured, then \iffontchar only determines if the glyph exists in the main font and not if it is available as a fallback. Commented May 3, 2023 at 17:25
  • @MarcelKrüger That is worth knowing. fontspec has its own methods for fallback font, which I believe I understand.
    – user287367
    Commented May 3, 2023 at 17:30
  • 1
    @MarcelKrüger if you were egreg, you'd be stealing a tick by now Commented May 3, 2023 at 17:45
  • @MarcelKrüger Do you perhaps know how one can check this for a fallback font via Lua. other than the obvious to use the iffontchar and buld a Lua function?
    – yannisl
    Commented Jan 8 at 18:14

You must log in to answer this question.