It is possible to have a symbol or group behave to the left as if it had one particular math character class and to the right as if it had another?
One typical case where this comes up is when one parenthesizes part of a longer expression. For example, enclosing the first part of \(U \rightarrow U \rightarrow U\)
in square brackets (\([U \rightarrow] U \rightarrow U\)
) will lead to the closing square bracket ]
being too close to the following U
. In this case, creating a new \mathrel
out of the arrow and the closing square bracket (\([U \mathrel{\rightarrow ]} U \rightarrow U\)
) solves the problem:
but a fully general solution would be nice.
Another example: Perhaps I would like to define an asymmetric relation symbol 🍂
(a leaf, whatever this might stand for) for which I would like to make it visually clear that it conceptually binds closer to its right-hand argument than to the left. The result should look like this: M 🍂v
. Unlike the title of this question, this one would actually be "\mathord to the right and \mathrel to the left". (Perhaps this is a two-argument function that accepts a matrix and a vector. The assumption is that there is a good reason for using infix notation and for writing it closer to the vector. Maybe it transforms the vector before multiplying the vector to the matrix, in a way that the vector transformation makes only sense if combined with matrix multiplication. Note that I've picked such an example for visual clarity, but pairing \mathord
up with \mathbin
instead of \mathrel
might be more realistic.)
Perhaps a better example: I might define a typecast operator for some formal language. I'd like to denote the typecast expression as expr ∽τ
(using \backsim
), with type τ
set closer to the symbol ∽
: it's as if ∽
first merged with the target type to then form a left-unary typecast operator; we can even enumerate all such operators ∽τ
under the assumption that the number of possible target types τ
is small.
The hacky solution to do a lot of hierarchical math character class assignment (i.e. \(M \mathrel{\mathord{\someleafsymbol} v}\)
for my first leaf example) is dispreferred. I was thinking of a macro \DeclareTwofaceMathchar{lclass}{rclass}{symbol}
where lclass
and rclass
are among \mathord
, \mathop
, \mathbin
, ...
If there is no such fully general solution, an explanation for why there is none will also be a good answer.
Somewhat related is my Addendum about a "genuine unary plus" at the bottom of this question: What is a good method for producing a unary plus/minus sign that always works?