From bfa7c6612a8c83982239daadda8bd5769cf236cb Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 7 Aug 2021 20:20:15 +0000 Subject: pyluatex (7aug21) git-svn-id: svn://tug.org/texlive/trunk@60185 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua | 20 +++++++++++++++++--- Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty | 14 ++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua index 506b8bf9cf8..d7e27bc6cb9 100644 --- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua +++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.lua @@ -37,6 +37,7 @@ local tcp = nil local env_end = nil local env_lines = nil +local parent_env = nil local last_code = nil local last_output = nil @@ -149,15 +150,28 @@ local function record_line(line) 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 diff --git a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty index 0709ba76000..81fa87ea827 100644 --- a/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty +++ b/Master/texmf-dist/tex/lualatex/pyluatex/pyluatex.sty @@ -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@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@inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3)}} +\newcommand*{\pyluatex@inline}[3]{\directlua{pyluatex.execute([==[#1]==], #2, #3)}} -\newcommand*{\py}[1]{\python@inline{#1}{true}{true}} -\newcommand*{\pyq}[1]{\python@inline{#1}{true}{false}} +\newcommand*{\py}[1]{\pyluatex@inline{#1}{true}{true}} +\newcommand*{\pyq}[1]{\pyluatex@inline{#1}{true}{false}} -\newcommand*{\pyc}[1]{\python@inline{#1}{false}{true}} -\newcommand*{\pycq}[1]{\python@inline{#1}{false}{false}} +\newcommand*{\pyc}[1]{\pyluatex@inline{#1}{false}{true}} +\newcommand*{\pycq}[1]{\pyluatex@inline{#1}{false}{false}} \newcommand*{\pysession}[1]{\directlua{pyluatex.session = [==[#1]==]}} -- cgit v1.2.3