[Tex/LaTex] Math mode accents and spacing

accentsmath-modespacing

I'm using accents to produce a variant of the \in operator but when I place an accent on it, as in \tilde{\in}, I get spacing that is different from \in, see the example and the image below. My question is: what is the best way to make it so that \tilde{\in} get the same spacing as \in?

In the example below I also provide two failed attempts of getting the right spacing. I'm not especially accustomed to math mode and definitions of operators. Maybe the right way to go with \DeclareMathOperator?

\documentclass{article}

\begin{document}

The spacing I want:
\[
w_{1} \in w_{2}
\]

The spacing I get with an accent:
\[
w_{1} \tilde{\in} w_{2}
\]

Better spacing but an ugly hack:
\[
w_{1}~\tilde{\in}~w_{2}
\]

The wrong spacing (too tight?):
\[
w_{1} \mathop{\tilde{\in}} w_{2}
\]

\end{document}

Example of math mode accents and spacing

Best Answer

An accented symbol is treated by TeX as an ordinary one; you have to tell it that you want a relation symbol:

\( w_{1} \mathrel{\tilde{\in}} w_{2} \)

The commands for declaring a math symbol are

  • \mathord (ordinary)
  • \mathbin (binary operation)
  • \mathrel (binary relation)
  • \mathop (operator, use with care)

An ordinary symbol is typeset without any spacing around it. A binary operation is something like +; for example, if one wanted to define a "mod" operation, a correct way would be

\newcommand{\bmod}{\mathbin{\textrm{mod}}}

(amsmath does it in a quite different way, but that's not the point). A binary relation is like <; the spacing around binary relation symbols is larger than around operation symbols. Moreover the space around relation symbols is uncompressible, while it is for operations.

As already said, putting an accent over a symbol makes it lose its predefined nature: the accented cluster is considered as an ordinary symbol; therefore we have to state explicitly its nature.

Related Question