Friday, October 8, 2021

pandoc: quite good conversion from Latex to docx with references and preserving tikz figures

This works surprisingly well, with all the figures and even rendering the BibTex references: 

> pandoc -C -s main.tex --natbib -o main.docx 

this will produce a document with citations using the  (Author, year) format, to produce citations with a numeric format download the ieee.csl file and call:  

> pandoc -C -s main.tex --natbib --csl=ieee.csl  -o main.docx  


To preserve tikz figures a specialized tikz-to-png filter is needed.  It should be downloaded in the current directory and use the call: 

> pandoc -C -s main.tex --natbib --csl=ieee.csl  --from latex+raw_tex --lua-filter=tikz-to-png.lua -o main.docx  


Figure numbers and captions are not preserved (for obscure reasons), however  table numbering can be  preserved using the document type  -t odt+native_numbering  or  -t docx+native_numbering. 

> pandoc -C -s main.tex --natbib --csl=ieee.csl  --from latex+raw_tex --lua-filter=tikz-to-png.lua -t docx+native_numbering -o main.docx  


Cross-references to sections and figures tables can be recovered with the resolve-references filter but the final format won't be great

> pandoc -C -s main.tex --natbib --csl=ieee.csl  --from latex+raw_tex --lua-filter=tikz-to-png.lua --lua-filter=resolve-references.lua -t docx+native_numbering -o main.docx  


Sources: 
https://waterprogramming.wordpress.com/2018/08/26/converting-latex-to-ms-word-docx-almost-perfectly/
https://tex.stackexchange.com/questions/268196/how-to-convert-latex-to-word-using-pandoc-and-keep-citations-as-numeral

No comments:

Post a Comment