答案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
。