galgebra.printer

ANSI Enhanced Text Printing, Text Printer and LaTeX Printer for all Geometric Algebra classes

Members

galgebra.printer.isinteractive()[source]

We will assume that if ipython is running then jupyter notebook is running.

galgebra.printer.coef_simplify(expr)[source]

fcts = find_functions(expr) return expr.collect(fcts)

galgebra.printer.oprint(*args, dict_mode=False)[source]

Debug printing for iterated (list/tuple/dict/set) objects. args is of form (title1, object1, title2, object2, …) and prints:

title1 = object1 title2 = object2 …

If you only wish to print a title set object = None.

class galgebra.printer.GaPrinter(settings=None)[source]
doprint(expr)

Returns printer’s representation for expr (as a string)

emptyPrinter(expr)

str(object=’‘) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

classmethod set_global_settings(**settings)

Set system-wide printing settings.

class galgebra.printer.GaPrintable[source]

Mixin class providing default implementations of printing hooks

class galgebra.printer.GaLatexPrinter(settings=None)[source]

The latex printer is turned on with the function (in ga.py) -

Format(Fmode=True, Dmode=True, ipy=False)

where Fmode is the function printing mode that surpresses printing arguments, Dmode is the derivative printing mode that does not use fractions, and ipy=True is the Ipython notebook mode that does not redirect the print output.

The latex output is post processed and displayed with the function (in GAPrint.py) -

xpdf(filename=’tmplatex.tex’, debug=False)

where filename is the name of the tex file one would keep for future inclusion in documents and debug=True would display the tex file immediately.

There are three options for printing multivectors in latex. They are acessed with the multivector member function -

A.Fmt(self, fmt=1, title=None)

where fmt=1, 2, or 3 determines whether the entire multivector A is printed entirely on one line, or one grade is printed per line, or one base is printed per line. If title is not None then the latex string generated is of the form -

title+’ = ‘+str(A)

where it is assumed that title is a latex math mode string. If title contains ‘%’ it is treated as a pure latex math mode string. If it does not contain ‘%’ then the following character mappings are applied -

‘grad’ -> ‘bm{nabla} ‘ ‘*’ -> ‘’ ‘^’ -> ‘W ‘ ‘|’ -> ‘cdot ‘ ‘>’ -> ‘lfloor ‘ ‘<’ -> ‘rfloor ‘

In the case of a print statement of the form -

print title, A

everthing in the title processing still applies except that the multivector formatting is one multivector per line.

For print statements of the form -

print title

where no program variables are printed if title contains ‘#’ then title is printed as regular latex line. If title does not contain ‘#’ then title is printed in equation mode. ‘%’ has the same effect in title as in the Fmt() member function.

doprint(expr)

Returns printer’s representation for expr (as a string)

embed_super(s)

Embed s in {} if there is a superscript in s

emptyPrinter

alias of builtins.str

parenthesize_super(s)

Parenthesize s if there is a superscript in s

classmethod set_global_settings(**settings)

Set system-wide printing settings.

galgebra.printer.print_latex(expr, **settings)[source]

Prints LaTeX representation of the given expression.

galgebra.printer.Format(Fmode: bool = True, Dmode: bool = True, inverse='full')[source]

Turns on latex printing with configurable options.

This redirects printer output so that latex compiler can capture it.

Format() is also required for printing from ipython notebook (note that xpdf() is not needed to print from ipython notebook).

Parameters
  • Fmode

    • True – Print functions without argument list, \(f\)

    • False – Print functions with standard sympy latex formatting, \({{f}\lp {x,y,z} \rp }\)

  • Dmode

    • True – Print partial derivatives with condensed notation, \(\partial_{x}f\)

    • False – Print partial derivatives with standard sympy latex formatting, \(\pdiff{f}{x}\)

galgebra.printer.tex(paper=14, 11, debug=False, prog=False, pt='10pt')[source]

Post processes LaTeX output (see comments below), adds preamble and postscript.

This postprocessing has two main behaviors:

  1. Converting strings on the left hand side of the last = into TeX. This translates the *, ^, |, >, <, <<, >>, grad, and rgrad operators of galgebra into the appropriate latex operators. If there is no = in the line, no conversion is applied.

  2. Wrapping lines of latex into equation* environments if they are not already in environments, and moving labels that were prepended outside align environments inside those environments.

Both behaviors are applied line by line, unless a line starts with the following text:

#% or %

Disables only behavior 1 for the rest of the line.

##

Disables behaviors 1 and 2 until the end of the next line starting with ##. This includes processing any of the other special characters, which will be emitted verbatim.

#

Disables behaviors 1 and 2 for the rest of the line.

We assume that if tex() is called, then Format() has been called at the beginning of the program.

galgebra.printer.xpdf(filename=None, paper=14, 11, crop=False, png=False, prog=False, debug=False, pt='10pt', pdfprog='pdflatex')[source]

Post processes LaTeX output (see comments below), adds preamble and postscript, generates tex file, inputs file to latex, displays resulting pdf file.

Arg Value Result pdfprog ‘pdflatex’ Use pdfprog to generate pdf output, only generate tex if pdfprog is None crop True Use “pdfcrop” to crop output file (pdfcrop must be installed, linux only) png True Use “convert” to produce png output (imagemagick must be installed, linux only)

We assume that if xpdf() is called then Format() has been called at the beginning of the program.

galgebra.printer.def_prec(gd: dict, op_ord: str = '<>|,^,*')None[source]

This is used with the GAeval() function to evaluate a string representing a multivector expression with a revised operator precedence.

Parameters
  • gd – The globals() dictionary to lookup variable names in.

  • op_ord – The order of operator precedence from high to low with groups of equal precedence separated by commas. The default precedence, '<>|,^,*', is that used by Hestenes ([HS84], p7, [DL03], p38). This means that the <, >, and | operations have equal precedence, followed by ^, and lastly *.

galgebra.printer.GAeval(s: str, pstr: bool = False)[source]

Evaluate a multivector expression string s.

The operator precedence and variable values within the string are controlled by def_prec(). The documentation for that function describes the default precedence.

The implementation works by adding parenthesis to the input string s according to the requested precedence, and then calling eval() on the result.

For example consider where X, Y, Z, and W are multivectors:

def_prec(globals())
V = GAeval('X|Y^Z*W')

The sympy variable V would evaluate to ((X|Y)^Z)*W.

Parameters
  • s – The string to evaluate.

  • pstr – If True, the values of s and s with parenthesis added to enforce operator precedence are printed.