序列等价:\sim 下有一些文本

序列等价:\sim 下有一些文本

符号\sim在数学中用于表示序列的等价性。如何在 LaTeX 中做到这一点?

我试过

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\isEquivTo}{\sim}

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

\end{document}

在此处输入图片描述

但输出不是我想要的。我希望+\infty位于\sim符号下方。是否有一个命令\isEquivTo可以自动将 置于+\infty符号下方,甚至无需输入\limits

答案1

如果希望运算符得到尊重,\limits则应使用\DeclareMathOperator*。但是,对于所需的符号来说,这是错误的工具,因为它会生成具有错误间距的运算符而不是关系符号。然后

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

似乎更符合您的需求。请注意,它将\underset“知道”这\sim是一个关系符号,因此它将在其周围使用正确的间距。

\documentclass{article}
\usepackage{amsmath}

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

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

\end{document}

在此处输入图片描述

另一方面,在内联时,在符号下设置下标不会产生良好的结果;这里有一个更好的定义,\underset仅在显示样式中使用。仔细查看输出,看看为什么最好不要使用\underset内联公式的形式。

\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}

在此处输入图片描述

如果您想要类似的语法\isEquivTo_{+\infty},您可以这样做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}

您将会看到第一个调用就完成了\sim

相关内容