Per-input math modes and Markdown facts
Status
This design records the implemented per-input math contract. The math guide and reference describe its use.
Problem
markdown.math selects one mode for the entire site. A page that combines Markdown inputs cannot choose a different mode for each input. Templates also cannot tell whether a declared input contains recognized math or which mode applies, so conditional resource loading needs a separate manual flag that can drift from the content.
Desired behavior
Keep [markdown] math in heine.toml as the site-wide default. Allow an authored .page file to override the mode for each declared Markdown input:
[content]
main = "main.md"
example = "example.md"
[markdown.math]
main = "katex"
example = "tex"Each entry names a declared .md input and selects off, katex, mathml, or tex. An input without an override uses the site default. Both inline and display math in that input use its effective mode. Heine reports an authored-file diagnostic for unknown input names, non-Markdown inputs, and invalid modes.
markdown(content="main") uses the named input's effective mode, including when Heine prepares Markdown for block components or applies a table of contents, margin footnotes, citations, or renderer replacements. The markdown filter accepts an optional math argument with the same four modes; without it the filter uses the site default. An invalid argument is a template error. The filter cannot infer a source from its text value. Existing restrictions on source-aware inputs and renderer directives remain in force.
Expose the effective mode and whether the input contains recognized inline or display math as page.markdown.<name>.math.mode and page.markdown.<name>.math.present. The facts are derived from source-level Markdown using the effective mode and its parser options. Code, escaped delimiters, and raw HTML blocks or tag attributes do not count as recognized Markdown math; Markdown parsed between inline HTML tags still follows the parser’s normal rules. In off mode, math parsing is disabled and present is false. For segmented inputs, analyze segments independently and combine their facts: present is true if any segment contains recognized math. The facts describe the declared input, not the content actually selected by a template.
A template can use these facts to conditionally link its own resources:
{% if page.markdown.main.math.mode == "katex" and page.markdown.main.math.present %}
{% set css = asset(id="assets/katex/katex.css") %}
<link rel="stylesheet" href="{{ css.url }}">
{% endif %}
{{ markdown(content="main") }}For segments or content obtained from another page, a template can pass the source's effective mode to the filter explicitly. The site remains responsible for combining facts for the inputs it actually renders and for resources required by its own HTML or external renderers.
Scope and design constraints
- Preserve existing behavior for sites without overrides or filter arguments.
- Resolve modes per page declaration, even if multiple declarations refer to the same file. Use the same effective mode for source validation, Markdown facts, search text, headings and tables of contents, citations, footnotes, component preparation, and final rendering wherever relevant.
- Reuse the existing Markdown analysis traversal where practical; do not infer math from a raw string search. Preserve deterministic output and useful source spans.
- Do not infer the final HTML page's complete resource requirements, automatically insert assets, select fonts, inspect raw HTML, or alter external-renderer profiles.
- Do not add a per-expression mode, separate inline and display modes, or a new renderer.
- Keep full-build and quick-build behavior consistent with their documented guarantees; check changes to source, page metadata, and the site default.
Acceptance criteria and tests
- A fixture page with two Markdown inputs renders their distinct effective modes and exposes accurate facts before the template's head is rendered. An input without an override uses the site default.
- Verify all four modes, inline and display math, empty inputs, escaped dollars, code, raw HTML, segmented content, and math-looking text with parsing off. Test a shared input under different page declarations.
- Verify the source-aware function, prepared components, tables of contents, citations, footnotes, and renderer directives with overrides. Verify word counts and search extraction follow the same effective parsing mode.
- Verify filter default and explicit arguments, including invalid values, segmented text, content from another page, and retained source-aware restrictions.
- Verify diagnostics for missing names, non-Markdown input, and invalid configuration, with useful source locations.
- Verify a template loads KaTeX CSS for a selected input containing KaTeX math and omits the link for a selected input without it. Exercise mixed-mode composition without claiming automatic page-wide detection.
- Update the reference, math and declared-content guides, Markdown facts documentation, tutorial and glossary if applicable, and changelog. Update the starter site and kit together if they provide a cohesive example; check their reference-site synchronization and affected locales.
- Run the repository's required formatting, Clippy, and test checks.