algebraixlib.util.latexprinter module

A conversion utility that manipulates a MathObject into a LaTeX representation.

The main entry point is the math_object_to_latex function; it delegates to the appropriate conversion function according to the argument type.

class algebraixlib.util.latexprinter.Config[source]

Bases: object

Module configuration values.

colorize_output = True
short_atom_len = 10
short_set_len = 4
algebraixlib.util.latexprinter.nested_set_helper(depth)[source]

This function inserts the appropriate number of spaces for indentation, based on how many nests sets of sets that are currently being printed. :param depth: Indicates the current number of nests of sets :return: A snippet of LaTeX representing the correct amount of space when starting a new line of printing.

algebraixlib.util.latexprinter.set_hasa_set(a_set)[source]

A interim function for determining the structure of a set.

Parameters:a_set – The set to test.
Returns:True if the set provided contains elements which are also sets.
algebraixlib.util.latexprinter.math_object_to_latex(mobj, short: bool=False, _depth: int=0)[source]

Prints a math object formatted in LaTeX. If it is not provided with a specific math object, returns an error string.

Parameters:
  • mobj – The object that you want to translate into LaTeX. It must be a Set, Atom, Couplet or Undef().
  • short – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
  • _depth – Defaults to 0, to not be exposed to a caller. Is incremented when the provided math object is a set that contains a set.
Returns:

string of LaTeX markup representing the provided math object.

algebraixlib.util.latexprinter.iprint_latex(variable_name: str, variable_value=None, short: bool=False)[source]

A utility to display variables in IPython notebooks.

Parameters:
  • variable_name – The name of the variable to display.
  • variable_value – The optional value of the variable. If it is missing, the variable value is fetched from the caller’s frame; a variable with the name variable_name is assumed to exist in this case.
  • short – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
algebraixlib.util.latexprinter.atom_to_latex(atom, short: bool=False)[source]

Prints an atom formatted in LaTeX. For example the “atom(“scooby”)” will be represented in LaTeX as “mbox{scooby}”

The atom is wrapped in mbox tag to enforce that it remains on one line. Note, currently the str function on a atom returns the value wrapped in single quotes.

Returns an error string if the atom is not of type Atom.

Parameters:
  • atom – The atom to be turned into LaTeX.
  • short – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
Returns:

The LaTeX markup of the atom.

algebraixlib.util.latexprinter.couplet_to_latex(couplet, short: bool=False)[source]

Prints a couplet formatted in LaTeX.

Note, currently this implementation only supports couplets which contain atoms. The LaTeX of a couplet which contains non atom math objects might look malformed.

For example the “Couplet(left=atom(“scooby”), right=atom(“doo”)” will be represented in LaTeX as “(mbox{scooby}{mapsto}{mbox{doo}})”

Returns an error string if the couplet is not of type Couplet.

Parameters:
  • couplet – The couplet to be turned into LaTeX.
  • short – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
Returns:

The LaTeX markup of the couplet.

algebraixlib.util.latexprinter.set_to_latex(mobj_set, short: bool=False, depth=0)[source]

Prints a set formatted in LaTeX.

The function checks to see if a set contains another set, if it does, then the elements are printed by row on new lines, instead of horizontally. The elements are also indented under the outer brackets. This indentation is continued until the nesting stops.

Returns an error string if the couplet is not an algebraixlib.mathobjects.couplet.Couplet.

Parameters:
  • mobj_set – The set to be turned into LaTeX.
  • short – When set to True, a short version of the content is generated. Longer parts are abbreviated with ellipses (‘...’). Defaults to False.
  • depth – A counter of how many tabs to insert when printing the elements; default is 0.
Returns:

The LaTeX markup of the set or an error message.

algebraixlib.util.latexprinter.mset_to_latex(mobj_mset, short: bool=False, depth=0)[source]