Consider this MnotWE:
\documentclass[12pt,letterpaper]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\newcommand*{\fnn}[1]{\text{\texttt{#1}}}
\newcommand*{\Ker}[1]{\textsc{ker}(\fnn{#1})}
\begin{document}
$\Ker{f}$
\end{document}
It produces the error:
Undefined control sequence. $\Ker{f}
However, this compiles just fine:
\documentclass[12pt,letterpaper]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\newcommand*{\fnn}[1]{\text{\texttt{#1}}}
\newcommand*{\Ker}[1]{\textsc{ker}(#1)}
\begin{document}
$\Ker{f}$
\end{document}
Why?
Best Answer
The
\text
macro requiresamsmath
(or at leastamstext
thatamsmath
loads).However, once
amsmath
is loaded,\text
becomes redundant and\texttt
suffices also if\fnn
is in a subscript or superscript. You should consider\mathtt
, though. The reason should be clear from the following example:As you see, the italic context also acts on the argument to
\fnn
. Adding\text
would do nothing better.Here's a possibly better definition:
If you are not short of math groups, adding
would be even better:
The output is the same, but with the “easy version” above you might risk shape changes in case the context where you use
\Ker
is italic or boldface and the font family you use provides variant shape/weight for small caps.Note: I didn't load
lmodern
just to make the example more general. It would be the same with it.