LaTeX Grammar Tool

LaTeX Grammar Tool#

The LaTeX Grammar Tool helps improve the grammar, clarity, and wording of LaTeX documents while preserving LaTeX commands and mathematical expressions.

Description#

This tool processes LaTeX files using a ChatGPT-compatible API to improve grammar and phrasing while maintaining all LaTeX formatting, commands, and structures.

Usage#

ml_research_tools latex-grammar [options] input_file.tex
Usage: ml_research_tools latex-grammar [-h] [--config CONFIG]
                                       [--output OUTPUT]
                                       [--latexdiff LATEXDIFF] [--diff DIFF]
                                       [--system-prompt SYSTEM_PROMPT]
                                       [--user-prompt USER_PROMPT]
                                       [--max-words MAX_WORDS]
                                       [--no-words-regroup]
                                       input_file

Check and improve LaTeX grammar and style with LLM

Positional Arguments:
  input_file            Path to the LaTeX file to process

Options:
  -h, --help            show this help message and exit
  --config, -c CONFIG   Path to configuration file

Outputs:
  --output, -o OUTPUT   Path to save the diff file (default:
                        <input>_improved.tex)
  --latexdiff LATEXDIFF
                        Generate latexdiff file
  --diff DIFF           Generate diff file

Prompt:
  --system-prompt SYSTEM_PROMPT
                        Override system prompt
  --user-prompt USER_PROMPT
                        Override user prompt template
  --max-words MAX_WORDS
                        Maximum words per chunk
  --no-words-regroup    Do not split lines for readability

Examples#

Basic usage:

ml_research_tools latex-grammar paper.tex --output-file improved_paper.tex

Create a diff file to review changes:

ml_research_tools latex-grammar paper.tex --diff-file paper.diff

Use latexdiff to generate a PDF highlighting changes:

ml_research_tools latex-grammar paper.tex --latexdiff-file paper_diff.tex
pdflatex paper_diff.tex

Configuration#

The tool can be customized using a configuration file with the following structure:

[api]
max_words_per_chunk = 1024

[prompts]
system = Your custom system prompt here
user = Your custom user prompt template here

Configuration can be specified with the --config-file option.