# How to display the font size in use in the final output

How can I display the font size in use at a particular point of the document.

For example, in the following code, I produced a PDF file showing the fonts actually used for each shape and size,

\documentclass{article}

\usepackage{fontspec}
\usepackage{pgffor}
\usepackage{xcolor}

\definecolor{mred} {cmyk}{0,1,1,0.6}
\definecolor{mblue}{cmyk}{1,1,0,0.2}

\setmainfont{Minion Pro}

\long\def\testfont{
\foreach \size in
{normalsize, Large, Huge}
{\csname\size\endcsname\testshape}}

\long\def\testshape{
\vskip\baselineskip
\csname\size\endcsname\size
\vskip\baselineskip
\foreach \shape in {up, it, sc, bf}
{\par\csname text\shape\endcsname
{
\textcolor{mred}{\directlua{tex.print(font.fonts[font.current()].fullname)}}
\textcolor{mblue}{\shape}
}}
\vskip\baselineskip}

\begin{document}
\pagestyle{empty}
\flushleft
\rmfamily\testfont\vfill
\end{document}


This will produce the following. (as you see fontspec or luaotfload does not select correct optical fonts, see my answer for Using MinionPro for the main font and Fontspec for the monospaced font of how to workaround this)

My question is that, instead of print "normalize", "Large", "Huge", I would like to print things like "10pt" or just "10", so I can see the actual font size, just like in this example I can see the actual fonts used.

I know this can be done with things like Acrobat. But in that way, one has to click numerous times of his mouse to examine the fonts. I would prefer a more automatically way, similar to the way I print the fonts names in the example.

-

I don't know whether I understand you question right. Here is my interpretation ;-)

\documentclass[11pt]{article}
\begin{document}
\makeatletter
orig: \f@size

\verb+\small+ \small \f@size

\verb+\normalsize+ \normalsize \f@size

\verb+\large+ \large \f@size

\verb+\Huge+ \Huge \f@size
\makeatother
\end{document}

-
thanks a lot, for your correctness and quickness –  Yan Zhou Jun 11 '11 at 8:47

font.fonts[font.current()].size gives the size in scaled points. Dividing by 65536 wil give the size in pts.

-

\f@size is the internal macro in LaTeX2e NFSS. If a font is not specified through NFSS, this may fail. To know the size of LaTeX commands like \large, you can read classes document.

Furthermore, you don't need to use direct Lua code to get the font name.

Here is the low-level method to show the font size:

\documentclass{article}
\font\1="TeX Gyre Termes"
\begin{document}

\fontname\font\ at \the\fontdimen6\font
% cmr10 at 10.00002pt

\1
\fontname\font\ at \the\fontdimen6\font
% TeX Gyre Termes at 10.0pt
\end{document}


\fontdimen6 is the length of 1em. \font after \fontname and \fontdimen means current font. See Chapter 4 of TeX by Topic for more explanations.

-
I know \fontname, but it won't work very well. For example it will give the following while loading fonts with fontspec MinionPro/S=8:mode=node;script=latn;language=DFLT;+liga;+tlig;+trep;+onum;+pnum‌​;expansion = default;protrusion = mnr; at 5.0pt. It is much better to have Minion Pro Caption than MinionPro/S=8 –  Yan Zhou Jun 11 '11 at 9:34