py_asciimath.utils.utils

class py_asciimath.utils.utils.UtilsMat

Bases: object

Static class to check matrix-structure of a string and returns its LaTeX translation.

It performs two opertions:

  1. Given a string, it checks if the string could be a rendered as LaTeX matrix. A correct matrix structure is: L [… (, …)*], [… (, …)*] (, [… (, …)*])* R or L (… (, …)*), (… (, …)*) (, (… (, …)*))* R, where L and R are all the possible left and right parenthesis defined by the parser; ‘[… (, …)*]’ or ‘(… (, …)*)’ identifies a row in the matrix which can be made by one or more columns, comma separated. In order to be considered as a matrix, the string must contain at leat two rows and every rows must contain the same number of columns
  2. Given a correctly matrix-like string, it returns the LaTeX translation: col (& col)* \ col (& col)* (\ col (& col)*)*
classmethod check_mat(s)

Given a string, runs a matrix-structure check. Returns True if the string s has a matrix-structure-like, False otherwise. It returns also the row delimiters.

Parameters:s (str) – Input string to be matrix-checked
Returns:
True, [left_par, right_par] if the string s
has a matrix-like structure; False, [] otherwise
Return type:bool, list
classmethod get_latex_mat(s, row_par=['[', ']'])

Given a known matrix-structured string, translate it into the matrix LaTeX format.

Parameters:
  • s (str) – Input string
  • max_cols (int) – How many columns per rows
  • row_par (list, optional) – Row delimiters
Returns:

LaTeX well-formed matrix

Return type:

str

classmethod get_mathml_mat(s, row_par=['[', ']'])

Given a known matrix-structured string, translate it into the matrix LaTeX format.

Parameters:
  • s (str) – Input string
  • max_cols (int) – How many columns per rows
  • row_par (list, optional) – Row delimiters
Returns:

MathML well-formed matrix

Return type:

str

classmethod get_row_par(s)

Given a string, it returns the first index i such that the char in position i of the string is a left parenthesis, ‘(‘ or ‘[‘, and the open-close parenthesis couple, needed to identify matrix rows in the string.

Parameters:s (str) – Input string
Returns:
Index i of the first open parenthesis,
and the list [left_par, right_par]. -1 and [] if no parenthesis is found
Return type:int, list
py_asciimath.utils.utils.alias_string(mapping, init=False, alias=True, prefix='', lang_from=None)
py_asciimath.utils.utils.check_connection(url='www.google.com', timeout=10.0)

Check connection against url.

Parameters:
  • url (str, optional) – URL to check connection against
  • timeout (float, optional) – Connection timeout
Returns:

True, if there is a connection, False otherwise

Return type:

bool

py_asciimath.utils.utils.flatten(l)

Flatten a list (or other iterable) recursively