TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to make a list of headings with their font sizes:

I envision something like the following:

\documentclass{article}
\begin{document}
\section{{\textbackslash}section \makeatletter\f@size pt\makeatother}
\subsection{{\textbackslash}subsection\makeatletter\f@size pt\makeatother}
\subsubsection{{\textbackslash}subsubsection\makeatletter\f@size pt\makeatother}
\paragraph{{\textbackslash}paragraph\makeatletter\f@size pt\makeatother}
\end{document}

I suspect this is an expansion problem. I saw this question: How could I check what font size is in pt for \section, \subsection, and \subsubsection?

But I would like to know why my code does not work.

share|improve this question
up vote 5 down vote accepted

Your code doesn't work because you're issuing \makeatletter at the wrong time; category codes are not changed when tokens have already been absorbed.

You need

\makeatletter
\section{\textbackslash section\f@size pt}
\makeatother

but it's better to use a specific macro.

\documentclass{article}

\newcommand{\cs}[1]{\textbackslash #1}
\makeatletter
\newcommand{\fs}{\f@size pt}
\makeatother

\begin{document}

\section{\cs{section}: \fs}

\subsection{\cs{subsection}: \fs}

\subsubsection{\cs{subsubsection}: \fs}

\end{document}

enter image description here

share|improve this answer
    
Thanks for the most recent edits, I was just wondering about wrapping the sections with \makeatletter and \makeatother. That solidified my understanding. I assume the reason why the other code is better is to keep all category code changes out of the body? – macmadness86 Jan 21 at 7:53
    
@macmadness86 No, the other code is better because you don't repeat code. – yo' Jan 21 at 8:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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