summaryrefslogtreecommitdiff
path: root/macros/luatex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-07-16 03:01:07 +0000
committerNorbert Preining <norbert@preining.info>2021-07-16 03:01:07 +0000
commit01b14a20f8942ab0c52aeb8abffa85b811c7a95a (patch)
tree2db57d63324f0141577f40d9e8a8a035b131e176 /macros/luatex
parent55ae461252a599d6bc951065a37c16a8971fc560 (diff)
CTAN sync 202107160301
Diffstat (limited to 'macros/luatex')
-rw-r--r--macros/luatex/latex/pyluatex/README.md4
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex.lua32
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex.pdfbin64343 -> 65417 bytes
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex.sty5
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex.tex11
5 files changed, 39 insertions, 13 deletions
diff --git a/macros/luatex/latex/pyluatex/README.md b/macros/luatex/latex/pyluatex/README.md
index f9e727fabf..a555ec2008 100644
--- a/macros/luatex/latex/pyluatex/README.md
+++ b/macros/luatex/latex/pyluatex/README.md
@@ -54,3 +54,7 @@ Ubuntu 20.04, macOS Catalina 10.15 and Windows Server 2019.
We use the great [json.lua](https://github.com/rxi/json.lua) library under the terms
of the [MIT license](https://opensource.org/licenses/MIT).
+## Further Information
+Author: Tobias Enderle
+
+Development: https://github.com/tndrle/PyLuaTeX
diff --git a/macros/luatex/latex/pyluatex/pyluatex.lua b/macros/luatex/latex/pyluatex/pyluatex.lua
index 07d8ea49d3..4f904afe15 100644
--- a/macros/luatex/latex/pyluatex/pyluatex.lua
+++ b/macros/luatex/latex/pyluatex/pyluatex.lua
@@ -36,6 +36,7 @@ local script = file.join(folder, "pyluatex-interpreter.py")
local tcp = nil
local python_lines = {}
+local python_output = nil
local env_end = "\\end{python}"
@@ -71,28 +72,34 @@ local function request(data)
return response.success, response.output
end
-local function print_input(code)
+local function log_input(code)
texio.write_nl("PyLuaTeX input for session \"" .. pyluatex.session .. "\": " .. code)
end
-local function print_output(code)
+local function log_output(code)
texio.write_nl("PyLuaTeX output: " .. code)
end
+local function print_lines(str)
+ for s in str:gmatch("[^\r\n]+") do
+ tex.sprint(s)
+ end
+end
+
function pyluatex.execute(code, write)
- if pyluatex.verbose then print_input(code) end
+ if pyluatex.verbose then log_input(code) end
local success, output = request({ session = pyluatex.session, code = code })
if success then
- if pyluatex.verbose then print_output(output) end
+ if pyluatex.verbose then log_output(output) end
if write then
- tex.sprint(output)
+ print_lines(output)
else
return output
end
else
- if not pyluatex.verbose then print_input(code) end
- print_output(output)
+ if not pyluatex.verbose then log_input(code) end
+ log_output(output)
if write then
tex.sprint(err_cmd("Python error (see above)"))
end
@@ -100,6 +107,13 @@ function pyluatex.execute(code, write)
return nil
end
+function pyluatex.print_env()
+ if python_output ~= nil then
+ print_lines(python_output)
+ python_output = nil
+ end
+end
+
local function record_line(line)
local s, e = line:find(env_end)
if s ~= nil then
@@ -108,7 +122,8 @@ local function record_line(line)
local code = table.concat(python_lines, "\n")
local output = pyluatex.execute(code, false)
if output ~= nil then
- return output .. line:sub(s)
+ python_output = output
+ return line:sub(s)
else
return env_end .. err_cmd("Python error (see above)") .. line:sub(e + 1)
end
@@ -120,6 +135,7 @@ end
function pyluatex.record_env()
python_lines = {}
+ python_output = nil
luatexbase.add_to_callback("process_input_buffer", record_line, "pyluatex_record_line")
end
diff --git a/macros/luatex/latex/pyluatex/pyluatex.pdf b/macros/luatex/latex/pyluatex/pyluatex.pdf
index 2ff342d0f8..4e93fb2935 100644
--- a/macros/luatex/latex/pyluatex/pyluatex.pdf
+++ b/macros/luatex/latex/pyluatex/pyluatex.pdf
Binary files differ
diff --git a/macros/luatex/latex/pyluatex/pyluatex.sty b/macros/luatex/latex/pyluatex/pyluatex.sty
index 752f19d0e7..b9ce3f9717 100644
--- a/macros/luatex/latex/pyluatex/pyluatex.sty
+++ b/macros/luatex/latex/pyluatex/pyluatex.sty
@@ -9,7 +9,7 @@
%% version 2005/12/01 or later.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{pyluatex}[2021/07/14 v0.1.2 Execute Python code on the fly]
+\ProvidesPackage{pyluatex}[2021/07/15 v0.1.3 Execute Python code on the fly]
\RequirePackage{expl3}
\ExplSyntaxOn
@@ -30,7 +30,8 @@
\directlua{pyluatex.start([==[\pyluatex@executable]==])}
-\newenvironment{python}{\directlua{pyluatex.record_env()}}{}
+\newenvironment{python}{\directlua{pyluatex.record_env()}}%
+{\directlua{pyluatex.print_env()}}
\newcommand*{\py}[1]{%
\directlua{pyluatex.execute([==[print(str(#1), end='')]==], true)}%
diff --git a/macros/luatex/latex/pyluatex/pyluatex.tex b/macros/luatex/latex/pyluatex/pyluatex.tex
index a6a66fbde2..c64d757945 100644
--- a/macros/luatex/latex/pyluatex/pyluatex.tex
+++ b/macros/luatex/latex/pyluatex/pyluatex.tex
@@ -15,7 +15,7 @@
\usepackage{url}
\title{The \emph{pyluatex} package}
\author{Tobias Enderle\\\url{https://github.com/tndrle/PyLuaTeX}}
-\date{v0.1.2 (2021/07/14)}
+\date{v0.1.3 (2021/07/15)}
\begin{document}
\maketitle
\raggedright
@@ -72,13 +72,18 @@ The folder \inlcode|example| contains additional example documents:
Demonstrates the use of different Python sessions in a document
\item \inlcode|data-visualization.tex|\\[0.5ex]
Demonstrates the visualization of data using \textit{pgfplots} and \textit{pandas}
+\item \inlcode|matplotlib-external.tex|\\[0.5ex]
+ Demonstrates how \textit{matplotlib} plots can be generated and included in a document
+\item \inlcode|matplotlib-pgf.tex|\\[0.5ex]
+ Demonstrates how \textit{matplotlib} plots can be generated and included in a document using \textit{PGF}
\end{itemize}
For more intricate use cases have a look at our tests in the folder \inlcode|test|.
\section{Installation}
-PyLuaTeX is not yet available through package managers or CTAN\footnote{\url{https://ctan.org}}.
+PyLuaTeX is available on CTAN\footnote{\url{https://ctan.org/pkg/pyluatex}} and in MiKTeX.
+It will be available in TeX Live soon (when you read this it probably already is).
-To install PyLuaTeX, do the following steps:
+To install PyLuaTeX \textbf{manually}, do the following steps:
\begin{enumerate}
\item Locate your local \textit{TEXMF} folder\\[0.5ex]
The location of this folder may vary. Typical defaults for TeX Live are \inlcode|~/texmf| for Linux,