Skip to content

Fix MathJax equations not re-rendering after instant navigation - #543

Merged
aarmey merged 2 commits into
mainfrom
fix/docs-equation-rendering
Sep 9, 2026
Merged

Fix MathJax equations not re-rendering after instant navigation#543
aarmey merged 2 commits into
mainfrom
fix/docs-equation-rendering

Conversation

@aarmey

@aarmey aarmey commented Sep 9, 2026

Copy link
Copy Markdown
Member

Root cause

mkdocs.yml already had pymdownx.arithmatex (with generic: true) enabled and included the MathJax CDN script via extra_javascript, so equations render correctly on a page's first load.

However, the theme also enables navigation.instant, which swaps page content client-side (fetch + DOM replace) instead of doing a full page load when navigating between docs pages. MathJax's default runtime only auto-typesets once, on the initial page load — it has no way to know that navigation.instant swapped in new <span class="arithmatex">…</span> markup on a subsequent page, so any docs page reached via in-app navigation showed raw $...$ / $$...$$ LaTeX source instead of rendered math.

This is a documented gotcha for MathJax + mkdocs-material's instant navigation feature: MathJax needs to be explicitly re-typeset via a document$.subscribe(...) hook (mkdocs-material's instant-navigation event) on every page swap.

Fix

  • Added docs/javascripts/mathjax.js, which:
    • configures MathJax's tex.inlineMath/tex.displayMath delimiters and options.processHtmlClass to match what pymdownx.arithmatex (generic mode) emits
    • subscribes to document$ and clears/re-typesets MathJax on every instant-navigation page swap
  • Added this file to extra_javascript in mkdocs.yml, loaded before the polyfill and MathJax CDN scripts (so window.MathJax config is set before the MathJax runtime script parses it).

Test plan

  • uv sync --group docs
  • uv run mkdocs build --strict completes with no errors/warnings
  • Verified built HTML (site/component_ordering/index.html, site/tutorial/index.html, etc.) contains <span class="arithmatex"> spans from equations in docs/component_ordering.md, docs/tutorial.md, and docs/unequal_cell_counts.md
  • Verified docs/javascripts/mathjax.js is emitted in the page <head> before the polyfill/MathJax CDN <script> tags, in the correct order for MathJax to pick up the config
  • Confirmed no other files were touched (no pyproject.toml/dependency changes — that's tracked separately in scrise.plotting.stability imports tlviz, which is not declared as a dependency #541)

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

🤖 Generated with Claude Code

aarmey and others added 2 commits September 8, 2026 19:48
scrise/plotting/__init__.py unconditionally imports stability.py, which
imports tlviz.factor_tools. tlviz was only listed in the "analysis"
dependency group, not in the package's core dependencies, so a plain
`pip install scRISE` followed by `import scrise.plotting` raised
ModuleNotFoundError. Add tlviz to core dependencies, matching the
existing precedent of matplotlib/seaborn/hdf5plugin being both core
deps and members of the analysis group, and regenerate uv.lock.

Fixes #541

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The theme enables navigation.instant, which swaps page content via
client-side fetch instead of a full page load. MathJax's default
startup only typesets once on initial load, so pymdownx.arithmatex
equations on any page reached via instant navigation stayed as raw
LaTeX source instead of rendering.

Add docs/javascripts/mathjax.js, which configures MathJax's tex
delimiters/options to match arithmatex's generic mode and subscribes
to document$ (mkdocs-material's instant-navigation event) to clear
and re-typeset MathJax on every page swap, per mkdocs-material's
documented MathJax + instant navigation setup. Load it before the
polyfill/MathJax CDN scripts in extra_javascript.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@aarmey
aarmey merged commit 717566a into main Sep 9, 2026
6 checks passed
@aarmey
aarmey deleted the fix/docs-equation-rendering branch September 9, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant