# How do I define a custom infix operator in math mode? An alternative to \operatorname

As an example of what I do not want, take

$\mathrm{C} \operatorname{F} 4$


produces different spacing between the star and the operands than

$a \ast 4$


How do I mitigate this?

I can't use definitions outside of the math mode environment.

In this specific case, I want to use \ast \ast as an infix symbol.

• Could you precise the question? What are you trying to do, exactly? Also, you should not use \rm, use \mathrm instead. – Vincent Jan 18 '20 at 23:22
• fixed it. thanks for pointing that out. but \rm suffices for my current goal, if I do anything serious ill use \mathrm – schuelermine Jan 18 '20 at 23:26
• your question is very unclear, but \mathbin{...} will give ... the spacing rules that + has. – David Carlisle Jan 19 '20 at 0:08
• Do you want “C*” to behave like a single operator? – egreg Jan 19 '20 at 9:15
• Maybe, if you describe what you want to get rather than what you don't – egreg Jan 19 '20 at 9:27

Something like this?

\documentclass{article}
\newcommand{\astast}{\mathbin{{\ast}{\ast}}}
\begin{document}
$A \astast B$
\end{document}


Explanation: \ast is a binary operator, with the spacing that comes with it. Enclosing it in braces {\ast} turns it into an ordinary math atom, so two of these next to each other have no intervening space. Then \mathbin turns the whole construct into a binary operator.

If you want to emulate the “double asterisk” ** used for exponentiation, then

\mathbin{{*}{*}}


is what you need.

The asterisk * by itself produces a Bin atom, without needing \mathbin around it. However two Bin atoms in a row don't make a single Bin atom, because a Bin requires operands around it. Thus the second * would be made into an ordinary symbol.

However, you can make any subformula into a Bin atom by typing it as the argument to \mathbin. By rule, no spacing would be used between the two asterisks with \mathbin{**} (the first would be turned into a unary symbol, just like in -1, and the second into an ordinary, because of the rule above). However, it's better to be more careful and type

\mathbin{{*}{*}}


(the braces hide the nature of * turning it into an ordinary), because the output of

\mathbin{***}


might surprise you. To the contrary, \mathbin{{*}{*}{*}} would not have the problem.