diff --git a/news/changelog-1.12.md b/news/changelog-1.12.md index c4bf00005c8..362b716a4ed 100644 --- a/news/changelog-1.12.md +++ b/news/changelog-1.12.md @@ -78,6 +78,7 @@ All changes included in 1.12: ### `quarto render` - ([#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. +- ([#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`. ## Extensions diff --git a/src/command/render/filters.ts b/src/command/render/filters.ts index a3f8fe4d477..2c9c75ede4e 100644 --- a/src/command/render/filters.ts +++ b/src/command/render/filters.ts @@ -76,6 +76,7 @@ import { mergeConfigs } from "../../core/config.ts"; import { projectType } from "../../project/types/project-types.ts"; import { readCodePage } from "../../core/windows.ts"; import { formatHasBootstrap } from "../../format/html/format-html-info.ts"; +import { resolveHtmlMathMethod } from "../../format/html/format-html-math.ts"; import { activeProfiles, kQuartoProfile } from "../../quarto-core/profile.ts"; import { filterBuiltInExtensions, @@ -608,7 +609,12 @@ async function quartoFilterParams( params[kShortcodes] = params[kShortcodes] || []; (params[kShortcodes] as string[]).push(...extShortcodes); } - params[kHtmlMathMethod] = defaults?.[kHtmlMathMethod]; + // a command line math flag overrides html-math-method for Pandoc, so the + // filters (e.g. equation numbering) must see it too + const flagMathMethod = resolveHtmlMathMethod(format, options.flags); + params[kHtmlMathMethod] = flagMathMethod?.fromFlag + ? flagMathMethod.method + : defaults?.[kHtmlMathMethod]; const figResponsive = format.metadata[kFigResponsive] === true; if (figResponsive) { diff --git a/tests/smoke/render/render-math-method-flag.test.ts b/tests/smoke/render/render-math-method-flag.test.ts index 0aa2f56ea50..b40acf55f4b 100644 --- a/tests/smoke/render/render-math-method-flag.test.ts +++ b/tests/smoke/render/render-math-method-flag.test.ts @@ -30,3 +30,21 @@ testRender(input, "html", false, [ /window\.backupDefine = window\.define/, ]), ], {}, ["--math-method", "katex"]); + +// The equation number must survive a method that ignores \tag. The number is +// matched in the rendered MathML, not in its TeX annotation. +const mathmlNumber = /]*>\(<\/mo>1<\/mn>/; +testRender(input, "html", false, [ + noErrorsOrWarnings, + ensureFileRegexMatches(output.outputPath, [mathmlNumber]), +], {}, ["--math-method=mathml"]); + +// --mathml is deprecated since Pandoc 3.11 and warns, so no warning check +testRender(input, "html", false, [ + ensureFileRegexMatches(output.outputPath, [mathmlNumber]), +], {}, ["--mathml"]); + +testRender(input, "html", false, [ + noErrorsOrWarnings, + ensureFileRegexMatches(output.outputPath, [/2<\/sup>\s*\(1\)/]), +], {}, ["--math-method=plain"]);