texlive[63491] Master/texmf-dist: pyluatex (5jun22)

commits+karl at tug.org commits+karl at tug.org
Sun Jun 5 23:02:05 CEST 2022


Revision: 63491
          http://tug.org/svn/texlive?view=revision&revision=63491
Author:   karl
Date:     2022-06-05 23:02:04 +0200 (Sun, 05 Jun 2022)
Log Message:
-----------
pyluatex (5jun22)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/beamer.tex
    trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/repl.tex
    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	2022-06-05 14:27:22 UTC (rev 63490)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/README.md	2022-06-05 21:02:04 UTC (rev 63491)
@@ -34,7 +34,7 @@
 ```
 **Note:** PyLuaTeX starts Python 3 using the command `python3` by default.
 If `python3` does not start Python 3 on your system, find the correct command
-and replace `\usepackage{pyluatex}` with `\usepackage[executable={your python command}]{pyluatex}`.
+and replace `\usepackage{pyluatex}` with `\usepackage[executable=<your python command>]{pyluatex}`.
 For example, `\usepackage[executable=python.exe]{pyluatex}`.
 
 2\. Compile using LuaLaTeX (shell escape is required)
@@ -49,8 +49,8 @@
 * Python 3
 * Linux, macOS or Windows
 
-Our automated tests currently use TeX Live 2021 and Python 3.7+ on
-Ubuntu 20.04, macOS Big Sur 11 and Windows Server 2019.
+The automated tests currently use TeX Live 2022 and Python 3.8+ on
+Ubuntu 20.04, macOS Big Sur 11 and Windows Server 2022.
 
 ## License
 [LPPL 1.3c](http://www.latex-project.org/lppl.txt) for LaTeX code and

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/beamer.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/beamer.tex	2022-06-05 14:27:22 UTC (rev 63490)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/beamer.tex	2022-06-05 21:02:04 UTC (rev 63491)
@@ -8,7 +8,7 @@
 %% and version 1.3c or later is part of all distributions of LaTeX
 %% version 2005/12/01 or later.
 
-\documentclass{beamer}
+\documentclass[t]{beamer}
 
 \usepackage{pyluatex}
 \usepackage{listings}
@@ -64,13 +64,17 @@
 %%%%%%%%%%%%%%%%%%%%%% frame
 
 \begin{frame}{Important}
-Using PyLuaTeX environments (\emph{python} or \emph{pythonq}) inside BEAMER frames
-requires the \emph{fragile} option for those frames.
+Using PyLuaTeX environments (\texttt{python}, \texttt{pythonq}, or \texttt{pythonrepl}) inside BEAMER frames
+requires the \texttt{fragile} option for those frames.
+
+\medskip
+If you don't use overlays in a frame, i.e. the frame contains only a single slide,
+you can use the \texttt{fragile=singleslide} option.
 \end{frame}
 
 %%%%%%%%%%%%%%%%%%%%%% frame
 
-\begin{frame}[fragile]{Slide 1}
+\begin{frame}[fragile=singleslide]{Python environment inside frame}
 \begin{pythonq}
 msg = 'Hello slide 1'
 
@@ -96,27 +100,31 @@
 print(msg)
 \end{pythonq}
 
-\begin{frame}{Slide 1}
+\begin{frame}{Python environment outside frame}
 \pytypeset
 
-The \emph{fragile} option is not required in this frame because
-the \emph{pythonq} environment is outside the frame.
-Only the macro \emph{\textbackslash pytypeset} for typesetting the code and output is inside
+The \texttt{fragile} option is not required in this frame because
+the \texttt{pythonq} environment is outside the frame.
+Only the macro \texttt{\textbackslash pytypeset} for typesetting the code and output is inside
 the frame.
+
+\medskip
+Inline Python still works: The result of \pyq{17 + 300}$\coderaw$ is \outputraw
 \end{frame}
 
 %%%%%%%%%%%%%%%%%%%%%% frame
 
-\newenvironment{typesetpython}
-    {\PyLTVerbatimEnv\begin{pythonq}}
-    {\end{pythonq}\pytypeset}
-
-\begin{frame}[fragile]{Slide 2}
-\begin{typesetpython}
+\begin{frame}[fragile]{Overlays}
+\begin{pythonq}
 msg = 'Custom environment'
 
 print(msg)
-\end{typesetpython}
+\end{pythonq}
+\pytypeset
+\pause
+
+In this frame, \texttt{fragile} is required instead of \texttt{fragile=singleslide},
+because we use overlays.
 \end{frame}
 
 \end{document}

Modified: trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/repl.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/repl.tex	2022-06-05 14:27:22 UTC (rev 63490)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/example/repl.tex	2022-06-05 21:02:04 UTC (rev 63491)
@@ -57,9 +57,9 @@
 \maketitle
 
 PyLuaTeX allows you to run and typeset Python code in an interactive console
-or read–eval–print loop (REPL) fashion. Very much like in an IPython session,
+or read–eval–print loop (REPL) fashion. Very much like in an interactive python session,
 code is prefixed with \verb|>>>| (or \verb|...| in case of multi-line commands)
-and the results are printed automatically.
+and the results are added to the output buffer automatically.
 
 Both code and output are stored in PyLuaTeX's ouput buffer and can be accessed
 by \verb|pyluatex.get_last_output()|. In this way, you can adjust the typesetting

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	2022-06-05 14:27:22 UTC (rev 63490)
+++ trunk/Master/texmf-dist/doc/lualatex/pyluatex/pyluatex.tex	2022-06-05 21:02:04 UTC (rev 63491)
@@ -15,7 +15,7 @@
 \usepackage{url}
 \title{The \emph{pyluatex} package}
 \author{Tobias Enderle\\\url{https://github.com/tndrle/PyLuaTeX}}
-\date{v0.4.4 (2022/03/16)}
+\date{v0.5.0 (2022/06/05)}
 \begin{document}
 \maketitle
 \raggedright
@@ -56,7 +56,7 @@
 \end{tcblisting}
 \textbf{Note:} PyLuaTeX starts Python 3 using the command \inlcode|python3| by default.
 If \inlcode|python3| does not start Python 3 on your system, find the correct command
-and replace \inlcode|\usepackage{pyluatex}| with \inlcode|\usepackage[executable={your python command}]{pyluatex}|.
+and replace \inlcode|\usepackage{pyluatex}| with \inlcode|\usepackage[executable=<your python command>]{pyluatex}|.
 For example, \inlcode|\usepackage[executable=python.exe]{pyluatex}|.
 \item  Compile using Lua\LaTeX{} (shell escape is required)
 \begin{tcblisting}{breakable,listing only,
@@ -131,32 +131,35 @@
 
 \subsection{Macros}
 \begin{itemize}
-\item \inlcode|\py{code}|\\[0.5ex]
-  Executes (object-like) \inlcode|code| and writes its string representation to the document.\\[0.5ex]
+\item \inlcode|\py{<code>}|\\[0.5ex]
+  Executes (object-like) \inlcode|<code>| and writes its string representation to the document.\\[0.5ex]
   \textit{Example:} \inlcode|\py{3 + 7}|
-\item \inlcode|\pyq{code}|\\[0.5ex]
-  Executes (object-like) \inlcode|code|. Any output is suppressed.\\[0.5ex]
+\item \inlcode|\pyq{<code>}|\\[0.5ex]
+  Executes (object-like) \inlcode|<code>|. Any output is suppressed.\\[0.5ex]
   \textit{Example:} \inlcode|\pyq{3 + 7}|
-\item \inlcode|\pyc{code}|\\[0.5ex]
-  Executes \inlcode|code|. Output (e.g. from a call to \inlcode|print()|) is written to the document.\\[0.5ex]
+\item \inlcode|\pyc{<code>}|\\[0.5ex]
+  Executes \inlcode|<code>|. Output (e.g. from a call to \inlcode|print()|) is written to the document.\\[0.5ex]
   \textit{Examples:} \inlcode|\pyc{x = 5}|, \inlcode|\pyc{print('hello')}|
-\item \inlcode|\pycq{code}|\\[0.5ex]
-  Executes \inlcode|code|. Any output is suppressed.\\[0.5ex]
+\item \inlcode|\pycq{<code>}|\\[0.5ex]
+  Executes \inlcode|<code>|. Any output is suppressed.\\[0.5ex]
   \textit{Example:} \inlcode|\pycq{x = 5}|
-\item \inlcode|\pyfile{path}|\\[0.5ex]
-  Executes the Python file specified by \inlcode|path|. Output (e.g. from a call to \inlcode|print()|) is written to the document.\\[0.5ex]
+\item \inlcode|\pyfile{<path>}|\\[0.5ex]
+  Executes the Python file specified by \inlcode|<path>|. Output (e.g. from a call to \inlcode|print()|) is written to the document.\\[0.5ex]
   \textit{Example:} \inlcode|\pyfile{main.py}|
-\item \inlcode|\pyfileq{path}|\\[0.5ex]
-  Executes the Python file specified by \inlcode|path|. Any output is suppressed.\\[0.5ex]
+\item \inlcode|\pyfileq{<path>}|\\[0.5ex]
+  Executes the Python file specified by \inlcode|<path>|. Any output is suppressed.\\[0.5ex]
   \textit{Example:} \inlcode|\pyfileq{main.py}|
-\item \inlcode|\pysession{session}|\\[0.5ex]
-  Selects \inlcode|session| as Python session for subsequent Python code.\\[0.5ex]
+\item \inlcode|\pysession{<session>}|\\[0.5ex]
+  Selects \inlcode|<session>| as Python session for subsequent Python code.\\[0.5ex]
   The session that is active at the beginning is \inlcode|default|.\\[0.5ex]
   \textit{Example:} \inlcode|\pysession{main}|
-\item \inlcode|\pyoption{option}{value}|\\[0.5ex]
-  Assigns \inlcode|value| to the package option \inlcode|option| anywhere in the document. For more information consider
+\item \inlcode|\pyoption{<option>}{<value>}|\\[0.5ex]
+  Assigns \inlcode|<value>| to the package option \inlcode|<option>| anywhere in the document. For more information consider
   the Package Options section.\\[0.5ex]
   \textit{Example:} \inlcode|\pyoption{verbose}{true}|
+\item \inlcode|\pyif{<test>}{<then clause>}{<else clause>}|\\[0.5ex]
+  Evaluates the Python boolean expression \inlcode|<test>|, and then executes either the \LaTeX{} code in \inlcode|<then clause>| or the \LaTeX{} code in \inlcode|<else clause>|.\\[0.5ex]
+  \textit{Example:} \inlcode|\pyif{a == 1}{$a = 1$}{$a \neq 1$}|
 \end{itemize}
 \subsection{Environments}
 \begin{itemize}
@@ -197,8 +200,8 @@
 \item Python 3
 \item Linux, macOS or Windows
 \end{itemize}
-Our automated tests currently use TeX Live 2021 and Python 3.7+ on
-Ubuntu 20.04, macOS Big Sur 11 and Windows Server 2019.
+The automated tests currently use TeX Live 2022 and Python 3.8+ on
+Ubuntu 20.04, macOS Big Sur 11 and Windows Server 2022.
 
 \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.

Modified: trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua	2022-06-05 14:27:22 UTC (rev 63490)
+++ trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua	2022-06-05 21:02:04 UTC (rev 63491)
@@ -141,7 +141,7 @@
     return t
 end
 
-function pyluatex.execute(code, auto_print, write, repl_mode)
+function pyluatex.execute(code, auto_print, write, repl_mode, store)
     local full_code
     if auto_print then
         full_code = "print(str(" .. code .. "), end='')"
@@ -159,14 +159,17 @@
             ignore_errors = pyluatex.ignore_errors
         }
     )
-    last_code = split_lines(code)
-    last_output = split_lines(output)
+    local output_lines = split_lines(output)
+    if store then
+        last_code = split_lines(code)
+        last_output = output_lines
+    end
 
     if success or pyluatex.ignore_errors then
         if pyluatex.verbose or not success then log_output(output) end
 
         if write then
-            tex.print(last_output)
+            tex.print(output_lines)
         end
     else
         if not pyluatex.verbose then log_input(full_code) end
@@ -195,7 +198,7 @@
             table.insert(env_lines, code_in_line)
         end
         local code = table.concat(env_lines, "\n")
-        local success = pyluatex.execute(code, false, false, env_repl_mode)
+        local success = pyluatex.execute(code, false, false, env_repl_mode, true)
         if success or pyluatex.ignore_errors then
             return line:sub(s)
         else
@@ -235,7 +238,7 @@
         elseif code:sub(-1) == "\n" then
             code = code:sub(0, -2)
         end
-        pyluatex.execute(code, false, write, repl_mode)
+        pyluatex.execute(code, false, write, repl_mode, true)
     else
         tex.sprint(err_cmd("File not found: " .. path))
     end

Modified: trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty	2022-06-05 14:27:22 UTC (rev 63490)
+++ trunk/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty	2022-06-05 21:02:04 UTC (rev 63491)
@@ -9,7 +9,7 @@
 %% version 2005/12/01 or later.
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{pyluatex}[2022/03/16 v0.4.4 Execute Python code on the fly]
+\ProvidesPackage{pyluatex}[2022/06/05 v0.5.0 Execute Python code on the fly]
 
 \RequirePackage{expl3}
 \ExplSyntaxOn
@@ -66,7 +66,7 @@
 
 \newenvironment{pythonrepl}{\directlua{pyluatex.record_env("pythonrepl", true)}}{}
 
-\newcommand*{\pyluatex at inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3, false)}}
+\newcommand*{\pyluatex at inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3, false, true)}}
 
 \newcommand*{\py}[1]{\pyluatex at inline{#1}{true}{true}}
 \newcommand*{\pyq}[1]{\pyluatex at inline{#1}{true}{false}}
@@ -81,4 +81,11 @@
 \newcommand*{\pyfileq}[1]{\directlua{pyluatex.run_file([==[#1]==], false, false)}}
 \newcommand*{\pyfilerepl}[1]{\directlua{pyluatex.run_file([==[#1]==], false, true)}}
 
+\newcommand*{\pyif}[1]{%
+    \ifnum1=\directlua{pyluatex.execute([==['1' if (#1) else '0']==], true, true, false, false)}\relax
+        \expandafter\@firstoftwo
+    \else
+        \expandafter\@secondoftwo
+    \fi}
+
 \endinput



More information about the tex-live-commits mailing list.