summaryrefslogtreecommitdiff
path: root/macros/luatex/latex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/latex')
-rw-r--r--macros/luatex/latex/pyluatex/README.md2
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex-interpreter.py7
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex.lua6
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex.pdfbin82190 -> 84163 bytes
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex.sty28
-rw-r--r--macros/luatex/latex/pyluatex/pyluatex.tex11
6 files changed, 43 insertions, 11 deletions
diff --git a/macros/luatex/latex/pyluatex/README.md b/macros/luatex/latex/pyluatex/README.md
index feb77a04bc..a6faac70c2 100644
--- a/macros/luatex/latex/pyluatex/README.md
+++ b/macros/luatex/latex/pyluatex/README.md
@@ -50,7 +50,7 @@ executed. For this reason, it is recommended to compile trusted documents only.
* Linux, macOS or Windows
Our automated tests currently use TeX Live 2021 and Python 3.7+ on
-Ubuntu 20.04, macOS Catalina 10.15 and Windows Server 2019.
+Ubuntu 20.04, macOS Big Sur 11 and Windows Server 2019.
## License
[LPPL 1.3c](http://www.latex-project.org/lppl.txt) for LaTeX code and
diff --git a/macros/luatex/latex/pyluatex/pyluatex-interpreter.py b/macros/luatex/latex/pyluatex/pyluatex-interpreter.py
index 0e8b32035f..4d713e7ab3 100644
--- a/macros/luatex/latex/pyluatex/pyluatex-interpreter.py
+++ b/macros/luatex/latex/pyluatex/pyluatex-interpreter.py
@@ -1,7 +1,7 @@
"""
MIT License
-Copyright (c) 2021 Tobias Enderle
+Copyright (c) 2021-2022 Tobias Enderle
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -84,10 +84,13 @@ class Handler(socketserver.StreamRequestHandler):
interpreters = defaultdict(Interpreter)
while True:
data = self.rfile.readline().decode('utf-8')
- if len(data) == 0:
+ if len(data) == 0: # socket closed, LuaTeX process finished
return
data = json.loads(data)
+ if data == 'shutdown':
+ return
+
interpreter = interpreters[data['session']]
code = textwrap.dedent(data['code'])
if data['repl_mode']:
diff --git a/macros/luatex/latex/pyluatex/pyluatex.lua b/macros/luatex/latex/pyluatex/pyluatex.lua
index 6e9c6abb63..f95ab989c0 100644
--- a/macros/luatex/latex/pyluatex/pyluatex.lua
+++ b/macros/luatex/latex/pyluatex/pyluatex.lua
@@ -1,7 +1,7 @@
--[[
MIT License
-Copyright (c) 2021 Tobias Enderle
+Copyright (c) 2021-2022 Tobias Enderle
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -73,6 +73,10 @@ function pyluatex.start(executable)
end
end
+function pyluatex.shutdown()
+ tcp:send(json.encode("shutdown") .. "\n")
+end
+
local function request(data)
tcp:send(json.encode(data) .. "\n")
local output = tcp:receive("*l")
diff --git a/macros/luatex/latex/pyluatex/pyluatex.pdf b/macros/luatex/latex/pyluatex/pyluatex.pdf
index 0318eda2cb..23699dd22b 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 ab015d9638..cf67916d19 100644
--- a/macros/luatex/latex/pyluatex/pyluatex.sty
+++ b/macros/luatex/latex/pyluatex/pyluatex.sty
@@ -1,4 +1,4 @@
-%% Copyright 2021 Tobias Enderle
+%% Copyright 2021-2022 Tobias Enderle
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
@@ -9,15 +9,15 @@
%% version 2005/12/01 or later.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{pyluatex}[2021/11/05 v0.4.0 Execute Python code on the fly]
+\ProvidesPackage{pyluatex}[2022/02/04 v0.4.1 Execute Python code on the fly]
\RequirePackage{expl3}
\ExplSyntaxOn
\sys_if_engine_luatex:TF{}{%
-\PackageError{PyLuaTeX}{LuaTeX~is~required}{}%
+ \PackageError{PyLuaTeX}{LuaTeX~is~required}{}%
}
\sys_if_shell_unrestricted:TF{}{%
-\PackageError{PyLuaTeX}{Shell~escape~required~(add~-shell-escape~option)}{}%
+ \PackageError{PyLuaTeX}{Shell~escape~required~(add~-shell-escape~option)}{}%
}
\ExplSyntaxOff
@@ -27,6 +27,7 @@
\DeclareStringOption[python3]{executable}
\DeclareBoolOption{ignoreerrors}
\DeclareBoolOption{verbose}
+\DeclareStringOption[veryveryend]{shutdown}
\ProcessKeyvalOptions*
\ifpyluatex@ignoreerrors
@@ -41,6 +42,25 @@
\fi
\directlua{pyluatex.start([==[\pyluatex@executable]==])}
+\ExplSyntaxOn
+\cs_generate_variant:Nn \tl_if_eq:nnTF { V }
+\tl_if_eq:VnTF{\pyluatex@shutdown}{veryveryend}{%
+ \RequirePackage{atveryend}
+ \AtVeryVeryEnd{\directlua{pyluatex.shutdown()}}
+}{%
+ \tl_if_eq:VnTF{\pyluatex@shutdown}{veryenddocument}{%
+ \RequirePackage{atveryend}
+ \AtVeryEndDocument{\directlua{pyluatex.shutdown()}}
+ }{%
+ \tl_if_eq:VnTF{\pyluatex@shutdown}{off}{}{%
+ \PackageError{PyLuaTeX}{%
+ Invalid~value~for~package~option~"shutdown":~\pyluatex@shutdown
+ }{}%
+ }
+ }
+}
+\ExplSyntaxOff
+
\newcommand*{\PyLTVerbatimEnv}{\directlua{pyluatex.set_parent_env([==[\@currenvir]==])}}
\newenvironment{python}{\directlua{pyluatex.record_env("python", false)}}%
diff --git a/macros/luatex/latex/pyluatex/pyluatex.tex b/macros/luatex/latex/pyluatex/pyluatex.tex
index 86374249af..594d1c0e90 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.4.0 (2021/11/05)}
+\date{v0.4.1 (2022/02/04)}
\begin{document}
\maketitle
\raggedright
@@ -139,8 +139,13 @@ For an example, see the Typesetting Code section.
By default, PyLuaTeX aborts the compilation process when Python reports an error.
If the \inlcode|ignoreerrors| option is set, the compilation process is not aborted.\\[0.5ex]
\textit{Example:} \inlcode|\usepackage[ignoreerrors]{pyluatex}|
+\item \inlcode|shutdown|\\[0.5ex]
+ Specifies when the Python process is shut down. (default: \inlcode|veryveryend|)\\[0.5ex]
+ \textit{Options:} \inlcode|veryveryend|, \inlcode|veryenddocument|, \inlcode|off|\\[0.5ex]
+ PyLuaTeX uses the hooks of the package \textit{atveryend} to shut down the Python interpreter when the compilation is done. With the option \inlcode|veryveryend|, Python is shut down in the \inlcode|\AtVeryVeryEnd| hook. With the option \inlcode|veryenddocument|, Python is shut down in the \inlcode|\AtVeryEndDocument| hook. With the option \inlcode|off|, Python is not shut down explicitly. However, the Python process will shut down when the LuaTeX process finishes even if \inlcode|off| is selected. Using \inlcode|off| on Windows might lead to problems with SyncTeX, though.\\[0.5ex]
+ \textit{Example:} \inlcode|\usepackage[veryenddocument]{pyluatex}|
\end{itemize}
-Package options (except for \inlcode|executable|) can be changed in the document with the
+Package options (except for \inlcode|executable| and \inlcode|shutdown|) can be changed in the document with the
\inlcode|\pyoption| command, e.g. \inlcode|\pyoption{verbose}{true}| or \inlcode|\pyoption{ignoreerrors}{false}|.
\subsection{Macros}
@@ -212,7 +217,7 @@ in your environment definition, e.g.
\item Linux, macOS or Windows
\end{itemize}
Our automated tests currently use TeX Live 2021 and Python 3.7+ on
-Ubuntu 20.04, macOS Catalina 10.15 and Windows Server 2019.
+Ubuntu 20.04, macOS Big Sur 11 and Windows Server 2019.
\section{Typesetting Code}
Sometimes, in addition to having Python code executed and the output written to your document, you also want to show the code itself in your document.