SPB Git

Repository Public Research preview

latex-to-word.md 3.5 KB 61 lines markdown

1# LaTeX to Word23## Why a recipe is needed45`pandoc main.tex -o main.docx` produces a Word file in which every `\ref{…}` is empty or shows the6label name, floats have no number, and equations have no number. pandoc reads the `.tex` source7only; the numbers exist nowhere but in the `.aux` file that LaTeX writes when it compiles.89## The recipe1011```bash12node scripts/latex.mjs compile main.tex          # produces the .aux13node scripts/latex.mjs docx main.tex             # → .latex-build/main.docx14node scripts/latex.mjs docx main.tex --out submission/paper.docx --csl styles/apa.csl15```1617`docx` does the following, and reports counts for each:18191. **Flattens** the document: `\input`, `\include` and `\subfile` are expanded, comments removed.202. **Reads the `.aux`**: every `\newlabel{key}{{number}{page}…}`.213. **Replaces references** in the source: `\ref{k}` → `3`; `\eqref{k}` → `(3)`; `\autoref`,22   `\cref`, `\Cref` → `Figure 3`, `Table 2`, `Section 4` (English names, from the kind of the23   label); `\pageref{k}` → the page; lists such as `\cref{a,b}` → `Figures 1 and 2`.244. **Numbers captions**: "Figure N. " or "Table N. " is written at the start of the caption of25   each float that has a label.265. **Numbers equations**: the label of each numbered equation or `align` row is replaced by its27   number set at the right of the formula.286. **Calls pandoc** with `--number-sections` and, when a `.bib` file is declared, `--citeproc`.2930The flattened, resolved source is kept as `.latex-build/<name>.pandoc.tex`: read it when a31passage converts badly.3233`unresolved_labels` lists references with no number in the `.aux`; they appear as `??` in the34Word file. The command exits 1 when there are any.3536## What does not survive3738| Element | In the Word file |39|---|---|40| Cross-references | Plain text. They do not update if the reader moves a figure |41| Equation numbers | Typed beside the equation; not Word's own numbering |42| Section numbers | Numbered by pandoc in order. They differ from the PDF when the document has unnumbered sections, appendices lettered A, B …, or custom counters |43| Citations and reference list | Re-rendered by citeproc: author–date by default, whatever the LaTeX style was. Pass `--csl` with the journal's CSL file to match |44| TikZ / pgfplots figures | Lost. Export them to PNG or PDF first and include those files |45| PDF and EPS images | Linked as they are; Word often cannot display them. Convert to PNG |46| Macros | Simple `\newcommand` definitions are expanded by pandoc; macros with complex arguments, `\def` tricks and package-specific commands are dropped or left as text |47| Tables | Simple `tabular` converts. `multirow`, `multicolumn` with rules, `longtable` options, `siunitx` columns and coloured cells convert partly or not at all |48| Theorems, algorithms, listings | Text is kept, numbering and styling mostly lost |49| Layout | Margins, fonts, spacing, float placement, headers and footers: all Word defaults |50| Footnotes | Kept. `\thanks` and affiliation footnotes may be misplaced |51| Names in other languages | `\cref` names are written in English ("Figure", "Table") |5253## Before sending the file5455Open it. Check, at least: the title block, one reference of each kind (section, figure, table,56equation), each table, each figure, the reference list, and search for `??` and `[`. Say in your57report that the file was produced by conversion and which of the items above apply.5859When the recipient will edit the text and send it back, tell them the cross-references are static60text; changes then have to be carried back into the LaTeX source by hand.61
Files main
Menu

Theme