Skip to main content

A tool to accept, reject, or process LaTeX documents using the 'changes' package.

Project description

LaTeX-merge-changes

A modern, command-line tool to interactively or automatically process LaTeX documents that use the changes package. This project serves as an updated and more robust Python-based alternative to the original pyMergeChanges.py script.

Key Features

  • Interactive Mode: Prompts you for each change (\added, \deleted, \replaced, etc.), allowing you to accept, reject, or keep the markup for each one individually.
  • Automatic Modes:
    • --accept-all: Automatically accepts all changes in the document.
    • --reject-all: Automatically rejects all changes.
    • --remove-highlights: Removes all highlights and comments without accepting or rejecting.
  • Smart Line Handling: Correctly removes entire lines for \deleted{...} commands that occupy a full line, preventing unwanted blank lines in your output.
  • Standard CLI Interface: Supports common flags like --help and --version.
  • Easy Installation: Can be installed easily using modern Python packaging tools like pip or uv.

Installation

Using uv (Recommended)

uv is an extremely fast Python package installer and resolver.

uv tool install latex-merge-changes

Using pip

You can also use the standard Python package installer, pip.

pip install latex-merge-changes

For Developers

If you want to contribute to the project, you can install it in editable mode:

# 1. Clone the repository
git clone https://github.com/your-username/latex-merge-changes.git
cd latex-merge-changes

# 2. Install in editable mode using uv or pip
uv tool install -e .
Project Structures
```plaintext
latex-merge-changes/
├── src/
│   └── latex_merge_changes/
│       ├── __init__.py
│       ├── __main__.py
│       ├── cli.py              # 命令行界面逻辑 (argparse, 文件 I/O)
│       ├── core.py             # 核心处理逻辑,完全与 UI 解耦
│       ├── handlers.py         # 交互处理器 (CLI 交互, 自动处理)
│       └── commands.py         # 定义所有 LaTeX 命令及其行为
├── tests/
│   └── test_core.py            # 针对 core.py 的单元测试
├── pyproject.toml              # 项目元数据和构建配置 (替代 setup.py)
├── README.md                   # 项目说明
└── LICENSE                     # 许可证文件 (GPLv3)
```

**Separation of Concerns**:

`__init__.py`: 包初始化文件, 用于暴露公共 API
`__main__.py`: 允许通过 python -m latex_merge_changes 运行
`core.py`: 这是项目的大脑。它只负责解析字符串和应用转换。它不知道文件系统,也不依赖 print() 或 input()。这是为未来 UI 预留的关键接口。
`cli.py`: 这是项目的“外壳”。它负责解析命令行参数、读写文件,并将 core 模块与用户连接起来。
`handlers.py`: 这是 core 和 cli 之间的桥梁。core 模块在需要用户决策时,会调用一个“处理器”(Handler),这个处理器决定了如何获取决策(是从命令行 input(),还是根据 -a/-r 标志自动决定)。
`commands.py`: 将每个 LaTeX 命令 (\added, \deleted 等) 的具体逻辑封装起来,使添加新命令变得极其简单。

Usage

The tool follows a standard command-line structure.

Basic Syntax

latex-merge-changes [OPTIONS] INFILE OUTFILE
  • INFILE: The path to your source .tex file containing changes markup.
  • OUTFILE: The path where the processed .tex file will be saved.

Options

Short Long Description
-h --help Show the help message and exit.
-v --version Show the program's version number and exit.
-a --accept-all Accept all changes automatically without prompting.
-r --reject-all Reject all changes automatically without prompting.
-rh --remove-highlights Remove all highlights and comments automatically without prompting.

Note: The automatic modes (-a, -r, -rh) are mutually exclusive. If you provide more than one, the tool will prioritize one based on implementation details. You should only use one at a time.

Examples

Let's say you have a file named document.tex with the following content:

document.tex

\documentclass{article}
\usepackage[final]{changes} % Using final option to show changes

\begin{document}

This is an \added{excellent} example of the tool.

\deleted{This entire line will be removed.}

We can also \replaced{demonstrate}{show} how replacements work.

\end{document}

1. Interactive Mode

Run the tool without any automatic flags to enter interactive mode.

$ latex-merge-changes document.tex final_document.tex

Your terminal will prompt you for each change:

Found command: \added
  - Original: {}
  - Changed:  {excellent}
Accept (a), Reject (r), or Keep markup (k)? a

Found command: \deleted
  - Original: {This entire line will be removed.}
  - Changed:  {}
Accept (a), Reject (r), or Keep markup (k)? a

Found command: \replaced
  - Original: {demonstrate}
  - Changed:  {show}
Accept (a), Reject (r), or Keep markup (k)? r
...
Successfully processed file and saved result to 'final_document.tex'

2. Automatic Mode (Accept All)

To quickly accept all changes and generate a clean final version:

latex-merge-changes --accept-all document.tex final_document.tex

This will run without any prompts. The resulting final_document.tex will look like this:

final_document.tex

\documentclass{article}
\usepackage[final]{changes} % Using final option to show changes

\begin{document}

This is an excellent example of the tool.

We can also demonstrate how replacements work.

\end{document}

Notice how the deleted line was removed completely without leaving an empty line.

License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

latex_merge_changes-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

latex_merge_changes-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file latex_merge_changes-0.1.0.tar.gz.

File metadata

  • Download URL: latex_merge_changes-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.14

File hashes

Hashes for latex_merge_changes-0.1.0.tar.gz
Algorithm Hash digest
SHA256 edcd828046659a443c318fc32b5fcfcce8be005c0401937b24807dd075ee3ad1
MD5 93bb7faab8f64fe8e08fb8a634b61d73
BLAKE2b-256 f2a2444cd41e889d3e7049dac19a672a5a1f5829dcdac1f3ee56d12b0307e2bc

See more details on using hashes here.

File details

Details for the file latex_merge_changes-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for latex_merge_changes-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b27b537fe9127271c6e0f4e3579e75ab95198179e8833d09a83e7bd9258ee67
MD5 da1936ee7e310008d6c9fb9f2b65e675
BLAKE2b-256 fdde86c4ddf6f4e697ba3892ca896c7718723c22761c4dcdbe41411e581034aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page