21

There are a lot of results for "setting" the font size, but I can't find one how to "get" them.

Here's some code from What point (pt) font size are \Large etc.? I can use to check what font size for \normalsize, \large, etc.

\makeatletter

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

\makeatother

\begin{document}

\thefontsize\normalsize

\end{document}

But \thefontsize\section doesn't work...

Could anyone help me how to get it?

  • You can also "get" them by looking at the respective sectioning commands in the document class (and associated font size files, like *.clo). – Werner Jul 23 '13 at 18:13
25

You can do a similar thing by putting the \thefontsize command inside the argument of the sectioning command. In this case the command doesn't need to take an argument. (If you want to use the same command as in your code above, just type \thefontsize{} instead.

\documentclass{book}
\makeatletter
\newcommand\thefontsize{The current font size is: \f@size pt}
\makeatother
\begin{document}
\chapter{\thefontsize}
\section{\thefontsize}
\subsection{\thefontsize}
\subsubsection{\thefontsize}
\end{document}

output of code

21

A variation on Alan's answer can show you also all font attributes:

\documentclass{book}
\usepackage[T1]{fontenc}
\newcommand\thefont{\expandafter\string\the\font}

\begin{document}
\chapter{\thefont}
\section{\thefont}
\subsection{\thefont}
\subsubsection{\thefont}
\thefont
\end{document}

enter image description here

What's the trick? It uses rather low level functionality of TeX; actually all control sequences in

\expandafter\string\the\font

are primitives of TeX. The primitive \font is used for assigning a name to a font loading its metric file, but it can follow \the (see The \the command) and, in this case, it returns a control sequence corresponding to what's needed to use the current font (a low level command, not the high level \bfseries and siblings). For example, in the default setting and for normal text,

\the\font

would return the control sequence \OT1/cmr/m/n/10 (that's not writable without special tricks). With \string we can print that control sequence, but we need to make \the act before \string does its job, so the need for \expandafter. I've used the T1 encoding in the example because in the OT1 encoding the slot normally allotted to the backslash is occupied by .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.