diff options
Diffstat (limited to 'macros/latex/contrib/runcode/runcode.sty')
-rw-r--r-- | macros/latex/contrib/runcode/runcode.sty | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/macros/latex/contrib/runcode/runcode.sty b/macros/latex/contrib/runcode/runcode.sty index ae859085b4..21e85f9908 100644 --- a/macros/latex/contrib/runcode/runcode.sty +++ b/macros/latex/contrib/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}[2023/01/18 runcode v1.8] +\ProvidesPackage{runcode}[2023/06/13 runcode v1.9] \newif\ifruncode % Change to \runcodefalse if you want to suspend code execution @@ -313,13 +313,17 @@ % \inln{Arg #1}{Arg #2}[Arg #3] is used to execute short source code % and embed resulting output. % Arg #1 is the executable program; -% Arg #2 is the source code -% Arg #3 is the type output (if skipped or with empty value the default type is +% Arg #2 is the source code; +% Arg #3 is the output file name (optional); +% Arg #4 is the type output (if skipped or with empty value the default type is % inline; vbox = verbatim in a box); -\NewDocumentCommand{\inln}{m m O{inline}}{\- - \stepcounter{codeOutput}\unskip - \unskip\setvalue{\tmpname}{\generated/\jobname_inln\thecodeOutput}\unskip\unskip\unskip +\NewDocumentCommand{\inln}{m m O{} O{inline}}{\- + \unskip + \ifthenelse{\isempty{#3}} + {\stepcounter{codeOutput}\unskip\unskip\setvalue{\tmpname}{\generated/\jobname_inln\thecodeOutput}\unskip\unskip\unskip} + {\unskip\setvalue{\tmpname}{\generated/#3}\unskip\unskip\unskip} + \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 @@ -332,7 +336,7 @@ \fi % end cache mode \IfFileExists{\tmpname.tex} {\checkZeroBytes{\tmpname.tex}\unskip - \ifstrequal{#3}{vbox} + \ifstrequal{#4}{vbox} {\begin{tcolorbox} \ifminted\unskip \inputminted{text}{\tmpname.tex}\unskip @@ -354,7 +358,7 @@ {\runExtCode{#1}{#2}{#3}[#4]} } -\NewDocumentCommand{\inlnR}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","R","\tmpname.txt")'} m O{inline}}{\IfBeginWith{#2}{```}{\inln{python3 -c 'from talk2stat.talk2stat import client;rc0="""#2""";rc0=rc0.lstrip("```").rstrip("```");client("./","R",f"```{rc0}```")'}{#2}[#3]}{\inln{#1}{#2}[#3]}} +\NewDocumentCommand{\inlnR}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","R","\tmpname.txt")'} m O{} O{inline}}{\IfBeginWith{#2}{```}{\inln{python3 -c 'from talk2stat.talk2stat import client;rc0="""#2""";rc0=rc0.lstrip("```").rstrip("```");client("./","R",f"```{rc0}```")'}{#2}[#3][#4]}{\inln{#1}{#2}[#3][#4]}} \NewDocumentCommand{\runJulia}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","julia","#2")'} m m O{}} { @@ -364,7 +368,7 @@ {\runExtCode{#1}{#2}{#3}[#4]} } -\NewDocumentCommand{\inlnJulia}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","julia","\tmpname.txt")'} m O{inline}}{\IfBeginWith{#2}{```}{\inln{python3 -c 'from talk2stat.talk2stat import client;rc0="""#2""";rc0=rc0.lstrip("```").rstrip("```");client("./","julia",f"```{rc0}```")'}{#2}[#3]}{\inln{#1}{#2}[#3]}} +\NewDocumentCommand{\inlnJulia}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","julia","\tmpname.txt")'} m O{} O{inline}}{\IfBeginWith{#2}{```}{\inln{python3 -c 'from talk2stat.talk2stat import client;rc0="""#2""";rc0=rc0.lstrip("```").rstrip("```");client("./","julia",f"```{rc0}```")'}{#2}[#3][#4]}{\inln{#1}{#2}[#3][#4]}} \NewDocumentCommand{\runMatlab}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","matlab","#2")'} m m O{}} { @@ -374,7 +378,7 @@ {\runExtCode{#1}{#2}{#3}[#4]} } -\NewDocumentCommand{\inlnMatlab}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","matlab","\tmpname.txt")'} m O{inline}}{\IfBeginWith{#2}{```}{\inln{python3 -c 'from talk2stat.talk2stat import client;rc0="""#2""";rc0=rc0.lstrip("```").rstrip("```");client("./","matlab",f"```{rc0}```")'}{#2}[#3]}{\inln{#1}{#2}[#3]}} +\NewDocumentCommand{\inlnMatlab}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","matlab","\tmpname.txt")'} m O{} O{inline}}{\IfBeginWith{#2}{```}{\inln{python3 -c 'from talk2stat.talk2stat import client;rc0="""#2""";rc0=rc0.lstrip("```").rstrip("```");client("./","matlab",f"```{rc0}```")'}{#2}[#3][#4]}{\inln{#1}{#2}[#3][#4]}} \NewDocumentCommand{\runPython}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","python","#2")'} m m O{}} @@ -385,7 +389,7 @@ {\runExtCode{#1}{#2}{#3}[#4]} } -\NewDocumentCommand{\inlnPython}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","python","\tmpname.txt")'} m O{inline}}{\IfBeginWith{#2}{```}{\inln{python3 -c 'from talk2stat.talk2stat import client;rc0="""#2""";rc0=rc0.lstrip("```").rstrip("```");client("./","python",f"```{rc0}```")'}{#2}[#3]}{\inln{#1}{#2}[#3]}} +\NewDocumentCommand{\inlnPython}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","python","\tmpname.txt")'} m O{} O{inline}}{\IfBeginWith{#2}{```}{\inln{python3 -c 'from talk2stat.talk2stat import client;rc0="""#2""";rc0=rc0.lstrip("```").rstrip("```");client("./","python",f"```{rc0}```")'}{#2}[#3][#4]}{\inln{#1}{#2}[#3][#4]}} %%%%%%%% |