Debian Codegraph @

texmf-dist/doc/lualatex/pyluatex/example/typesetting-example.tex

raw
1 %% Copyright 2021-2026 Tobias Enderle
2 %%
3 %% This work may be distributed and/or modified under the
4 %% conditions of the LaTeX Project Public License, either version 1.3c
5 %% of this license or (at your option) any later version.
6 %% The latest version of this license is in
7 %% http://www.latex-project.org/lppl.txt
8 %% and version 1.3c or later is part of all distributions of LaTeX
9 %% version 2005/12/01 or later.
10
11 % DESCRIPTION
12 % The code typesetting example below
13
14 \documentclass{article}
15
16 \usepackage{pyluatex}
17 \usepackage{listings}
18 \usepackage{luacode}
19
20 \begin{luacode}
21 function pytypeset()
22 tex.print("\\begin{lstlisting}[language=Python]")
23 tex.print(pyluatex.get_last_code())
24 tex.print("\\end{lstlisting}")
25 tex.print("") -- ensure newline
26 end
27 \end{luacode}
28
29 \newcommand*{\pytypeset}{%
30 \noindent\textbf{Input:}
31 \directlua{pytypeset()}
32 \textbf{Output:}
33 \begin{center}
34 \directlua{tex.print(pyluatex.get_last_output())}
35 \end{center}
36 }
37
38 \begin{document}
39
40 \begin{python}[quiet]
41 greeting = 'Hello PyLuaTeX!'
42 print(greeting)
43 \end{python}
44 \pytypeset
45
46 \end{document}