From caf6be20a2712141f1568ed4d9a3c393c8c9df8c Mon Sep 17 00:00:00 2001 From: Arnoques Date: Thu, 3 Sep 2015 18:51:27 -0300 Subject: [PATCH 1/3] Update python.sty All temp files are named as *.tmp.* to ease cleaning. Avoid useless use of cat (it interfered with the 'inspect' python module). --- python.sty | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/python.sty b/python.sty index 346c89b..29f8f97 100644 --- a/python.sty +++ b/python.sty @@ -18,11 +18,15 @@ %% %% You can find an online copy of the GPL at %% http://www.gnu.org/copyleft/gpl.html . -%% +%% %% Note: shell-escape needs to be activated for this to work. %% This can either be done by passing -shell-escape as an option to %% latex or by adding/changing "shell_escape = t" in your texmf.cnf . +% 0.3 -> 0.4: All temp files are named as *.tmp.* to ease cleaning. +% Avoid useless use of cat (it interfered with the inspect python module). +% -- Arnoques +% % 0.21 -> 0.3: Intermediate files are now stored with different filenames. % The return code of each Python shell execution is stored in an .rc file. % Any stderr output of a failed Python shell execution is inserted as @@ -58,7 +62,7 @@ \def\@python[#1]{% \gdef\@pythoninclude{#1} -\immediate\openout\@out=\@outname.py +\immediate\openout\@out=\@outname.tmp.py \newlinechar='15 \begingroup \catcode`\^^M=12 % \let\do\@makeother\dospecials\obeyspaces% @@ -69,14 +73,14 @@ \immediate\closeout\@out \@writemodule \ifwindows -\immediate\write18{type \@pythoninclude\space\@outname.py 2> nul: | python > \@outname.py.out 2> \@outname.py.err & call echo ^\@percentchar ERRORLEVEL^\@percentchar > \@outname.rc} +\immediate\write18{type \@pythoninclude\space\@outname.tmp.py 2> nul: | python > \@outname.tmp.py.out 2> \@outname.tmp.py.err & call echo ^\@percentchar ERRORLEVEL^\@percentchar > \@outname.tmp.rc} \else -\immediate\write18{cat \@pythoninclude\space\@outname.py | /usr/bin/env python > \@outname.py.out 2> \@outname.py.err; echo -n $? > \@outname.rc} +\immediate\write18{/usr/bin/env python \@pythoninclude\space\@outname.tmp.py > \@outname.tmp.py.out 2> \@outname.tmp.py.err; echo -n $? > \@outname.tmp.rc} \fi -\immediate\input\@outname.py.out +\immediate\input\@outname.tmp.py.out % Read the return code of the executed Python script. -\immediate\openin\@retcode=\@outname.rc +\immediate\openin\@retcode=\@outname.tmp.rc \immediate\read\@retcode to \rc \immediate\closein\@retcode @@ -85,7 +89,7 @@ \ifnumequal{\rc}{0}{}{% \begingroup \color{red} - \verbatiminput{\@outname.py.err} + \verbatiminput{\@outname.tmp.py.err} \endgroup } @@ -93,19 +97,19 @@ } \def\@writemodule{% -\immediate\openout\@module=latex.py +\immediate\openout\@module=latex.tmp.py \immediate\write\@module{jobname="\@outname"} \immediate\closeout\@module} % BUGS: % -% \immediate\write18{cat \@pythoninclude\space\jobname.py | python > \jobname.py.out 2>\jobname.py.err} +% \immediate\write18{cat \@pythoninclude\space\jobname.tmp.py | python > \jobname.tmp.py.out 2>\jobname.tmp.py.err} % % 1. Watch out for indentation done by aucTeX in Emacs % % 2. Let the package accept a "final version" option, such % that the output of each python run is saved such that it can be -% inserted into the document by hand +% inserted into the document by hand % (conference, journals are not likely to compile with % shell_escape or have python). % @@ -113,5 +117,5 @@ % \def\prepython#1{% % \gdef\@prepython{#1} % } -% sed -e 's/^ //g' cluster.py -% \immediate\write18{\@prepython\space\jobname.py > \ +% sed -e 's/^ //g' cluster.tmp.py +% \immediate\write18{\@prepython\space\jobname.tmp.py > \ From 8c67f9932a19b10e20819c125fc71ba06f66bbc3 Mon Sep 17 00:00:00 2001 From: Arnoques Date: Thu, 3 Sep 2015 18:54:03 -0300 Subject: [PATCH 2/3] Added a makefile Another option for building: uses make and latexmk --- makefile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 makefile diff --git a/makefile b/makefile new file mode 100644 index 0000000..e26e3bc --- /dev/null +++ b/makefile @@ -0,0 +1,21 @@ +TARGET=example + +all: $(TARGET).pdf + echo done + +$(TARGET).dvi: $(TARGET).tex + latexmk -shell-escape $(TARGET).tex + +$(TARGET).pdf: $(TARGET).dvi + dvipdf $(TARGET).dvi + +code: $(TARGET).dvi + echo 'from math import *' > $(TARGET).all.py + ls $(TARGET)*.tmp.py | sort -V | xargs cat | grep -v '^from ' >> $(TARGET).all.py + sed -i '/^savevar/d;/^printme/d;/^printvar/d;/^endprint/d' $(TARGET).all.py + +clean: + $(RM) *.tmp.* $(TARGET).dvi $(TARGET).aux $(TARGET).log $(TARGET).toc + +clean-gen: clean + $(RM) $(TARGET).pdf $(TARGET).all.py *.pyc From 89f99ee0404967421af7f54dd23731ecd68adaff Mon Sep 17 00:00:00 2001 From: Arnoques Date: Thu, 3 Sep 2015 18:55:37 -0300 Subject: [PATCH 3/3] Added makefile to readme --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index a3408df..33829af 100644 --- a/README.rst +++ b/README.rst @@ -22,3 +22,6 @@ pytex.vim python.sty A LaTeX package that allows direct embedding of python scripts in LaTeX documents. + +makefile + Another option for compiling. Uses make and latexmk.