18

I'm trying to convert my equations I make in Microsoft Office Word 2013 to LaTeX because I would like to post my equations I make in word at math.stackexchange.com.

I'm able to convert it to MathML. But if I post it here it doesn't really look like it should be. Is it possible to convert MathML to LaTeX?

<math xmlns:mml="http://www.w3.org/1998/Math/MathML">
    <mtable>
        <mtr>
            <mtd>
                <mrow>
                    <maligngroup/>
                    <mi>a</mi>
                    <mo>&lt;</mo>
                    <mi>x</mi>
                    <mo>&lt;</mo>
                    <mi>a</mi>
                    <mo>+</mo>
                    <msub>
                        <mrow>
                            <mi>δ</mi>
                        </mrow>
                        <mrow>
                            <mn>1</mn>
                        </mrow>
                    </msub>
                    <malignmark/>
                    <mo>⇒</mo>
                    <mfenced open="|" close="|" separators="|">
                        <mrow>
                            <msub>
                                <mrow>
                                    <mi>f</mi>
                                </mrow>
                                <mrow>
                                    <mn>1</mn>
                                </mrow>
                            </msub>
                            <mfenced separators="|">
                                <mrow>
                                    <mi>x</mi>
                                </mrow>
                            </mfenced>
                            <mo>-</mo>
                            <msub>
                                <mrow>
                                    <mi>L</mi>
                                </mrow>
                                <mrow>
                                    <mn>1</mn>
                                </mrow>
                            </msub>
                        </mrow>
                    </mfenced>
                    <mo>&lt;</mo>
                    <mfrac>
                        <mrow>
                            <msub>
                                <mrow>
                                    <mi>L</mi>
                                </mrow>
                                <mrow>
                                    <mn>1</mn>
                                </mrow>
                            </msub>
                            <mo>-</mo>
                            <msub>
                                <mrow>
                                    <mi>L</mi>
                                </mrow>
                                <mrow>
                                    <mn>2</mn>
                                </mrow>
                            </msub>
                        </mrow>
                        <mrow>
                            <mn>2</mn>
                        </mrow>
                    </mfrac>
                </mrow>
            </mtd>
        </mtr>
        <mtr>
            <mtd>
                <mrow>
                    <maligngroup/>
                    <malignmark/>
                    <mo>⇒</mo>
                    <msub>
                        <mrow>
                            <mi>L</mi>
                        </mrow>
                        <mrow>
                            <mn>1</mn>
                        </mrow>
                    </msub>
                    <mo>-</mo>
                    <mfrac>
                        <mrow>
                            <msub>
                                <mrow>
                                    <mi>L</mi>
                                </mrow>
                                <mrow>
                                    <mn>1</mn>
                                </mrow>
                            </msub>
                            <mo>-</mo>
                            <msub>
                                <mrow>
                                    <mi>L</mi>
                                </mrow>
                                <mrow>
                                    <mn>2</mn>
                                </mrow>
                            </msub>
                        </mrow>
                        <mrow>
                            <mn>2</mn>
                        </mrow>
                    </mfrac>
                    <mo>&lt;</mo>
                    <msub>
                        <mrow>
                            <mi>f</mi>
                        </mrow>
                        <mrow>
                            <mn>1</mn>
                        </mrow>
                    </msub>
                    <mfenced separators="|">
                        <mrow>
                            <mi>x</mi>
                        </mrow>
                    </mfenced>
                    <mo>&lt;</mo>
                    <msub>
                        <mrow>
                            <mi>L</mi>
                        </mrow>
                        <mrow>
                            <mn>1</mn>
                        </mrow>
                    </msub>
                    <mo>+</mo>
                    <mfrac>
                        <mrow>
                            <msub>
                                <mrow>
                                    <mi>L</mi>
                                </mrow>
                                <mrow>
                                    <mn>1</mn>
                                </mrow>
                            </msub>
                            <mo>-</mo>
                            <msub>
                                <mrow>
                                    <mi>L</mi>
                                </mrow>
                                <mrow>
                                    <mn>2</mn>
                                </mrow>
                            </msub>
                        </mrow>
                        <mrow>
                            <mn>2</mn>
                        </mrow>
                    </mfrac>
                </mrow>
            </mtd>
        </mtr>
        <mtr>
            <mtd>
                <mrow>
                    <maligngroup/>
                    <malignmark/>
                    <mo>⇒</mo>
                    <mfrac>
                        <mrow>
                            <msub>
                                <mrow>
                                    <mi>L</mi>
                                </mrow>
                                <mrow>
                                    <mn>1</mn>
                                </mrow>
                            </msub>
                            <mo>+</mo>
                            <msub>
                                <mrow>
                                    <mi>L</mi>
                                </mrow>
                                <mrow>
                                    <mn>2</mn>
                                </mrow>
                            </msub>
                        </mrow>
                        <mrow>
                            <mn>2</mn>
                        </mrow>
                    </mfrac>
                    <mo>&lt;</mo>
                    <msub>
                        <mrow>
                            <mi>f</mi>
                        </mrow>
                        <mrow>
                            <mn>1</mn>
                        </mrow>
                    </msub>
                    <mo>(</mo>
                    <mi>x</mi>
                    <mo>)</mo>
                </mrow>
            </mtd>
        </mtr>
    </mtable>
    <mi> </mi>
</math>

It should look like this:

https://skydrive.live.com/redir?resid=8FEA31C0ACCF70F0!135

enter image description here

5
  • 1
    A quick google would have led you to this
    – Seamus
    Dec 5, 2012 at 16:26
  • I've seen that one, but Sciwriter crashes in windows 7. And pandoc doesn't seem to do MathML to Latex.
    – Kasper
    Dec 5, 2012 at 16:37
  • I was thinking that using mathjax there should be a way to do this. But I've no idea how.
    – Kasper
    Dec 5, 2012 at 16:45
  • 1
    If the system on Maths-SX were set up correctly (and I have no information as to whether it is or isn't) you wouldn't have to do this. MathJaX can accept MathML as its input so you ought to be able to post raw MathML and have it just work. But I expect that the HTML sanitiser on the SE network wouldn't allow that. Shame. Dec 5, 2012 at 16:57
  • 2
    @AndrewStacey just looked at a math.sx page they use <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> so are only configured for tex-like input. Dec 5, 2012 at 17:29

2 Answers 2

17

The XSLT at

https://github.com/davidcarlisle/web-xslt/tree/master/pmml2tex

converts MathML to TeX it's been fairly extensively used over the years including generating almost all the images in Chapter 4 of the MathML3 spec (as part of a pipeline Content MathML to Presentation MathML to TeX to images.)

It currently skips maligngroup and produces

enter image description here

From the supplied XML.

It would be trivial to add the extra & by hand to restore the alignment. Changing matrix to aligned and adding two & produces

enter image description here

5
  • 2
    Ok, thank you very much. I hope this is what I'm looking for. But I've absolutely no idea how to use this. Could you help me? How do I download these files ?
    – Kasper
    Dec 5, 2012 at 16:56
  • Wow ! freaking awesome ! How did you do that ?!
    – Kasper
    Dec 5, 2012 at 17:04
  • 3
    @KasperPeulen, well I have used LaTeX and MathML before:-) Dec 5, 2012 at 17:06
  • 2
    You can download the files by going to code.google.com/p/web-xslt/source/browse/trunk/pmml2tex and looking at each and clicking on "raw file" over on the left. you then need an xslt2 engine (eg saxon) and java -jar saxon9.jar myfile.xml pmml2tex.xsl will produce the tex output. saxon is free but off topic here. Dec 5, 2012 at 17:08
  • Okay, I need to go now. But tonight I'm going to try to get similar results as you got. Thank you very much !
    – Kasper
    Dec 5, 2012 at 17:09
5

My answer is probably not directly following your question but I think it is useful to mention the Mathtype equation editor. This is a commercial product that plugs into Word and it allows export or conversion to LaTeX equations directly from the word document. This will remove one step from your work flow and may make sense if you need to make many conversions.

1
  • Using the mathtype converter, I'm able to get very good and quick results. The only problem is that the alignment breaks, but this is quickly restored. Awesome !
    – Kasper
    Dec 6, 2012 at 0:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .