diff options
author | Karl Berry <karl@freefriends.org> | 2022-08-21 20:03:00 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-08-21 20:03:00 +0000 |
commit | 3d5dec9f27a0d36db279079511e5148bf2c3009d (patch) | |
tree | fcb30f742c1a46cb7cdaeadba1f07b66a4e17c21 /Master/texmf-dist/tex | |
parent | 231590ac054d62d9ae566b9602bae29ec52bc062 (diff) |
runcode (21aug22)
git-svn-id: svn://tug.org/texlive/trunk@64161 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/runcode/runcode.sty | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/Master/texmf-dist/tex/latex/runcode/runcode.sty b/Master/texmf-dist/tex/latex/runcode/runcode.sty index 27202b469ad..873fab14c1e 100644 --- a/Master/texmf-dist/tex/latex/runcode/runcode.sty +++ b/Master/texmf-dist/tex/latex/runcode/runcode.sty @@ -4,7 +4,7 @@ % % This package is based on an ongoing work by Haim Bar and HaiYing Wang, and comments and questions are welcome! -\ProvidesPackage{runcode}[2022/08/10 runcode v1.6] +\ProvidesPackage{runcode}[2022/08/20 runcode v1.7] \newif\ifruncode % Change to \runcodefalse if you want to suspend code execution @@ -144,7 +144,8 @@ \usepackage{fvextra} \fi -\immediate\write18{mkdir -p tmp} +\newcommand{\generated}{generated} +\immediate\write18{mkdir -p \generated} \definecolor{bg}{rgb}{0.95,0.95,0.95} % code block background color @@ -226,8 +227,8 @@ \IfFileExists{#2}{ \stepcounter{codeOutput} \ifthenelse{\isempty{#3}} - { \setvalue{\tmpname}{tmp/\jobname_tmp\thecodeOutput.tex} } - { \setvalue{\tmpname}{tmp/#3.tex} } + { \setvalue{\tmpname}{\generated/\jobname_tmp\thecodeOutput.tex} } + { \setvalue{\tmpname}{\generated/#3.tex} } % toggle \runcode above if you want to enable/disable code execution \ifthenelse{\isempty{#4}} { \ifruncode @@ -250,8 +251,8 @@ \NewDocumentCommand{\includeOutput}{m O{vbox}}{\- \ifthenelse{\isempty{#1}} - {\setvalue{\tmpname}{tmp/\jobname_tmp\thecodeOutput.tex}} - {\unskip\setvalue{\tmpname}{tmp/#1.tex}\unskip}\unskip + {\setvalue{\tmpname}{\generated/\jobname_tmp\thecodeOutput.tex}} + {\unskip\setvalue{\tmpname}{\generated/#1.tex}\unskip}\unskip % even if the code is not executed, but we ran it before, we can use a % cached version if it exists. \IfFileExists{\tmpname} @@ -288,7 +289,7 @@ \NewDocumentCommand{\inln}{m m O{inline}}{\- \stepcounter{codeOutput}\unskip - \unskip\setvalue{\tmpname}{tmp/\jobname_inln\thecodeOutput}\unskip\unskip\unskip + \unskip\setvalue{\tmpname}{\generated/\jobname_inln\thecodeOutput}\unskip\unskip\unskip \ifruncode % cache mode - don't try to run the code, just get the previous results \IfBeginWith{#2}{```}{\ifruncode\immediate\write18{#1 > \tmpname.tex}\unskip\fi} {\newwrite\tempfile @@ -362,17 +363,17 @@ \NewDocumentCommand{\runPythonBatch}{m m}{%\-\\ \stepcounter{codeOutput} \ifthenelse{\isempty{#2}} % set the output file name - { \setvalue{\tmpname}{tmp/\jobname_tmp\thecodeOutput.tex} } - { \setvalue{\tmpname}{tmp/#2.tex} } + { \setvalue{\tmpname}{\generated/\jobname_tmp\thecodeOutput.tex} } + { \setvalue{\tmpname}{\generated/#2.tex} } \IfFileExists{#1}{ \ifruncode \newwrite\tempfile - \immediate\openout\tempfile=tmp/\jobname_#1 + \immediate\openout\tempfile=\generated/\jobname_#1 \immediate\write\tempfile{import dill} \immediate\write\tempfile{from os.path import exists} - \immediate\write\tempfile{if exists('tmp/session'):} - \immediate\write\tempfile{ dill.load_session('tmp/session')} + \immediate\write\tempfile{if exists('\generated/session'):} + \immediate\write\tempfile{ dill.load_session('\generated/session')} \immediate\write\tempfile{} \newread\infile \openin\infile=#1 @@ -383,10 +384,10 @@ \repeat \endgroup \closein\infile - \immediate\write\tempfile{dill.dump_session('tmp/session')} + \immediate\write\tempfile{dill.dump_session('\generated/session')} \immediate\write\tempfile{} \immediate\closeout\tempfile - \immediate\write18{python3 tmp/\jobname_#1 > \tmpname} + \immediate\write18{python3 \generated/\jobname_#1 > \tmpname} \fi } { |