TeXUtils

Author

Marcel Simader

Date

12.07.2021

New in version v0.2.0.

vspace(length)

Inserts a vertical space of length length in the document.

parentheses(text)

Puts text in parentheses like so: \left( text \right).

brackets(text)

Puts text in brackets like so: \left[ text \right].

braces(text)

Puts text in braces like so: \left\{ text \right\}.

matrix(matr, matrix_type='', labels=None, tab_width=4)

Converts a nested sequence of any object to a math-mode compatible matrix. The sequence may not be empty and all nested sequences must be of equal length.

The available options are "", "p", "b", and "B" for matrix, pmatrix (parentheses), bmatrix (brackets), and Bmatrix (braces, requires amsmath) respectively.

Parameters
  • matr (Sequence[Sequence[Any]]) – the nested sequence to convert to a matrix string

  • matrix_type (Literal[, p, b, B]) – which kind of matrix to create, either "", "p", "b", or "B"

  • labels (Optional[Sequence[Any]]) – an optional sequence of strings to label both the top row and first column, can only be used for square matrices and must be of equal length to the first and second dimensions

  • tab_width (int) – how wide a tab character should be considered to be in characters for formatting the string output

Raises

ValueError – if matr contains no elements, if nested sequences of matr are not all the same size, if the labels option is set for non-square matrices, if the labels sequence is not the same size as the first and second dimensions of matr

Returns

the nested sequence as math-mode compatible matrix in string form

Return type

str

p_matrix(matr, labels=None, tab_width=4)

Parentheses alias for specifying a matrix type.

See also

Function matrix() for details

b_matrix(matr, labels=None, tab_width=4)

Brackets alias for specifying a matrix type.

See also

Function matrix() for details

B_matrix(matr, labels=None, tab_width=4)

Braces alias for specifying a matrix type.

See also

Function matrix() for details

tex_maths_string(s)

Formats the given object in a LaTeX-friendly way for math mode.

cls

Behaviour if isinstance(s, cls)

Fraction

print as LaTeX fraction

Set

print set in curly braces, call tex_maths_string() on each object of the set

Tuple or List

print list or tuple in square brackets, call tex_maths_string() on each object of the set except if the object is a string

Algebraic Structure

print the set using tex_maths_string(), and format the operator names as text, both set and operators are in parentheses

Default behaviour is to call the __str__ method of an object.

param s

the object to format

return

a string which can be written to a LaTeX document in a math mode environment