Skip to content

Use Fira Math for matplotlib math rendering via custom fontset#599

Merged
nikosavola merged 3 commits into
mainfrom
copilot/change-math-font-to-fira-math
May 12, 2026
Merged

Use Fira Math for matplotlib math rendering via custom fontset#599
nikosavola merged 3 commits into
mainfrom
copilot/change-math-font-to-fira-math

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

  • Diagnose why math isn't rendering: mathjax4_config overwrites Sphinx's default window.MathJax = {options: {processHtmlClass: ...}} needed for math inside mathjax_ignore sections
  • Fix: include processHtmlClass in mathjax4_config so the overwrite still contains the required setting
  • Verify fix: test build confirms both options now appear in the final window.MathJax assignment
  • Pre-commit hooks pass

Summary by Sourcery

Switch documentation math rendering to MathJax with Fira Math and ensure math is correctly processed in Sphinx HTML output.

Enhancements:

  • Configure MathJax via sphinx.ext.mathjax and mathjax4_config so Sphinx HTML math is processed even inside mathjax_ignore sections.
  • Update Matplotlib style configuration to use the Fira Math font for math rendering in plots.

Build:

  • Add Fira Math font download to the Makefile font installation target used for docs builds.

CI:

  • Extend the GitHub Pages workflow to download and install the Fira Math font for documentation builds.

Chores:

  • Remove the sphinxcontrib-katex dependency from the docs extra and Sphinx configuration.

@github-actions github-actions Bot added documentation Improvements or additions to documentation ci Pull requests that update GitHub Actions code labels May 12, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 12, 2026

Reviewer's Guide

Switches Sphinx math rendering from KaTeX to MathJax with a custom MathJax config to use the Fira Math font and ensure math inside MyST-generated mathjax_ignore sections is still processed, and wires Fira Math into both CI and local doc font installation.

File-Level Changes

Change Details Files
Replace KaTeX with Sphinx MathJax and configure MathJax to use Fira Math while preserving Sphinx’s required processHtmlClass so math in mathjax_ignore sections renders correctly.
  • Swap sphinxcontrib.katex for sphinx.ext.mathjax in the Sphinx extension list.
  • Remove sphinxcontrib-katex from the docs extra dependencies in pyproject.toml.
  • Add a mathjax4_config dictionary that sets options.processHtmlClass to the regex expected by Sphinx and configures output.font to mathjax-fira, with comments explaining the double-assignment behavior of window.MathJax and the MyST mathjax_ignore interaction.
docs/conf.py
pyproject.toml
Ensure the Fira Math font is available in both CI and local documentation builds so Matplotlib can render math with the configured font.
  • Introduce a FIRA_MATH_URL environment variable/Makefile variable pointing to the FiraMath-Regular.otf release asset.
  • Extend the GitHub Pages workflow’s font installation step to download FiraMath-Regular.otf into the temporary font directory before copying into /usr/local/share/fonts/qpdk.
  • Extend the Makefile install-doc-fonts target to download FiraMath-Regular.otf into the temp font directory alongside existing fonts.
.github/workflows/pages.yml
Makefile

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file python Pull requests that update python code labels May 12, 2026
Copilot AI requested a review from nikosavola May 12, 2026 11:59
@nikosavola nikosavola marked this pull request as ready for review May 12, 2026 15:47
@nikosavola nikosavola added this pull request to the merge queue May 12, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The Fira Math download URL is duplicated in both the GitHub Actions workflow and the Makefile; consider centralizing this versioned URL in a single place (or deriving one from the other) to avoid drift on future upgrades.
  • Since mathjax4_config fully overwrites the earlier window.MathJax assignment, consider explicitly mirroring any other Sphinx defaults you rely on (beyond processHtmlClass) or adding a brief comment noting that additional MathJax options must be kept in sync with Sphinx’ defaults if they change.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The Fira Math download URL is duplicated in both the GitHub Actions workflow and the Makefile; consider centralizing this versioned URL in a single place (or deriving one from the other) to avoid drift on future upgrades.
- Since `mathjax4_config` fully overwrites the earlier `window.MathJax` assignment, consider explicitly mirroring any other Sphinx defaults you rely on (beyond `processHtmlClass`) or adding a brief comment noting that additional MathJax options must be kept in sync with Sphinx’ defaults if they change.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Merged via the queue into main with commit f931db2 May 12, 2026
29 checks passed
@nikosavola nikosavola deleted the copilot/change-math-font-to-fira-math branch May 12, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Pull requests that update GitHub Actions code dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants