# How to “get” the size of the section header

I've got to format some text in the style of the section header. So what I would like to do is sort of "get" the parameters that define the section header (i.e. size, formatting, fontstyle) and apply that to the text. However, I'm too much of a newbie in tex and googling didn't really help me out.

I'd rally appreciate hints :-)

• as in “read the source and copy it”, or do you want a macro that works out what’s in the current definition of \section and proceeds from there? – wasteofspace Sep 19 '12 at 8:44
• More like read the source size, source format and source font (latter if necessary) and the apply it to the text – JoeD Sep 19 '12 at 8:52

The current font identifier can be accessed to with \the\font. So this works:

\documentclass{article}

\newcommand{\getsectionfont}{\setbox0=\vbox{\section*{a\xdef\TheSectionFont{\the\font}}}}
\AtBeginDocument{\getsectionfont}

\begin{document}
\section{Some text just to see the result}

The following quotation will use the section font
\begin{quotation}\TheSectionFont
Some text just to see the result
\end{quotation}

\end{document}


We typeset a mock section title without printing it, but we use it to access the font. It's better to do it "at begin document" so all packages have been loaded.

The two lines should be the last before \begin{document}; with them you'll have the declaration \TheSectionFont to choose the font available also in definitions you make before those two lines (provided they don't typeset any text).

Just some more information. We need the low level \xdef because we want that

1. the meaning of \TheSectionFont is known outside the \vbox which makes a group;

2. the combination \the\font is expanded at the moment of the definition.

\xdef is equivalent to \global\edef; with a simple \def this wouldn't work, because \the\font always refers to the current font. On the other hand, \the can be expanded and when followed by \font the expansion is precisely the internal command that TeX uses to select the current font.

• And... if I need to access the value in a macro? – Egor Hans Dec 4 '17 at 8:50
• @EgorHans Isn't \TheSectionFont what you want? – egreg Dec 4 '17 at 9:46
• Oh, overlooked the last paragraph of the first part. Then it's all fine. – Egor Hans Dec 4 '17 at 18:27
• One more quick question: Is applying it to chapters and parts as trivial as one would expect, i.e. just replacing \section* with \chapter* or \part*, respectively? – Egor Hans Dec 4 '17 at 18:30