I want to change the text according to its current font color.
I can test argument against font family
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[svgnames]{xcolor}
\usepackage[scaled=0.84]{beramono}
\usepackage{pdftexcmds}
\makeatletter
\newcommand{\MyChange}[1]{%
\ifnum\pdf@strcmp{\f@family}{\ttdefault}=\z@%
{\bfseries #1}%
\else%
{\sffamily #1}%
\fi%
}%
\makeatother
\begin{document}
\noindent First:\MyChange{Normal should become SF}\\
{\color{red} Second:\MyChange{Red should become SF}}\\
{\tt Third:\MyChange{tt should be bold}}\\
{\tt\color{red} Fourth:\MyChange{Red tt should be bold}}
\end{document}
I wish I could have something like this
\makeatletter
\newcommand{\MyChange}[1]{%
\ifnum\pdf@strcmp{\f@color}{red}=\z@%
{\bfseries\large #1}%
\else%
{\sffamily\scriptsize #1}%
\fi%
}%
\makeatother
But I get error
! Undefined control sequence.
\MyChange #1->\ifnum \pdf@strcmp {\f@color
}{red}=\z@ {\bfseries \large #1}\...
l.19 ... First:\MyChange{Normal should become SF}
\\