Skip to content

Commit 5bf4366

Browse files
authored
Fix HTML equation numbers lost with --mathml or --math-method (#15358)
* Keep HTML equation numbers when the math method comes from a CLI flag Crossref equation numbering picks \tag{n} for MathJax and KaTeX and \qquad(n) for every other method, reading the html-math-method filter param. That param came from the Pandoc defaults only, so a method chosen on the command line never reached the filter. On Bootstrap HTML the defaults say mathjax, so --mathml, --math-method=mathml and --math-method=plain got \tag{1}, which those methods drop: the equation number disappeared from the output. The param now comes from resolveHtmlMathMethod when a flag chose the method, as the KaTeX post-processor, the template patch and llms.md output already do. Without a flag it keeps the defaults value, so the default webtex URL Quarto fills in is unchanged. The flag is not written into the defaults or format.pandoc: the template patch relies on telling a flag apart from html-math-method. One visible change: --katex or --mathjax on HTML without Bootstrap now numbers with \tag{1} instead of \qquad(1), as Bootstrap HTML already does. * Add changelog entry for equation numbers with CLI math flags
1 parent 8779794 commit 5bf4366

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎news/changelog-1.12.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ All changes included in 1.12:
7878
### `quarto render`
7979

8080
- ([#15321](https://github.com/quarto-dev/quarto-cli/pull/15321)): Support Pandoc's `--math-method` option, so `--math-method=katex` works with `--embed-resources` and in `llms.md` output, as `--katex` does.
81+
- ([#15358](https://github.com/quarto-dev/quarto-cli/pull/15358)): Fix equation numbers missing from HTML output when the math method is chosen with `--mathml` or `--math-method`.
8182

8283
## Extensions
8384

‎src/command/render/filters.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import { mergeConfigs } from "../../core/config.ts";
7676
import { projectType } from "../../project/types/project-types.ts";
7777
import { readCodePage } from "../../core/windows.ts";
7878
import { formatHasBootstrap } from "../../format/html/format-html-info.ts";
79+
import { resolveHtmlMathMethod } from "../../format/html/format-html-math.ts";
7980
import { activeProfiles, kQuartoProfile } from "../../quarto-core/profile.ts";
8081
import {
8182
filterBuiltInExtensions,
@@ -608,7 +609,12 @@ async function quartoFilterParams(
608609
params[kShortcodes] = params[kShortcodes] || [];
609610
(params[kShortcodes] as string[]).push(...extShortcodes);
610611
}
611-
params[kHtmlMathMethod] = defaults?.[kHtmlMathMethod];
612+
// a command line math flag overrides html-math-method for Pandoc, so the
613+
// filters (e.g. equation numbering) must see it too
614+
const flagMathMethod = resolveHtmlMathMethod(format, options.flags);
615+
params[kHtmlMathMethod] = flagMathMethod?.fromFlag
616+
? flagMathMethod.method
617+
: defaults?.[kHtmlMathMethod];
612618

613619
const figResponsive = format.metadata[kFigResponsive] === true;
614620
if (figResponsive) {

‎tests/smoke/render/render-math-method-flag.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,21 @@ testRender(input, "html", false, [
3030
/window\.backupDefine = window\.define/,
3131
]),
3232
], {}, ["--math-method", "katex"]);
33+
34+
// The equation number must survive a method that ignores \tag. The number is
35+
// matched in the rendered MathML, not in its TeX annotation.
36+
const mathmlNumber = /<mo[^>]*>\(<\/mo><mn>1<\/mn>/;
37+
testRender(input, "html", false, [
38+
noErrorsOrWarnings,
39+
ensureFileRegexMatches(output.outputPath, [mathmlNumber]),
40+
], {}, ["--math-method=mathml"]);
41+
42+
// --mathml is deprecated since Pandoc 3.11 and warns, so no warning check
43+
testRender(input, "html", false, [
44+
ensureFileRegexMatches(output.outputPath, [mathmlNumber]),
45+
], {}, ["--mathml"]);
46+
47+
testRender(input, "html", false, [
48+
noErrorsOrWarnings,
49+
ensureFileRegexMatches(output.outputPath, [/<sup>2<\/sup>\s*\(1\)/]),
50+
], {}, ["--math-method=plain"]);

0 commit comments

Comments
 (0)