LaTeX Expression project

Python module for easy LaTeX typesetting of algebraic expressions in symbolic form with automatic substitution and result computation

LaTeX Expression is a Python module for easy LaTeX typesetting of algebraic expressions in symbolic form with automatic substitution and result computation, i.e. of the form var = generalExpression = substitutedExpression = result, e.g.
r = 3.0 m
F = 4.0 kN
M = r*F = 3.0*4.0 = 12 kNm
The module can be beneficially combined with LaTeX Python package (see examples).
example1.py:
  import latexexpr
  v1 = latexexpr.Variable('H_{ello}',3.25,'m')
  print '$$ %s $$'%v1
  v2 = latexexpr.Variable('W^{orld}',5.63,'m')
  print '$$ %s $$'%v2
  e1 = latexexpr.Expression('E_{xample}',v1+v2,'m')
  print '$$ %s $$'%e1
  
example1.tex:
  \documentclass[12pt]{report}
  \begin{document}
  (Almost) minimal working example for \LaTeX\ Expression.
  \input{example1.py}
  \end{document}
  
compiled by a shell script:
  #!/bin/sh
  python example1.py > example1.py.tex
  pdflatex example1.tex
  


Alternativaly, to produce exactly the same output, you can use Python package to exclude running Python directly:

example2.tex:
  \documentclass[12pt]{report}
  \usepackage{python}
  \begin{document}
  (Almost) minimal working example for \LaTeX\ Expression.
  \begin{python}
  import latexexpr
  v1 = latexexpr.Variable('H_{ello}',3.25,'m')
  print '$$ %s $$'%v1
  v2 = latexexpr.Variable('W^{orld}',5.63,'m')
  print '$$ %s $$'%v2
  e1 = latexexpr.Expression('E_{xample}',v1+v2,'m')
  print '$$ %s $$'%e1
  \end{python}
  \end{document}
  
compiled by a shell script:
  #!/bin/sh
  pdflatex --shell-escape example2.tex
  
LaTeX Expression is a free software distributed under GNU LGPL license.

Currently implemented features:
  • Variable class, representing single physical or mathematical variable;
  • Operation class, representing combination of one or more variables, expression or other operation. This allows building complex operation hierarchy within single expression;
  • Expression class, wrapping final operation by symbolic name and physical unit;
  • auxiliary functions saveGlobals() and loadGlobals() for easy manipulation with several Python sessions within one LaTeX file;

See documentation and/or examples for more information.
Contact: e-mail
Last update: 4th September 2022
© 2011 - 2022   Jan Stránský
All rights reserved
Valid XHTML 1.1
Valid CSS