3

I am working on a LuaLaTeX package, and at one point I have to pass the full names of the three basic font families (roman, sans, mono) to another tool. I have found and checked that I can correctly do that for the currently active font, but that's not exactly what I need:

fonts.hashes.identifiers[font.current()].fullname

correctly produces, e.g. "Linux Libertine O", if that's what is currently used for typesetting. (I don't know if that's the correct or easiest way to get to that, so I'd be glad about simplifications.

However, as said I need also the font names defined with \setmainfont, \setsansfont and \setmonofont. From the documentation is looks like font.id() is my best bet, but so far I didn' have any luck.

[Edit:] When I say "font names" I mean the "family name" of the three fonts that are defined in the mandatory argument of the \setXXXXfont commands, ignoring any specification that can be done in the optional argument.

2
  • Your question is rather unclear. \setmainfont doesn't define one specific font but a whole family with various shapes and weights. Jan 18, 2018 at 16:25
  • Hm, it's difficult to update the question, as in the meantime I have realized that there is another, more fundamental issue for me to be solved (and that can't properly be mixed into this question: before dealing with the three roman/sans/mono fonts I need to know how to actually retrieve the font family from a Lua font object. AFAICS I can get fullname (which is pretty inconsistently used between font companies), psname and name, which is a concatenation of different information incluting the psname. But I don't see a way to get to the "family" yet.
    – uli_1973
    Jan 18, 2018 at 21:39

1 Answer 1

3

After a longer discussion on the luaTeX mailing list and with the fontspec developer I found a working solution (although I find it somewhat awkward). The idea is activating the three font families one after another, capture them as "current", and wrap everything in a group. The trick is the use of \edef.

\begingroup
\rmfamily \edef\rmfamilyid{\fontid\font}%
\ssfamily \edef\ssfamilyid{\fontid\font}%
\ttfamily \edef\ttfamilyid{\fontid\font}%
\directlua{
    myfonts = { }
    myfonts.rm =
    fonts.hashes.identifiers[\rmfamilyid].shared.rawdata.metadata['familyname']
    myfonts.sf =
    fonts.hashes.identifiers[\ssfamilyid].shared.rawdata.metadata['familyname']
    myfonts.tt =
    fonts.hashes.identifiers[\ttfamilyid].shared.rawdata.metadata['familyname']
}%
\endgroup

After that the three family names are available in the myfonts Lua table.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .