pytexit.pytexit module¶
Convert a Python expression in a LaTeX formula
-
pytexit.pytexit.for2tex(a, **kwargs)¶ Converts FORTRAN formula to Python Formula
Parameters: a (str) – FORTRAN formula Other Parameters: kwargs (dict) – forwarded to py2tex()function. Seepy2tex()doc.Examples
convert FORTRAN formula to LaTeX with for2tex:
for2tex(r'2.8d-11 * exp(-(26500 - 0.5 * 1.97 * 11600 )/Tgas)')
-
pytexit.pytexit.py2tex(expr, print_latex=True, print_formula=True, dummy_var='u', output='tex', tex_enclosure='$$', tex_multiplier='\\times', simplify_output=True, upperscript='ˆ', lowerscript='_', verbose=False, simplify_fractions=False, simplify_ints=True, simplify_multipliers=True)¶ Return the LaTeX expression of a Python formula
Parameters: - expr (string) – a Python expression
- print_latex (boolean) – if True, prints the latex expression in the console
- dummy_var (string) – dummy variable displayed in integrals
- output ('tex' / 'word') – if ‘tex’, output latex formula. If word, output a Word MathTex formula (may be a little different)
- tex_enclosure (string) –
enclosure for latex formula.
Default: “$$””
- tex_multiplier (raw string) –
multiplication operator for latex formula.
r’ imes’: 2*2 -> 2 x 2 (Default) r’{ imes}’: 2*2 -> 2x2 r’cdot’: 2*2 -> 2 · 2 r’{cdot}’: 2*2 -> 2·2
Other Parameters: simplify_output (boolean) –
if
True, simplify output. Ex:1x10^-5 --> 10^-5
See
simplify()for more information. DefaultTruesimplify_ints (boolean) –
if
True, simplify integers (useful for Python 2 expressions). Ex:1. --> 1
See
LatexVisitorfor more information. DefaultTruesimplify_fractions (boolean) –
if
True, simplify common fractions. Ex:0.5 --> 1/2
See
LatexVisitorfor more information. DefaultFalsesimplify_multipliers (boolean) –
if
True, simplify float multipliers during parsing. Ex:2*a -> 2a
See
LatexVisitorfor more information. DefaultTrue
Returns: - returns the latex expression in raw text, to be used in your reports or
- to display in an IPython notebook
Notes
Will return
'\\'instead of'\'because we don’t want those to be interpreted as regular expressions. Useprint(result)to get the correct LaTex formula.See also
References
Initial work from Geoff Reedy on StackOverflow: https://stackoverflow.com/a/3874621/5622825 . Kudos.
Similar projects:
- https://github.com/iogf/lax : “A pythonic way of writting latex.”
- https://github.com/JelteF/PyLaTeX : “A Python library for creating LaTeX files”
- sympy can also write LaTeX output.