Can I define a macro \foo
so that $\foo$
produces:
- bold sans-serif "foo", if the surrounding text is bold
- normal sans-serif "foo" otherwise.
In particular, "foo" should never be typeset in italics.
MWE that does not quite work:
\documentclass[a4paper]{article}
\usepackage{amsmath,amsthm}
\newtheorem{theorem}{Theorem}
\newcommand{\foo}{\textsf{foo}}
\begin{document}
\section{This should be bold: $\foo$, \boldmath$2^\foo$}
This should be normal: $\foo$, $2^\foo$.
\begin{theorem}This should be normal: $\foo$, $2^\foo$.\end{theorem}
\end{document}
Here I get slanted text in the theorem environment; otherwise it looks good. If I try e.g.:
\newcommand{\foo}{\textnormal{\textsf{foo}}}
then it is always in normal font, not bold.
Can I just somehow "turn off italics" without "turning off bold"?
Best Answer
you can add one more level to the font specification for
\foo
:\textup
would also work, but requires the "argument" form,\textup{foo}
. both are defined in "basic" latex, so no extra packages are needed.edit: as pointed out by Jukka in a comment, this is the best of all possibilities:
it will size correctly if used in sub- or superscripts, and it will avoid a (meaningless) font warning that is produced by both
\textup
and\upshape
when used in this manner.edit 2: Bernard provides a variation for the typing minimalists that works as well: