asciimath / asciimathml

A new home for asciimathml
http://asciimath.org/
MIT License
958 stars 184 forks source link

Inline Asciimath #83

Open saivan opened 6 years ago

saivan commented 6 years ago

Mathjax-node has support for asciimath, but it seems that asciimath isn't able to be used to produce inline equations, you can read about the issue here, they asked to raise the issue upstream, so I am asking:

Is there a mechanism to support an inline display mode with asciimath?

drlippman commented 6 years ago

There has never been in AsciiMath a per-equation way to enable/disable displaystyle.

As noted in that thread, AsciiMathML has a configuration option for whether the whole page should be rendered using displaystyle or not, and MathJax does expose that variable so it can be set via the MathJax config object. Right now the variable is only read once on Init. Perhaps what's needed is some externally exposed function in the AsciiMath jax to change the value of displaystyle, so your code could adjust the setting before asking for the expression to be rendered.

Or, in the Translate function in the AsciiMath input jax, it could look for a mode=____ in the script type, like the TeX input jax does on line 2232, then temporary set ASCIIMATH.config.displaystyle based on that. Then in MathJax-node you could add a new "TYPES" that would add that mode into the script, like it does for display TeX. For backwards compatibility, it'd be best to keep display mode the default.

Those changes would be MathJax and MathJax-Node changes, though. If there's something you think needs to happen in AM itself, let me know.

drlippman commented 6 years ago

Just to flush out my thoughts above (totally untested, of course):

In MathJax-node you'd add a new TYPES like "inline-AsciiMath": "asciimath; mode=inline"

Then in the MathJax AM input jax, you'd add a line a like: var forceinline = (script.type.replace(/\n/g," ").match(/(;|\s|\n)mode\s*=\s*inline(;|\s|\n|$)/) != null);

then before the parseMath call, if (forceinline) { olddisplaystyle = ASCIIMATH.config.displaystyle; ASCIIMATH.config.displaystyle = false;}

and after the parseMath call, if (forceinline) {ASCIIMATH.config.displaystyle = olddisplaystyle;}