28

This is a counterpart to "How can I typeset an exam or assignment paper in LaTeX?", which was from a teacher looking for a template to compose assignments and exams. I'm a student, and I'd like to submit PDFs or printouts composed in LaTeX in response to assignments submitted as Word documents.

As a math and engineering student, I regularly receive emailed or uploaded assignments with .doc (and now .docx) attachments, which generally contain a numbered list of questions (often with parts A, B, C, etc.) to answer. Styles or other advanced Word structuring tools are rarely used. These assignments also frequently contain equations, tables, and images or Microsoft drawing objects (Usually circuits, graphs, or timing diagrams). I don't really mind copying the images over, or, if they're simple, drawing them myself (as I'll likely have to make changes to it in my answer anyways). However, on a long math assignment, the equations get tedious, and a little error in copying is a big problem.

From the tug.org converter page, I see winw2ltx, Word2TeX and Word-To-LaTeX (These utilities have such clever names...) which have some support for equation transformation.

One thing which isn't clear from the documentation is whether the MathType extension to Word must be used to create the equation, or whether it can simply convert an Equation Editor or .docx equation to LaTeX if it's installed on my computer.

The holy grail of answers to this question would be a utility which:

  • Recognizes MS Word numbered lists and outlines (I, 1, a, i, etc.).
  • Is faster than copy-pasting the text of each question into, say, the exam document class, writing the equations, and drawing the diagrams. This is what I do right now. Not too bad, but it adds half an hour to every assignment.
  • Makes better looking documents than the original Word document. I'd like to do a little evangelism here.
  • Includes support for equations, tables, and images.
  • Can import both .doc and .docx files. Saving the .docx as a .doc is not acceptable, as it renders the equations as bitmaps. Saving the .doc as .docx might be acceptable.

I don't really need it to structure the document; if it just sticks some selected text into a section of my LaTeX document, that would be plenty.

7
  • 3
    I'm rather surprised that you often have math assignments distributed in .doc and .docx. My sympathies!
    – vanden
    Commented Jul 27, 2010 at 15:27
  • @vanden - One of my professors had a set of Word .doc files, organized in 30- to 50-page units totaling in excess of 200 ages, which he used to teach upper-level analog circuit design. Kirchhoff's laws, Thevenin and Norton transformations, node/mesh analysis, filter design, transfer functions, time/S domain, and the related algebraic, integral, and differential equations and example circuits...it was an astonishing piece of work. And it was ugly to read, impossible to maintain or manage, and impossible to search for information. Commented Jul 27, 2010 at 18:38
  • It's much easier to search OOXML files than .doc files. Commented Jul 28, 2010 at 8:49
  • 3
    vanden: I'm much faster in typing math in Word (2007+) than LaTeX; the former of which uses a streamlined and logical evolution of LaTeX's math markup facilities. The old equation editor was horrible, indeed. But the current math typesetting is actually quite decent.
    – Joey
    Commented Sep 7, 2011 at 11:19
  • @Joey A latex user can do the same by using something like this if he/she prefers. So, that's not a good excuse for sticking with MS word. Commented Feb 19, 2020 at 7:29

6 Answers 6

18

I'm sorry I wont be able to provide any answer other than: "Don't do it!"

Other than using some of the converters that you and other people have suggested, which may give you a reasonable place to start, there is really no satisfactory solution to convert an existing Word document into a LaTeX one. This is difficult to implement, and for a good reason. Word and LaTeX have two completely different approaches at describing and encoding documents. Word (as most people use it) stores formatting information while LaTeX encodes the "logical structure" of a document (which then gets translated to TeX formatting instructions while compiling). Trying to get a LaTeX document out of a Word document is somewhat similar to trying to obtain a C++ program from it's binary: You can do it, but the results wont be pretty.

You are better off taking a printout of your assignments and typing the whole thing yourself in LaTeX. Of course you can copy/paste large bodies of text, but for equations there is nothing better than typing them yourself. If you do this for a while, and show your beautiful documents to your teachers and colleagues, you might be even able to convince them to switch to LaTeX all together.

LaTeX is not a format to store pretty documents, it is a fully-fledged system to create those documents.

10
  • Absolutely agree with this. OpenOffice.org provides an extension for this, but results are never as good as hand-written documents. Commented Jul 28, 2010 at 11:41
  • 3
    As I said, I don't need the tool to structure it! All I want is to move the numbered list and the inlined equations into a section of my LaTeX document. I can strip titles, footnotes, page numbers, etc, and I don't care about including margins, fonts, styles, and all the other formatting stuff that Word does. I want to do the structuring in LaTeX. I just want to start with the content which is locked up in my word document. Commented Jul 28, 2010 at 14:36
  • @rivanvx - I'll give OO.org a try as well. Commented Jul 28, 2010 at 14:37
  • But you were asking for the tool also to parse the equations in the Word document, which I wouldn't advice for the same reasons. You shouldn't write syntactic equations, write semantic equations instead. Commented Jul 28, 2010 at 15:48
  • 2
    Juan: I've never seen anyone use semantic math in LaTeX. In fact, to this date I wasn't even aware that existed. As for Word: Used properly it encodes the structure and semantics of the document as well as LaTeX. The magic word is styles and most people who actually know Word will use them properly, making a conversion for the largest part of a document very straightforward and mechanical.
    – Joey
    Commented Sep 7, 2011 at 11:24
16

I recommend docx2tex. Against your criteria:

  • Recognizes MS Word numbered lists and outlines (I, 1, a, i, etc.).
    • Yes, although it doesn't try to keep enum types;
  • Is faster than copy-pasting the text of each question into, say, the exam document class, writing the equations, and drawing the diagrams. This is what I do right now. Not too bad, but it adds half an hour to every assignment.
    • It is automatic, provided it recognises all of your OOXML markup (it doesn't handle everything).
  • Makes better looking documents than the original Word document. I'd like to do a little evangelism here.
    • It gives pretty easy-to-read, vanilla Latex. I don't call that beautiful, but it's easier to beautify than Word.
  • Includes support for equations, tables, and images.
    • Yes. It converts included images to .eps files; I'm not sure what quality that gives you with included SVG files.
  • Can import both .doc and .docx files. Saving the .docx as a .doc is not acceptable, as it renders the equations as bitmaps. Saving the .doc as .docx might be acceptable.
    • Only docx files. Provided you have Word 2007 or later, this shouldn't be a problem.

Issues: It's abandonware, not updated since November 2008. It only supports the DVI toolchain. It's native to Windows, being a C#/.NET3 based technology, and works very well there; away from Windows, it supposedly it works with Mono, although the last time I tried, about 18 months ago, it did not work. It's docx/OOXML-only technology. although since conversion of RTF/.doc to .docx is very well-behaved, this should not be a problem.

The TUG 2008 talk announcing the technology was recorded by River Valley TV.

3
  • I'll give it a shot! Vanilla LaTeX is what I'm looking for. Commented Jul 28, 2010 at 14:29
  • Thank you for this hint. I installed it and it converted my 119 page file to TeX. But it did not convert the pictures to eps. It keeps on saying: "ERROR: Unable to start ImageMagicK".
    – Michael S.
    Commented Oct 23, 2015 at 11:24
  • @gentlesea - Try asking your problem as a new question and link to it from a comment to me. I can't debug uses of docx2tex in a comment thread. Commented Nov 3, 2015 at 15:59
8

In my experience Pandoc does a decent job of converting from MS Word 2016 files (.docx) to LaTeX. After installation on OSX El Capitan, I ran the following command to convert my MS Word file:

pandoc -f docx -t latex -o out.tex in.docx

Granted you'll still have to make some edits to match the original, but it is way better than starting afresh and it's free. Also, it supports OSX, Windows and Linux.

1
  • Excellent solution, thank you for this jolt to my memory, I always wanted to try pandoc (excellent solution in Haskell, very robust and versatile) but didn't have needs for it until now. The result is very good and much faster than doing this by hand. Also, reasonably clean even without hand-editing.
    – Jedai
    Commented May 2, 2016 at 9:06
1

Instead of including a .docx document, I ended up saving it as a pdf, and include that (multipage) pdf with the pdfpages package. This works actually surprisingly well!

For the useage of pdfpages, refer to this answer.

1

This website is in beta state but is constantly improving. If you follow all guidelines then you can get pretty descent ".tex" code and ".pdf". If you face any issues ,leave them a message and they will fix it.

Give it a try https://www.docx2latex.com/

1

I signed in, just to answer this question :)

Yesterday I was having the same problem where I've had the word document full of complex equations and I wanted them in Latex code. But somehow accidently I found a inefficient but somehow hacky solution to quickly change your word equations into Latex.

I have MS Office 365.

  • First open your document
  • Then select any equation
  • In the menu bar near "Help", you'll see the option named as "Equation" Click it
  • Now go to the Standard toolbar, you'll see the option for you to write Latex code with named as "{} Latex" Click it
  • Now click the button right next to the Latex which is named as "Convert", and choose "All-linear"enter image description here. BOOM

It will take a bit of time according to the length of your document, but after done you'll see most of the equation written in latex form. I really don't know how this is working but somehow I found this by myself.

Now it doesn't guarantee that it will change all the equations in Latex, I do found few errors and some equations just stays the same, but your work will be done.

If this works for you, please let the community know. Do know that it will only convert the equations ;) Thank you.

You must log in to answer this question.

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