long division

315 views
Skip to first unread message

David Carlisle

unread,
Oct 22, 2012, 7:33:46 AM10/22/12
to mathja...@googlegroups.com
This is perhaps a feature request for some future version....


I got asked the other day for information about systems that generate
the MathML3 long division markup. Since I didn't know of any I
produced the following over the weekend.
I'm a bit worried about posting it here as Davide will probably die
laughing at my JavaScript but anyway....

http://dpcarlisle.blogspot.co.uk/2012/10/mathml-long-division.html

The form there takes input from two text boxes but it could just as
easily be something more TeX-ike like

\longdivision[lefttop]{567}{17}

to generate

<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mlongdiv>
<mn>17</mn>
<mn>33</mn>
<mn>567</mn>
<msgroup position='1' shift='-1'>
<msgroup>
<mn>51</mn>
<msline length='2'/>
</msgroup>
<msgroup>
<mn>57</mn>
<mn>51</mn>
<msline length='3'/>
</msgroup>
<msgroup position='1'>
<mn>6</mn>
</msgroup>
</msgroup>
</mlongdiv>
</math>

Of course it would only make sense in a mathjax context if the
resulting mlongdiv could be rendered in more than just IE/MathPlayer
which is probably more work than I put in to generate the layout
description, but I thought I'd float a feature request anyway.

David

Marc Grober

unread,
Oct 22, 2012, 11:05:03 AM10/22/12
to mathja...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I thought you had produced a MathJax implementation for longdiv or
polynom and raced to the URL ;-)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.16 (Darwin)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQEcBAEBAgAGBQJQhWCfAAoJEMCi9wxDaNqEDUoH/19G94gNoYnTJuvQNw7uwGlv
xKq2LEQmMpkErd3Zd49WN+i/M3aPFZMPs72e6MzrmBwsmEqlOB5mcA9lF5U1/ofD
YfUIMvAeADn619N67bBq/Y4eNmHVcImftsYXLoYRyB/Ds5yJvOs/aZ/CBFcOCMbH
zwpywQJzSoheCKBTKIpSkwj6KeyaAZR1bTfkUc+Tz4sNVRVDjA/NzHA4dRBaGF7C
Y+LswjyvuZGfgR8PFO3u6Mh6OyuKP+VFbwpwcLns7FFl78Mem08JZ0IWBYf7TSD2
ly8wJvLvnUQv6pD9MidwKUod2kL4dnMJabjTP1RH3BtJwR238XTXeeXaw9C0U2k=
=qKfa
-----END PGP SIGNATURE-----

David Carlisle

unread,
Oct 22, 2012, 7:42:13 PM10/22/12
to mathja...@googlegroups.com, marc....@gmail.com
On 22 October 2012 16:05, Marc Grober <marc....@gmail.com> wrote:

> I thought you had produced a MathJax implementation for longdiv or
> polynom and raced to the URL ;-)



well...

That was producing MathML3 mlongdiv which mathjax doesn't like much,
but it was also producing a plain text ascii art representation. With
a bit of encouragement that can be annotated with latex commands
making it into a array-and-underline combination that doesn't have the
accessibility advantages of mlongdiv but does have the advantage of
working with mathml2 systems such as mathjax.

Something like:

\def\?{\phantom{0}}
\begin{array}{r@{}l}
&\?\?\?37986704\\
325\hspace{.2em})\hspace{-.2em}\overline{\strut\hspace{1em}}\hspace{-1.5em}&\overline{\strut12345678912}\\
&\underline{\?975}\\
&\?2595\\
&\?\underline{2275}\\
&\?\?3206\\
&\?\?\underline{2925}\\
&\?\?\?2817\\
&\?\?\?\underline{2600}\\
&\?\?\?\?2178\\
&\?\?\?\?\underline{1950}\\
&\?\?\?\?\?2289\\
&\?\?\?\?\?\underline{2275}\\
&\?\?\?\?\?\?\?141\\
&\?\?\?\?\?\?\underline{\?\?\?0}\\
&\?\?\?\?\?\?\?1412\\
&\?\?\?\?\?\?\?\underline{1300}\\
&\?\?\?\?\?\?\?\?112
\end{array}

Then I just had to get my head round some of the examples Davide has
posted from time to time on how to hook a JavaScript function as the
back end for a new tex macro \longdiv and:


http://html5mathml.googlecode.com/svn/trunk/longdiv-mj-mml2.html

The body of which is simply

<body>


<p>\longdiv{12345678912}{325}</p>
$$
\longdiv{12345678912}{325}
$$
<p>\longdiv{534}{17}</p>
$$
\longdiv{534}{17}
$$
</body>

with mathjax rendering the displays as long division.

It isn't quite right yet (column alignment is out by one in some cases
but that can't be that hard to fix when I'm next awake)

David

--
http://dpcarlisle.blogspot.com/
Reply all
Reply to author
Forward
0 new messages