6

I started using \mathsf{} for things that one would normally use \operatorname{} for, since it's better distinguishable from non-math text. However, I've read that \operatorname{} has better spacing.

Is there a way to change the font used by \operatorname so I can continue using that, but with the different font?

4 Answers4

12

In unicode-math, you can use the command

\setoperatorfont\mathsf

Otherwise, you can use code like egreg’s here to set the \operator@font to \sfdefault:

\documentclass{article}
\usepackage{amsmath}

\DeclareSymbolFont{sansops}{OT1}{\sfdefault}{m}{n} \SetSymbolFont{sansops}{bold}{OT1}{\sfdefault}{b}{n}

\makeatletter \renewcommand\operator@font{\mathgroup\symsansops} \makeatother

\begin{document} [ f(t) = a \sin (-t) + b \cos(-t) + c \sinh(t) + d \cosh (t) + k \exp (t) ] \end{document}

Computer Modern sample

For most documents, OT1 encoding will work. If you need accented Latin letters, but not uppercase Greek, you can change the legacy encoding from OT1 to T1. If you need lowercase Greek, you will need to find a sans-serif font that comes in the OML encoding.

Davislor
  • 44,045
7

If you use pdfLaTeX and one of the "standard" LaTeX document classes -- article, report, and book -- to compile your document, you could run

\makeatletter
\renewcommand\operator@font{\sf}
\makeatother

in order to use the default sans-serif font for operator names.

A full MWE:

\documentclass{article}
  \makeatletter
  \renewcommand\operator@font{\sf}
  \makeatother
\begin{document}
$\sin \cos \det \ln \exp$
\end{document}
Mico
  • 506,678
  • Why \sf and not \sffamily? – daleif Jul 09 '21 at 09:30
  • 1
    @daleif - Using \sffamily generates a "LaTeX Error: Command \sffamily invalid in math mode" error message. – Mico Jul 09 '21 at 10:07
  • 2
    That's interesting, one would assume \sf should not be used since the 90s, seems that did not follow along – daleif Jul 09 '21 at 10:09
  • 4
    @daleif there isn't an interface to do this so the "2e way" would be to define a math command to do essentially what \sf does in math mode, but if you are using a class where \sf is defined, just using \sf is easier. – David Carlisle Jul 09 '21 at 10:32
1

If your aim is to set text and mathematical context a part from each other, you may consider a distinct and dedicated math font for the later. Why not eulervm in conjunction to mathptmx

enter image description here

with the MWE of

\documentclass{article}
\usepackage{mathptmx, eulervm}

\begin{document} The standard deviation $\sigma_{n-1}$ of the sample was computed as

\begin{equation} \sigma_{n - 1} = \sqrt{ \frac{1}{n - 1} \sum^n_{i = 1} (x_i - \bar{x})^2} \end{equation}

\end{document}

1

The other answers are great, but for my purposes the easiest and most flexible solution was to simply combine \operatorname{} and \mathsf{}, and write e.g.

\newcommand{\sflim}{\operatorname{\mathsf{lim}}}.

That has the advantage that I can use "operator names" with different font styles in the same document.