PypTeX is the Python Preprocessor for LaTeX. It allows one to embed Pythoncode fragments in a LaTeX template file.
pip install pyptex
pdflatex
.Put the following in example.tex
:
\documentclass{article}
@{from sympy import *}
\begin{document}
$$\int x^3\,dx = @{S('integrate(x^3,x)')}+C$$
\end{document}
The command pyptex example.tex
will generate example.pdf
and an intermediarypure-LaTeX file example.pyptex
. The resulting PDF can be foundhere
pyptex
executable tries to locate the Python 3 executable using /usr/bin/env python3
. If this is causing you problems, try python -u -m pyptex example.tex
instead.If you want to use TeXShop on Mac, put the following into ~/Library/TeXShop/Engines/pyptex.engine
and restart TeXShop:
#!/bin/bash
pyptex $1
Detailed documentation can be found here