[Tex/LaTex] How to neatly space the equals sign when using probabilities

amsmathmath-mode

When the equals sign is used as part of the probability notation it looks a little odd when typeset in LaTeX, especially when a lot of equals sign occurs in the same line.

E.g.,

\[ \Pr(A=a) = \Pr(B=b \mid C=c) \]

<Typsesetted equation above>

The spacing between the equal sign is the same for both the 'equal to' relation and the ones between the random variable (A, B, C) and the constants (a, b, c).

Is ther a way to make the spacing between the latter smaller be than the former, or am I just overthinking this?

Best Answer

It's straightforward to define a macro such as \newcommand\myeq{\mkern1.5mu{=}\mkern1.5mu} -- choose the argument of \mkern to suit your personal preferences -- and thus to rewrite your equation as

 \Pr(A\myeq a)  &= \Pr(B\myeq b \mid C\myeq c)

In the TeXbook (p. 174, near bottom of page), though, DEK suggests not reducing the whitespace around the = symbols but, instead, adding more whitespace elsewhere in the full equation via judiciously-placed \, directives:

 \[ \Pr(\, A=a \,) = \Pr(\, B=b \mid C=c \,) \]

A full MWE:

enter image description here

\documentclass{article}
\newcommand\myeq{\mkern1.5mu{=}\mkern1.5mu}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\Pr(A=a)       &= \Pr(B=b \mid C=c) \\           % original form
\Pr(A\myeq a)  &= \Pr(B\myeq b \mid C\myeq c) \\ % less whitespace around "="
\Pr(\, A=a \,) &= \Pr(\, B=b \mid C=c \,)        % *more* whitespace
\end{align*}
\end{document}
Related Question