2

For complex length manipulation (see here), I would need to get the font size that was passed as an option to the document class:

\documentclass[12pt]{article}
\newlength{\mainfontsize}
\setlength{\mainfontsize}{\@ptsize}

I would like it to work on all the main classes including beamer and extarticle. Currently this fails on beamer. How to make it work? (and I don't want the exact size of the font like 10.95pt for 11pt, I want the option that was passed).

4

Since most classes define their own option handling system you need one different macro for each.

For example, for 12pt, article (and the standard LaTeX classes) store just 2 in \@ptsize. extarticle stores 12. beamer stores {size12.clo} in a \beamer@size macro, and memoir stores 12 in \@memptsize. Not exactly standardised.

Here's a macro that checks for these classes and uses the correct macro accordingly, then stores the font size (from the option, not the actual font size) in a length:

\documentclass[14pt]{extarticle}
\makeatletter
\newcommand{\deffontsize}[1]{%
  \setlength#1%
    {%
      \vincent@ifclassloaded {beamer}
        \get@beamersize
        {%
          \vincent@ifclassloaded {memoir}
            \get@memoirsize
            {%
              \vincent@ifclassloaded {extarticle}
                \get@extartsize
                \get@standardsize
            }%
        }%
    }%
}
\def\vincent@ifclassloaded#1{%
  \expandafter\ifx\csname ver@#1.cls\endcsname\relax
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi}
\def\get@beamersize{%
  \expandafter\expandafter\expandafter\get@@beamersize
  \expandafter\@firstofone\beamer@size}
\def\get@@beamersize size#1.clo{#1 pt}
\def\get@memoirsize{\@memptsize pt}
\def\get@extartsize{\@ptsize pt}
\def\get@standardsize{1\@ptsize pt}
\makeatother
\begin{document}
\newlength\mainfontsize
\deffontsize{\mainfontsize}
\the\mainfontsize
\end{document}

For other classes you'd need to add another conditional and the corresponding macro to get the option.

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.