Changing operator font for only one operator

fontsmath-operatorssans-serif

I want to declare a custom operator op that is supposed to use sans-serif font.
No other operator (\sin etc.) shall use sans-serif.


I tried to use \DeclareMathOperator which yields correct spacing but I seem unable to change the font for only this one operator.

I also tried a simple \newcommand which allows me to use sans-serif, but messes up the spacing.

enter image description here

How can I combine both approaches to get a sans-serif operator with correct operator spacing while not changing the font for all operators?


\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}

\DeclareMathOperator{\op}{op}
\newcommand\opsans{\mathsf{op}}

\begin{document}
\noindent
Correct spacing: \[a \op_k b\]
Wrong spacing: \[a \opsans_k b\]

\end{document}

Best Answer

Try

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}

\DeclareMathOperator{\op}{op}
\DeclareMathOperator{\opp}{\mathsf{op}}

\begin{document}
\noindent
\[a \op_k b\]

\noindent
\[a \opp_k b\]

\end{document}

Works fine here.

enter image description here

Related Question