texlive[60185] Master/texmf-dist: pyluatex (7aug21)
commits+karl at tug.org
commits+karl at tug.org
Sat Aug 7 22:20:15 CEST 2021
Revision: 60185
http://tug.org/svn/texlive?view=revision&revision=60185
Author: karl
Date: 2021-08-07 22:20:15 +0200 (Sat, 07 Aug 2021)
Log Message:
-----------
pyluatex (7aug21)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md
trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.pdf
trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex
trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md 2021-08-07 20:19:57 UTC (rev 60184)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md 2021-08-07 20:20:15 UTC (rev 60185)
@@ -36,7 +36,6 @@
\randint{2}{5}
\end{document}
```
-
2\. Compile using LuaLaTeX (shell escape is required)
```
lualatex -shell-escape example.tex
Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex 2021-08-07 20:19:57 UTC (rev 60184)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex 2021-08-07 20:20:15 UTC (rev 60185)
@@ -15,7 +15,7 @@
\usepackage{url}
\title{The \emph{pyluatex} package}
\author{Tobias Enderle\\\url{https://github.com/tndrle/PyLuaTeX}}
-\date{v0.2.0 (2021/07/26)}
+\date{v0.3.0 (2021/08/07)}
\begin{document}
\maketitle
\raggedright
@@ -58,8 +58,6 @@
\randint{2}{5}
\end{document}
\end{tcblisting}
-\end{enumerate}
-\begin{enumerate}
\item Compile using Lua\LaTeX{} (shell escape is required)
\begin{tcblisting}{breakable,listing only,
size=fbox,colframe=black!8,boxrule=3pt,colback=black!8}
@@ -178,6 +176,16 @@
\item \inlcode|pythonq|\\[0.5ex]
Same as the \inlcode|python| environment, but any output is suppressed.
\end{itemize}
+You can create your own environments based on the \inlcode|python| and \inlcode|pythonq| environments.
+However, since they are verbatim environments, you have to use the macro \inlcode|\PyLTVerbatimEnv|
+in your environment definition, e.g.
+\begin{tcblisting}{breakable,listing only,
+ size=fbox,colframe=black!8,boxrule=3pt,colback=black!8}
+\newenvironment{custompy}
+{\PyLTVerbatimEnv\begin{python}}
+{\end{python}}
+\end{tcblisting}
+
\section{Requirements}
\begin{itemize}
\item Lua\LaTeX{}
@@ -194,7 +202,7 @@
This provides a lot of flexibility for your typesetting.
After a PyLuaTeX macro or environment has been executed, the corresponding Python code and output can be accessed via the Lua functions \inlcode|pyluatex.get_last_code()| and \inlcode|pyluatex.get_last_output()|, respectively.
-Both functions return a Lua table\footnote{\url{https://www.lua.org/pil/2.5.html}} where each table item corresponds to a line of code or output.
+Both functions return a Lua table\footnote{\url{https://www.lua.org/pil/2.5.html}} (basically an array) where each table item corresponds to a line of code or output.
A simple example for typesetting code and output using the \textit{listings} package would be:
\begin{tcblisting}{breakable,listing only,
@@ -238,6 +246,7 @@
After that, the custom macro \inlcode|\pytypeset| is responsible for typesetting the code and its output.
Using a different code listings package like \textit{minted}, or typesetting inline code is very easy.
+You can also define your own environments that combine Python code and typesetting.
See the \inlcode|typesetting-*.tex| examples in the \inlcode|example| folder.
\section{How It Works}
Modified: trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua 2021-08-07 20:19:57 UTC (rev 60184)
+++ trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua 2021-08-07 20:20:15 UTC (rev 60185)
@@ -37,6 +37,7 @@
local env_end = nil
local env_lines = nil
+local parent_env = nil
local last_code = nil
local last_output = nil
@@ -149,15 +150,28 @@
end
function pyluatex.record_env(quiet)
- if quiet then
- env_end = "\\end{pythonq}"
+ local name
+ if parent_env ~= nil then
+ name = parent_env
+ parent_env = nil
else
- env_end = "\\end{python}"
+ if quiet then
+ name = "pythonq"
+ else
+ name = "python"
+ end
end
+ env_end = "\\end{" .. name .. "}"
env_lines = {}
luatexbase.add_to_callback("process_input_buffer", record_line, "pyluatex_record_line")
end
+function pyluatex.set_parent_env(name)
+ if parent_env == nil then
+ parent_env = name
+ end
+end
+
function pyluatex.run_file(path, write)
local f = io.open(path, "r")
if f then
Modified: trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty 2021-08-07 20:19:57 UTC (rev 60184)
+++ trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty 2021-08-07 20:20:15 UTC (rev 60185)
@@ -9,7 +9,7 @@
%% version 2005/12/01 or later.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{pyluatex}[2021/07/26 v0.2.0 Execute Python code on the fly]
+\ProvidesPackage{pyluatex}[2021/08/07 v0.3.0 Execute Python code on the fly]
\RequirePackage{expl3}
\ExplSyntaxOn
@@ -30,18 +30,20 @@
\directlua{pyluatex.start([==[\pyluatex at executable]==])}
+\newcommand*{\PyLTVerbatimEnv}{\directlua{pyluatex.set_parent_env([==[\@currenvir]==])}}
+
\newenvironment{python}{\directlua{pyluatex.record_env(false)}}%
{\directlua{pyluatex.print_env()}}
\newenvironment{pythonq}{\directlua{pyluatex.record_env(true)}}{}
-\newcommand*{\python at inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3)}}
+\newcommand*{\pyluatex at inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3)}}
-\newcommand*{\py}[1]{\python at inline{#1}{true}{true}}
-\newcommand*{\pyq}[1]{\python at inline{#1}{true}{false}}
+\newcommand*{\py}[1]{\pyluatex at inline{#1}{true}{true}}
+\newcommand*{\pyq}[1]{\pyluatex at inline{#1}{true}{false}}
-\newcommand*{\pyc}[1]{\python at inline{#1}{false}{true}}
-\newcommand*{\pycq}[1]{\python at inline{#1}{false}{false}}
+\newcommand*{\pyc}[1]{\pyluatex at inline{#1}{false}{true}}
+\newcommand*{\pycq}[1]{\pyluatex at inline{#1}{false}{false}}
\newcommand*{\pysession}[1]{\directlua{pyluatex.session = [==[#1]==]}}
More information about the tex-live-commits
mailing list.