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. See py2tex() doc.


convert FORTRAN formula to LaTeX with for2tex:

for2tex(r'2.8d-11 * exp(-(26500 - 0.5 * 1.97 * 11600 )/Tgas)')

See also

for2py(), py2tex()

pytexit.pytexit.py2tex(expr, print_latex=None, print_formula=None, 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

  • expr (string) – a Python expression
  • print_latex (boolean) – if True, prints the latex expression in the console
  • print_formula (boolean) – if True, prints the formula 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. Default True

  • simplify_ints (boolean) –

    if True, simplify integers (useful for Python 2 expressions). Ex:

    1. --> 1

    See LatexVisitor for more information. Default True

  • simplify_fractions (boolean) –

    if True, simplify common fractions. Ex:

    0.5 --> 1/2

    See LatexVisitor for more information. Default False

  • simplify_multipliers (boolean) –

    if True, simplify float multipliers during parsing. Ex:

    2*a  -> 2a

    See LatexVisitor for more information. Default True


  • returns the latex expression in raw text, to be used in your reports or
  • to display in an IPython notebook


Will return '\\' instead of '\' because we don’t want those to be interpreted as regular expressions. Use print(result) to get the correct LaTex formula.

You can also change the global variables pytexit.PRINT_FORMULA or pytexit.PRINT_LATEX to avoid passing them as parameters every time you call the function.

See also



Initial work from Geoff Reedy on StackOverflow: . Kudos.

Similar projects: