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
--helpand--version. - Easy Installation: Can be installed easily using modern Python packaging tools like
piporuv.
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.texfile containingchangesmarkup.OUTFILE: The path where the processed.texfile 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.
Metadata
Release files for latex-merge-changes 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| latex_merge_changes-0.1.0.tar.gz | 9.8 kB | Without provenance | Details for latex_merge_changes-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| latex_merge_changes-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for latex_merge_changes-0.1.0-py3-none-any.whl |
Total release size: 22.0 kB
Release files / latex_merge_changes-0.1.0.tar.gz
| Download URL | latex_merge_changes-0.1.0.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
edcd828046659a443c318fc32b5fcfcce8be005c0401937b24807dd075ee3ad1
|
|
BLAKE2b-256 checksum How to use checksums |
f2a2444cd41e889d3e7049dac19a672a5a1f5829dcdac1f3ee56d12b0307e2bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.14
|
Release files / latex_merge_changes-0.1.0-py3-none-any.whl
| Download URL | latex_merge_changes-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b27b537fe9127271c6e0f4e3579e75ab95198179e8833d09a83e7bd9258ee67
|
|
BLAKE2b-256 checksum How to use checksums |
fdde86c4ddf6f4e697ba3892ca896c7718723c22761c4dcdbe41411e581034aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.14
|
Security for latex-merge-changes 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.