latex

The latex module contains the following submodules:

from trouver.helper.tests import _test_directory
# from trouver.latex.preamble import divide_preamble

Identify the main tex file in a folder


find_main_latex_file

 find_main_latex_file (directory:os.PathLike)

*Identify the main LaTeX file in a given directory.

The main LaTeX file is determined based on the presence of: - A \documentclass command - A \begin{document} command

Parameters: - directory: The path to the directory containing LaTeX files.

Returns: - The full path to the main LaTeX file if found; otherwise, raises an error.

Raises: - FileNotFoundError: If no suitable main LaTeX file is found.*

Type Details
directory PathLike
Returns Path The full path to the main LaTeX file if found; otherwise, raises an error.
latex_folder = _test_directory() / 'latex_examples' / 'latex_example_with_inputs_and_includes'
find_main_latex_file(latex_folder)
# main_file = latex_folder / 'main.tex'
# with open(main_file, 'r', encoding='utf-8') as file:
#     document = file.read()
# preamble, body = divide_preamble(document)
# commands = custom_commands(preamble)
# output = replace_input_and_include(body, latex_folder, commands)
WindowsPath('c:/Users/hyunj/Documents/Development/Python/trouver/nbs/_tests/latex_examples/latex_example_with_inputs_and_includes/main.tex')