# If a math operator doesn't exist, type it as text in a certain font

Is it possible to have some kind of condition where, if you type an operator in math mode and it doesn't exist, it types it as text in a certain font?

In particular, when I write complexity papers I often want to use the \mathsf font for the myriad of abbreviations in the field. The complexity package does OK, but is missing a lot of stuff which I then manually declare with \DeclareMathOperator. If this "else" statement existed for operators, that would be incredibly useful.

• \newcommand*\complexityoperator[1]{\mathop{\mathsf{#1}}}? – Henri Menke Dec 21 '16 at 23:57
• @HenriMenke I'd use \operatorname instead of \mathop, but that's the idea. – egreg Dec 22 '16 at 0:08
• @egreg Isn’t \operatorname more or less just \mathop{\operator@font#1}? – Henri Menke Dec 22 '16 at 0:16
• @HenriMenke No, it's much more. See tex.stackexchange.com/a/84308/4427 – egreg Dec 22 '16 at 6:57

You shouldn't use \mathsf anyway. The complexity package defines

\lang
\func
\class


along with \newlang, \newfunc and \newclass. So, if you have the class QQ, you should either use \class{QQ} or do

\newclass{\QQ}{QQ}


(the command name can be chosen arbitrarily, provided it is not already taken) in the preamble and use \QQ in the document.

In this way you ensure that changing the options to the package will be honored by your commands.

Example:

\documentclass{article}
\usepackage{complexity}

\newclass{\Q}{Q}
\newclass{\NQ}{NQ}

\begin{document}

I propose two new problems: $\Q\ne\NQ$
and $\class{BBC}=\class{BBQ}$.

\end{document}


• Fair enough. I will follow the rules :p – MCT Dec 22 '16 at 21:15