I know LaTeX doesn't have strings as such but I want to be able to get and save the human readable version of the current font name.

\f@family does not work as expected because it shows the base font not the variant.

I saw somewhere on here an answer from @DavidCarlisle which gets the information I want but I can't find that answer again. It used \expandafter\meaning\the\font and it does print what I need plus stuff I don't.

How can I "save" that information and extract the substring which is just the human friendly font name? So it would capture NotoSerif-ExtraBold from example c below.

I thought the source code for fontspec might show me but I can't understand it.

I have seen \StrBetween from xstring but I can't make it work.

StrBetween ( \StrBetween{\expandafter\meaning\the\font}{s}{t} )

has nothing between the ears ( ) I think it should at least print elec since the output starts select font. I thought may StrBetween was seeing the actual \expandafter... so I tried \expandafter\expandafter... but that did not work either.

Minimal Not Working Example


% I don't know if you are supposed to load the packages

% The font choices are deliberately silly to show the font name printing is working
     BoldFont       = NotoSerif-ExtraBold
    ,ItalicFont     = NotoSerif-ExtraLightItalic
    ,BoldItalicFont = NotoSerif-BlackItalic
     BoldFont       = NotoSans-ExtraCondensedBlack
    ,ItalicFont     = NotoSans-LightItalic
    ,BoldItalicFont = NotoSans-CondensedSemiBoldItalic
     BoldFont       = NotoSansMono-ExtraCondensedExtraBold
    ,ItalicFont     = AnonymousPro-Italic
    ,BoldItalicFont = AnonymousPro-BoldItalic.ttf
    % could not get it to work without the .ttf


a. \normalfont serif normal \rmdefault\ \howbig\ pt

b. \normalfont serif normal \expandafter\meaning\the\font\ \howbig\ pt

c. \normalfont serif bold \bfseries\expandafter\meaning\the\font\ \howbig\ pt

d. \normalfont sans italic \sffamily\expandafter\meaning\the\font\ \howbig\ pt

e. \normalfont mono bold italic \ttfamily\bfseries\itshape\expandafter\meaning\the\font\ \howbig\ pt

correct but unusable output

which used \expandafter\meaning\the\font to print some font information, for example:

. The font name I w

1 Answer 1


Is this what you want? Sorry for not mixing the mono fonts, but there are problems with AnonymousPro.


% The font choices are deliberately silly to show the font name printing is working
  UprightFont    = *-Medium,
  BoldFont       = *-ExtraBold,
  ItalicFont     = *-ExtraLightItalic,
  BoldItalicFont = *-BlackItalic,
  Scale = 0.9
  UprightFont    = *-CondensedMedium,
  BoldFont       = *-ExtraCondensedBlack,
  ItalicFont     = *-LightItalic,
  BoldItalicFont = *-CondensedSemiBoldItalic,
  Scale = MatchUppercase,
  UprightFont    = *-Regular,
  BoldFont       = *-Bold,
  ItalicFont     = *-Italic,
  BoldItalicFont = *-BoldItalic,
  Scale = MatchUppercase,

  \str_set:Nx \l_tmpa_str { \fontname\font }
  \regex_replace_once:nnN { \:.* } { } \l_tmpa_str
  \regex_replace_once:nnN { \A \[(.*)\] \Z } { \1 } \l_tmpa_str
  \regex_replace_once:nnN { \.[^\.]* \Z } { } \l_tmpa_str
  \str_use:N \l_tmpa_str



a. {serif normal \rmdefault\ \howbig\ pt}

b. {serif normal \extractfont\ \howbig\ pt}

c. {serif bold \bfseries\extractfont\ \howbig\ pt}

d. {sans italic \sffamily\extractfont\ \howbig\ pt}

e. {mono bold italic \ttfamily\bfseries\itshape\extractfont\ \howbig\ pt}


enter image description here

The primitive construct \fontname\font provides the current font name (without select font at the beginning) and I remove everything from the first colon inclusive, then possible brackets [] around the font name and finally a possible extension (from a period followed by characters not including periods up to the end).

  • Perfect, thank you @egreg. Your code that strips the unwanted parts is even better than I had hoped for. The exact mono font didn't matter. I was just picking fonts with different names to test the code really was picking the current font.
    – Doc Octal
    Sep 3, 2021 at 22:56

You must log in to answer this question.

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