[AsciiMath] Linig up decimals with simple addition equations

106 views
Skip to first unread message

thesh...@gmail.com

unread,
Nov 2, 2014, 12:28:27 PM11/2/14
to mathja...@googlegroups.com
I am new to MathJax and have been humbled by the quick help I have received to get me on my way. I have been able to manhandle fairly complex equations thanks to your help. Interestingly, I have stumbled on what seems like the simplest of equations. I am trying to illustrate an addition equation while lining up the decimals. Can someone help me with the syntax using AsciiMath?

I am trying to get +98.005 + 3.0021,  to line up the decimals with the sum of 101.0071

Thanks, again for all the help!


Davide P. Cervone

unread,
Nov 2, 2014, 3:16:58 PM11/2/14
to mathja...@googlegroups.com
The AsciiMath input language doesn't really give you enough control to handle the spacing needs for something like this.  One thing you need is the ability to have "invisible" material so that you can insert spaces that are the same size as other parts of the equation.  You can add such a command using

<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("AsciiMath Jax Config",function () {
  var AM = MathJax.InputJax.AsciiMath.AM;
  AM.symbols.push(
    {input:"phantom", tag:"mphantom", output:"phantom", tex:null, ttype:AM.TOKEN.UNARY}
  );
});
</script>

before the script that loads MathJax.js.  This makes `phantom(...)` make an invisible version of its argument.

With that, you can do something horrible like this:

`{:(phantom{text{+}0}98.005),
   (text{+}phantom{00}3.0021):} 
   /
   (phantom{text{+}}101.0071)`

which will get you something like what you are looking for.  But the spacing isn't perfect, and it is hard to work with in general.  You really would like to be able to make arrays that are right-fistified to make this easier (this one is left-justified), and be able to insert horizontal rules rather than use fractions to do it.

It is much easier to do this in TeX than in AsciiMath.  Depending on the configuration file you are loading, you may already be able to use both in the same document.  In that case, then

$$\begin{array}{r}
98.005\phantom{0}\\[-2pt]
+\quad 3.0021\\
\hline
101.0071
\end{array}$$

Might be an easier way to do it.  Here, the "\begin{array}{r}...\end{array}" is an array that has one right-justified column.  The entries are the numbers that you have, and we use \phantom{0} to make the blank space at the right of the first number (all the digits have the same width, so it doesn't matter what digit you use).  The "\hline" is the horizontal line for the addition, and the "\\" represents the ends of the lines of the array.  The "[-2pt]" brings the two lines a little closer together, which helps the vertical spacing between the first two numbers.

I think you will find the TeX forms easier to work with in the long run.

Davide



--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

thesh...@gmail.com

unread,
Nov 3, 2014, 9:33:11 AM11/3/14
to mathja...@googlegroups.com, dp...@union.edu
Thanks, once again, Davide! Really can't thank you enough! That did the trick.
Message has been deleted

Shae Waters

unread,
Nov 5, 2014, 11:43:01 AM11/5/14
to mathja...@googlegroups.com, dp...@union.edu
Hi Davide,
So, adding the phantom script seemed to work. That is, until I checked the dreaded IE. I am using IE 11. IE is rendering all the other equations properly, but it is not rendering the phantom "class" you helped me create. Is there any known issues that you know of with IE? I have attached a snapshot from Firefox which works correctly and another snapshot from IE which displays incorrectly. Thanks, again for all of your help!

Shae


On Sunday, November 2, 2014 3:16:58 PM UTC-5, Davide P. Cervone wrote:
correct.png
incorrect.png

Peter Krautzberger

unread,
Nov 6, 2014, 5:42:35 AM11/6/14
to mathja...@googlegroups.com, Davide P. Cervone
Hi Shae,

Is there any known issues that you know of with IE?

Thanks for the feedback. That looks like a bug in asciimathml. The 'to' in `phantom' is interpreted as the standard "to" macro, breaking the phantom macro. I've filed an issue on the asciimath repo https://github.com/mathjax/asciimathml/issues/28.

All the content has to be Accessibility-friendly [...]

For accessibility, generally speaking you should deliver MathML which is the standard format that math accessibility tools understand (ChromeVox, VoiceOver, NVDA, MathPlayer-driven tools likes Texthelp, JAWS). You can additionally create speech text by pre-processing with MathJax-node which includes Volker Sorge's speech-rule-engine (an isolated and expanded ChromeVox engine). 

and we are allowing the user to have a great deal of customization. [...]

MathJax can extend any input on the fly. But TeX has more built-in functionality that a user can use on the fly (\newcommand etc).

Our system is fully responsive (adapts itself to whatever screen size/device the user has) [...]

Check out our linebreaking options.

I was wondering if you could help me understand why someone might choose AsciiMath over Tex?

AsciiMath is designed to be simpler, styled after the input of graphing calculators and other traditions of ascii notation. It was created by Peter Jipsen to match the needs of US college students.  By design, asciimath is more limited than MathJax's TeX/LaTeX input (let alone real TeX/LaTeX). 

Which one is more suitable is really a question of balance and content strategy. For school-level math, I would guess that asciimath should be sufficient but you already ran into trouble so clearly some things are not in scope.

There is also a more complicated underlying problem when it comes to the specific problem of aligning at decimals. MathML provides constructions that fit via the so-called Elementary Math elements. However, MathJax does not yet support these on the output end (and therefore there are no input macros that would help create them). Implementing these is relatively high up in our backlog but it's a question of resources.

is one more efficient than the other with rendering? [...]

There should be virtually no difference in rendering speed between any of the inputs because MathJax is modular: input is converted to MathML and output generated from MathML. The input conversion is very simple and fast, the output is the bottleneck.

Render times with a large volume of users is a big concern to us [...]

I'm not sure I understand this concern. MathJax rendering happens client-side so it should be independent of the number of users (but will naturally depend on the number of equations). How do you see the number of users affecting client-side rendering speed?

Regards,
Peter.

Davide P. Cervone

unread,
Nov 6, 2014, 6:34:58 AM11/6/14
to Shae Waters, mathja...@googlegroups.com
[The last few messages from this conversation didn't go to the list (I forgot to reply to all), so I'm forwarding the solution, given below]

I am wondering if you have put the config script BEFORE the script that loads MathJax.js or AFTER it?  It needs to come BEFORE it (as I mentioned in the message).  If it is after, it may not be available to MathJax when MathJax loads, and so it will not see your configuration.  My recollection is that IE is one of those for which that is an issue.  Make sure the configuration script comes before the script that loads MathJax.js.

Davide

Gosh, I must have blew over that EVER SO IMPORTANT detail. LoL. That was the problem. Once I reordered the scripts correctly, it worked just fine. Thanks again for taking so much time to educate me. You have been a lifesaver as I have been a bit pressed to demo some of this Algebra course. I really, genuinely, appreciate it!

Shae



<correct.png><incorrect.png>

Reply all
Reply to author
Forward
0 new messages