3

Please consider the very simple latex file below

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}


\begin{equation}
 \label{eq:somelabel}
   e=mc^2
\end{equation}

The equation \ref{eq:somelabel} is a typical formula.


\end{document}

which is saved as test_latex.tex. When I try to convert this to a word document with

pandoc test_latex.tex -o -s test_word.docx

in the test_word.docx file the reference to the equation is not correct (instead of a number I see the label).

How can I fix this? Many thanks!

6
  • 1
    You might be out of luck: github.com/jgm/pandoc/issues/2851
    – DG'
    Jan 26, 2021 at 21:11
  • 3
    make4ht -f odt test_latex compiles your file correctly. It creates ODT, not DOCX, but Word can open it too.
    – michal.h21
    Jan 26, 2021 at 21:28
  • I wonder if this github.com/tomduck/pandoc-eqnos can help or it requires me to start from a markdown file....
    – larry77
    Jan 26, 2021 at 21:57
  • pandoc-eqnos will need markdown input. Give make4ht a try!
    – DG'
    Jan 26, 2021 at 22:07
  • 1
    Pandoc is great and you can do a lot with pandoc-crossref and other filters, but you need to write in markdown to make the most of it
    – DG'
    Jan 27, 2021 at 8:24

1 Answer 1

2

This is my work around:

  1. Convert LaTeX document to epub3 document with MathML by using tex4ebook utility: tex4ebook -f epub3 test_latex.tex "mathml"
  2. Convert this output to MS Word document by using Pandoc: pandoc test_latex.epub -o test_latex.docx

Note that you might need to revise your LaTeX source file before feeding it to tex4ebook, this utility is very fragile and expects a very simple LaTeX document (i.e. documents that use only basic packages). If you get some error messages, you should try with a small fraction of your LaTeX document and detect the reason of the error (error messages produced by tex4ebook does not help at all). In my case I removed some packages like enumitem, tikz, fancyhdr, etc.. I have also figured out that labels and references including colons like \label{eq:chap1-eq1} cause error, so i changed them as \label{eq-chap1-eq1} you should detect all issues like this by trying small fractions of your document.

I have managed to convert large documents like a whole book with this method.

You must log in to answer this question.

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