LaTeX Grammar Checker and Improver Tool

This tool processes LaTeX files using any ChatGPT-compatible API to improve grammar and wording while preserving LaTeX commands and structures.

class ml_research_tools.tex.latex_grammar_tool.LatexGrammarTool(services)[source]#

Bases: BaseTool

Tool for checking and improving grammar in LaTeX documents.

Initialize the LaTeX grammar tool.

name: str = 'latex-grammar'#
description: str = 'Check and improve LaTeX grammar and style with LLM'#
__init__(services)[source]#

Initialize the LaTeX grammar tool.

Return type:

None

classmethod add_arguments(parser)[source]#

Add tool-specific arguments to the parser.

Return type:

None

Parameters:

parser (ArgumentParser)

execute(config, args)[source]#

Execute the grammar improvement with the provided arguments.

Parameters:
  • config (Config) – Global configuration

  • args (Namespace) – Parsed command-line arguments

Return type:

int

Returns:

Exit code (0 for success, non-zero for error)

load_config(config_path=None)[source]#

Load configuration from file or use defaults.

Return type:

Dict[str, Any]

Parameters:

config_path (str | None)

read_latex_file(file_path)[source]#

Read content from a LaTeX file.

Return type:

str

Parameters:

file_path (str)

static split_into_chunks(text, max_words)[source]#

Split text into chunks respecting paragraph breaks (double newlines). Each chunk will contain at most max_words words.

Return type:

List[str]

Parameters:
create_diff_file(original, improved, output_path)[source]#

Create a file showing differences in standard unified diff format for VSCode highlighting.

Parameters:
  • original (str)

  • improved (str)

  • output_path (str)

create_latexdiff_file(original, improved, output_path)[source]#

Create a diff file using latexdiff for better LaTeX-aware diff.

Return type:

bool

Parameters:
  • original (str)

  • improved (str)

  • output_path (str)

static remove_think_tags(text)[source]#

Removes all <think>…</think> tags and their content from the input text.

Parameters:

text (str) – Text potentially containing <think> tags

Returns:

Cleaned text with all <think> tags and their content removed

Return type:

str

post_process_chunk(text)[source]#