summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-04-18 20:21:51 +0000
committerKarl Berry <karl@freefriends.org>2021-04-18 20:21:51 +0000
commit15fd1f6957a2e1a325621ad3f307697c8c32b5ca (patch)
tree5b46fe147edaadbaa9cfba3645b9b72411c59c1e /Master/texmf-dist
parentb3b353ffa73411314302bcc58efcaf0a83560249 (diff)
runcode (18apr21)
git-svn-id: svn://tug.org/texlive/trunk@58908 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/latex/runcode/runcode.pdfbin169426 -> 170764 bytes
-rw-r--r--Master/texmf-dist/doc/latex/runcode/runcode.tex16
-rw-r--r--Master/texmf-dist/tex/latex/runcode/runcode.sty55
3 files changed, 53 insertions, 18 deletions
diff --git a/Master/texmf-dist/doc/latex/runcode/runcode.pdf b/Master/texmf-dist/doc/latex/runcode/runcode.pdf
index 1a8d909f4c4..13fcdea4da3 100644
--- a/Master/texmf-dist/doc/latex/runcode/runcode.pdf
+++ b/Master/texmf-dist/doc/latex/runcode/runcode.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/runcode/runcode.tex b/Master/texmf-dist/doc/latex/runcode/runcode.tex
index 5d994757394..977a41bc244 100644
--- a/Master/texmf-dist/doc/latex/runcode/runcode.tex
+++ b/Master/texmf-dist/doc/latex/runcode/runcode.tex
@@ -1,6 +1,6 @@
- % LaTeX Package: runcode v1.0 2020/10/04
+ % LaTeX Package: runcode v1.1 2021/04/17
%
- % Copyright (C) 2020 by Haim Bar and HaiYing Wang
+ % Copyright (C) 2021 by Haim Bar and HaiYing Wang
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
@@ -15,9 +15,9 @@
\documentclass{ltxdoc}
\usepackage[hyphens]{url}
%\usepackage{runcode}
-\ProvidesPackage{runcode}[2020/10/04 runcode v1.0]
+\ProvidesPackage{runcode}[2021/04/17 runcode v1.1]
\begin{document}
- \title{The \textsf{runcode} package\thanks{This document corresponds to \textsf{runcode}~v1.0, dated~2020/10/04.}}
+ \title{The \textsf{runcode} package\thanks{This document corresponds to \textsf{runcode}~v1.1, dated~2021/04/17.}}
\author{Haim Bar and HaiYing Wang \\ \texttt{haim.bar@uconn.edu}, \texttt{haiying.wang@uconn.edu}}
\maketitle
@@ -25,7 +25,7 @@
It is recommended to use this package in the server-mode together with the Python talk2stat package. Currently, the server-mode supports Julia, MatLab, Python, and R. More languages will be added.
-For more details and usage examples, refer to the package's github repository, at
+For more details and usage examples and troubleshooting, refer to the package's github repository, at
\url{https://github.com/Ossifragus/runcode}.
}
@@ -49,6 +49,7 @@ Available options are:
\item \texttt{run}: run source code, and store results in cache files.
\item \texttt{cache}: use cached results.
\item \texttt{stopserver}: stop the \textit{talk2stat} server(s) when the pdf compilation is done.
+\item \texttt{nohup}: when using the server-mode, some editors terminate all child processes after LaTeX compiling such as Emacs with Auctex. For this case, use the nohup option. It set the variable notnohup to be false, and the server will not be terminated by the parent process.
\item \texttt{nominted}: use the \textit{fvextra} package [\url{https://ctan.org/pkg/fvextra}] instead of the \textit{minted} package [\url{https://ctan.org/pkg/minted}] to show code (\textit{fvextra} does not require Python's pygments package [\url{https://pygments.org/}], but it does not provide syntax highlights).
\end{itemize}
* Requires the Python package \textit{talk2stat} to be installed.
@@ -140,6 +141,11 @@ Available options are:
\end{itemize}
+\section{Revisions}
+\begin{itemize}
+\item v1.1, April 17, 2021: Added a nohup option; improved error handling (missing code files, zero bytes in output files.)
+\end{itemize}
+
%
\section{Contributing}
We welcome your contributions to this package by opening issues on GitHub and/or making a pull request. We also appreciate more example documents written using \textsf{runcode}.
diff --git a/Master/texmf-dist/tex/latex/runcode/runcode.sty b/Master/texmf-dist/tex/latex/runcode/runcode.sty
index 0059a17b862..6737fd213f6 100644
--- a/Master/texmf-dist/tex/latex/runcode/runcode.sty
+++ b/Master/texmf-dist/tex/latex/runcode/runcode.sty
@@ -14,6 +14,11 @@
\mintedtrue
\DeclareOption{nominted}{\mintedfalse}
+% Some editors terminate all child processes after LaTeX compiling such as Emacs with Auctex. For this case, use the nohup option. It set the variable notnohup to be false, and the server will not be terminated by the parent process.
+\newif\ifnotnohup
+\notnohuptrue
+\DeclareOption{nohup}{\notnohupfalse}
+
\DeclareOption{R}{
% create a configuration file for R server if it does not exist.
\IfFileExists{R.config}{}{
@@ -27,9 +32,11 @@
}
% Start the server. Need to run just once. Can comment out after the first
% compilation, but remember to terminate the server
- \immediate\write18{python3 -c 'from talk2stat.talk2stat import server,client; server("./","R") if not client("./","R","``` ```") else print("server is already running")'}
- % Some editors terminate all child processes after LaTeX compiling such as Emacs with Auctex. For this case, use the following line instead of the above line.
- % \immediate\write18{nohup python3 -c 'from talk2stat.talk2stat import server,client; server("./","R") if not client("./","R","``` ```") else print("server is already running")' &}
+ \ifnotnohup
+ {\immediate\write18{python3 -c 'from talk2stat.talk2stat import server,client; server("./","R") if not client("./","R","``` ```") else print("server is already running")'}}
+ \else
+ {\immediate\write18{nohup python3 -c 'from talk2stat.talk2stat import server,client; server("./","R") if not client("./","R","``` ```") else print("server is already running")' &}}
+ \fi
}
\DeclareOption{julia}{
@@ -45,8 +52,11 @@
}
% Start the server. Need to run just once. Can comment out after the first
% compilation, but remember to terminate the server
- \immediate\write18{python3 -c 'from talk2stat.talk2stat import server,client; server("./","julia") if not client("./","julia","``` ```") else print("server is already running")'}
- % \immediate\write18{nohup python3 -c 'from talk2stat.talk2stat import server,client; server("./","julia") if not client("./","julia","``` ```") else print("server is already running")' &}
+ \ifnotnohup
+ {\immediate\write18{python3 -c 'from talk2stat.talk2stat import server,client; server("./","julia") if not client("./","julia","``` ```") else print("server is already running")'}}
+ \else
+ {\immediate\write18{nohup python3 -c 'from talk2stat.talk2stat import server,client; server("./","julia") if not client("./","julia","``` ```") else print("server is already running")' &}}
+ \fi
}
\DeclareOption{matlab}{
@@ -62,8 +72,11 @@
}
% Start the server. Need to run just once. Can comment out after the first
% compilation, but remember to terminate the server
- \immediate\write18{python3 -c 'from talk2stat.talk2stat import server,client; server("./","matlab") if not client("./","matlab","``` ```") else print("server is already running")'}
- % \immediate\write18{nohup python3 -c 'from talk2stat.talk2stat import server,client; server("./","matlab") if not client("./","matlab","``` ```") else print("server is already running")' &}
+ \ifnotnohup
+ {\immediate\write18{python3 -c 'from talk2stat.talk2stat import server,client; server("./","matlab") if not client("./","matlab","``` ```") else print("server is already running")'}}
+ \else
+ {\immediate\write18{nohup python3 -c 'from talk2stat.talk2stat import server,client; server("./","matlab") if not client("./","matlab","``` ```") else print("server is already running")' &}}
+ \fi
}
\DeclareOption{stopserver}{
@@ -76,6 +89,7 @@
\ProcessOptions*
+\usepackage{morewrites} % allow more than 16 \write
\usepackage[many]{tcolorbox} % to put boxes around text
\usepackage{xcolor} % for highlighting
\usepackage[utf8x]{inputenc}
@@ -132,19 +146,24 @@
% Args #3 and #4 are the first and last line to show (optional).
\NewDocumentCommand{\showCode}{m m O{} O{}}{% \-\\
- \ifthenelse{\isempty{#3}}{
+ \IfFileExists{#2}{
+ \ifthenelse{\isempty{#3}}{
\ifminted
\inputminted[fontsize=\footnotesize,linenos, frame=single, bgcolor=bg, breaklines=true]{#1}{#2}
\else
- \VerbatimInput[fontsize=\footnotesize,frame=single,breaklines]{#2}
+ \VerbatimInput[fontsize=\footnotesize,linenos=true,frame=single,breaklines]{#2}
\fi
}{
\ifminted
\inputminted[fontsize=\footnotesize,linenos,frame=single, bgcolor=bg, breaklines=true, firstline=#3, lastline=#4, firstnumber=1]{#1}{#2}
\else
- \VerbatimInput[fontsize=\footnotesize,frame=single,breaklines, firstline=#3, lastline=#4, firstnumber=1]{#2}
+ \VerbatimInput[fontsize=\footnotesize,linenos=true,frame=single,breaklines, firstline=#3, lastline=#4, firstnumber=1]{#2}
\fi
+ }
+ }{
+ \textcolor{red}{\textbf{showCode: File #2 does not exist!}}
}
+
}
@@ -158,6 +177,7 @@
% to \runcode; run = force the code to run; cache or anything else =
% use cache)
\NewDocumentCommand{\runExtCode}{m m m O{}}{
+ \IfFileExists{#2}{
\stepcounter{codeOutput}
\ifthenelse{\isempty{#3}}
{ \setvalue{\tmpname}{tmp/\jobname_tmp\thecodeOutput.tex} }
@@ -170,6 +190,9 @@
}{
\ifstrequal{#4}{run}{\immediate\write18{#1 #2 > \tmpname }}{}
}
+ }{
+ \textcolor{red}{\textbf{runExtCode: File #2 does not exist!}}
+ }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -200,9 +223,15 @@
{\input{\tmpname}}}}
% if code execution disabled, and no cache:
{\begin{tcolorbox}
- Code execution disabled (cache not available).
+ \textbf{Output file \tmpname~ not found}. Check the file name (it may be that the file name was given with the suffix .tex. If so, remove it). If the file name is correct the problem may be because code execution is disabled and no cache is available. If so, force the code to run again (using the [run] option).
\end{tcolorbox}}}
+
+\NewDocumentCommand{\checkZeroBytes}{m}{
+ \immediate\write18{python3 -c 'import os; print("ZERO BYTES IN OUTPUT", file=open("#1", "a")) if os.path.getsize("#1") == 0 else True'}
+}
+
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \inln{Arg #1}{Arg #2}[Arg #3] is used to execute short source code
% and embed resulting output.
@@ -223,7 +252,7 @@
\immediate\write18{#1 \tmpname.txt > \tmpname.tex}\unskip
\fi}
\IfFileExists{\tmpname.tex}
- {\unskip
+ {\checkZeroBytes{\tmpname.tex}\unskip
\ifstrequal{#3}{vbox}
{\begin{tcolorbox}[breakable,colback=red!5!white,colframe=red!75!black]
\ifminted\unskip
@@ -233,7 +262,7 @@
\fi
\end{tcolorbox}}
{\unskip\input{\tmpname.tex}\unskip}}
- {\textcolor{red}{notrun}}}
+ {\textcolor{red}{\textbf{Output file \tmpname~ not found}}}}
\NewDocumentCommand{\runR}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","R","#2")'} m m O{}}
{