# How to get the font size parameter passed to the main standard classes?

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).

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%
{%
\get@beamersize
{%
\get@memoirsize
{%
\get@extartsize
\get@standardsize
}%
}%
}%
}
\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.