Skip to content

Instantly share code, notes, and snippets.

@SHDShim
Last active November 13, 2024 08:16
Show Gist options
  • Save SHDShim/717fd9f60f98f85eee5e70831d6ac8a0 to your computer and use it in GitHub Desktop.
Save SHDShim/717fd9f60f98f85eee5e70831d6ac8a0 to your computer and use it in GitHub Desktop.
Pandoc - LaTeX to WORD conversion

LaTeX to WORD conversion

In most cases, it is simpler to (1) read a PDF file directly in WORD, or (2) use save as function in Acrobat Reader to save as a DOC file.

Install Pandoc

Pandoc can be installed in anaconda by

conda install pandoc

or in brew.

brew install pandoc

How to use

I strongly recommand to use brew version. For brew, switch to the brew environment first.

swt_brew # custom command in .bash_profile

Then go to the folder where you have .tex files to convert. Run the following command:

pandoc  --citeproc -f latex -s FeSH-JGR.tex -o FeSH-JGR.docx --bibliography=FeSH.bib

Change the file names appropriately.

  • The command works only with brew version of pandoc for me.
  • Note that the order betweeen pandoc-crossref and citeproc should not change.
  • Run multiples of time (unconfirmed).
  • Pandoc knows how to deal with bibunits and \input{}.
  • Note that line number referencing and citing do not work with pandoc.
  • Do not place both -F pandoc-crossref and --citeproc at the same time, it will repeat the figure and table caption titles.
  • Note that renumbering for figures and tables (for example S1 for supplementary contents) are all ignored. So be careful if this is important.

For numbered citations, such as Nature and Science

pandoc  --citeproc -f latex -s Nature-main\ text.tex --csl=../nature.csl -o main.docx --bibliography=B30.bib

Source: https://tex.stackexchange.com/questions/268196/how-to-convert-latex-to-word-using-pandoc-and-keep-citations-as-numeral

*.csl can be donwloaded from: https://github.com/citation-style-language/styles. A range of journal format is available there.

Word to LaTeX conversion

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

LaTeX to html conversion

pandoc -F pandoc-crossref  --citeproc --mathjax -f latex -t html -s FeSH-JGR.tex -o FeSH-JGR.html --bibliography=FeSH.bib

For better outcome to html:

  • convert all pdf figures to png figures
  • \multicolumn is not compatible with pandoc
  • Figure labelings are properly done, but not for table labeling. I try everything but so far the line above is the best. If you remove any of -F pandoc-crossref and --citeproc from the line above, it will mess up the citations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment