[Tex/LaTex] How to test for the current font


The situation is the following, I have one font a with one feature and another font b with another feature and I am writing a command that if the current font is a need to switch to font b but if the font is c needs to do nothing. Basically:

if currentfont is a set font b

How can this be accomplished?

Okey I will admit that I asked this question because I was working on a solution for this question and I thought this if else question was a separate question (was I wrong?) but now I am stuck for real… I have spent some time trying to follow the suggestions from the answers here but I keep failing. This example:





\chapter{The number 4 is more than 2}

\section{The number 4 is}
    If I write chapter \ref{anotherChapter} like this is
    looks oki.
    But the number in the header is a small i not a \textsc{i} and same
    thing in the table of content and the chapter header\dots
    \caption{Lorem ipsum}
    \center \LARGE LOREM IPSUM
\section{More than 4}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur
tempus facilisis nunc, sit amet suscipit ligula fermentum ac. Ut
fringilla, elit eget facilisis venenatis, risus massa viverra sem, a
placerat massa odio a mauris
\chapter{Another chapter}

Gives this error (edited):

! Undefined control sequence.
<argument> \equal 
                  {\f@family }{pplj}
l.29 \chapter{The number 4 is more than 2}


Seems I have gotten myself into a lot of trouble using these old style numbers… What am I doing wrong?

Best Answer

You can access the current font using the \font command, i.e. using \the\font which expand to e.g. \OT1/cmr/m/n/10 for the normal Computer Modern font. You could save the expansion texts of font a and the compare it to the result of \the\font.

Using TeX if-switches:

% switch to font 'a'
% Save expansion text:

Then you can use \iffonta{<yes>}{<no>} afterwards. Alternatively simply add the required code directly in the macro and don't use the \expandafter\@firstoftwo/\expandafter\@secondoftwo part:

      % change to font b
Related Question