Built-in modules#

aspell#

This module defines the connection between LaTeXBuddy and GNU Aspell.

class latexbuddy.modules.aspell.Aspell#
static find_languages()#

Returns all languages supported by the current aspell installation. Omits specific language variations like ‘en-variant_0’.

Returns

list of supported languages in str format

Return type

list[str]

format_errors(out, line_number, file)#

Parses Aspell errors and returns list of Problems.

Parameters
  • line_number (int) – the line_number for the location

  • out (list[str]) – line-split output of the aspell command

  • file (TexFile) – the file path

Return type

list[latexbuddy.problem.Problem]

run_checks(config, file)#

Runs the Aspell checks on a file and returns the results as a list.

Requires Aspell to be set up.

Parameters
  • config (ConfigLoader) – the configuration options of the calling LaTeXBuddy instance

  • file (TexFile) – LaTeX file to be checked (with built-in detex option)

Return type

list[latexbuddy.problem.Problem]

BibTeX#

class latexbuddy.modules.bib_checkers.BibtexDuplicates#
run_checks(config, file)#

Runs the checks and returns a list of discovered problems.

Parameters
  • config (ConfigLoader) – the configuration options of the calling LaTeXBuddy instance

  • file (TexFile) – LaTeX file to be checked (with built-in detex option)

Return type

list[latexbuddy.problem.Problem]

class latexbuddy.modules.bib_checkers.NewerPublications#
run_checks(config, file)#

Runs the checks and returns a list of discovered problems.

Parameters
  • config (ConfigLoader) – the configuration options of the calling LaTeXBuddy instance

  • file (TexFile) – LaTeX file to be checked (with built-in detex option)

Return type

list[latexbuddy.problem.Problem]

latexbuddy.modules.bib_checkers.get_bibfile(file)#

Checks the given file text for a ibliography{} command and returns the full path of the input BibTeX file. For now only works with a single BibTeX file.

Parameters

file (TexFile) – TexFile object of the LaTeX file to check

Returns

Return type

pathlib.Path | None

latexbuddy.modules.bib_checkers.parse_bibfile(bibfile)#

Parses the given BibTeX file to extract the publications.

Parameters

bibfile (Path) – Path object of the BibTeX file to be parsed

Returns

the title, year, and BibTeX Id of each publication as 3-Tuple

Return type

(str, str, str)

ChkTeX#

This module defines the connection between LaTeXBuddy and ChkTeX.

ChkTeX Documentation: https://www.nongnu.org/chktex/ChkTeX.pdf

Diction#

class latexbuddy.modules.diction.Diction#
format_errors(out, original, file, texfile)#

Parses diction errors and returns list of Problems.

Parameters
  • original (list[str]) – lines of file to check as list

  • out (list[str]) – line split output of the diction command with empty lines removed

  • file – the file path

Return type

list[latexbuddy.problem.Problem]

run_checks(config, file)#

Runs the checks and returns a list of discovered problems.

Parameters
  • config (ConfigLoader) – the configuration options of the calling LaTeXBuddy instance

  • file (TexFile) – LaTeX file to be checked (with built-in detex option)

Return type

list[latexbuddy.problem.Problem]

LanguageTool#

This module defines the connection between LaTeXBuddy and LanguageTool.

class latexbuddy.modules.languagetool.LanguageTool#

Wraps the LanguageTool API calls to check files.

check_tex(file)#

Runs the LanguageTool checks on a file.

Parameters

file (TexFile) – the file to run checks on

Return type

list[latexbuddy.problem.Problem]

execute_commandline_request(file)#

Execute the LanguageTool command line app to check the text.

Parameters

file (TexFile) – TexFile object representing the file to be checked

Returns

app’s response

Return type

dict | None

find_disabled_rules(config)#

Reads all disabled rules and categories from the specified configuration and saves the result in the instance.

Parameters

config (ConfigLoader) – configuration options to be read

Return type

None

find_languagetool_command()#

Searches for the LanguageTool command line app.

This method also checks if Java is installed.

Return type

None

find_languagetool_command_prefix()#

Finds the prefix of the shell command executing LanguageTool in the commandline.

Return type

list[str]

find_supported_languages()#

Acquires a list of supported languages from the version of LanguageTool that is currently used.

Return type

list[str]

static format_errors(raw_problems, file)#

Parses LanguageTool errors and converts them to LaTeXBuddy Error objects.

Parameters
  • raw_problems (dict) – LanguageTool’s error output

  • file (TexFile) – TexFile object representing the file to be checked

Return type

list[latexbuddy.problem.Problem]

lt_languages_get_request(server_url)#

Sends a GET request to the specified URL in order to retrieve a JSON formatted list of supported languages by the server.

If the response format is invalid, this method will most likely fail with an exception.

Parameters

server_url (str) –

Return type

list[str]

lt_post_request(file, server_url)#

Send a POST request to the LanguageTool server to check the text.

Parameters
  • file (TexFile) – TexFile object representing the file to be checked

  • server_url (str) – URL of the LanguageTool server

Returns

server’s response

Return type

dict | None

matches_language_regex(language)#

Determines whether a given string is a language code by matching it against a regular expression.

Parameters

language (str) –

Return type

bool

static parse_error_replacements(json_replacements, max_elements=5)#

Converts LanguageTool’s replacements to LaTeXBuddy suggestions list.

Parameters
  • json_replacements (list[dict]) – list of LT’s replacements for a particular word

  • max_elements (int) – Caps the number of replacements for the given error

Returns

list of string values of said replacements

Return type

list[str]

run_checks(config, file)#

Runs the LanguageTool checks on a file and returns the results as a list.

Requires LanguageTool (server) to be set up. Local or global servers can be used.

Parameters
  • config (ConfigLoader) – the configuration options of the calling LaTeXBuddy instance

  • file (TexFile) – LaTeX file to be checked (with built-in detex option)

Return type

list[latexbuddy.problem.Problem]

class latexbuddy.modules.languagetool.LanguageToolLocalServer#

Defines an instance of a local LanguageTool deployment.

static find_free_port(port=None)#

Tries to find a free port for the LanguageTool server.

Parameters

port (int) – port to check first

Returns

a free port that the LanguageTool server can listen at

Return type

int

get_server_run_command()#

Searches for the LanguageTool server executable.

This method also checks if Java is installed.

Return type

None

static is_port_in_use(port)#

Checks if a port is already in use.

Parameters

port (int) – port to check

Returns

True if port already in use, False otherwise

Return type

bool

start_local_server(port=8081)#

Starts the LanguageTool server locally.

Parameters

port (int) – port for the server to listen at

Returns

the actual port of the server

Return type

int

stop_local_server()#

Stops the local LanguageTool server process.

Return type

None

wait_till_server_up()#

Waits for the LanguageTool server to start.

Raises

ConnectionError – if server didn’t start

Return type

None

class latexbuddy.modules.languagetool.Mode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Describes the LanguageTool mode.

LanguageTool can be run as a command line program, a local server, or a remote server.

Log filter#

class latexbuddy.modules.logfilter.LogFilter#

A Filter for log files.

Using TexFilt: https://www.ctan.org/tex-archive/support/texfilt

format_problems(raw_problems_path, file)#

Formats the output to a List of Problems.

Parameters
  • raw_problems_path (Path) – Path to TexFilt output

  • file (TexFile) – file to check

Returns

a list of problems

Return type

list[latexbuddy.problem.Problem]

run_checks(config, file)#

Runs the Texfilt checks on a file and returns the results as a list.

Parameters
  • config (ConfigLoader) – configurations of the LaTeXBuddy instance

  • file (TexFile) – the file to run checks on

Returns

a list of problems

Return type

list[latexbuddy.problem.Problem]

Own checkers#

Proselint#

Yalafi#