Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current mathjax loading on per-page basis breaks math in table of contents #9686

Closed
burp opened this issue Sep 29, 2021 · 3 comments · Fixed by #11597
Closed

Current mathjax loading on per-page basis breaks math in table of contents #9686

burp opened this issue Sep 29, 2021 · 3 comments · Fixed by #11597
Labels
extensions:mathematics The `sphinx.ext.imgmath`, `sphinx.ext.jsmath`, or `sphinx.ext.mathjax` extensions type:bug

Comments

@burp
Copy link

burp commented Sep 29, 2021

Describe the bug

When a page doesn't use mathjax (:math:) it doesn't load mathjax. This breaks titles in the table of contents that do use math.

How to Reproduce

  • perform a sphinx-quickstart
  • add 'sphinx.ext.mathjax' to extensions
  • create otherpage.rst
:math:`1+1=\alpha`
==================

Test page with math in title.

add otherpage to toctree of index.rst.

  • make html

Expected behavior

Math is properly rendered in table of contents of index.html

Your project

n/a

Screenshots

2021-09-29-133959_1084x394_scrot

OS

Linux

Python version

3.9.1

Sphinx version

3.5.1 and also 4.2.0 (probably also newer)

Sphinx extensions

sphinx.ext.mathjax

Extra tools

No response

Additional context

See implementation on per-page loading #6241

@mmcky
Copy link

mmcky commented Feb 17, 2022

@chrisjsewell I have taken a look but can't see anywhere in sphinx if there is a state variable tracking the presence of math on a page. I suspect it might not be flagged anyway if there was given this issue. Do you think the best "technical" way forward here would be a post_transform that parses pages checking for math markup in references and then to ensure MathJax loads on that page?

I came up against this issue in sphinx-exercise when math is used in titles (and the referenced location doesn't render the math due to missing MathJax. This could be fixed at the extension level but given this issue it seems to be a broader problem.

@K20shores
Copy link

For what it's worth, a quick workaround is to include some invisible text:

:math:`\phantom{~}`

@humitos
Copy link
Contributor

humitos commented Jul 26, 2022

I've hit a similar problem some time ago (see #9174). You could set Sphinx.set_html_assets_policy("always") to force Sphinx including assets in all the pages, not only on those ones that are used.

@AA-Turner AA-Turner added this to the some future version milestone Sep 29, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2023
@AA-Turner AA-Turner added the extensions:mathematics The `sphinx.ext.imgmath`, `sphinx.ext.jsmath`, or `sphinx.ext.mathjax` extensions label Jan 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions:mathematics The `sphinx.ext.imgmath`, `sphinx.ext.jsmath`, or `sphinx.ext.mathjax` extensions type:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants