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

Adapt ForceEquations for Sphinx 8.2 #822

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AA-Turner
Copy link

@mgeier
Copy link
Member

mgeier commented Feb 17, 2025

Thanks for this PR!

This works in most cases, but sadly not in all.

The problem is that there are multiple situations where math/LaTeX stuff can appear:

  • Markdown cells, inline math
  • Markdown cells, block math
  • Code output cells

All three are handled separately and it's quite fiddly.

I tested it in #824 and this shows the problem with Markdown block math: https://nbsphinx--824.org.readthedocs.build/en/824/a-markdown-file-block.html

I don't know yet why that happens (I've actually expected problems with Markdown inline math, but that seems to work fine), and I have limited time to investigate ...

@AA-Turner
Copy link
Author

I don't know yet why that happens (I've actually expected problems with Markdown inline math, but that seems to work fine), and I have limited time to investigate ...

The new behaviour includes MathJax if a math or math_block node is traversed in the document. Does the custom markdown parsing here construct math nodes?

A

@AA-Turner
Copy link
Author

Alternatively, you could call app.set_html_assets_policy('always'), which forcibly includes the mathjax script in every page.

A

@mgeier
Copy link
Member

mgeier commented Feb 18, 2025

The new behaviour includes MathJax if a math or math_block node is traversed in the document. Does the custom markdown parsing here construct math nodes?

It turns out that the block math (that doesn't work correctly) ends up in custom `:nbsphinx-math:`...` roles, which I've defined there:

.. role:: nbsphinx-math(raw)
:format: latex + html
:class: math

How can I make those be recognized as math?

Alternatively, you could call app.set_html_assets_policy('always'), which forcibly includes the mathjax script in every page.

OK, thanks, I think I can use this as work-around (slightly worse than the current work-around) in case we don't find a better solution.

env = self.document.settings.env
if env.config.nbsphinx_assume_equations:
env.get_domain('math').data['has_equations'][env.docname] = True
if sphinx.version_info[:2] >= (8, 2):
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity: Why are you putting [:2] there?
Shouldn't it behave identically when you drop it?

This was referenced Mar 3, 2025
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.

2 participants