6

Is there a way to format long division in MathJax so it looks like this:

     125     (Explanations)
   4)500
     4        (4 ×  1 = 4)
     10       (5 -  4 = 1)
      8       (4 ×  2 = 8)
      20      (10 -  8 = 2)
      20      (4 ×  5 = 20)
       0      (20 - 20 = 0)

but obviously correctly formatted?

Jamie Twells
  • 1,924
  • 4
  • 26
  • 56
  • To be honest, simply the symbol )‾‾‾‾‾‾ in MathJax, and nothing else would be nice. Similar to how I type \sqrt{} and the square root symbol stretches over the whole number. – Jamie Twells Apr 04 '14 at 17:30

2 Answers2

19

Here is a modification of Werner's answer that gets you what you want. It uses MathJax's enclose extension to insert a MathML <menclose> element that handles the long-division symbol.

$$
\require{enclose}
\begin{array}{rll}
    125 && \hbox{(Explanations)} \\[-3pt]
   4 \enclose{longdiv}{500}\kern-.2ex \\[-3pt]
      \underline{4\phantom{00}} && \hbox{($4 \times 1 = 4$)} \\[-3pt]
      10\phantom{0} && \hbox{($5 - 4 = 1$)} \\[-3pt]
      \underline{\phantom{0}8\phantom{0}} && \hbox{($4 \times 2 = 8$)} \\[-3pt]
      \phantom{0}20 && \hbox{($10 - 8 = 2$)} \\[-3pt]
      \underline{\phantom{0}20} && \hbox{($4 \times 5 = 20$)} \\[-3pt]
      \phantom{00}0
  \end{array}
$$

The result is

enter image description here

Davide Cervone
  • 11,211
  • 1
  • 28
  • 48
  • That's very good. It's a shame the code's so ugly, but thank you. I'm not sure which answer to accept since this is an improvement on Werner's answer. – Jamie Twells Apr 04 '14 at 19:35
  • 1
    Yes, the code is ugly, but this answer typesets so much better than the other, and comes with the official stamp of approval of the MathJax author. I think this should be the accepted answer. – Nathan Jun 08 '16 at 16:53
5

You can use

$$
  \begin{array}{rl}
    \underline{125} & \hbox{(Explanations)} \\[-5pt]
    4 | 500 \\
      \underline{4\phantom{00}} & \hbox{($4 \times 1 = 4$)} \\
      10\phantom{0} & \hbox{($5 - 4 = 1$)} \\
      \underline{\phantom{0}8\phantom{0}} & \hbox{($4 \times 2 = 8$)} \\
      \phantom{0}20 & \hbox{($10 - 8 = 2$)} \\
      \underline{\phantom{0}20} & \hbox{($4 \times 5 = 20$)} \\
      \phantom{00}0
  \end{array}
$$

This is how it renders on Math.SE:

enter image description here

Werner
  • 14,324
  • 7
  • 55
  • 77
  • Hmm... Ok, I suppose that's as close as I'm going to get. I'm not too worried about the `(Explanations)` bit, since I can just write that in later, but the actual symbol was what I was after. I assume an official )‾‾‾‾ symbol doesn't exist? (But thank you for your input, that's very helpful) – Jamie Twells Apr 04 '14 at 17:36