Skip to content

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?

@mgeier
Copy link
Member

mgeier commented May 1, 2025

In #836, I have added example equations to the docs that would show (if rebased) that this PR doesn't work for block math.

@gabalafou
Copy link
Contributor

I created an alternative solution:

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.

3 participants