I want a particular spacing behavior for a custom operator. I can produce the desired spacing by setting math classes (\mathord
and so forth), but I have to do it on a case-by-case basis since no single math class works for all situations. Is there a more automatic solution?
In my document, the operator $(A\smalltriangleright B)$
means "coerce from A to B". It's a prefix operator and it takes subscripts in some situations.
When an operator is applied to an argument, there should be some space between operator and argument. Either mathbin space or mathrel space would be acceptable.
When operators are composed using the function composition operator
\circ
, they should act as ordinary symbols with\circ
playing the role of binary operator.
I haven't been able to get a single definition of the operator that has the right spacing in both situations:
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathabx}
\newcommand{\coerceSub}[3]{(\mathord{#1}\smalltriangleright\mathord{#2})_{#3}}
\begin{document}
In an operator application, the ``mathrel'' version looks better.
\begin{gather}
% OK
\mathrel{\coerceSub uv1} x \\
% Not OK: no space between operator and operand
\coerceSub uv1 x
\end{gather}
In an operator composition, the plain version looks better.
\begin{gather}
% Not OK: no space between \circ and c
\mathrel{\coerceSub vw1} \circ c \\
% OK
\coerceSub vw1 \circ c
\end{gather}
\end{document}
\mathop
for operators (\mathrel
is for relations and expects infix placement).\mathop
converts a following\mathbin
into a\mathord
so loses the spacing. Hence I suggested\mathinner
in my answer, even though it isn't really an inner operation.