Symbols denoting equivalence relations are typically used in two ways. They are either binary relation symbols denoting that two elements are equivalent or they appear as ordinary symbols in the standard notation for quotients of sets by equivalence relations. In the latter case LaTeX needs to be told explicitly that we want to treat the equivalence symbol as an ordinary symbol.
The code
\documentclass{minimal}
\begin{document}
Good spacing: $x \sim y$.
Bad spacing: $X / \sim$.
Good spacing: $X / \mathord\sim$.
\end{document}
produces
I wonder whether it is possible for \sim
to automatically convert to \mathord
class in such situations. I think it would be enough to make it so that \sim
is \mathrel
unless it immediately follows /
in which case it should be \mathord
.
Best Answer
No, a relation symbol will behave as such in all contexts and there is no “look back to see what came before me”. You could do a look forward for
/
to see whether what follows is a relation symbol and, in this case, treat it as an ordinary one. However this method has several limitations, because it would always require/
(in math mode) to be followed by something still belonging to math mode.The specific problem, quite common when dealing with equivalence relations, can be solved in a different way:
so that the call
will do what you want and will also provide a good markup for possible improvement of the typesetting (a different slash, some spacing, whatever). The trick is bracing
#2
, so it will be a subformula and become an ordinary atom.Here is a possible implementation of the “look forward”, which assumes that
/
will always be followed by something that should be considered as an ordinary atom:I don't recommend it.