CTAN Comprehensive TeX Archive Network

Directory macros/luatex/latex/pyluatex

README.md

PyLua

Execute Python code on the fly in your documents

PyLua allows you to execute Python code and to include the resulting output in your documents in a single compilation run. documents must be compiled with Lua for this to work.

Example

1. document example.tex

\documentclass{article}

\usepackage{pyluatex}

\begin{python}
import math
import random

random.seed(0)

greeting = 'Hello PyLuaTeX!'
\end{python}

\newcommand{\randint}[2]{\py{random.randint(#1, #2)}}

\begin{document}
\py{greeting}

$\sqrt{371} = \py{math.sqrt(371)}$

\randint{2}{5}
\end{document}

2. Compile using Lua (shell escape is required)

lualatex --shell-escape example.tex

Note: PyLua 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}. For example, \usepackage[executable=python.exe]{pyluatex}.

Note: Running with the shell escape option enabled allows arbitrary code to be executed. For this reason, it is recommended to compile trusted documents only.

Requirements

  • Lua
  • Python 3
  • Linux, macOS or Windows

License

LPPL 1.3c for code and MIT license for Python and Lua code and other files.

Further Information

Author: Tobias Enderle

Development: https://github.com/tndrle/PyLua

Download the contents of this package in one zip archive (114.1k).

PyLua – Execute Python code on the fly in your documents

PyLua allows you to execute Python code and to include the resulting output in your documents in a single compilation run. documents must be compiled with Lua for this to work.

PyLua runs a Python InteractiveInterpreter (actually several if you use different sessions) in the background for on-the-fly code execution. Python code from your file is sent to the background interpreter through a TCP socket. This approach allows your Python code to be executed and the output to be integrated in your file in a single compilation run. No additional processing steps are needed. No intermediate files have to be written. No placeholders have to be inserted.

PackagePyLuaTeX
Bug trackerhttps://github.com/tndrle/PyLuaTeX/issues
Repositoryhttps://github.com/tndrle/PyLuaTeX
Version0.6.3
LicensesMIT License
The Project Public License 1.3c
Copyright2021–2024 Tobias Enderle
MaintainerTobias Enderle
Contained inTeX Live as pyluatex
MiKTeX as pyluatex
TopicsLua
Callback
Experimental 3
...
Guest Book Sitemap Contact Contact Author