latex module

This module provides utilities for managing LaTeX files, including compilation, creating figures, tables, and handling Beamer slides.

compile(x=None)

Compiles LaTeX files in the current directory or specified files.

Parameters:

x (str or list, optional) – Filename or list of filenames to compile. If None, compiles all .tex files in the current directory.

Raises:

RuntimeError – If pdflatex or bibtex is not available in the system.

is_command_available(command)

Checks if a command is available in the system’s PATH.

Parameters:

command (str) – The command to check.

Returns:

True if the command is available, False otherwise.

Return type:

bool

make_figure(image_filename, position='h', caption=None, label='', hspace='0cm', height='6.5cm', width=None, caption_top=True, center_image=True, filename=None)

Constructs a LaTeX figure environment.

Parameters:
  • image_filename (str) – Path and filename of the image file.

  • position (str) – Position specifier for the figure (‘h’, ‘t’, ‘b’, ‘p’). Default is ‘h’.

  • caption (str, optional) – Caption for the figure. Default is None.

  • label (str) – Label for referencing the figure. Default is ‘’.

  • hspace (str) – Horizontal position offset of the image. Default is ‘0cm’.

  • height (str) – Height of the image. Default is ‘6.5cm’.

  • width (str) – Width of the image. Default is None.

  • caption_top (bool) – Whether to place the caption above the figure. Default is True.

  • center_image (bool) – Whether to center the image in the figure environment. Default is True.

  • filename (str, optional) – Path to save the generated LaTeX figure file. Default is None.

Returns:

LaTeX string for the figure environment.

Return type:

str

make_handout(slides_file_name, handout_file_name)

Generates a LaTeX handout file for Beamer slides.

Parameters:
  • slides_file_name (str) – Name of the original slides file.

  • handout_file_name (str) – Name of the generated handout file.

make_tabular(data, table_spec='', row_format={}, column_format={}, hlines=[], clines={}, pos='c', filename=None)

Constructs a LaTeX tabular environment.

Parameters:
  • data (numpy.ndarray) – 2D array with data for the table.

  • table_spec (str) – Column alignment string for the tabular environment. Default is ‘’.

  • row_format (dict) – Row-specific formatting.

  • column_format (dict) – Column-specific formatting.

  • hlines (list) – List of row numbers for horizontal lines. Default is [].

  • clines (dict) – Dictionary of row numbers and column range strings for clines. Default is {}.

  • pos (str) – Vertical positioning specifier (‘b’, ‘c’, ‘t’). Default is ‘c’.

  • filename (str, optional) – Path to save the LaTeX tabular file. Default is None.

Returns:

LaTeX string for the tabular environment.

Return type:

str

make_table(data, table_spec='', row_format={}, column_format={}, hlines=[], clines={}, position='h', caption=None, label='', caption_top=True, center_table=True, filename=None)

Constructs a LaTeX table environment with tabular content.

Parameters:
  • data (numpy.ndarray) – 2D array with data for the table.

  • table_spec (str) – Column alignment string for the tabular environment. Default is ‘’.

  • row_format (dict) – Row-specific formatting.

  • column_format (dict) – Column-specific formatting.

  • hlines (list) – List of row numbers for horizontal lines. Default is [].

  • clines (dict) – Dictionary of row numbers and column range strings for clines. Default is {}.

  • position (str) – Position specifier for the table (‘h’, ‘t’, ‘b’, ‘p’). Default is ‘h’.

  • caption (str, optional) – Caption for the table. Default is None.

  • label (str) – Label for referencing the table. Default is ‘’.

  • caption_top (bool) – Whether to place the caption above the table. Default is True.

  • center_table (bool) – Whether to center the table in the environment. Default is True.

  • filename (str, optional) – Path to save the LaTeX table file. Default is None.

Returns:

LaTeX string for the table environment.

Return type:

str

pdf_latex(file_name)

Compiles a LaTeX file using pdflatex.

Parameters:

file_name (str) – Name of the LaTeX file to compile.

Raises:

RuntimeError – If pdflatex or bibtex is not available in the system.

python_script(script)

Executes a Python script or list of scripts.

Parameters:

script (str or list) – Filename or list of filenames for Python scripts.