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?

1 Answer 1

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

5
  • Thanks a lot, that's perfect. Out of curiosity, is the "3 is mathrel, 2 is mathbin" documented anywhere that you know of?
    – Clément
    Nov 29, 2023 at 17:10
  • 1
    @Clément In the TeXbook, of course.
    – egreg
    Nov 29, 2023 at 17:11
  • Silly me ;-) Thanks!
    – Clément
    Nov 29, 2023 at 17:16
  • 1
    I'd never heard about \binrel. It is impressive how we discover new tools every day... Thanks.
    – Sigur
    Nov 29, 2023 at 17:29
  • 3
    @Sigur Nice, isn't it? You find an explanation at tex.stackexchange.com/a/18338/4427
    – egreg
    Nov 29, 2023 at 18:03

You must log in to answer this question.

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