mathjax / MathJax-demos-web

A repository with examples using mathjax-v3
https://mathjax.github.io/MathJax-demos-web
Apache License 2.0
256 stars 106 forks source link

Can you provide more js example code for mathjax3? Especially mml3. #49

Closed ykla closed 4 months ago

ykla commented 5 months ago

I can hardly find any open source implementations or usage examples of mml3 on github. I'm currently simply merging two people's code to implement as a plugin for Markdown it to enable the use of mathjax for Markdown in a variety of places. but I'm expecting to use mml3 for the output, and at the moment this code can only be used with the normal output/chtml and svg outputs, but the code for those outputs is not reproducible Currently, the code only uses normal output/chtml and svg output, but the code for these outputs is not reproducible. Please forgive me for not being much of a programmer. https://github.com/taophilosophy/markdown-it-mathjax3/tree/26fd2dd37036c148d634eb89a646108a77e0b4ce Currently it works fine and can only output svg and chtml code located. All other updated code is unavailable for testing, and I don't know exactly how to write it. Thank you very much.

dpvc commented 5 months ago

I'm expecting to use mml3 for the output, and at the moment this code can only be used with the normal output/chtml and svg outputs

Yes, MathJax v3 and v4 only produce SVG or CHTML output, not MathML directly.

but the code for those outputs is not reproducible

I'm not sure what that means. Can you say more about what you re trying to suggest, here?

If you are looking to output MathML, there is an example of a replacement for the NativeMML output from v2. It is an example using the MathJax-components infrastructure, but you are using the direct-module approach, so should need to modify it to that setting. In particular, you would need to conclude the renderActions configuration options in your document options when you create the MathJax document with mathjax.document().

I haven't gone through your code very carefully, but it looks like your renderMath() function is called for every math expression, and that you create a new MathJax document each time. You could probably just set that up once and use it for all the math (that would allow you to use \newcommand in one expression and have it affect later expressions, for example, and would allow you to use \label and \ref. It seems you are calling RegisterHTMLHandler every time, which is not necessary (you only need to register the handler once, and you only need to create the liteAdaptor() once. However, if this is running in a browser, you don't want to use the liteAdaptor, but rather the browserAdaptor. That way you don't have to include all the LiteDOM code in your app.

Finally, you might find the MathJax node demos repository to be useful, in particular the direct examples, since you are making direct calls to the MathJax modules. See, for example, the tex2mml example.