8

I am using \sim as a binary operator and was wondering which of the following two was correct:

\documentclass{article}
\begin{document}
    \[a \sim b\]
    \[a \mathrel{\sim} b\]
\end{document}

enter image description here

which prompted the more general question: how to know if \mathrel is needed with a particular symbol / commmand?

Clément
  • 5,591

1 Answers1

12

You look at the definition.

> latexdef sim

\sim: \mathchar"3218

The initial 3 tells you this is a relation symbol. Similarly

> latexdef oplus

\oplus: \mathchar"2208

tells you that \oplus is a binary operation symbol.

You can also look in Scott Pakin's “Comprehensive List” with texdoc comprehensive or online on texdoc.org where you find \sim in table 89 “Binary relations”.

Or you can do a test that can tell you about a symbol being a \mathrel or a \mathbin (you'd get \relax in other cases).

\documentclass{article}
\usepackage{amsmath}

\makeatletter \newcommand{\BinOrRel}[1]{% \binrel@{#1}\texttt{\string#1 is \meaning\binrel@@}% } \makeatother

\begin{document}

\BinOrRel{\sim}

\BinOrRel{\oplus}

\BinOrRel{\sum}

\end{document}

enter image description here

egreg
  • 1,121,712