I am using LuaLaTeX with opentype fonts. None of the fonts are TeX fonts; they are either commercially licensed, or custom-made. No problem, everything is working great so far.
Is it possible to detect which font is being used at a particular point in a string of text? (EDIT Answer: Yes. See below). I saw this:
How can I test for the current font?
But it does not seem to work outside of TeX fonts. (EDIT Actually, yes it does.)
Here is why I wish to know: I have a custom glyph that comes in variations, in a custom font. The variations in size and weight are harmonious with surrounding fonts (Garamond, Utopia, Palatino, SourceSans, whatever). If the user changes the surrounding font, I would like the custom glyph to automatically change, using a command that detects the surrounding font and picks the correct glyph variation.
Note that the locally-used font, in a text string, may be different from the document defaults.
If this is a really big coding issue, then it would be easier for me to ignore it, and change the glyphs by hand. But if it's simple, can you point me in the right direction?
SECOND EDIT: MWE, now changed to show how it works. Thanks, egreg. I didn't catch the part about \expandafter\string earlier.
% !TeX program = LuaLaTeX
% !TEX encoding = UTF-8
\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\newfontfamily{\fGaramond}{Adobe Garamond Pro}[ ]
\newcommand\fontGaramond[1]{{\fGaramond #1}}
\newfontfamily{\fMyriad}{Myriad Pro}[ ]
\newcommand\fontMyriad[1]{{\fMyriad #1}}
\setmainfont{Adobe Garamond Pro}
\begin{document}
This text is in the main font, Garamond.
Code: {\expandafter\string\the\font} is here. \fontMyriad{But this is in Myriad.
Code: {\expandafter\string\the\font} is here.}
Back to Garamond.\par
\end{document}
\newfontfeature
macro of the fontspec package? This macro should let you program up the custom glyph substitution in advance, i.e., in a way that doesn't require knowledge of which font is in use at the moment. (Of course, the glyph variant has to be available for all fonts that will be used, but that appears to be the case anyway.)\expandafter\string\the\font