Command that returns current font size as a length?
\makeatletter
\newcommand*\fsize{\dimexpr\f@size pt\relax}
\makeatother
This way you can use the macro like \setlength{\baselineskip}{1.33\fsize}
.
\selectfont
is the switch the changes the font. You can tie into this and update \fsize
:
\documentclass{article}
\usepackage{letltxmacro}
\newlength{\fsize}
% https://tex.stackexchange.com/q/88001/5764
\LetLtxMacro\oldselectfont\selectfont
\makeatletter
\DeclareRobustCommand{\selectfont}{\oldselectfont\setlength{\fsize}{\f@size pt}}
\makeatother
\begin{document}
\tiny\the\fsize
\scriptsize\the\fsize
\footnotesize\the\fsize
\small\the\fsize
\normalsize\the\fsize
\large\the\fsize
\Large\the\fsize
\LARGE\the\fsize
\Huge\the\fsize
\end{document}
If you set the length, it won't change until you reset it. What you need is a macro:
\makeatletter
\newcommand{\currentfsize}{\f@size pt}
\makeatother
Example (using the code by Werner):
\documentclass{article}
\makeatletter
\newcommand{\currentfsize}{\f@size pt}
\makeatother
\newdimen\fsize
\newcommand{\setfsize}{\setlength{\fsize}{\currentfsize}}
\begin{document}
\setfsize % should be 10pt
\tiny\currentfsize
\scriptsize\currentfsize
\footnotesize\currentfsize
\small\currentfsize
\normalsize\currentfsize
\large\currentfsize
\Large\currentfsize
\LARGE\currentfsize
\Huge\currentfsize
\the\fsize % should be 10pt (printed in \Huge size)
\end{document}
As you see, setting \fsize
at the beginning doesn't change its value.