Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\documentclass{article}

\newcommand{\nptime}{\ensuremath{\sf NP}}
\newcommand{\bnptime}{\ensuremath{\sf\bf NP}}

\begin{document}
  \nptime\\
  \bnptime
\end{document}

I'm trying to make a macro to typeset "NP" in boldface sans-serif font, but as demonstrated by my MWE, it's not working. BF seems to force a serif font.

Alternatively, I'd be happy to find an opposite to \ensuremath, but I can't seem to find one. I tried \text{} to no avail.

The following similar MWE does the same thing.

\documentclass{article}

\newcommand{\nptime}{{\sf NP}}
\newcommand{\bnptime}{{\sf\bf NP}}

\begin{document}
  \nptime\\
  \bnptime
\end{document}
share|improve this question
    
You simply need \newcommand{\bnptime}{\textsf{\textbf{NP}}} that works both in text and math. Notice that \bf and \sf are deprecated commands. –  egreg Feb 14 '13 at 23:03
    

1 Answer 1

up vote 6 down vote accepted

There's no need of \ensuremath: just use

\newcommand{\nptime}{\textsf{NP}}
\newcommand{\bnptime}{\textsf{\textbf{NP}}}

so that \nptime and \bnptime work both in text and math mode, even scaling when used in subscript or superscript if the amsmath package is used.


You discovered why \sf, \bf and all two letter font change commands are deprecated (and they have been since more than 10 years): the combination \sf\bf is simply equivalent to \bf, just like \sf\it would produce normal italic, not sans serif, and \it\sf would produce upright sans serif.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.