Difference between commands `\setminus` and `\backslash`
In the Computer Modern math font family, the shapes of \setminus
and \backslash
are identical. (Aside: the vertical size of \backslash
can be modified by \left
and \right
directives; that's not the case for \setminus
.) That does not mean, though, that the symbols get typeset identically. This is because \backslash
has status mathord
("math ordinary"), whereas \setminus
has status mathbin ("math binary operators"). Having status mathbin
means that in combinations of mathord-mathbin-mathord -- as in U\setminus V
-- a "medspace" amount of whitespace gets inserted on both sides of the \setminus
symbol.
In contrast, TeX does not insert whitespace between math atoms (to use a TeX jargon word) of status mathord
. Hence, no extra whitespace is inserted in U\backslash V
.
Finally, mainly for the sake of completeness, it's worth mentioning the existence of the macro \smallsetminus
, which is provided by the amssymb
package. As one can tell from the final row of the following table, \smallsetminus
looks rather different from \setminus
, doesn't it?
\documentclass{article}
\usepackage{xcolor,array,booktabs,amssymb}
\begin{document}
\begin{tabular}{@{} >{$}l<{$} l @{}}
$Result$ & LaTeX code \\
\midrule
\setminus\mkern-9mu\color{red}\backslash & \verb+\setminus\mkern-9mu\color{red}\backslash+ \\
\addlinespace
B\setminus D & \verb+B\setminus D+ \\
B\mathbin{\setminus}D & \verb+B\mathbin{\setminus}D+ \\
B\:{\setminus}\:D & \verb+B\:{\setminus}\:D+ \\
B\mkern4mu{\setminus}\mkern4mu D & \verb+B\mkern4mu{\setminus}\mkern4mu D+ \\
\addlinespace
B{\setminus}D & \verb+B{\setminus}D+ \\
B\backslash D & \verb+B\backslash D+ \\
\addlinespace
B\smallsetminus D & \verb+B\smallsetminus D+
\end{tabular}
\end{document}