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:
\documentclass{article}
\usepackage{fontspec} % Compile only with lualatex
\setmainfont{EB Garamond} % Or any OpenType font.
% begin pseudo-code:
\IfFontHasCharTF{\mainfont}{"2015}{\def\myowndash{"2015}}{\def\myowndash{"2014}}
% end pseudo-code
\begin{document}
They were speaking:\par
\myowndash Hello, Harry.\par
\myowndash Hello, Sue.\par
It was a brief conversation.\par
\end{document}
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.
\iffontchar\font "2015