Есть такой код:
\newcommand{\python}[1]{%
\immediate\write18{python #1 > ./py.out 2> ./py.err}
\immediate\input"py.out"}
\newcommand{\ptn}[1]{%
\python{./path_to_your_scripts/script_name.py #1}}
\newcommand{\peval}[1]{%
\python{-c "print #1" |./works/sedder.sh}}
При вводе «\peval{30+4}м» выводится:
Emergency stop. \peval{30+4}м (followed by: \peval{30+4}м....)