Add inline LaTeX math support via OMML injection#225
Conversation
Introduces $...$ inline math syntax that converts LaTeX expressions to native PowerPoint math objects (OMML) using MML2OMML.XSL. Activated by the new `mathxsl` metadata option. Falls back to literal text if the option is unset or conversion fails. - pptx_math.py: new module for LaTeX -> MathML -> OMML conversion - paragraph.py: sentinel-based inline math parser and OMML injector - md2pptx: `mathxsl` processing option and math inserter initialisation - docs/user-guide.md: document `mathxsl` option and inline math syntax - README.md: note latex2mathml and lxml as optional dependencies
|
I like this - but I need to check it out in detail. As this requires a fair amount of documentation I intend to address it after your others @troutrot . |
|
Question: Is there a python package to pull in to support all this - whose presence md2pptx can test for (preferably with the level being returned)? |
|
I take it you're suggesting I publish this as a standalone PyPI If so, happy to do it. I checked PyPI and didn't find anything One caveat to flag: the MathML→OMML step uses Microsoft's Will update the PR once |
|
Actually we need md2pptx more actively involved: The idea is to have the user code something in a md2pptx input file that creates the OMML. Your code probably does that. All I was asking was if it used a python shim to get to the underlying code. And does that code run on all architectures python-pptx runs on? |
|
Again, don't take this as a negative but we will need to document this deviation from standard markdown. There is a section for that in the User Guide. If there IS a dialect of Markdown that supports this let me know - and I can nod to it when documenting it as a deviation. I also need to see how this renders. Can you post a screenshot? |
|
Thanks for the clarification! Let me address your points directly:
Regarding architectures: Yes, the Python code itself runs on all architectures that python-pptx supports (Windows, Mac, Linux). However, there is one caveat: the MathML-to-OMML conversion currently requires the MML2OMML.XSL stylesheet. Since this file ships with Microsoft Office, Mac or Linux users would need to manually supply this file and specify its path in the markdown header (e.g., mathxsl: /path/to/MML2OMML.XSL).
GitHub Flavored Markdown (GFM) (via MathJax) Jupyter Notebooks Pandoc Markdown Obsidian / Notion
Could you please wait until tomorrow for the screenshot? I am currently working on a Mac that doesn't have the MML2OMML.XSL file, and I don't have the previously generated PPTX file at hand. I tested the code on another machine where the environment is fully set up. I will have access to that machine tomorrow, so I will generate the file and post the screenshot here as soon as I can! Let me know if the current dependency setup (requiring the XSL file) is acceptable for now. |
|
Thanks for all this. Please don't touch the User Guide - particularly as I am currently editing it. And it needs care in getting from .mdp to .md plus .log and then to .html. (mdpre is an important step in this.) |
|
I'm also bothered by a simple Would something like Also what would an incantation that put the equation on its own line look like? And would we like some kind of equation reference number? (Perhaps these are stretch objectives.) |
|
Thanks for raising this, Martin! You make a great point about a simple $ colliding with currency (like "costs $5 to $10"). To avoid custom tags, there are two established Markdown standards to handle this safely. I can implement whichever you prefer: Option 1: Spacing Rules (Jupyter / Pandoc) Option 2: Backticks (GitHub / GitLab) Which inline math approach do you prefer for md2pptx? Regarding your other questions: Equations on their own line (\$\$...\$\$): This is the standard for block math. I haven't implemented this in the current PR yet, but I plan to add it! Equation reference numbers: As you guessed, true cross-referencing (linking) is definitely a stretch objective. As for simply displaying an equation number (like using \tag{1}), I haven't fully verified how the OMML conversion handles that specific layout yet, so I will investigate and test it! Let me know your thoughts on the inline syntax! |
|
Just to answer the "equation in a block" question I have used the following for "alien syntax" elsewhere in md2pptx: Triple backtick on a line with eg "mathml" as the second word on the line. Ending with another triple backtick line. A slightly weird way of doing equation numbers might be a third parameter so... where If the inline equation use case isn't wanted the above would be all that needs implementing. |
|
You are absolutely right. After thinking about it, I completely agree that trying to parse inline math can introduce unwanted errors and edge cases. Keeping the parser safe and simple should be the top priority. As a compromise for the future: Let's leave the inline math support (like the GitHub-style \$`...`\$") and the \$\$...\$\$ block syntax as a future enhancement or a separate PR down the road. For now, getting this solid code block implementation merged is a great first step. |
|
Great. So what syntax are you going for? Triple backtick with A nice benefit of that is you get multiple lines supported. I assume this will add XML into the tree, rather than a rendered image. The advantage of the latter is controllable dimensions. |
|
Thanks for the feedback.
I will update the PR with this code block implementation in the coming days! |
|
I have no problem with I hope you are able to make the generated stuff fit within a rendering rectangle - as that is the primitive that enables multiple blocks on a slide. (Or even one without colliding with a title.) |
|
|
One thought that occurred to me:
|


Summary
$...$inline math syntax that renders as native PowerPoint math objects (OMML)mathxslmetadata option specifies the path toMML2OMML.XSL(included with Microsoft Office)pptx_math.pymodule handles LaTeX → MathML → OMML conversion vialatex2mathmlandlxml$...$text if the option is unset or conversion failsUsage
Add to your Markdown metadata:
Then use inline math in bullet text:
Requirements
MML2OMML.XSLis included with a local Microsoft Office installation.