Fix false math-mode warning for \tag* with math content

\tag*{...} (amsmath's unnumbered tag) incorrectly triggered an "open
inline math \( used inside existing math mode" warning when its
argument contained inline math, e.g. \tag*{\(\dagger\)} or
\tag*{$abc$}. \tag{...} without the star already worked.

The linter marks \tag's argument group as text-mode so nested math
delimiters are allowed, but the literal * between \tag and { was
tokenized separately and reset that flag before the argument group
was reached. \tag now consumes an immediately following * so the
text-mode flag survives to the argument group.
This commit is contained in:
Mark
2026-07-07 02:36:08 +10:00
parent 05565653a1
commit 26aed11841
2 changed files with 25 additions and 1 deletions
@@ -1107,12 +1107,24 @@ const InterpretTokens = function (
seq === 'intertext' ||
seq === 'shortintertext' ||
seq === 'textnormal' ||
seq === 'tag' ||
seq === 'reflectbox' ||
seq === 'textrm'
) {
// next group will be in text mode regardless
nextGroupMathMode = false
} else if (seq === 'tag') {
// next group will be in text mode regardless
nextGroupMathMode = false
// \tag* (unnumbered tag) - skip over the '*' so it doesn't reset
// nextGroupMathMode before the argument group is reached
const nextToken = Tokens[i + 1]
if (
nextToken &&
nextToken[1] === 'Text' &&
text.substring(nextToken[2], nextToken[3]) === '*'
) {
i = i + 1
}
} else if (seq === 'tikz') {
// try to read any optional params [BAR]...., advance if found
const newPos = readOptionalGeneric(TokeniseResult, i)
@@ -350,6 +350,18 @@ describe('LatexLinter', function () {
assert.equal(errors.length, 0)
})
it('should accept math tag* commands', function () {
const { errors } = Parse(
'\\begin{align}\n\\pi=3 \\tag*{\\(\\dagger\\)}\n\\end{align}\n'
)
assert.equal(errors.length, 0)
})
it('should accept math tag* commands with $ math mode', function () {
const { errors } = Parse('$\\tag*{$abc$}$\n')
assert.equal(errors.length, 0)
})
it('should accept math \\def commands', function () {
const { errors } = Parse(
'\\def\\peb[#1]{{\\left\\lfloor #1\\right\\rfloor}}'