You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I did a typesetting test of the same equation here, and I get:
Whilst there are small differences, the asciimath behaves a lot more like the display latex from what I'm seeing. Is there perhaps a way to get a similar output from the asciimath (I thought it would have something to do with the line height, but I can't get the inline latex output with the squished integrals, from asciimath)
Ah, I forgot that asciimath input always creates a wrapping displaystyle (so the stretchiness and label positions are as in your screenshot). But the content should not be a block-like as you have it - and I can't reproduce that.
Oh this was rendered offline to an SVG - I just gave it a string and got this. I just happened to place the result there with some css. What I'd like to do though, is to get the small integrals with asciimath somehow - because for now, I can only specify inlineTeX to get that kind of output.
AsciiMath has a configuration parameter displaystyle that controls whether it adds the displaystyle="true" wrapper for the math or not. You can set that parameter in the MathJax configuration block before typesetting the math, and so can control the display style of the resulting math output.
Here is an example of how to do that.
#! /usr/bin/env node
varmjAPI=require(".");vardisplaystyle=true;functionsetDisplay(display){if(display!==displaystyle){mjAPI.config({MathJax: {AsciiMath: {displaystyle: display}}});mjAPI.start();displaystyle=display;}}functiongetMath(math,callback){mjAPI.typeset({math: math,format: "AsciiMath",mml: true},function(data){console.log(data.mml);if(callback)callback();});};setDisplay(true);getMath("int x dx",function(){setDisplay(false);getMath("int x dx");});
Note that you have to restart MathJax after making the change (that's that mjAPI.start() call), since the configuration setting is only read by MathJax at startup (AsciiMath processes all math with the same setting).
The output from this script is
<mathxmlns="http://www.w3.org/1998/Math/MathML" alttext="int x dx"><mstyledisplaystyle="true"><mo>∫</mo><mi>x</mi><mrow><mi>d</mi><mi>x</mi></mrow></mstyle></math><mathxmlns="http://www.w3.org/1998/Math/MathML" alttext="int x dx"><mstyle><mo>∫</mo><mi>x</mi><mrow><mi>d</mi><mi>x</mi></mrow></mstyle></math>
which you can see has displaystyle="true" in the first case, but not in the second. So this gives you control over the display setting.
Note that you must use callbacks to make sure that the previous meth is typeset before you change the display setting, since otherwise you will restart MathJax before the previous math is complete, and that can cause problems.
I basically have an always running mathjax server to avoid having to restart mathjax, because it gets very slow on a large page. Wouldn't it make sense to support this in the format section, so we don't need to restart mathjax every time we are thrown an inline equation?
Wouldn't it make sense to support this in the format section
I didn't say it wouldn't. I was just trying to give you a mechanism to do what you asked.
If you have a large page with lots of math, you could send all the inline math first, and then all the display math, and only have to restart once. So you can minimize the restarts.
Okay, after ploughing through the code, I'm not so sure how I would go about adding this functionality. I stumbled across this thread from a few years ago, and I'm not sure how relevant it still is.
In mathjax-node, I can't see any easy way to avoid changing the initial defaults object by restarting mathjax (so I can't make a PR without a fork and commit unless I'm mistaken).
I am able to fix my problem by just having two mathjax instances on my server to handle the different math input possibilities, but I still think this functionality would be useful to implement; so I'd like to figure out how to do it.
Any pointers or suggestions would be most welcome :)
Activity
[-]The ability to specify inline asciimath equations[/-][+]Specify inline asciimath equations[/+]pkra commentedon Oct 17, 2017
AsciiMath only supports inline mode so I'm guessing you are after display-style AsciiMath input.
That would be an upstream feature request for https://github.com/asciimath/asciimathml/ though.
saivan commentedon Oct 18, 2017
So I did a typesetting test of the same equation here, and I get:
Whilst there are small differences, the asciimath behaves a lot more like the display latex from what I'm seeing. Is there perhaps a way to get a similar output from the asciimath (I thought it would have something to do with the line height, but I can't get the inline latex output with the squished integrals, from asciimath)
pkra commentedon Oct 18, 2017
Ah, I forgot that asciimath input always creates a wrapping
displaystyle(so the stretchiness and label positions are as in your screenshot). But the content should not be a block-like as you have it - and I can't reproduce that.Please post a self-contained example.
saivan commentedon Oct 18, 2017
Oh this was rendered offline to an SVG - I just gave it a string and got this. I just happened to place the result there with some css. What I'd like to do though, is to get the small integrals with asciimath somehow - because for now, I can only specify
inlineTeXto get that kind of output.pkra commentedon Oct 19, 2017
Thanks for clarifying.
As before, that's a limitation of asciimath; try filing an issue upstream.
saivan commentedon Oct 19, 2017
Awesome, I'll do that! Thanks @pkra 😄
dpvc commentedon Oct 19, 2017
AsciiMath has a configuration parameter
displaystylethat controls whether it adds thedisplaystyle="true"wrapper for the math or not. You can set that parameter in the MathJax configuration block before typesetting the math, and so can control the display style of the resulting math output.Here is an example of how to do that.
Note that you have to restart MathJax after making the change (that's that
mjAPI.start()call), since the configuration setting is only read by MathJax at startup (AsciiMath processes all math with the same setting).The output from this script is
which you can see has
displaystyle="true"in the first case, but not in the second. So this gives you control over the display setting.Note that you must use callbacks to make sure that the previous meth is typeset before you change the display setting, since otherwise you will restart MathJax before the previous math is complete, and that can cause problems.
saivan commentedon Oct 19, 2017
I basically have an always running mathjax server to avoid having to restart mathjax, because it gets very slow on a large page. Wouldn't it make sense to support this in the format section, so we don't need to restart mathjax every time we are thrown an inline equation?
pkra commentedon Oct 19, 2017
Thanks, @dvpc - I had forgotten about that setting.
I'd be ok with that. @saivan if you want to make a PR, that would facilitate the discussion.
dpvc commentedon Oct 19, 2017
I didn't say it wouldn't. I was just trying to give you a mechanism to do what you asked.
If you have a large page with lots of math, you could send all the inline math first, and then all the display math, and only have to restart once. So you can minimize the restarts.
saivan commentedon Oct 20, 2017
I'll do that, thanks so much for being so helpful guys :)
I really do wish more people used asciimath, they don't know what they are missing out on :P
saivan commentedon Oct 20, 2017
Okay, after ploughing through the code, I'm not so sure how I would go about adding this functionality. I stumbled across this thread from a few years ago, and I'm not sure how relevant it still is.
In mathjax-node, I can't see any easy way to avoid changing the initial defaults object by restarting mathjax (so I can't make a PR without a fork and commit unless I'm mistaken).
I am able to fix my problem by just having two mathjax instances on my server to handle the different math input possibilities, but I still think this functionality would be useful to implement; so I'd like to figure out how to do it.
Any pointers or suggestions would be most welcome :)
saivan commentedon Dec 18, 2017
Was this closed because it is no longer relevant?
pkra commentedon Dec 18, 2017
Sorry. Re-opening.
I had closed this because it was a question about an upstream technology asciimath.
But I now see that we had discussed a PR to do something here.
FWIW, I do think it would be better to raise the issue upstream and find an official way for asciimath to support display equations.
saivan commentedon Dec 19, 2017
I'll just go ahead and post this issue to asciimath then