My thoughts and experiments.

© 2018. Dmitry Dolgov All rights reserved.

The Knife

I really don’t know how I lived before without pandoc. It’s an amazing tool, that saved me from a terrible pain of latex -> MS Word convertion. If you’re writing many scientific documents in latex format, and faced with the demand to convert it into MS Word, you can understand me. It’s like a tiresome point-and-click game, which can consume unbelievable amount of time.

Pandoc can do it, and I’m not kidding. All you need is to create a source file in markdown format and copy all latex formulas. In this post you can find several details.

What do we need to install pandoc? I’ll advise stack:

$ stack install pandoc pandoc-citeproc pandoc-crossref

pandoc-citeproc and pandoc-crossref will be used to generate nice bibliography and references.

Now we can do something like this:

$$\frac{\partial \vec{u}}{\partial t} + (\vec{u} \cdot \nabla) \vec{u} = - \frac{1}{\rho} \nabla p + \nabla \sigma + \vec{f}$$ {#eq:navier_stokes:motion}

$$\frac{\partial \rho}{\partial t} + \nabla \cdot (\rho \vec{u}) = 0$$ {#eq:navier_stokes:continuity}

ang get a nice result (e.g. from Word Online):

Here you can see a label eq:navier_stokes:motion for corresponding equation. General template for references is:

some_content {#type:label}

label will be used here [@type:label]

More documentation about types and usage is here. You can enable pandoc-crossref using command line argument --filter:

$ pandoc --filter pandoc-crossref -o result.docx 

Note, that if we will use begin/end environment or “\\” for multiple equations, pandoc couldn’t generate MS Word formula. Also, you shouldn’t forget about empy line between equations.

To use bibliography we can create a regular bib file and enable pandoc-cireproc like this:

$ pandoc --filter pandoc-crossref --bibliography report.bib -o result.docx

The default citation style in Pandoc is Chicago author-date, but you can change it. E.g. if you’re writing an academic paper in Russian, I bet you would like to use GOST standard. You can get a corresponding csl file here, and use it like this:

$ pandoc --filter pandoc-crossref --bibliography report.bib --csl=gost.csl -o result.docx

The last one thing is a language. If you’re writing in Russian, you can suffer from encoding issues - to avoid this you need to specify language:

$ pandoc --filter pandoc-crossref --bibliography report.bib --csl=gost.csl -o result.docx -V lang:russian

That’s it, you will get a well-formed MS Word file with nice formulas.

comments powered by Disqus