# 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]{memoir}
\makeatletter
\newcommand{\deffontsize}[1]{%
{\get@beamersize#1}
{%
{\get@memoirsize#1}
{%
{\get@extartsize#1}
{\get@standardsize#1}
}%
}%
}
\expandafter\ifx\csname ver@#1.cls\endcsname\relax
\expandafter\@secondoftwo
\else
\expandafter\@firstoftwo
\fi}
\def\get@beamersize#1{%
\expandafter\get@@beamersize\beamer@size#1}
\def\get@@beamersize#1#2{%
\get@@@beamersize#1\st@p#2}
\def\get@@@beamersize size#1.clo\st@p#2{%
\setlength{#2}{#1pt}}
\def\get@memoirsize#1{%
\setlength{#1}{\@memptsize pt}}
\def\get@extartsize#1{%
\setlength{#1}{\@ptsize pt}}
\def\get@standardsize#1{%
\setlength{#1}{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.