Skip to content

Instantly share code, notes, and snippets.

@xcodebuild
Created October 9, 2014 14:02
Show Gist options
  • Save xcodebuild/63b544cf31ab68bef927 to your computer and use it in GitHub Desktop.
Save xcodebuild/63b544cf31ab68bef927 to your computer and use it in GitHub Desktop.
Use python in latex
\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