25

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?

2
  • 7
    \[ \Pr(A{=}a) = \Pr(B{=}b \mid C{=}c) \]
    – gernot
    Apr 18, 2017 at 11:04
  • 1
    @gernot I use a similar "hack" whenever expressing values that are offset from a variable e.g. p{-}1, k{+}1 (as opposed to expressing a calculation e.g. b=a+1, when I leave the spacing unaffected).
    – Joffan
    Apr 18, 2017 at 17:54

7 Answers 7

16

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}
6
  • That's great, I prefer your \myeq alternative. Coming to the second part of the question: is it necessary? Is it advisable to make this alteration to the math typesetting when submitting it to a journal (e.g., an Elsevier/IEEE journal)?
    – Ébe Isaac
    Apr 18, 2017 at 11:19
  • @ÉbeIsaac - As long as what you're doing isn't bizarre or odd- looking, the journal will probably not modify your LaTeX code significantly. That said, you may want to ponder the question of how much value-added your notation provides.
    – Mico
    Apr 18, 2017 at 11:33
  • 1
    @Mico I wish I could back up your comment, but I've had simple things broken automatically like a nicefrac-style inline fraction macro, changing ⅓x into 1/3x (when I pointed it out we settled on (1/3)x). I understand why, but my point is it gets broken by machine.
    – Chris H
    Apr 19, 2017 at 16:20
  • @ChrisH - Thanks for this. I guess that what constitutes "bizarre and odd-looking" can be quite subjective and idiosyncratic. Maybe the nicefrac package was just too advanced for the Journal you had to deal with...
    – Mico
    Apr 19, 2017 at 16:27
  • 1
    @ChrisH -- 1/(3x) would definitely be wrong. Glad you caught the issue in time.
    – Mico
    Apr 19, 2017 at 21:34
19

I turn my comment to an answer since I think it is an adequate solution, in particular in this situation, and it is simpler than the other approaches. I also find no flaw in its visual appearance. It also makes sense to me logically, since A=a can be viewed as a compound label for an event, not necessarily as an equation. Even if it's an equation, it's just too tiny to be granted the same rights as other equations.

enter image description here

\documentclass{article}
\begin{document}
\[ \Pr(A{=}a) = \Pr(B{=}b \mid C{=}c) \]
\end{document}
1
  • 2
    and above all it's a no-brainer :-)
    – PatrickT
    Mar 11, 2021 at 9:50
12

This reduces by half the space around the equals sign in the argument to \Pr; it also has the advantage of being able to set the size of the delimiters in an optional argument.

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiterX\PrArg[1]{(}{)}{%
  \renewcommand\given{\Conditional{\delimsize}}%
  \begingroup\lccode`~=`= \lowercase{\endgroup\let~}\reducedequals
  \edef\equals{\mathchar\the\mathcode`= }%
  \mathcode`="8000
  #1%
}
\providecommand\given{}
\newcommand{\Conditional}[1]{%
  \nonscript\;#1\vert\nonscript\;\mathopen{}%
}
\renewcommand{\Pr}{\operatorname{Pr}\PrArg}
\newcommand{\reducedequals}{%
  \mskip-.5\thickmuskip
  \equals
  \mskip-.5\thickmuskip
  \nobreak
}

\begin{document}

$\Pr{A=a} = \Pr{B=b \given C=c}$

$\Pr[\big]{A=\frac{1}{2}} = \Pr[\Big]{B=b \given C=\sqrt{\frac{a^{2^n}}{b}}}$

\end{document}

enter image description here

6

This is not for the manual of best practices, but between treat the equal sing as a very spaced math relation (that is the default equivalent to \mathrel{=}) or suppress all this extra space treating the symbol like text (\mbox{=} or \text{=} with amsmat) or simply grouping it ({=}) as gernot pointed, that may be is too drastic, in this case you can simply treat it as an unary or binary operator (\mathop{=} or \mathbin{=} respectively) although syntactically sound odd. To further but not complete shrinkage, another simple option is add negative spaces in both sides (\!=\!). Anyway, it could also a good idea increase a bit the space for the "main equal" sign (with \,=\, for instance). My preference is use both \!=\! and \,=\,. Example:

mwe

\documentclass[twocolumn]{article}

%just for the mwe format, no need of preamble code for solutions.
\usepackage{tabto} 
\setlength{\parskip}{.3ex}
\TabPositions{.7\linewidth}

\begin{document}

\( \Pr(A=a) = \Pr(B=b \mid C=c) \) \tab  default\par 
\( \Pr(A\mathrel=a)  = \Pr(B\mathrel=b  \mid C\mathrel=c) \)    \tab  \verb|\mathrel|\par 
\( \Pr(A\mathbin=a)  = \Pr(B\mathbin=b  \mid C\mathbin=c) \)    \tab  \verb|\mathbin|\par
\( \Pr(A\mathop{=}a) = \Pr(B\mathop{=}b \mid C\mathop{=}c) \)   \tab  \verb|\mathop|\par
\( \Pr(A\!=\!a) = \Pr(B\!=\!b \mid C\!=\!c) \)                  \tab  \verb|\!=\!|\par
\( \Pr(A{=}a) = \Pr(B{=}b \mid C{=}c) \)                        \tab  \verb|{=}|\par
$\vdots$\par
\( \Pr(A\!=\!a) \,=\, \Pr(B\!=\!b \mid C\!=\!c) \)      \tab  and  \verb|\,=\,|

\end{document}
0
4
\let\originalPr\Pr
\def\Pr(#1){\originalPr(\mathmakebox{\thickmuskip=.5\thickmuskip #1})}

Tweak that .5 at will.

1
  • You can also work with active characters to not need that \mathmakebox that makes things unbreakable in there.
    – Manuel
    Apr 18, 2017 at 11:12
2

You can re-define the = as binary operator in Pr argument and I recommend to enlarge the \thickmuskip for relations (spacing for the outer = etc.), when such "Pr" equations are commonly used in your document.

\def\Pr(#1){\mathop{\rm Pr}({\mathcode`=="203D #1})}
\multiply\thickmuskip by3 \divide\thickmuskip by2

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

\bye
1
  • 1
    This will change the spacing around all relation symbols, throughout the document and kill its stretchability.
    – egreg
    Apr 19, 2017 at 10:08
2

To get the effect of automatically adding {} around every = inside \Pr, use \scriptstyle to eliminate the space around = and the relsize package to scale back up.

\documentclass{article}
\usepackage{relsize, mathtools}
\renewcommand\Pr[1]{\text{P({\larger[2]$\scriptstyle#1$})}}

\begin{document}
\[\text P(A{=}a) = \text P(B{=}b {\mid} C{=}c)\]
\[\Pr{A=a} = \Pr{B=b \mid C=c}\]
\end{document}

This method will remove space around = as well as <, ≤, +, etc inside \Pr. One operator from which you might not want space removed is the conditional probability pipe \mid.

To remove space from all operators except \mid:

\documentclass{article}
\usepackage{relsize, mathtools}
\renewcommand\Pr[1]{\begingroup
    \renewcommand\mid{\;|\;}
    \text{P({\larger[2]$\scriptstyle#1$})}
    \endgroup}

\begin{document}
\[\Pr{A=a} = \Pr{B=b \mid C=c}\]
\[\scriptstyle \Pr{A=a} = \Pr{B=b \mid C=c}\]
\end{document}

As depicted, this forces space around \mid even in \scriptstyle environments, where operators typically do not have space.

To remove space from \mid in \scriptstyle or \scriptscriptstyle \Pr only:

\documentclass{article}
\usepackage{relsize, mathtools}
\renewcommand\Pr[1]{\begingroup
    \renewcommand\mid{\mathchoice{\;|\;}{\;|\;}{\;|\;}{|}}
    \mathchoice
        {\text{P({\larger[2]$\scriptstyle#1$})}}
        {\text{P({\larger[2]$\scriptstyle#1$})}}
        {\text{P({\larger[4]$\scriptscriptstyle#1$})}}
        {\text{P({\larger[2]$\scriptscriptstyle#1$})}}
    \endgroup}

\begin{document}
\[\Pr{A=a} = \Pr{B=b \mid C=c}\]
\[\scriptstyle \Pr{A=a} = \Pr{B=b \mid C=c}\]
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .