2

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?

3

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.

  • Thanks for your answer. I wish I could simply use $\isEquivTo_{...}$ instead of a command. – Colas Jan 21 '17 at 14:17
  • My intention is not to argue with you. Actually, my true goal is to redefine \sim and use it as \sum for instance... – Colas Jan 21 '17 at 14:31
  • 1
    @Colas What's the conceptual difference between \isEquivTo_{...} and \isEquivTo{...}? However, I added it. Please, state your problems in full. – egreg Jan 21 '17 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.