[Tex/LaTex] How to store and restore the current font size

fontsizemacros

In relation with this example: New command without brackets inside new environment, I have to pass the current font size to the environment, but I prefer it takes it by itself?

To make it clear, I would like to store the selectfont parameters and reuse them later.

There is an obvious bracket solution, but the OP of the related question doesn't want to use brackets.

\documentclass{article}
\pagestyle{empty}

\begin{document}

\begin{itemize}

\item Bla

\item{\small Small is small} 

\item Bla is not small, but the OP of the related question doesn't want to use brackets.

\end{itemize}

\end{document}

I then try to make a switch system inside the \item macro and for this I have to know what are the fontsize parameters, to store and restore them.

\documentclass{article}
\pagestyle{empty}
\usepackage{paralist,xparse}

\newcommand{\Com}[1][\hspace{1cm}]{\item[#1\aftergroup\footnotesize]}

\NewDocumentEnvironment{Itemize}
    {O{}    % item caracter ex $\bullet$
    D<>{\normalsize}}{%
    \begin{list}{#2#1\aftergroup#2}{%
        \setlength{\labelwidth}{0em} % adapt as you want
        \setlength{\leftmargin}{0pt}
        \setlength{\itemindent}{5pt}%
    }}{%
    \end{list}}


\begin{document}

\large

\begin{Itemize}[$\bullet$]<\large>
\item One
\item Two
\Com This is my comment
\item Three
\Com This is my comment
\end{Itemize}

Back to current font size !

\end{document}

Best Answer

\documentclass{article}
\usepackage{lipsum}
\usepackage{pgf}
\usepackage{pgffor}


%This is my suggestion (with @Circumscribe's comment in account):

\makeatletter
\newcommand{\savefont}{\xdef\oldfontsize{\f@size}\xdef\oldblskip{\f@baselineskip}}
\newcommand{\backtoppevfont}{\fontsize{\oldfontsize}{\oldblskip}\selectfont}
\makeatother


%Just added to demonstrate "unknown" font
\def\randomSize{%
\pgfmathsetmacro{\a}{random(1,4)}%
\foreach \fnt[count=\i from 1] in {\tiny,\footnotesize,\large,\Large}{%
\ifnum \a=\i\global\let\fs\fnt\breakforeach
\fi}\expandafter\string\fs\fs%
}
\begin{document}


Here is a text... and a random change of font to:\randomSize'' Test! RFont \savefont

That turned into \small\verb|\small| here and restored to \backtoppevfont RFont1!

\end{document}

Output:

enter image description here

Related Question