Article 6CR50 Convert LaTeX to Microsoft Word

Convert LaTeX to Microsoft Word

by
John
from John D. Cook on (#6CR50)

I create nearly all my documents in LaTeX, even documents that might be easier to create in Word. The reason is that even if a particular document would be easier to write in Word, my workflow is more efficient if everything is in LaTeX. LaTeX makes small, plain text files that work well with version control and searching, and I can edit them with the same editor I use for writing code and everything else I do.

Usually I send read-only documents to clients. They don't know or care what program created the PDF I sent them. The fact that they cannot edit my reports is a feature, not a bug: if I'm going to sign off on something, I need to be sure that it doesn't include any changes that someone else made that I'm unaware of.

But occasionally I do need to send clients a file they can edit, and this usually means Microsoft Word. Lawyers particularly want Word documents.

It's possible to create a PDF using LaTeX and copy-and-paste the content into a Word document. This works, but you'll have to redo all your formatting.

A better approach is to use Pandoc. The command

 pandoc foo.tex -o -s foo.docx

will convert the LaTeX file foo.tex directly to the Word document foo.docx. You may have to touch up the Word document a little, but it will retain more of the original formatting than if you when from LaTeX to Word via PDF.

You could wrap this in a script for convenience and so you don't have to remember the pandoc syntax.

 #!/opt/local/bin/perl $tex = $ARGV[0]; ($doc = $tex) =~ s/\.tex$/.docx/; exec "pandoc $tex -o $doc";

You could save this to tex2doc and run

 tex2doc foo.tex

to produce foo.docx.

The post Convert LaTeX to Microsoft Word first appeared on John D. Cook.
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments