I use the following command in my preamble for highlighting.
\newcommand{\zz}[1]{{\color{blue}\sffamily #1}}
However, I'd like to add the functionality so that I can also include math in it. Currently, statements like
\zz{Testing, $\mathcal{T}$, $4$, $5$}
will cause issues during compilation because something about sffamily not agreeing with math mode. It will still output the correct PDF, but since I'm getting that error, I feel like I'm doing something fundamentally wrong in the command definition.
I tried looking at using conditionals, however the closest I got was
\newcommand{\zz}[1]{
\ifthenelse{\relax\ifmmode}
{\color{blue} #1}
{\color{blue}\sffamily #1}
}
which did not work. Any help is greatly appreciated!
$, a simple solution is to use\ensuremath{}. So using\zz{Testing, \ensuremath{\mathcal{T}}, \ensuremath{4}, \ensuremath{5}}should work fine. But, before get too used to using\ensuremath{}everywhere, please do have a look at When not to use \ensuremath for math macro?. – Peter Grill Nov 12 '20 at 19:18