Convert a LaTeX paper to Microsoft Word (.docx) with pandoc
while keeping the mathematics, the figures and an IEEE-style bibliography, and
applying a Word style template.
The script handles the cases pandoc does not cover on its own:
- IEEE bibliography. Citations are numbered
[1], [2], ...in order of appearance. The reference text is taken from the.bblproduced byIEEEtran.bst, and a DOI is appended to each entry (read from thedoifield in the.bib). - Cross references.
\refand\eqrefare replaced by the numbers LaTeX already computed, read from the.auxfile (soAlgorithm~\ref{...}becomesAlgorithm 3,Eq.~\eqref{...}becomesEq. (2), and so on). - Equations. Displayed equations are centered and numbered with the number at
the right margin, using a right-aligned tab (Word's native equation-numbering
layout, not a table).
Pseudocode (
algorithm/algorithmic) gets a left-aligned header (heading, Input, Output) framed by a top and bottom rule, followed by the numbered steps in a two-column table (one row per line) so every line stays separate, while the inline math is preserved as real Word equations. - Figures. Figures are embedded whatever their format. They are looked up in the
folder given with
--fig-dir(the folder of the.texwhen it is left empty), then in the\graphicspathfolders andfigures/, by bare name or with any extension. PDF, EPS, PS and SVG, which Word cannot embed, are rendered to PNG. - Word styles. When a template is supplied, pandoc uses it, the tables are centered, and the auto-generated paragraph styles (figure/table captions, author, date) are mapped onto the template styles.
- Python 3.8 or newer (standard library only).
- pandoc 2.11 or newer (3.x recommended).
- A compiled LaTeX project: the converter needs the
.auxand.bblfiles, so run LaTeX and BibTeX once before converting. The.bblmust come from a numeric, appearance-ordered style such asIEEEtran. - To embed PDF, EPS or SVG figures, one of poppler (
pdftocairo,pdftoppm), PyMuPDF, ImageMagick or Ghostscript — whichever is installed is used, best first (rsvg-convert, Inkscape orcairosvgfor SVG). PNG and JPG need nothing extra.
# Convert the bundled example:
python latex_to_word.py main.tex -d ./example -t ./reference.docxOptions:
| Option | Meaning |
|---|---|
main.tex |
main .tex file (default: main.tex) |
-d, --paper-dir |
folder holding the LaTeX sources (default: current folder) |
-t, --template |
Word template; copied into the paper folder as reference.docx and used as the style template |
-o, --output |
output .docx path (default: <main>.docx inside the paper folder) |
-g, --fig-dir |
folder holding the figures, in any format (PDF, EPS, SVG, PNG, JPG, ...); left empty, the folder of the .tex is used |
--fig-dpi |
resolution used to render PDF/EPS/SVG figures to PNG (default: 300) |
--year-after-authors |
put the publication year in parentheses after the last author (author-year style, e.g. for HJS) instead of at the end of the entry |
Figures live next to the .tex unless you say otherwise; point --fig-dir at
another folder when they are kept apart from the sources:
python latex_to_word.py main.tex -d ./my-paper -g ~/Pictures/my-paper-figuresBy default the references keep the IEEE layout, with the year at the end of each
entry. Add --year-after-authors to get the author-year layout:
[1] J. Yin, Z. Zheng, and L. Cao (2012), "USpan: ...," in Proceedings ... pp. 660-668. DOI: ...
The same settings can be passed through the L2W_MAIN, L2W_DIR, L2W_TEMPLATE,
L2W_FIG_DIR, L2W_FIG_DPI and L2W_YEAR_AFTER_AUTHORS environment variables when
you prefer to set them once:
L2W_DIR=example L2W_MAIN=main.tex L2W_TEMPLATE=reference.docx python latex_to_word.pyWhen it finishes, the converter prints a short review checklist: items found in
this run (references without a DOI, cross references it could not resolve, figures
that did not embed) followed by general reminders about the parts pandoc cannot
reproduce exactly (theorem numbering, equation-number alignment, pseudocode
layout, styles). Open the .docx in Word and go through the list.
Latex2WordHJS.ipynb runs the same conversion on Google Colab. The first cell
installs a recent pandoc; the second cell has input boxes for the LaTeX folder,
the Word template and the main file; the third cell downloads the result.
latex_to_word.py the converter
Latex2WordHJS.ipynb Google Colab notebook
reference.docx Word style template (Title, Subtitle, Figure, Table, ...)
example/ minimal runnable sample paper
The example/ folder is a small, self-contained paper (title, abstract, numbered
equations, two pseudocode algorithms with pruning, a lemma, a figure, a table, and
cross references to all of them plus two citations). It already ships with the
.aux and .bbl files and the figure, so you can run the converter on it right
away. Point -d at your own LaTeX project to convert your paper instead.
pandoc maps document elements onto named paragraph styles. The supplied
reference.docx defines Title, Subtitle, Abstract, Figure, Table and
the heading styles. To change the look of the output, edit those styles in
reference.docx (or supply your own template with -t) and run the converter
again. The script copies the chosen template into the paper folder as
reference.docx before calling pandoc.
Comments, bug reports and suggestions are welcome. Please open an issue on GitHub or send an email to thaitm@huflit.edu.vn.
Released under the MIT License. You may use, modify and redistribute the code freely, including in your own projects, as long as you keep the copyright and license notice.