Install
openclaw skills install pdf-translate-skillTranslate PDF documents or arXiv papers preserving formatting by extracting text and images, translating content, and generating a reconstructed LaTeX-based...
openclaw skills install pdf-translate-skillA comprehensive skill for translating PDF documents while maintaining their original layout, formatting, and visual structure. This skill combines multimodal analysis, text extraction, machine translation, and LaTeX typesetting to produce high-quality translated PDFs.
This skill supports two distinct translation workflows. Choose the appropriate mode based on your input:
| Mode | Input | Method | Quality |
|---|---|---|---|
| arXiv Mode | arXiv ID or URL | Download source TeX → Translate → Compile | Higher (preserves all formatting) |
| Local PDF Mode | Local PDF file | PDF → Images → Layout Analysis → Translate → Recreate in LaTeX | Good (reconstructed layout) |
Use arXiv Mode when:
2310.12345https://arxiv.org/abs/2310.12345 or https://arxiv.org/pdf/2310.12345.pdfUse Local PDF Mode when:
Fallback rule: If arXiv source download fails, fall back to Local PDF Mode.
pip install pymupdf pillow)# Python dependencies
pip install pymupdf pillow requests
# LaTeX (choose one)
# Ubuntu/Debian:
sudo apt install texlive-xetex texlive-lang-chinese
# macOS (Homebrew):
brew install mactex
# Windows: Download MiKTeX from https://miktex.org/
Preferred method for arXiv papers because source TeX files preserve all formatting automatically.
arXiv ID/URL → Download Source TeX → Translate TeX Content → Compile → PDF Output
Advantages over Local PDF Mode:
Detect if user provided:
2310.12345, hep-th/9901001https://arxiv.org/abs/2310.12345https://arxiv.org/pdf/2310.12345.pdfhttps://arxiv.org/abs/hep-th/9901001Extract arXiv ID from input:
/abs/ or /pdf/Download the source TeX files from arXiv:
# Using the provided script
python scripts/download_arxiv_source.py 2310.12345 output_dir/
# Or with URL
python scripts/download_arxiv_source.py https://arxiv.org/abs/2310.12345 ./
Manual download:
# Use arXiv's official source download
# Navigate to: https://arxiv.org/e-print/{arxiv_id}
# Download format: .tar.gz containing all source files
# Or use wget
wget -O source.tar.gz https://arxiv.org/e-print/2310.12345
tar -xzf source.tar.gz
The downloaded archive typically contains:
.tex file (usually named after the paper ID).bst, .cls).bib).pdf, .png, .eps)Find the main TeX file in the extracted contents:
main.tex, paper.tex)\documentclass or \begin{document} to identify the entry point.tex files to find the one with \maketitle or \begin{document}Read and translate the main TeX file:
1. Identify translatable content:
{ and } in regular text environments2. Preserve non-translatable elements:
$...$, \[...\])\ref{...}, \cite{...})3. Translation approach:
ctex or \usepackage{ctex} for Chinese support4. Key translation rules:
\section{...}, \subsection{...} content - translate the text inside\caption{...} content - translate inside\footnote{...} content - translate inside\includegraphics{} paths unchanged\bibliography{} unchangedExample translation:
% Original:
\section{Introduction}
We present a new method for...
% Translated:
\section{介绍}
我们提出了一种新的方法...
IMPORTANT: Compile THREE times to resolve all citations and references:
# Ensure Chinese support
# Add to preamble if not present:
\usepackage{ctex}
# Compile THREE times to resolve all citations and references
xelatex translated.tex # Pass 1: Initial compilation
xelatex translated.tex # Pass 2: Resolve citations/references
xelatex translated.tex # Pass 3: Final resolution
Or use the provided script:
python scripts/compile_latex.py translated.tex output_dir/ --passes 3
Why 3 passes?
\ref{}, \cite{}, and bibliography are correctly renderedIf compilation fails due to missing packages or files:
.sty, .cls, or .bst files\graphicspath for figure locations\input{} files are presentUser Input:
"请翻译这篇 arXiv 论文: https://arxiv.org/abs/2310.12345"
Workflow Execution:
Step 1: Detect arXiv ID
https://arxiv.org/abs/2310.123452310.12345Step 2: Download Source
python scripts/download_arxiv_source.py 2310.12345 ./arxiv_src
Step 3: Identify Main TeX File
main.tex (the main entry point)refs.bib, figures/, style filesStep 4: Translate TeX Content
main.tex\section{Abstract} → \section{摘要}$E = mc^2$ (unchanged)\cite{author2023} (unchanged)\includegraphics{fig1.pdf} (unchanged)main_zh.texStep 5: Add Chinese Support
\usepackage{ctex} or \usepackage[UTF8]{ctex} is in preambleStep 6: Compile to PDF
python scripts/compile_latex.py main_zh.tex ./output --passes 3
Step 7: Deliver Output
./output/main_zh.pdfCannot Download Source:
https://arxiv.org/e-print/{arxiv_id}Missing Package Errors:
.sty, .cls files from the original download to your working directory\usepackage{...} commands and ensure all referenced files existkpsewhich to check if packages are installed system-widearXiv ID Format:
YYMM.NNNNN (e.g., 2310.12345)archive/YYMMNNN (e.g., hep-th/9901001)Use this mode when translating local PDF files or when arXiv source is unavailable.
PDF Input → Page Images → Layout Analysis → Text Extraction → Translation → LaTeX Generation → PDF Output
Convert each PDF page to a high-quality image for multimodal analysis:
python scripts/pdf_to_images.py input.pdf output_pages/ --dpi 150
Output:
page_001.png, page_002.png, ... (page images)manifest.json (page dimensions and metadata)Extract original images from the PDF for reuse in the translated document:
python scripts/extract_images.py input.pdf output_extracted/
Output:
images/img_001_01.png, ... (extracted images)images_manifest.json (image positions and metadata)For each page image, analyze the layout and extract content:
Using multimodal analysis:
Prompt template for layout analysis:
Analyze this PDF page image and describe:
1. Overall layout structure (columns, margins, alignment)
2. Text blocks with their approximate positions and hierarchy
3. Images, figures, or tables with their locations
4. Any special elements (headers, footers, page numbers, footnotes)
Provide a structured description that can be used to recreate this layout in LaTeX.
Translate the extracted text while maintaining:
Translation guidelines:
Create LaTeX code that recreates the original layout with translated content.
Key considerations:
article for papers, report for longer documentsmulticol package\includegraphics with proper positioning (Insert the extracted images into their original positions)tabular or longtable (Insert the identical table at its original position)ctex package with XeLaTeXReference: See ./references/latex_templates.md for LaTeX generation details.
Template structure:
\documentclass[12pt, a4paper]{article}
\usepackage{ctex} % Chinese support
\usepackage{graphicx}
\usepackage{geometry}
% ... other packages
\begin{document}
% Translated content here
\end{document}
IMPORTANT: Compile THREE times to ensure all citations and references are properly resolved:
python scripts/compile_latex.py translated.tex output_dir/ --passes 3
Output:
translated.pdf (final translated document)Troubleshooting: If errors occur, refer to ./references/troubleshooting.md.
working_dir/
├── input.pdf
├── pages/ # Page images
├── extracted/ # Extracted images
├── translated.tex # Generated LaTeX
└── output.pdf # Final result
For each page:
Combine all pages into single LaTeX file:
base_template.tex as foundationCompile to PDF:
scripts/compile_latex.pyVerify output:
\section{Section Title}
Translated paragraph content here.
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{image.png}
\caption{Translated caption}
\end{figure}
\begin{multicols}{2}
\section{Left Column}
Content...
\section{Content Spanning}
...
\end{multicols}
\title{Translated Title}
\author{Authors}
\maketitle
\begin{abstract}
Translated abstract...
\end{abstract}
\section{Introduction}
Content...
\section{Methods}
Content...
\bibliographystyle{plain}
\bibliography{references}
references/latex_templates.md - LaTeX code patterns for various layoutsreferences/troubleshooting.md - Common issues and solutionsIf Chinese characters don't render:
If images don't appear in output:
\graphicspath includes correct directory\includegraphicsIf layout differs from original:
If LaTeX compilation fails:
download_arxiv_source.py script requires curl or wget to be installed.