LaTeXTrans Documentation

repository·main·Indexed 19 days ago

https://github.com/niutrans/latextrans

An end-to-end LaTeX document translation system that uses multi-agent collaboration to translate LaTeX source code into multilingual PDFs. It preserves formulas, layout, and cross-references by translating pre-processed source code rather than PDFs. The system includes a CLI for processing arXiv IDs and local projects, a Streamlit-based GUI, and specialized classes for parsing (LatexParser), compiling (LaTexCompiler), and reconstructing (LatexConstructor) LaTeX documents.

Tokens
4.1K
Snippets
13
Records
18
Agent score
66%

What's inside LaTeXTrans

  1. Overview of LaTeXTrans

    main
    LaTeXTrans is a specialized tool designed to translate documents written in LaTeX format into various target languages. A common use case is translating scientific papers from arXiv (e.g., English to Chinese) while preserving the LaTeX structure.
  2. How LaTeXTrans works

    main

    LaTeXTrans is a structured LaTeX document translation system based on multi-agent collaboration. Unlike traditional PDF translation methods that often break formulas and formatting, LaTeXTrans translates the pre-processed LaTeX source code directly.

    The system uses a workflow consisting of six specialized agents:

    1. Parser
    2. Translator
    3. Validator
    4. Summarizer
    5. Terminology Extractor
    6. Generator

    This approach ensures that formulas, layout, and cross-references remain intact while maintaining terminology consistency and generating a high-quality translated PDF that matches the original layout.

  3. Use the Streamlit GUI

    main

    For a graphical interface with progress bars, logs, and configurable parameters, you can use the Streamlit-based GUI.

    Option 1: Run the dedicated command

    latextrans-gui

    Option 2: Run via Streamlit directly

    streamlit run src/gui/streamlit_app.py
    latextrans-gui
  4. Install LaTeXTrans

    main

    To install LaTeXTrans, clone the repository and install it in editable mode using pip. It is recommended to use a Conda virtual environment.

    Prerequisites

    To compile LaTeX files and generate PDF outputs, you must have a LaTeX distribution installed:

    • MikTex (Recommended for being lightweight): When installing, ensure you select "install on the fly". You must also install Strawberry Perl to support compilation.
    • TeXLive

    Installation Steps

    Using Conda (Recommended):

    conda create -n latextrans python=3.10 -y
    conda activate latextrans
    git clone https://github.com/NiuTrans/LaTeXTrans.git
    cd LaTeXTrans
    pip install -e .

    Standard Installation:

    git clone https://github.com/NiuTrans/LaTeXTrans.git
    cd LaTeXTrans
    pip install -e .
    pip install -e .
  5. Launch the LaTeXTrans GUI

    main

    For a browser-based interface that shows live workflow progress, logs, and runtime configuration, you can launch the Streamlit-based GUI.

    Run either the dedicated command or the Streamlit command directly.

    # Using the dedicated CLI command
    latextrans-gui
    
    # Or running Streamlit directly
    streamlit run src/gui/streamlit_app.py
  6. Configure LaTeXTrans API settings

    main

    Before running translations, you must configure your Large Language Model (LLM) credentials in the config/default.toml file. You need to specify the model name, your api_key, and the base_url for the API.

    ModelRecommended base_url
    deepseek-chathttps://api.deepseek.com/v1/chat/completions
    gpt-4ohttps://api.openai.com/v1/chat/completions
    gemini-2.5-prohttps://generativelanguage.googleapis.com/v1beta/openai/chat/completions
    model = "deepseek-chat"
    api_key = "your_api_key_here"
    base_url = "https://api.deepseek.com/v1/chat/completions"
  7. Configure LaTeXTrans LLM settings

    main

    Before running translations, you must configure your Large Language Model (LLM) settings in the config/default.toml file. You need to provide the model name, your api_key, and the base_url for the API.

    Recommended base_url examples:

    • deepseek-chat: https://api.deepseek.com/v1/chat/completions
    • gpt-4o: https://api.openai.com/v1/chat/completions
    • gemini-2.5-pro: https://generativelanguage.googleapis.com/v1beta/openai/chat/completions
    model = "deepseek-chat"
    api_key = "your_api_key_here"
    base_url = "https://api.deepseek.com/v1/chat/completions"
  8. Use the latextrans CLI to translate LaTeX projects

    main

    The latextrans CLI (via main.py) allows you to automate the translation of LaTeX documents. You can provide input via arXiv IDs, local project directories, or compressed archives. The system uses a CoordinatorAgent to manage the translation workflow based on a TOML configuration file.

    Key Input Methods:

    • arXiv IDs: Use --arxiv to provide one or more arXiv IDs.
    • Local Projects: Use --project to provide paths to local directories or archive files (.zip, .tar, .tar.gz, .tgz).
    • Batch Processing: Use --all-existing to process all projects already present in the configured tex_sources_dir.
    # Translate a single arXiv paper
    latextrans --arxiv 2508.18791
    
    # Batch translate multiple arXiv papers
    latextrans --arxiv 2508.18791v2, 2407.01648
    
    # Translate a local project directory or archive
    latextrans --project /path/to/project_dir
    latextrans --project /path/to/archive.zip
    
    # Process all existing projects in the source directory
    latextrans --all-existing
  9. Launch the latextrans GUI via Streamlit

    main

    The latextrans graphical user interface can be launched using the Python entrypoint in src/gui/launcher.py. This command starts a Streamlit application that provides a visual interface for the translation tools. It is equivalent to running python -m streamlit run src/gui/streamlit_app.py from the project root.

    python src/gui/launcher.py
  10. Configure latextrans via TOML

    main

    The translation behavior is controlled by a TOML configuration file. The CLI can override several keys in this configuration.

    Configurable sections and keys via CLI:

    • llm_config.base_url: Set via --url.
    • llm_config.model: Set via --model.
    • llm_config.api_key: Set via --key.
    • paper_list: Extended by providing --arxiv IDs.
    • tex_sources_dir: Set via --source.
    • output_dir: Set via --output.

    If user_term is not set in the config, the system will automatically attempt to determine the arXiv category for downloaded papers.

  11. Translate local LaTeX projects

    main

    LaTeXTrans supports translating local files or directories using the --project flag.

    Compressed Archives

    Provide a path to a .zip, .tar, .tar.gz, or .tgz file:

    latextrans --project D:\path\to\paper_source.tar.gz

    Uncompressed Directories

    Provide the path to the extracted project directory:

    latextrans --project D:\path\to\paper_project_dir

    Process All Existing Projects

    To process all existing projects within the tex source directory, use:

    latextrans --all-existing

    Note: When using --arxiv or --project, LaTeXTrans only processes the explicitly specified input and will not scan other projects in tex source.

    latextrans --project D:\path\to\paper_project_dir
  12. Translate arXiv papers via CLI

    main

    You can translate papers directly using their arXiv ID. The system will download the LaTeX source, run the translation workflow (parsing, translating, reconstructing, and compiling), and save the results in the outputs folder.

    Single Paper

    Use the --arxiv flag with the ID. You can also specify a version (e.g., v2).

    latextrans --arxiv 2508.18791
    # Or with version
    latextrans --arxiv 2508.18791v2

    Batch Translation

    Provide multiple comma-separated arXiv IDs to translate them in bulk.

    latextrans --arxiv 2508.18791v2, 2407.01648
    latextrans --arxiv 2508.18791