summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/runcode
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-01-20 03:01:05 +0000
committerNorbert Preining <norbert@preining.info>2023-01-20 03:01:05 +0000
commit6d3235d032cbed920059ab39370928067056573a (patch)
treeaa934ccc80bd69cc4ca388f418a62fa0140e443b /macros/latex/contrib/runcode
parentc11207d3e9027d6aa4153a2103df58382d41e56e (diff)
CTAN sync 202301200301
Diffstat (limited to 'macros/latex/contrib/runcode')
-rw-r--r--macros/latex/contrib/runcode/README2
-rw-r--r--macros/latex/contrib/runcode/runcode.pdfbin245634 -> 247080 bytes
-rw-r--r--macros/latex/contrib/runcode/runcode.sty59
-rw-r--r--macros/latex/contrib/runcode/runcode.tex43
4 files changed, 74 insertions, 30 deletions
diff --git a/macros/latex/contrib/runcode/README b/macros/latex/contrib/runcode/README
index 0aaa36a304..4b75754042 100644
--- a/macros/latex/contrib/runcode/README
+++ b/macros/latex/contrib/runcode/README
@@ -1,4 +1,4 @@
-LaTeX Package: runcode 2022/08/20 v1.7
+LaTeX Package: runcode 2023/01/18 v1.8
----------------------------------------
The runcode package enables the execution of source code (e.g., R,
Julia, Matlab, shell, Python, etc.) and embed the results in the pdf file
diff --git a/macros/latex/contrib/runcode/runcode.pdf b/macros/latex/contrib/runcode/runcode.pdf
index 2c0f0d4db9..405f5a26fd 100644
--- a/macros/latex/contrib/runcode/runcode.pdf
+++ b/macros/latex/contrib/runcode/runcode.pdf
Binary files differ
diff --git a/macros/latex/contrib/runcode/runcode.sty b/macros/latex/contrib/runcode/runcode.sty
index 873fab14c1..ae859085b4 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}[2022/08/20 runcode v1.7]
+\ProvidesPackage{runcode}[2023/01/18 runcode v1.8]
\newif\ifruncode
% Change to \runcodefalse if you want to suspend code execution
@@ -12,9 +12,22 @@
\DeclareOption{run}{\runcodetrue}
\DeclareOption{cache}{\runcodefalse}
+% Choose the package for code typesetting. The default is minted.
+% The other two options are listings and fvextra. For backward compatibility,
+% it is possible to use nominted, in which case fvextra is used.
\newif\ifminted
\mintedtrue
-\DeclareOption{nominted}{\mintedfalse}
+\DeclareOption{nominted}{\mintedfalse}
+\DeclareOption{minted}{\mintedtrue\fvextrafalse\listingsfalse}
+
+\newif\iflistings
+\listingsfalse
+\DeclareOption{listings}{\listingstrue\mintedfalse\fvextrafalse}
+
+\newif\iffvextra
+\fvextrafalse
+\DeclareOption{fvextra}{\fvextratrue\mintedfalse\listingsfalse}
+
\newif\ifreducedspace
\reducedspacefalse
@@ -136,12 +149,18 @@
\usepackage{xparse}
\usepackage{xstring}
-% Use minted if it is loaded; otherwise use fvextra
+% Use minted by default; but the user can change to listings or fvextra.
\ifminted
\usepackage[cache=false]{minted}
\setminted{fontsize=\footnotesize,breaklines=true} % minted default
\else
+\iflistings
+\usepackage{listings}
+\lstset{escapeinside=`',columns=fixed, extendedchars=true, basicstyle=\ttfamily\small, frame = lines}
+\else
\usepackage{fvextra}
+\fvset{fontsize=\footnotesize, breaklines}
+\fi
\fi
\newcommand{\generated}{generated}
@@ -179,7 +198,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% \showCode prints the source code, using minted for a pretty layout
+% \showCode prints the source code, using minted or listings for a pretty layout
% Arg #1 is the programming language,
% Arg #2 is the source file name,
% Args #3 and #4 are the first and last line to show (optional).
@@ -194,7 +213,11 @@
\vspace{-\baselineskip}
\fi
\else
- \VerbatimInput[fontsize=\footnotesize,linenos=true,frame=single,breaklines]{#2}
+ \iflistings
+ \lstinputlisting[language=#1]{#2}
+ \else
+ \VerbatimInput{#2}
+ \fi
\fi
}{
\ifminted
@@ -204,7 +227,11 @@
\vspace{-\baselineskip}
\fi
\else
- \VerbatimInput[fontsize=\footnotesize,linenos=true,frame=single,breaklines, firstline=#3, lastline=#4, firstnumber=1]{#2}
+ \iflistings
+ \lstinputlisting[language=#1,firstline=#3, lastline=#4]{#2}
+ \else
+ \VerbatimInput[firstline=#3, lastline=#4, firstnumber=1]{#2}
+ \fi
\fi
}
}{
@@ -261,8 +288,11 @@
{\begin{tcolorbox}
\ifminted\unskip
\inputminted{text}{\tmpname}\unskip
+ \else\iflistings\unskip
+ \lstinputlisting{\tmpname}\unskip
\else\unskip
- \VerbatimInput[fontsize=\footnotesize,breaklines]{\tmpname}\unskip
+ \VerbatimInput{\tmpname}\unskip
+ \fi
\fi
\end{tcolorbox}}
{\unskip\ifstrequal{#2}{inline}
@@ -306,11 +336,14 @@
{\begin{tcolorbox}
\ifminted\unskip
\inputminted{text}{\tmpname.tex}\unskip
+ \else\unskip\iflistings\unskip
+ \lstinputlisting{\tmpname.tex}\unskip
\else\unskip
- \VerbatimInput[fontsize=\footnotesize,breaklines]{\tmpname.tex}\unskip
+ \VerbatimInput{\tmpname.tex}\unskip
+ \fi
\fi
\end{tcolorbox}}
- {\unskip\input{\tmpname.tex}\unskip}}
+ {\unskip{\input{\tmpname.tex}}\unskip}}
{\textcolor{red}{\textbf{Output file \tmpname~ not found}}}}
\NewDocumentCommand{\runR}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","R","#2")'} m m O{}}
@@ -321,7 +354,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;client("./","R","#2")'}{#2}[#3]}{\inln{#1}{#2}[#3]}}
+\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{\runJulia}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","julia","#2")'} m m O{}}
{
@@ -331,7 +364,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;client("./","julia","#2")'}{#2}[#3]}{\inln{#1}{#2}[#3]}}
+\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{\runMatlab}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","matlab","#2")'} m m O{}}
{
@@ -341,7 +374,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;client("./","matlab","#2")'}{#2}[#3]}{\inln{#1}{#2}[#3]}}
+\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{\runPython}{O{python3 -c 'from talk2stat.talk2stat import client; client("./","python","#2")'} m m O{}}
@@ -352,7 +385,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;client("./","python","#2")'}{#2}[#3]}{\inln{#1}{#2}[#3]}}
+\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]}}
%%%%%%%%
diff --git a/macros/latex/contrib/runcode/runcode.tex b/macros/latex/contrib/runcode/runcode.tex
index 6fbd691ebc..8751d4234e 100644
--- a/macros/latex/contrib/runcode/runcode.tex
+++ b/macros/latex/contrib/runcode/runcode.tex
@@ -1,4 +1,4 @@
-% LaTeX Package: runcode 2022/08/20 v1.7
+% LaTeX Package: runcode 2023/01/18 v1.8
%
% Copyright (C) 2020-2022 by Haim Bar and HaiYing Wang
%
@@ -49,7 +49,7 @@ package’s github repository, at \url{https://github.com/Ossifragus/runcode}.
\end{abstract}
\section{Installation}
-\label{sec:org7e4c2ed}
+\label{sec:org1037dff}
You can simply put the runcode.sty file in the \LaTeX{} project folder.
The server mode requires the
@@ -65,9 +65,9 @@ compiling a \LaTeX{} document.
\section{Usage}
-\label{sec:org2d22735}
+\label{sec:org325e4fc}
\subsection{Load the package:}
-\label{sec:orgbfab84d}
+\label{sec:orgbccebff}
\begin{minted}[]{latex}
\usepackage[options]{runcode}
\end{minted}
@@ -77,12 +77,16 @@ Available options are:
\begin{itemize}
\item \texttt{cache}: use cached results.
-\item \texttt{julia}: start server for \href{https://julialang.org/}{Julia} (requires
-\href{https://pypi.org/project/talk2stat/}{talk2stat}).
+\item \texttt{fvextra}: use the \href{https://ctan.org/pkg/fvextra}{fvextra} package to show code.
-\item \texttt{matlab}: start server for
-\href{https://www.mathworks.com/products/matlab.html}{MatLab} (requires
-\href{https://pypi.org/project/talk2stat/}{talk2stat}).
+\item \texttt{julia}: start server for \href{https://julialang.org/}{Julia} (requires \href{https://pypi.org/project/talk2stat/}{talk2stat}).
+
+\item \texttt{listings}: use the \href{https://ctan.org/pkg/listings?lang=en}{listings} package to show code.
+
+\item \texttt{matlab}: start server for \href{https://www.mathworks.com/products/matlab.html}{MatLab} (requires \href{https://pypi.org/project/talk2stat/}{talk2stat}).
+
+\item \texttt{minted}: use the \href{https://ctan.org/pkg/minted}{minted} package to show code (requires the \href{https://pygments.org/}{pygments} package).
+This is the default option.
\item \texttt{nominted}: use the \href{https://ctan.org/pkg/fvextra}{fvextra} package
instead of the \href{https://ctan.org/pkg/minted}{minted} package to show
@@ -117,6 +121,14 @@ the code block is controlled through the minted package,
\setminted[R]{linenos, frame=single, bgcolor=lightgray, breaklines=true}
\end{minted}
+Similarly, \href{https://ctan.org/pkg/fvextra}{fvextra} and \href{https://ctan.org/pkg/listings?lang=en}{listings} packages can be customized through the \texttt{\textbackslash{}lstset}
+and \texttt{\textbackslash{}fvset} commands, respectively, e.g.:
+
+\begin{minted}[]{latex}
+\lstset{basicstyle=\large, frame=single}
+\fvset{fontsize=\small, linenos=true, frame=single}
+\end{minted}
+
The outputs from executing codes are displayed in
\href{https://ctan.org/pkg/tcolorbox?lang=en}{tcolorbox}, so the style can
be customized with \texttt{\textbackslash{}tcbset},
@@ -127,7 +139,7 @@ be customized with \texttt{\textbackslash{}tcbset},
\end{minted}
\subsection{Basic commands:}
-\label{sec:org1b11cd1}
+\label{sec:org88340c8}
\begin{itemize}
\item \texttt{\textbackslash{}runExtCode\{Arg1\}\{Arg2\}\{Arg3\}[Arg4]} runs an external code.
@@ -144,9 +156,7 @@ else), use cached results (see more about the cache below).
\end{itemize}
\item \texttt{\textbackslash{}showCode\{Arg1\}\{Arg2\}[Arg3][Arg4]} shows the source code, using
-\href{https://ctan.org/pkg/minted}{minted} for a pretty layout or
-\href{https://ctan.org/pkg/fvextra}{fvextra} (if
-\href{https://pygments.org/}{pygments} is not installed).
+\href{https://ctan.org/pkg/minted}{minted} (requires \href{https://pygments.org/}{pygments}), \href{https://ctan.org/pkg/fvextra}{fvextra}, or \href{https://ctan.org/pkg/listings?lang=en}{listings}.
\begin{itemize}
\item \texttt{Arg1} is the programming language.
@@ -188,7 +198,7 @@ text.
\end{itemize}
\subsection{Language specific shortcuts:}
-\label{sec:org154f922}
+\label{sec:org591e87e}
\href{https://julialang.org/}{Julia}
\begin{itemize}
@@ -314,8 +324,9 @@ a file on the disk and then be called.
\section{Revisions}
-\label{sec:orgf446497}
+\label{sec:orgf884e2e}
\begin{itemize}
+\item v1.8, January 18, 2023, add support to \href{https://ctan.org/pkg/listings?lang=en}{listings.}
\item v1.7, August 20, 2022: changed the tmp/ folder to generated/ in order to
conform with CTAN suggestions; renamed the troubleshooting file.
\item v1.6, August 10, 2022: stop only configured/running servers; a new
@@ -333,7 +344,7 @@ code files, zero bytes in output files.)
\end{itemize}
\section{Contributing}
-\label{sec:org0730899}
+\label{sec:org0dce33b}
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 \texttt{runcode}.