BookTranslator
BookTranslator

How to Translate a LaTeX Document Without Breaking Math, Citations, or Labels

What to translate in a .tex file, what to leave alone, and why a translated file can compile cleanly and still lose its text. With a sample file, two free checkers, and a 9-run local LLM test.

To translate a LaTeX document, translate the prose and the reader-facing arguments of commands, such as section titles, captions, footnotes, and link text. Leave the commands, environment names, \label, \ref, and \cite keys, math, and verbatim blocks exactly as they are. Then make one change that no translator should make for you: set up the preamble for the target language, because a file that keeps its English preamble can compile without an error and still produce a PDF with the translated text missing.

That last point is the main result of a small test. We translated a 98-line LaTeX paper into Simplified Chinese nine times with a local model, in three different ways, and checked every result with a script and a compiler. The parts people usually worry about held up in all nine runs: labels, references, citations, equations, URLs, table columns, and braces came back intact, and every cross-reference resolved. The problems were elsewhere. The six runs whose prompt said "do not change the preamble" obeyed, compiled with exit code 0, and produced PDFs with no Chinese text in them at all. One run applied our "escape the % sign" rule inside a code listing, so the PDF prints a stray backslash. And at least three runs shifted the meaning of a sentence in ways no structural check can see.

Quick Answer: What to Translate and What to Leave Alone

Part of the fileExample from our sampleTranslate it?
Preamble: \documentclass, \usepackage, \newcommand\newcommand{\wpm}{\mathrm{wpm}}No, but add the target-language setup yourself (see below)
\title, \author, \date\title{Estimating Reading Time for Translated Ebooks}Title and date yes; names usually no
Headings\section{Method}\label{sec:method}Yes, the text in braces; keep the label
Labels and references\label{eq:time}, Section~\ref{sec:method}, \eqref{eq:time}Keep every key
Citations and bibliography keys\cite{brysbaert2019}, \bibitem{rayner2016}Keep the keys; translate entry text only if your field does
Inline and display math$r_c$, T = \frac{N}{r}No
Text inside math\text{ for English silent reading.}Yes. It prints as ordinary text.
Macros that take text\term{characters per minute}Translate the argument, keep the command
Captions and footnotes\caption{Reading rates used in this paper.}Yes
Verbatim and code listingsshelfmark count --unit chars book.epub # 100% of body textNo, including comments inside them
\url and the first argument of \href\href{https://example.org/shelfmark/survey}{online appendix}Keep the URL; translate the link text
Escaped characters20\%, \$12, R\&DKeep the backslash in prose
% comments% TODO: replace the Chinese rate ...Optional. Readers never see them.
Ties before referencesTable~\ref{tab:rates}Keep in languages that use spaces; optional in Chinese and Japanese

Everything else is ordinary prose: paragraphs, abstract, list items, and table cells.

What We Tested

We wrote sample-source.tex, a short invented paper about reading-time estimates for a fictional app called Shelfmark. It compiles cleanly and contains one example of each construct in the table above, plus a booktabs table, a figure with a caption, two % comments, a verbatim block with a bare % in it, and an inline bibliography.

Then we asked a local model to translate it into Simplified Chinese in three ways:

  1. Whole file. Paste the entire file and ask for a translated file that still compiles.
  2. Instructed. The same, plus seven rules: do not change the preamble, keep every command, environment, label, reference, and citation key, leave math alone except \text{}, leave verbatim blocks and URLs alone, keep special characters escaped, keep ties, and translate the prose, captions, footnotes, and link text.
  3. Segments. Keep the preamble out of the request entirely (only the \title line is sent, so \date stays in English), split the body at blank lines, skip the verbatim block, send each piece with the same rules, and reassemble.

The model was Qwen 3.6 27B (Q4_K_M) in LM Studio, with thinking turned off and temperature 0.3, on an Apple M4 Max with 64 GB of memory. We ran each condition three times, nine runs in total, on October 26, 2026. The script is run_llm_latex_test.py, and all nine outputs are published unedited in the outputs folder. If you have never set up a local model, our local LLM translation guide covers the settings.

We compiled every output with Tectonic 0.17.0, which uses the XeTeX engine, once exactly as returned and once with a Chinese setup added to the preamble. Then we read the text back out of each PDF. This was a small test of one model, one language pair, and one file. It shows which problems happen and how to catch them. It does not rank models or prompts.

Result: The Structure Survived; the Preamble Decided Whether Text Appeared

check_latex_translation.py compared each output with the source, and compile_check.py compiled it. The full outputs are in check-results.txt and compile-results.txt, and results.csv has one row per run.

CheckWhole fileInstructedSegments
Labels, references, citations, and bibliography keys unchanged3 of 33 of 33 of 3
Math unchanged (text inside \text{} translated)3 of 33 of 33 of 3
URLs, braces, and table columns intact3 of 33 of 33 of 3
Model added a Chinese package to the preamble3 of 30 of 30 of 3
Compiles as returned3 of 33 of 33 of 3
Chinese text actually in the PDF as returned3 of 30 of 30 of 3
Verbatim block unchanged3 of 32 of 33 of 3
% comments left in English3 of 33 of 31 of 3
Every reference and citation resolves after adding the Chinese setup3 of 33 of 33 of 3

Our checker initially reported changed math in the first run. The math was fine: Chinese word order had put $N$ before $r$ in one sentence. The published checker compares math segments as an unordered collection for this reason, so reordering is allowed but a changed symbol is not.

1. "Don't touch the preamble" produced a PDF with no Chinese in it

The preamble rule sounds like the safest instruction you can give. Our sample's preamble loads amsmath, booktabs, and hyperref and defines three macros, and none of that needs translating. So the instructed and segments runs left it alone, exactly as told.

But the default fonts in a standard LaTeX setup have no Chinese characters. Every one of those six files compiled with exit code 0. Tectonic did warn, once per missing character, with lines such as Missing character: There is no 估 (U+4F30) in font [lmroman17-regular], and the log file recorded between 554 and 577 of them per run. But a warning does not stop the build. When we extracted the text from those six PDFs, they contained the author names, the numbers, and the math, and zero Chinese characters. The three whole-file PDFs contained 481 to 490. A build script that checks only whether compilation succeeded, or a person who only skims the end of the output, would have shipped all six.

The three whole-file runs, which had no such rule, added \usepackage{ctex} on their own, and their PDFs were complete. That is not a reason to let a model rewrite your preamble. It is a reason to see the target-language setup as part of the translation job, done once, by you:

  • Chinese: load ctex, which supports pdfLaTeX, XeLaTeX, and LuaLaTeX. By default it picks fonts for your operating system; our log shows it loading its macOS font set. If the file has to compile the same way on other machines, \usepackage[UTF8,fontset=fandol]{ctex} uses the free Fandol fonts distributed with TeX Live, which Tectonic also downloads on demand. That is what compile_check.py adds.
  • Other languages: load babel with the target language, so hyphenation and generated words such as "Figure," "Table," and "Abstract" follow the new language. Japanese, Korean, and right-to-left languages each need their own setup.

After compiling, check the log for Missing character and read the PDF, not just the exit code. We tested only XeTeX through Tectonic; other engines report a missing font differently.

2. The escaping rule leaked into the code listing

Our instructions said to keep special characters escaped, and in prose that is the right rule: a bare % in LaTeX starts a comment and silently swallows the rest of the line. All nine runs kept 20\% in the abstract.

In the first instructed run, the model also applied the rule inside the verbatim block and translated the code comment there:

source:      shelfmark count --unit chars book.epub  # 100% of body text
translation: shelfmark count --unit chars book.epub  # 100\% 正文

Inside verbatim, nothing is a command, so the PDF prints 100\% with the backslash. The fix is not a better prompt. Never send verbatim, lstlisting, or minted blocks to a translator at all, as the segments condition did. Then translate any comment in them by hand if your readers need it.

3. Comments followed the request boundaries

The file has two % comments: a note above the macro definitions and a TODO above the code listing. The whole-file and instructed runs left both in English. The segments condition translated the TODO in two of three runs, because the TODO happened to sit in the same block as a paragraph we sent for translation. Two whole-file runs also added a comment of their own after the package they inserted.

None of this changes the PDF. It matters if the translated source goes back to co-authors or a repository, where a translated TODO no longer matches the original and an extra comment shows up in every diff. The checker reports translated comments as a warning so you can decide.

4. The structural checks passed and the meaning still changed

The abstract says "a label that is off by 20% is still useful." In three of nine runs, the Chinese said that labels with an error within 20% are still useful, which shifts a tolerance into a threshold. Several other runs reordered the sentence so that the "although" clause attaches to the wrong idea, and one became hard to follow. These are judgments by one reader comparing the Chinese with the English, not a blinded review, but the point does not depend on the exact count: every structural check passed on those files, because the 20\%, the macro, and the braces were all correct.

Two other changes were fine but worth knowing about. The whole-file runs wrote \$12 as 12美元 ("12 US dollars"), which removes the escaping question entirely. Two whole-file runs also dropped most of the ~ ties before \ref and \cite. That is harmless in Chinese, which does not put spaces between words, but in a language that does, a missing tie lets a line break separate "Table" from its number. The checker reports ties as a warning, not a failure.

A structural check tells you the file still works. It cannot tell you the paper still says the same thing. For that, use a bilingual read of the abstract, the claims, and the numbers, as described in our guide to reviewing a translated research paper.

A Workflow That Holds Up

  1. Get the source, and check what you may do with it. On arXiv, papers submitted in TeX usually offer their source through a Source link on the abstract page or the Other formats page, as a gzipped file or a tar archive when there are several files (arXiv help). Translating for your own reading is one thing. Publishing the translation is another: arXiv's own non-exclusive license limits reuse by others, while CC BY and CC BY-SA allow adaptations with attribution, and CC BY-NC-ND does not. Ask the authors when in doubt.

  2. Compile the original first. If it does not compile before translation, nothing you learn afterwards is reliable. Keep the original PDF for comparison.

  3. Set up the target language in the preamble yourself. Add ctex or babel as above, compile once with the English text, and commit that change separately.

  4. Translate the body without the preamble and without verbatim blocks. Use a tool that parses LaTeX, or send the body in pieces with explicit rules, as in our segments condition. TransLaTeX, an open-source tool built for this, replaces LaTeX constructs with tokens before sending the text to a machine translator. Its documentation also says it keeps the document header untouched, does not support macros, and handles single-file documents only, with no \input. Even a dedicated tool leaves the preamble decision to you.

  5. Run the structural check on every file pair.

    python3 check_latex_translation.py main.tex main-zh.tex --keep Shelfmark
    

    It compares the preamble, command names, environment order, labels, references, citations, bibliography keys, math, verbatim blocks, URLs, unescaped %, &, and #, brace balance, ties, comments, and any terms you ask it to keep. Expect the preamble line to fail after step 3 when you compare against the original; compare against your updated English file instead. For a project split across several \input files, check each pair.

  6. Compile and read the PDF.

    python3 compile_check.py main-zh.tex
    

    It reports unresolved references (??), unresolved citations ([?]), and missing glyphs. Then open the PDF and read the abstract, every caption, and every table against the original.

  7. Do a bilingual read of the claims and numbers. This is where our three changed sentences would have been caught. Keep a short translation glossary for the paper's technical terms so the same term is not translated three ways.

Where BookTranslator Fits

BookTranslator's document translator accepts .tex files along with PDF, DOCX, EPUB, Markdown, and other structured formats. Its FAQ says the result is returned in "a usable, format-appropriate file whenever that format supports it."

The product page does not describe how it treats LaTeX macros, math, or the preamble, and we did not run this sample through BookTranslator for this article. Whatever tool you use, do steps 1 to 3 before translating and steps 5 to 7 afterwards. A file that keeps an English-only preamble will still compile without Chinese text, and a changed claim will still pass every structural check.

If you only have the PDF of a paper, not its source, the workflow is different: see our guide to translating a research paper while keeping its structure. If your source is Markdown rather than LaTeX, the same split between machinery and prose applies, with different traps; we tested those in How to Translate Markdown Files.

Get the Test Files

Everything from this test is free to reuse:

Σχετικές Δημοσιεύσεις