在數學顯示模式下寫一個“\tag”,這樣它就不會自動用括號括起來,這樣 Overleaf 就不會抱怨

在數學顯示模式下寫一個“\tag”,這樣它就不會自動用括號括起來,這樣 Overleaf 就不會抱怨

如何在數學顯示模式下編寫 a \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 視窗沒有顯示紅點。

在此輸入影像描述

相關內容