# How to include the current font name in the document

Using plain TeX coding, how to I include the current font name in the document? I know it involves \the\font but can't recall the exact method.

This is for use in a font-sampler, so that before each font sample, an appropriate title appears identifying that font.

You can use \fontname\font to output the current font name in your document:

\def\samplefont#1{%
% set font style and save name
#1\edef\savedname{\fontname\font}%
% print small sample
{\leavevmode\tt\hbox to 1in{\savedname:\hss}}%
abcxyz ABCXYZ 123\par
}
\samplefont\rm
\samplefont\tt
\samplefont\bf
\samplefont\it
\samplefont\sl
\bye


From the TeXbook (p. 214)

• \the\⟨font⟩ produces a font identifier that selects the specified font. For example, ‘\the\font’ is a control sequence corresponding to the current font.

This is most useful only in \edef, to get an alias command for the current font:

{\it\xdef\thisfont{\the\font}abc}

{\thisfont abc}


will produce the same result.

For the external name of the current font, use \fontname\font (current font) or \fontname\tenrm (or whatever font selection command you want to use):

\fontname\font

\fontname\tenrm

\fontname\seveni

\bye