# Fix spacing when using \dot{}

If I type $a \sim b$, I get . However, if I type $a \dot{\sim} b$, I get this and the spacing is gone. Is there a way to regain latex's good spacing mechanism, i.e. add spaces if needed and avoid unnecessary spacing?

• )not tested, hence a comment, not an answer.) \sim is a relation, so typing $a \mathrel{\dot{\sim}} b$ should restore the proper class. – barbara beeton Nov 10 '15 at 19:55

You want to define a new command to make \dot{\sim} a binary relation:

\documentclass{article}
\usepackage{mathtools}

\newcommand{\dotrel}[1]{\mathrel{\dot{#1}}}

\begin{document}

$a\sim b$
$a\dotrel{\sim} b$
$a\dot{\sim} b$

\end{document}


• Can this solution be parametrized by the symbol, like = or \approx? – user3389669 Nov 10 '15 at 19:59
• @user3389669: You mean for \dot{=} and \dot{\approx}? Simply wrap a \mathrel{} around them. – Francis Nov 10 '15 at 20:01
• I meant something like \dotrel{<your symbol goes here>}, where you could insert arbitrary symbols, resulting in that symbol being printed dotted and being treated like a relation. – user3389669 Nov 10 '15 at 20:04
• @user3389669: Yes, I slightly modified my answer – Francis Nov 10 '15 at 20:07
• The TeXnical reason is that an Acc atom (resulting from <math accent>{<symbol>} (for instance \dot{\sim}) is then treated as an Ord atom (ordinary symbol) when the math list is transformed into a horizontal list. Enveloping the construction in \mathrel reestablishes the nature of the atom. – egreg Nov 10 '15 at 20:38

When you do something like \dot{\sim}, you're creating an Acc atom (for accent) which, by rule, is treated the same as an Ord atom (ordinary, like a normal letter) when the math list is converted into typesetting commands. See Rules 12 and 16 in Appendix G of the TeXbook (pages 443 and 445).

The amsmath package already defines an infrastructure it uses for trying and guess the right type of the second argument to \overset and \underset, so that, say, \overset{x}{=} results in a Rel atom.

The trick is to evaluate \binrel@ on the second argument, which will redefine \binrel@@ to be \mathrel, \mathbin or \mathord.

So the definition of a “smart dot” could be as follows:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\sdot}[1]{\binrel@{#1}\binrel@@{\dot{#1}}}
\makeatother

\begin{document}

Relation: $a \sdot{\sim} b$

Relation: $a \sim b$

Operation: $a \sdot{\times} b$

Operation: $a \times b$

\end{document}


Note that the spacing is the same for dotted and undotted symbols.

Try a \mathrel{\dot{\sim}} b`.