[Tex/LaTex] Equivalence of sequence: \sim with some text under

math-operators

The sign \sim is used in mathematics for equivalence of sequences. How to do it in LaTeX?

I tried

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\isEquivTo}{\sim}

\begin{document}
\[
\sin(n) + n \isEquivTo\limits_{+\infty} n
\]

\end{document}

enter image description here

but the output is not what I am looking for. I would like the +\infty to be under the \sim sign. Is it possible to have a command \isEquivTo that would automatically put the +\infty under the sign, without even typing \limits?

Best Answer

If you want an operator to respect \limits you should use \DeclareMathOperator*. However, this is the wrong tool for the required symbol, because it would make an operator rather than a relation symbol, with wrong spacing. Then

\newcommand{\isEquivTo}[1]{\underset{#1}{\sim}}

seems better for your needs. Note that \underset will “know” that \sim is a relation symbol, so it will use the right spacing around it.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\isEquivTo}[1]{\underset{#1}{\sim}}

\begin{document}
\[
\sin(n) + n \isEquivTo{+\infty} n
\]

\end{document}

enter image description here

On the other hand, setting the subscript under the symbol won't give good results when inline; here's a better definition that uses \underset only in display style. Look carefully at the output to see why it's better not using the \underset form for inline formulas.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\isEquivTo}[1]{%
  \mathpalette\isEquivToInner{#1}%
}
\newcommand{\isEquivToInner}[2]{%
  \ifx#1\displaystyle
    \underset{#2}{\sim}
  \else
    \sim_{#2}
  \fi
}

\begin{document}
some text some text some text some text some text some text some text some text
some text some text some text some text some text some text some text some text
$\displaystyle\sin(n) + n \isEquivTo{+\infty} n$
some text some text some text some text some text some text some text
some text some text some text some text some text some text some text
$\sin(n) + n \isEquivTo{+\infty} n$
some text some text some text some text some text some text some text
some text some text some text some text some text some text some text
\[
\sin(n) + n \isEquivTo{+\infty} n
\]
\end{document}

enter image description here

If you want a syntax like \isEquivTo_{+\infty}, you can do it with xparse:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\NewDocumentCommand{\isEquivTo}{e{_}}{\isEquivToA#1}
\NewDocumentCommand{\isEquivToA}{m}{%
  \IfNoValueTF{#1}
    {\sim}
    {\mathpalette\isEquivToB{#1}}%
}
\newcommand{\isEquivToB}[2]{%
  \ifx#1\displaystyle
    \underset{#2}{\sim}
  \else
    \sim_{#2}
  \fi
}

\begin{document}
Here is the command without subscript $n \isEquivTo n$

some text some text some text some text some text some text some text some text
some text some text some text some text some text some text some text some text
$\displaystyle\sin(n) + n \isEquivTo_{+\infty} n$
some text some text some text some text some text some text some text 
some text some text some text some text some text some text some text 
$\sin(n) + n \isEquivTo_{+\infty} n$
some text some text some text some text some text some text some text 
some text some text some text some text some text some text some text 
\[
\sin(n) + n \isEquivTo_{+\infty} n
\]
\end{document}

You will see that the first call just does \sim.