4 ways to print in GAlgebra


In [1]:
from sympy import *
from galgebra.ga import Ga
from galgebra.printer import Eprint, Format, xpdf

In [2]:
cga3d = Ga(r'e_1 e_2 e_3 e e_{0}',g='1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 -1,0 0 0 -1 0')

Printing in plain text


In [3]:
print(cga3d.I())


e_1^e_2^e_3^e^e_{0}

Enhanced Console Printing

If called Eprint() upfront, print() will do Enhanced Console Printing(colored printing with ANSI escape sequences):


In [4]:
!python -c "from galgebra.ga import Ga;from galgebra.printer import Eprint;Eprint();cga3d = Ga(r'e_1 e_2 e_3 e e_{0}',g='1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 -1,0 0 0 -1 0');print(cga3d.I())"


e_1^e_2^e_3^e^e_0

MathJax printing in Jupyter Notebook

In a Jupyter Notebook upfront, without calling print(), it will do LaTeX printing with MathJax for Geometric Algebra expressions.


In [5]:
cga3d.I()


Out[5]:
\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3}\wedge \boldsymbol{e}\wedge \boldsymbol{e}_{{0}} \end{equation*}

LaTeX printing

If called Format() upfront and xpdf() eventually, print() will do LaTeX printing (internally, the standard output will be redirected to a buffer for later consumption).


In [6]:
Format()

In [7]:
print(cga3d.I())

In [8]:
xpdf(filename='test_latex_output.tex',paper=(9,10),pdfprog=None)

In [9]:
!cat test_latex_output.tex


\documentclass[10pt,fleqn]{report}
\usepackage[vcentering]{geometry}
\geometry{papersize={9in,10in},total={8in,9in}}

\pagestyle{empty}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsbsy}
\usepackage{tensor}
\usepackage{listings}
\usepackage{color}
\usepackage{xcolor}
\usepackage{bm}
\usepackage{breqn}
\definecolor{gray}{rgb}{0.95,0.95,0.95}
\setlength{\parindent}{0pt}
\DeclareMathOperator{\Tr}{Tr}
\DeclareMathOperator{\Adj}{Adj}
\newcommand{\bfrac}[2]{\displaystyle\frac{#1}{#2}}
\newcommand{\lp}{\left (}
\newcommand{\rp}{\right )}
\newcommand{\paren}[1]{\lp {#1} \rp}
\newcommand{\half}{\frac{1}{2}}
\newcommand{\llt}{\left <}
\newcommand{\rgt}{\right >}
\newcommand{\abs}[1]{\left |{#1}\right | }
\newcommand{\pdiff}[2]{\bfrac{\partial {#1}}{\partial {#2}}}
\newcommand{\lbrc}{\left \{}
\newcommand{\rbrc}{\right \}}
\newcommand{\W}{\wedge}
\newcommand{\prm}[1]{{#1}'}
\newcommand{\ddt}[1]{\bfrac{d{#1}}{dt}}
\newcommand{\R}{\dagger}
\newcommand{\deriv}[3]{\bfrac{d^{#3}#1}{d{#2}^{#3}}}
\newcommand{\grade}[1]{\left < {#1} \right >}
\newcommand{\f}[2]{{#1}\lp{#2}\rp}
\newcommand{\eval}[2]{\left . {#1} \right |_{#2}}
\newcommand{\Nabla}{\boldsymbol{\nabla}}
\newcommand{\eb}{\boldsymbol{e}}
\usepackage{float}
\floatstyle{plain} % optionally change the style of the new float
\newfloat{Code}{H}{myc}
\lstloadlanguages{Python}

\begin{document}
\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3}\wedge \boldsymbol{e}\wedge \boldsymbol{e}_{{0}} \end{equation*}
\end{document}