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

MathML default output for Math #6092

Open
ocket8888 opened this issue Feb 21, 2019 · 16 comments
Open

MathML default output for Math #6092

ocket8888 opened this issue Feb 21, 2019 · 16 comments
Labels
builder:html help wanted markup type:enhancement enhance or introduce a new feature type:proposal a feature suggestion

Comments

@ocket8888
Copy link
Contributor

From the docs:

"Since mathematical notation isn’t natively supported by HTML in any way..."

That's not totally true. MathML is a part of the HTML5 spec, though browser support is spotty to say the least. Since the alternative without installing plugins is just math not working, maybe a good default would be to follow the spec for the output format?

@ocket8888 ocket8888 added the type:enhancement enhance or introduce a new feature label Feb 21, 2019
@tk0miya
Copy link
Member

tk0miya commented Feb 22, 2019

+0; I'm not good at MathML. So I can't say anything about default. But it will become standard of web (in future).

@tk0miya tk0miya added this to the some future version milestone Feb 22, 2019
@TimKam
Copy link
Member

TimKam commented Feb 22, 2019

Considering the lack of MathML support in many browsers, I don't think it makes any sense to set a MathML builder as the default option now. It would be poor design from the side of Sphinx to have a default output option that doesn't work for most users (i.e. people using Google Chrome/Chromium). I suggest updating the docs no and keeping this issue for the time MathML support has made it to Chrome.

@ocket8888
Copy link
Contributor Author

What kills me is that support was in Chrom(ium) but they removed it, citing "security issues" iirc. Apparently as of 2019 there is a team working on slowly re-introducing the support, starting with a core set of features.

@TimKam
Copy link
Member

TimKam commented Feb 25, 2019

Thanks for the info. I'll link to the official Chrome/Chromium trackers here:

@ocket8888
Copy link
Contributor Author

FWIW, the links you posted make mention of support in Firefox, Opera, Safari, and (skeptically) Edge. I know Google has a pretty huge market share, but according to Google itself most other big browsers have MathML support.

@tk0miya
Copy link
Member

tk0miya commented Feb 26, 2019

Either way, we have to implement MathML renderer. An extension like sphinx.ext.mathml is needed to add mathml support. I marked this as "help wanted". So it would be nice if somebody sends us a PR.

@ocket8888
Copy link
Contributor Author

I like to consider myself pretty familiar with MathML itself. If I wasn't such trash at writing parsers, I'd offer to write it.

Unless that's not necessary? Is there any chance Sphinx already creates ASTs for :math: and .. math contents?

@tk0miya
Copy link
Member

tk0miya commented Feb 27, 2019

I like to consider myself pretty familiar with MathML itself. If I wasn't such trash at writing parsers, I'd offer to write it.

Of course yes!

Is there any chance Sphinx already creates ASTs for :math: and .. math contents?

No, it is not parsed. docutils' spec says:

The math_block element contains a block of text in LaTeX math format [1] that is typeset as mathematical notation (display formula). The math_block element is generated during the initial parse from a "math" directive.

So we have user input text in LaTeX math format simply. So we need to write a code for converting LaTeX to MathML.

@ocket8888
Copy link
Contributor Author

That could be very hard/expensive. LaTeX lets you nest basically arbitrary content in a math block with things like \textnormal. I don't think you can do sectioning inside an equation, but afaik that's it. You can embed images or include external files, and most troublingly you can create and use your own macros. To be totally compliant with valid math block LaTeX, I think you'd need to implement a full LaTeX parser.

It'd be easier to support a limited subset like KaTeX, or to allow multiple representations of a single equation based on output type. Of course, that limits the kinds of complex things people sometimes do with math blocks. IMO they shouldn't be done in an equation, but it would be a breaking change.

For my money, I think maybe it'd be better/easier to make a MathML parser - since it's a far simpler language - and translate that into LaTeX equations at build time for LaTeX output. That's a major, breaking change to the directive/role so idk if that's preferable to implementing a LaTeX parser.

@mitya57
Copy link
Contributor

mitya57 commented Mar 6, 2019

So we need to write a code for converting LaTeX to MathML.

Docutils already contains some kind of a converter, however I am not sure how complete it is.

@tk0miya
Copy link
Member

tk0miya commented Mar 6, 2019

Good to know!

@NeroBurner
Copy link

related python project: https://github.com/roniemartinez/latex2mathml

@gmilde
Copy link

gmilde commented Nov 8, 2021

Docutils already contains some kind of a converter, however I am not sure how complete it is.

Docutils' latex2mathml.py got a major upgrade in version 0.18.
See https://docutils.sourceforge.io/docs/ref/rst/mathematics.html for supported LaTeX constructs (this link shows rendering with the HTML+CSS math output format provided by Docutils as an alternative) and https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/test/functional/expected/math_output_mathml.html (a shorter example compiled with the "--math-output=mathml" setting).

It is still provisional/in active development and there are plans to move the math format conversion to a transform in Docutils 1.0.

@bertini97
Copy link

Chrome is planned to support mathML soon: https://chromestatus.com/feature/5240822173794304

@BenjaminAster
Copy link

@bertini97 Chromium actually already supports MathML, so all modern browsers support it now! With the help of tools such as latex2mathml or LaTeXML I guess it should be possible to implement a sphinx.ext.mathml extension for MathML output in Sphinx. Note that Chromium only supports MathML Core, a subset of MathML that should be enough for most MathML use cases.
cc @TimKam

@gmilde
Copy link

gmilde commented Apr 9, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builder:html help wanted markup type:enhancement enhance or introduce a new feature type:proposal a feature suggestion
Projects
None yet
Development

No branches or pull requests

8 participants