在数学显示模式下编写一个 `\tag`,使其不会自动被括号括起来,并且 Overleaf 不会抱怨

在数学显示模式下编写一个 `\tag`,使其不会自动被括号括起来,并且 Overleaf 不会抱怨

我怎样才能编写一个\tag数学显示模式,使其不会自动被括号括起来,并且 Overleaf 不会抱怨?(我认为忽略 Overleaf 的抱怨是不好的做法。)

\documentclass{article}
\usepackage{amsmath, amssymb}

\begin{document}

The following would be perfect if the automatic parentheses enclosing the tag were removed:

\[J(2^m + l) = 2l + 1 \tag{for $m \geqq 0$ and $0 \leqq l < 2^m$}\]

The following output is good

\[J(2^m + l) = 2l + 1 \tag*{for $m \geqq 0$ and $0 \leqq l < 2^m$}\]

yet Overleaf complains about it; in particular, it introduces a red warning dot in the margin of the Code Editor, whose drop-down text reads:

\begin{verbatim}
unclosed open display math \[ found at $
unclosed open group { found at $
unexpected $ after open group {
unexpected $ after open display math \[
unexpected $ after open display math \[
unexpected $ after open display math \[
unexpected $ after open display math \[
\end{verbatim}

\end{document}

答案1

Overleaf 拒绝完全合法的 LaTeX 构造,这可不是件好事。另一方面,您不应该在这种情况下滥用标签,因为条件是方程式的一部分,而标签不是。

无论如何,你可以让 Overleaf 保持安静,使用\ttag

\newcommand{\ttag}{\tag*}

避免在显示前留空行,这是错误的。如果下一个文本开始一个新段落,则可以在显示后留空行。

\documentclass{article}
\usepackage{amsmath, amssymb}

\newcommand{\ttag}{\tag*}

\begin{document}

The following would be perfect if the automatic parentheses enclosing the tag were removed:
\[
J(2^m + l) = 2l + 1 
\tag{for $m \geqq 0$ and $0 \leqq l < 2^m$}
\]
The following output is good
\[
J(2^m + l) = 2l + 1 
\ttag{for $m \geqq 0$ and $0 \leqq l < 2^m$}
\]
But this output is much better
\[
J(2^m + l) = 2l + 1, 
\qquad\text{for $m \geqq 0$ and $0 \leqq l < 2^m$}
\]
as you can clearly see, because the conditions are part of the equation.

\end{document}

在此处输入图片描述

Overleaf 窗口没有显示红点。

在此处输入图片描述

相关内容