# Command to return both font size class and font size in pt

I am looking for a command to return both the font size class and the font size in pt.

The following approach from @Alan Munn as per this SE post prints font-size values for all standard classes:

\makeatletter
\newcommand\thefontsize[1]{{#1 The current font size is: \f@size pt\par}}
\makeatother

\begin{document}
\thefontsize\LARGE
\end{document}

The current font size is: 17.28pt


I would like to twist the output such that it also prints the label of the font-size class

\newcommand\thefontsize[1]{{#1 FONTSIZECLASS is printed as \f@size pt \par}}


e.g. for \LARGE

LARGE is printed as 17.28pt


If not feasible, maybe one could twist this SE post that prints The current font size is: XXpt to include chapter/section/subsection in the print-out, i.e. The section font size is: 17.28pt

\makeatletter
\newcommand\thefontsize{The HEADING font size is: \f@size pt}
\makeatother

\begin{document}
\chapter{\thefontsize}
\section{\thefontsize}
...
\end{document}


## Solution presented by @Peter Wilson: Extended MWE for future reference

\documentclass{article}
\makeatletter
\newcommand\getfontsizeofheading{The current font size is: \f@size pt}
% print given font size in point and in its "font size" (i.e. larger or smaller)
\newcommand\getfontsizeforfontsizeclass[1]{{\string #1 is printed as #1 \f@size pt\par}}
% print the entire string in the size of the fontsize (i.e. larger or smaller)
\newcommand\printfontsizeforfontsizeclass[1]{{#1 \string #1 is printed in \f@size pt\par}}
\makeatother

\begin{document}
\getfontsizeforfontsizeclass{\tiny}
\getfontsizeforfontsizeclass{\scriptsize}
\getfontsizeforfontsizeclass{\footnotesize}
\getfontsizeforfontsizeclass{\small}
\getfontsizeforfontsizeclass{\normalsize}
\getfontsizeforfontsizeclass{\large}
\getfontsizeforfontsizeclass{\Large}
\getfontsizeforfontsizeclass{\LARGE}
\getfontsizeforfontsizeclass{\huge}
\getfontsizeforfontsizeclass{\Huge}

\printfontsizeforfontsizeclass{\tiny}
\printfontsizeforfontsizeclass{\scriptsize}
\printfontsizeforfontsizeclass{\footnotesize}
...
\end{document}


...which results in (for printfontsizeforfontsizeclass)

## 2 Answers

Hopefully this will lead you to what you are after.

% fontdataprob.tex SE 552560

\documentclass{article}

\makeatletter
\newcommand{\thisfontsize}[1]{{#1 The \string #1'' font size is: \f@size pt\par}}
\newcommand{\printfontsize}[1]{{The \string #1'' font size is: #1 \f@size pt\par}}
\makeatother

\begin{document}
\thisfontsize{\LARGE}

\thisfontsize{\tiny}

\printfontsize{\LARGE}

\printfontsize{\tiny}
\end{document}


I showed two methods of printing out the font size. Hopefully one will be OK for you.

• Sorry for the irrelevancy, but ... Peter, are you there? Your herries.press email started bouncing a couple hours ago ("user unknown") and I don't know any alternative. Help?! – Karl Berry Jul 8 at 1:18
• @PeterWilson: Thank you so much! \newcommand\thefontsize[1]{{\string #1 is printed as #1 \f@size pt\par}} - this works like charm!! – mavericks Jul 8 at 6:13
• @Peter Wilson: I would love to give you a thumbs up for your answer, but with my 13 points I am not permitted yet (needs 15 at least to caste a vote) – mavericks Jul 11 at 10:04

If you use a standard class (no titlesec package), you can access the font used for headings with some nasty tricks.

The code below is not optimized and could be better, but it's easier to say in the document \meaning\section and look at the final part.

One can devise similar tricks for \chapter and \part, but they're more complex.

\documentclass[12pt]{article}

\makeatletter
\newcommand{\getsectionfont}[1]{% #1 = sectional level
\edef\section@font{\unexpanded\expandafter\expandafter\expandafter{\expandafter\@seventhofseven#1}}%
\begingroup\section@font\edef\x{\endgroup\def\noexpand\section@size{\f@size}}\x
\texttt{\string#1}: \texttt{\detokenize\expandafter{\section@font}}
(\section@size pt)%
}
\newcommand\@seventhofseven[7]{#7}
\makeatother

\begin{document}

\getsectionfont{\section}

\getsectionfont{\subsection}

\getsectionfont{\subsubsection}

\getsectionfont{\paragraph}

\getsectionfont{\subparagraph}

\bigskip

\texttt{\meaning\section}

\end{document}


• @greg: thanks a lot for your proposal. I use the getsectionfont-code in an Rmd document knitted with knitr. For this, I included thenewcommand definition in a Tex-template sourced by the file. Unfortunately, I receive the following error when copy & pasting your code ! Argument of \@seventhofseven has an extra }. <inserted text> \par l.478 getsectionfont{\section} – mavericks Jul 8 at 6:06
• @mavericks That probably depend on where you place the command. – egreg Jul 8 at 7:29
• hmm, interesting. Placed \makeatletter COMMAND-DEFINITION \makeatother into the template.tex just like the solution proposed by @Peter Wilson and then in the Rmd file the code \getsectionfont{\section} .... Anyway, many, many thanks! – mavericks Jul 8 at 7:55