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
\documentclass{article}
\usepackage{fontspec,xstring}
% I don't know if you are supposed to load the packages
\usepackage{AnonymousPro}
\usepackage{noto}
% The font choices are deliberately silly to show the font name printing is working
\setmainfont{NotoSerif-Medium}[
BoldFont = NotoSerif-ExtraBold
,ItalicFont = NotoSerif-ExtraLightItalic
,BoldItalicFont = NotoSerif-BlackItalic
]
\setsansfont{NotoSans-CondensedMedium}[
BoldFont = NotoSans-ExtraCondensedBlack
,ItalicFont = NotoSans-LightItalic
,BoldItalicFont = NotoSans-CondensedSemiBoldItalic
]
\setmonofont{NotoSansMono-Regular}[
BoldFont = NotoSansMono-ExtraCondensedExtraBold
,ItalicFont = AnonymousPro-Italic
,BoldItalicFont = AnonymousPro-BoldItalic.ttf
% could not get it to work without the .ttf
]
\makeatletter
\newcommand*{\howbig}{\f@size}
\newcommand*{\whatfontami}{\f@family}
\makeatother
\begin{document}
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
\end{document}
which used \expandafter\meaning\the\font
to print some font information, for example:
. The font name I w
Best Answer
Is this what you want? Sorry for not mixing the mono fonts, but there are problems with AnonymousPro.
The primitive construct
\fontname\font
provides the current font name (withoutselect 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).