# Is there a way to do a pair command?

I want to get the name of the fonts in the document while I write my document.

At the moment I am alright with

\newcommand{\FntNmeTitleA}{Felix Titling Regular}
\newfontfamily\FontTitleA[LetterSpace=4.5]{Felix Titling}

\FontTitleA This Text is written in \FntNmeTitleA!


But that sucks if I have a lot fonts and want to get the current name. Is there a way like known in many programming languages:

\FontTitleA This Text is written in \FontTitleA.name!


Cheers

• Is this useful? tex.stackexchange.com/questions/14377/… – user103221 Mar 25 '17 at 23:17
• Please provide a complete example. I assume you are using fontspec, but even this isn't guaranteed from the paltry fragements you've posted. As @RobtA says, with traditional typesetting, \f@family gives the current family. Other aspects of the current font are stored similarly, so you can retrieve and test them or whatever. (nfssext-cfr.sty does this extensively.) – cfr Mar 26 '17 at 1:01

In the standard case, the current font information is stored in a series of internal macros beginning with \f@.

\documentclass{article}
\begin{document}
\makeatletter
encoding \f@encoding\par
family \f@family\par
series \f@series\par
shape \f@shape\par
size \f@size\par
\makeatother
\end{document}


Compiled with pdfLaTeX:

Compiled with LuaLaTeX or (after a while) XeLaTeX:

With a custom font in LuaLaTeX, using fontspec:

\documentclass{article}
\usepackage{fontspec}
\newfontfamily\sylfaen{Sylfaen}
\begin{document}
\sylfaen
\makeatletter
encoding \f@encoding\par
family \f@family\par
series \f@series\par
shape \f@shape\par
size \f@size\par
\makeatother
\end{document}

• In the above example, with fontspec, where the font is Sylfaen(0), the (0) indicates that this is the first (usually, main) instance of how the font is used. If you do \newfontfamily\somefont{Sylfaen} with the same font, then {\somefont text} puts the text in Sylfaen(1). And so forth. So, if you want to extract only the font name, you can use a macro from the xstring package to get rid of the parenthesized number. – user103221 Mar 26 '17 at 12:33
• @RobtA You don't really need the xstring package for that, though. – cfr Mar 26 '17 at 16:07
• Thank you. Any idea how it could be possible to save that in a file or in the footnotes? – Sam H. Mar 27 '17 at 6:29
• I tried it like this: %[Praemble] \ExplSyntaxOn \tl_new:N \LtrFnt \makeatletter \NewDocumentCommand{\setLtrFnt}{o} { \tl_gset:Nn \LtrFnt {\expandafter\textttup\expandafter{\expandafter\string\the\font}} %{\f@family \f@series \f@shape } } \makeatother \NewDocumentCommand{\getLtrFnt}{}{% \tl_use:N \LtrFnt% } \ExplSyntaxOff \begin{document} \rmfamily{\setHdFnt} Hello World!\footnote{\ttfamily% Text used in main document: \getLtrFnt\\ \end{document} – Sam H. Mar 27 '17 at 6:44