Created
October 9, 2014 14:02
-
-
Save xcodebuild/63b544cf31ab68bef927 to your computer and use it in GitHub Desktop.
Use python in latex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\usepackage{verbatim} | |
\makeatletter | |
\newwrite\Code@out | |
\newcommand\python{\obeylines\expandafter\pythonArg\noexpand} | |
\newcommand\pythonArg[1][tmp.py.in]{% | |
\gdef\FNameIn{#1} | |
\gdef\FNameOut{tmp.py.out} | |
\begingroup | |
\@bsphack% | |
\immediate\openout\Code@out\FNameIn% | |
\let\do\@makeother\dospecials% | |
\catcode`\^^M\active% | |
\def\verbatim@processline{% | |
\immediate\write\Code@out{\the\verbatim@line}}% | |
\verbatim@start} | |
\def\endpython{% | |
\immediate\closeout\Code@out\@esphack | |
\endgroup | |
%Execute python script. Python directory must be in PATH. | |
\immediate\write18{python \FNameIn > \FNameOut} | |
\input{\FNameOut} | |
} | |
\makeatother | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment