pytexit.core.core module

Parser and core Routines

class pytexit.core.core.LatexVisitor(dummy_var, upperscript, lowerscript, verbose, simplify_multipliers, simplify_fractions, simplify_ints, tex_multiplier)

Bases: ast.NodeVisitor

Parameters:
  • simplify_multipliers (bool) –

    if True, simplify expression if multiplier is a float. Ex:

    2*a -> 2a
    a*3.5 -> 3.5a
    

    see visit_BinOp() for more information. Default True.

  • simplify_fractions (bool) – if True, simplify fractions. see visit_BinOp() for more information. Default False.
  • simplify_ints (bool) – see visit_BinOp() for more information. Default False.
brackets(expr)

Enclose expr in {…}

convert_symbols(expr)
division(up, down)
generic_prec(n)
generic_visit(n)

Called if no explicit visitor function exists for a node.

group(expr)

Returns expr, add brackets if needed

looks_like_int(a)

Check if the input a looks like an integer

operator(func, args=None)
parenthesis(expr)
power(expr, power)
prec(n)
prec_BinOp(n)
prec_UnaryOp(n)
sqrt(args)
visit_Add(n)
visit_Assign(n)

Rewrite Assign function (instead of executing it)

visit_BinOp(n)
visit_BitAnd(n)
visit_BitOr(n)
visit_BitXor(n)
visit_Call(n)

Node details : n.args, n.func, n.keywords, n.kwargs

visit_Compare(n)

Rewrite Compare function (instead of executing it)

visit_Invert(n)
visit_LShift(n)
visit_ListComp(n, kwout=False)

Analyse a list comprehension Output : - kw : used by some functions to display nice formulas (e.g : sum) - args : standard output to display a range in other cases

visit_Mod(n)
visit_Mult(n)
visit_Name(n)

Special features: - Recognize underscripts in identifiers names (default: underscore) - Recognize upperscripts in identifiers names (default: ˆ, valid in Python3) Note that using ˆ is not recommended in variable names because it may be confused with the operator ^, but in some special cases of extensively long formulas with lots of indices, it may help the readability of the code

visit_Not(n)
visit_Num(n)
visit_RShift(n)
visit_Sub(n)
visit_UAdd(n)
visit_USub(n)
visit_UnaryOp(n)
visit_list(n)
pytexit.core.core.preprocessing(expr, simplify)

Pre-process a string.

pytexit.core.core.replace_scientific(s)

Replace ‘NUMBER e NUMBER’ with powers of 10

pytexit.core.core.simplify(s)

Cleans the generated text in post-processing

pytexit.core.core.uprint(*expr)

Deals with encoding problems