![在数学显示模式下编写一个 `\tag`,使其不会自动被括号括起来,并且 Overleaf 不会抱怨](https://linux22.com/image/472164/%E5%9C%A8%E6%95%B0%E5%AD%A6%E6%98%BE%E7%A4%BA%E6%A8%A1%E5%BC%8F%E4%B8%8B%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AA%20%60%5Ctag%60%EF%BC%8C%E4%BD%BF%E5%85%B6%E4%B8%8D%E4%BC%9A%E8%87%AA%E5%8A%A8%E8%A2%AB%E6%8B%AC%E5%8F%B7%E6%8B%AC%E8%B5%B7%E6%9D%A5%EF%BC%8C%E5%B9%B6%E4%B8%94%20Overleaf%20%E4%B8%8D%E4%BC%9A%E6%8A%B1%E6%80%A8.png)
我怎样才能编写一个\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 窗口没有显示红点。