texlive[76189] Master/texmf-dist: piton (30aug25)
commits+karl at tug.org
commits+karl at tug.org
Sat Aug 30 21:47:06 CEST 2025
Revision: 76189
https://tug.org/svn/texlive?view=revision&revision=76189
Author: karl
Date: 2025-08-30 21:47:06 +0200 (Sat, 30 Aug 2025)
Log Message:
-----------
piton (30aug25)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/lualatex/piton/README.md
trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf
trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex
trunk/Master/texmf-dist/doc/lualatex/piton/piton.pdf
trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx
trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua
trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/piton/README.md 2025-08-30 19:46:54 UTC (rev 76188)
+++ trunk/Master/texmf-dist/doc/lualatex/piton/README.md 2025-08-30 19:47:06 UTC (rev 76189)
@@ -13,8 +13,8 @@
The package `piton` provides tools to typeset computer listings, with syntactic highlighting, by using the Lua library LPEG. It requires the use of `lualatex` and won't work with `xelatex` nor `pdflatex`.
+It requires the use of LuaLaTeX and won't work the other TeX engines (xelatex, pdflatex, etc.).
-
## Installation
The package `piton` is present in the distributions MiKTeX, TeXLive and MacTeX.
@@ -29,4 +29,6 @@
These files `piton.sty` and `piton.lua` are the only files necessary to use the extension `piton`.
You have to put them in the same directory as your document or (best) in a `texmf` tree.
+For the documentation in English, run: `lualatex piton.dtx`
+
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2025-08-30 19:46:54 UTC (rev 76188)
+++ trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2025-08-30 19:47:06 UTC (rev 76189)
@@ -11,17 +11,45 @@
{
splittable = 4 ,
math-comments,
- begin-escape = ! ,
- end-escape = ! ,
+ begin-escape = ? ,
+ end-escape = ? ,
begin-escape-math = \( ,
end-escape-math = \) ,
- detected-commands = { highLight , footnote } ,
+ detected-commands = { highLight , footnote , emph , textsl , textbackslash } ,
vertical-detected-commands = newpage ,
raw-detected-commands = { NomTable , rowcolor } ,
}
+\ExplSyntaxOn
+\dim_new:N \l__pantigny_width_dim
+
+\keys_define:nn { pantigny }
+ { width .dim_set:N = \l__pantigny_width_dim }
+
+\NewPitonEnvironment { Code } { O { } }
+ {
+ \SetPitonStyle{ Number = , Comment = , String = }
+ \PitonOptions{language = minimal}
+ \char_set_catcode_other:N |
+ \cs_set_eq:NN \emph \emphase
+ \dim_zero:N \l__pantigny_width_dim
+ \keys_set:nn { pantigny } { #1 }
+ \color{gray}
+ \dim_compare:nNnT \l__pantigny_width_dim > \c_zero_dim
+ {
+ \PitonOptions { width = \l__pantigny_width_dim }
+ \begin{minipage}[c]{\l__pantigny_width_dim}
+ }
+ }
+ { \dim_compare:nNnT \l__pantigny_width_dim > \c_zero_dim
+ { \end{minipage} }
+ }
+
+\ExplSyntaxOff
+
+
\usepackage[executable=python3.exe]{pyluatex}
\usepackage{xcolor}
@@ -122,6 +150,8 @@
\section{Présentation}
+
+
L'extension \pkg{piton} utilise la librairie Lua nommée LPEG\footnote{LPEG est
une librairie de capture de motifs (\emph{pattern-matching} en anglais) pour
Lua, écrite en C, fondée sur les PEG (\emph{parsing expression grammars}):
@@ -190,7 +220,7 @@
Les langages informatiques pris en charge par \pkg{piton} se classent en deux catégories :
\begin{itemize}
\item les langages reconnus nativement par \pkg{piton} qui sont au
-nombre de cinq : Python, OCaml, SQL, C (ou plutôt \CC) et deux
+nombre de quatre : Python, OCaml, SQL, C (ou plutôt \CC) plus deux
langages minimalistes nommés |minimal|\footnote{Le langage |minimal|
peut servir pour formater du pseudo-code :
cf.~p.~\pageref{minimal}.} et |verbatim|;
@@ -237,8 +267,8 @@
\indexenv{Piton}
-L'extension \pkg{piton} fournit plusieurs outils pour composer du code informatique : les
-commandes |\piton|, l'environnement |{Piton}| et la commande |\PitonInputFile|.
+L'extension \pkg{piton} fournit plusieurs outils pour composer du code informatique : la
+commande |\piton|, l'environnement |{Piton}| et la commande |\PitonInputFile|.
\begin{itemize}
\item La commande \DefinitionCommand{piton} doit être utilisée
@@ -250,11 +280,12 @@
La syntaxe et les particularités de la commande sont détaillées ci-après.
-\item L'environnement \Definition{\{Piton\}} doit être utilisé pour
-composer des codes de plusieurs lignes. Comme cet environnement prend son argument selon
-un mode verbatim, il ne peut pas être utilisé dans l'argument d'une commande LaTeX. Pour
-les besoins de personnalisation, il est possible de définir de nouveaux environnements
-similaires à |{Piton}| en utilisant la commande \DefinitionCommand{NewPitonEnvironment} :
+\item L'environnement \Definition{\{Piton\}} doit être utilisé pour composer des
+codes de plusieurs lignes. Comme cet environnement prend son argument selon un
+mode verbatim, il ne peut pas être utilisé dans l'argument d'une commande LaTeX.
+Pour les besoins de personnalisation, il est possible de définir de nouveaux
+environnements similaires à |{Piton}| en utilisant la commande
+\DefinitionCommand{NewPitonEnvironment} ou ses variantes :
cf.~partie~\ref{NewPitonEnvironment} p.~\pageref{NewPitonEnvironment}.
\item La commande \DefinitionCommand{PitonInputFile} doit être utilisée pour insérer et
@@ -297,8 +328,10 @@
{\color{cyan} mais les commandes |\{| et |\}| sont aussi fournies pour insérer des
accolades individuelles} ;
-\item les commandes LaTeX\footnote{Cela s'applique aux commandes commençant par une contre-oblique |\| mais également aux caractères actifs, c'est-à-dire ceux de catcode~13.} de l'argument de |\piton| sont complètement développées
-sans être exécutées
+\item les commandes LaTeX\footnote{Cela s'applique aux commandes commençant par
+ une contre-oblique |\| mais également aux caractères actifs, c'est-à-dire ceux
+ de catcode~13.} de l'argument de |\piton| sont complètement développées (au sens de TeX)
+ sans être exécutées
{\color{cyan} et on peut donc utiliser |\\| pour insérer une contre-oblique}.
\end{itemize}
@@ -422,7 +455,7 @@
l'instruction Lua |piton.get_last_code()| qui en est une version sans les
surcharges de formatage LaTeX (voir la partie \ref{API}, p.~\pageref{API}).}
de l'environnement courant dans ce fichier. À la première utilisation du fichier
-par \pkg{piton} (au cours d'une compilation avec LaTeX), celui-ci est effacé.
+par \pkg{piton} (au cours d'une compilation avec LuaLaTeX), celui-ci est effacé.
L'écriture du fichier ne se fait en fait qu'à la fin de la compilation avec LuaLaTeX.
\item \index{path-write} La clé \Definition{path-write} indique un chemin où
@@ -432,14 +465,14 @@
La clé \Definition{join} est similaire à la clé |write| mais les fichiers créés sont
\emph{joints} (comme «pièces jointes») dans le \textsc{pdf}. Attention :
certains lecteurs de \textsc{pdf} ne proposent pas d'outil permettant d'accéder à
-ces fichiers joints. Parmi les lecteurs qui le proposent, on peut citer le
-logiciel gratuit Foxit PDF Reader, disponible sur toutes les plateformes.
+ces fichiers joints.
+
\item \index{print (clé)}
La clé \Definition{print} contrôle l'affichage effectif du contenu des
environnements |{Piton}| dans le \textsc{pdf}. Bien entendu, la valeur initiale de cette
clé est |true|. Néanmoins, dans certains circonstances, il peut être utile
-d'utiliser |print=false| (dans le cas, par exemple, ou la clé |write|, ou bien
+d'utiliser |print=false| (dans le cas, par exemple, où la clé |write|, ou bien
la clé |join|, est utilisée).
\item \index{line-numbers} La clé \Definition{line-numbers} active la
@@ -493,7 +526,7 @@
Pour la commodité, un dispositif de factorisation du préfixe |line-numbers| est
disponible, c'est-à-dire que l'on peut écrire :
-\begin{Verbatim}
+\begin{Code}
\PitonOptions
{
line-numbers =
@@ -504,8 +537,11 @@
format = \footnotesize \color{blue}
}
}
-\end{Verbatim}
+\end{Code}
+Attention : le code précédent ne suffit pas à activer l'affichage des numéros de
+ligne. Pour cela, il faut encore utiliser la clé |line-numbers| de manière absolue
+(c'est-à-dire sans valeur).
\item \index{left-margin} La clé \Definition{left-margin} fixe une marge sur la
gauche. Cette clé peut être utile, en particulier, en conjonction avec la clé
@@ -558,11 +594,12 @@
(\emph{read-eval-print loop}). Pour un exemple d'utilisation de cette clé, voir
la partie \ref{pythonrepl} p.~\pageref{pythonrepl}.
+La valeurs initiale est : |gray!15|
\item \index{width (clé)} \label{width} La clé \Definition{width} fixe la largeur du
listing produit. La valeur initiale de ce paramètre est la valeur courante de
-|\linewidth|.
+|\linewidth| (paramètre LaTeX qui indique la largeur courante des lignes de texte).
Ce paramètre est utilisé pour :
\begin{itemize}
@@ -570,10 +607,11 @@
mise à |false|: cf. p.~\pageref{line-breaks}) ;
\item les fonds colorés spécifiés par les clés |background-color| et
|prompt-background-color| ;
-\item la largeur de la boîte LaTeX créée par la clé |box| quand celle-ci est
-utilisée (cf. p.~\pageref{box}) ;
-\item la largeur de la boîte graphique créée par la clé |tcolorbox| quand celle-ci
-est utilisée (cf. p.~\pageref{tcolorbox}).
+\item les fonds colorés tracés par la clé |\rowcolor|
+(cf.~p.\pageref{rowcolor});
+\item la largeur de la boîte LaTeX créée par la clé |box| (cf. p.~\pageref{box}) ;
+\item la largeur de la boîte graphique créée par la clé |tcolorbox|
+(cf. p.~\pageref{tcolorbox}).
\end{itemize}
\item \index{max-width (clé)} \colorbox{yellow!50}{\textbf{Nouveau 4.6}}
@@ -584,7 +622,7 @@
|width|) sera la largeur maximale des lignes du listing, c'est-à-dire la largeur naturelle
du listing.
-Pour la lisibilité du code |width=min| est un raccourci pour |max-width=\linewidth|.
+Pour la lisibilité du code, |width=min| est un raccourci pour |max-width=\linewidth|.
\item \index{show-spaces-in-strings} En activant la clé
\Definition{show-spaces-in-strings}, les espaces dans les chaînes de
@@ -614,12 +652,10 @@
\end{itemize}
\bigskip
-
-\begingroup
-\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+\begin{small}
\begin{Verbatim}
-~emphase&\begin{Piton}[language=C,line-numbers,@
-~emphase& splittable=4,gobble,background-color=gray!15,rounded-corners,width=min]@
+~emphase#\begin{Piton}[language=C,line-numbers,gobble,background-color=gray!15@
+~emphase# rounded-corners,width=min,splittable=4]@
void bubbleSort(int arr[], int n) {
int temp;
int swapped;
@@ -636,9 +672,9 @@
if (!swapped) break;
}
}
-~emphase&~textbackslash&@end{Piton}@
+~emphase#~textbackslash#@end{Piton}@
\end{Verbatim}
-\endgroup
+\end{small}
\begin{Piton}[language=C,line-numbers,gobble,
@@ -662,10 +698,6 @@
\end{Piton}
-
-
-
-
\bigskip
La commande |\PitonOptions| propose d'autres clés qui seront décrites plus loin (voir en
particulier la coupure des pages et des lignes p.~\pageref{breakable}).
@@ -701,10 +733,11 @@
de sa définition (c'est-à-dire après le mot-clé |def|). Elle utilise la commande
|\highLight| de \pkg{lua-ul} (qui nécessite lui-même le chargement de \pkg{luacolor}).
-\begin{Verbatim}
+\medskip
+\begin{Code}
\SetPitonStyle
{ Name.Function = \bfseries \highLight[red!30] }
-\end{Verbatim}
+\end{Code}
Ici, |\highLight[red!30]| doit être considéré comme le nom d'une fonction LaTeX qui prend
exactement un argument, puisque, habituellement, elle est utilisée avec
@@ -804,6 +837,7 @@
des \emph{documentation strings} pour avoir un fond coloré gris.
+\medskip
\begin{Verbatim}
~emphase#\SetPitonStyle{String.Doc = \rowcolor{gray!15}\color{black!80}}@
\begin{Piton}[width=min]
@@ -866,13 +900,13 @@
}
\medskip
-\begin{Verbatim}
+\begin{Code}
\NewDocumentCommand{\MyDefFunction}{m}
- {\hypertarget{piton:~#1}{\color[HTML]{CC00FF}{~#1}}}
-\NewDocumentCommand{\MyUserFunction}{m}{\hyperlink{piton:~#1}{~#1}}
+ {\hypertarget{piton:#1}{\color[HTML]{CC00FF}{#1}}}
+\NewDocumentCommand{\MyUserFunction}{m}{\hyperlink{piton:#1}{#1}}
-\SetPitonStyle{Name.Function = \MyDefFunction, ~emphase#UserFunction@ = \MyUserFunction}
-\end{Verbatim}
+\SetPitonStyle{Name.Function = \MyDefFunction, \emph{UserFunction} = \MyUserFunction}
+\end{Code}
\smallskip
@@ -946,34 +980,39 @@
Par exemple, avec l'instruction suivante, un nouvel environnement |{Python}| sera défini
avec le même comportement que l'environnement |{Piton}|:
-\begin{Verbatim}
-~emphase#\NewPitonEnvironment@{Python}{O{}}{\PitonOptions{~#1}}{}
-\end{Verbatim}
+\medskip
+\begin{Code}
+\emph{\NewPitonEnvironment}{Python}{O{}}{\PitonOptions{#1}}{}
+\end{Code}
\bigskip
Si on souhaite un environnement |{Python}| qui compose le code inclus dans une boîte de
\pkg{mdframed}, on peut écrire :
-\begin{Verbatim}[formatcom=\footnotesize\color{gray}]
+\begin{footnotesize}
+\begin{Verbatim}
\usepackage[framemethod=tikz]{mdframed} % dans le préambule
\end{Verbatim}
+\end{footnotesize}
-\begin{Verbatim}
-~emphase#\NewPitonEnvironment@{Python}{}
+\medskip
+\begin{Code}
+\emph{\NewPitonEnvironment}{Python}{}
{\begin{mdframed}[roundcorner=3mm]}
{\end{mdframed}}
-\end{Verbatim}
+\end{Code}
\bigskip
Avec ce nouvel environnement |{Python}|, on peut écrire :
-\begin{Verbatim}
-~emphase#\begin{Python}@
+\medskip
+\begin{Code}
+\emph{\begin{Python}}
def carré(x):
"""Calcule le carré de x"""
return x*x
-~emphase#\end{Python}@
-\end{Verbatim}
+\emph{\end{Python}}
+\end{Code}
\NewPitonEnvironment{Python}{}
{\begin{mdframed}[roundcorner=3mm]}
@@ -1042,7 +1081,9 @@
crochets, a été supprimé} (en fait, les symboles \verb+%+ pourraient être supprimés sans
problème).
-\begin{Verbatim}[formatcom=\small\color{gray}]
+\medskip
+\begin{small}
+\begin{Verbatim}
~emphase#\NewPitonLanguage@{Java}%
{morekeywords={abstract,boolean,break,byte,case,catch,char,class,%
const,continue,default,do,double,else,extends,false,final,%
@@ -1057,8 +1098,8 @@
morestring=[b]',%
}
\end{Verbatim}
+\end{small}
-
\NewPitonLanguage{Java}
{morekeywords={abstract,boolean,break,byte,case,catch,char,class,
const,continue,default,do,double,else,extends,false,final,
@@ -1157,8 +1198,8 @@
\smallskip
Si on souhaite composer un listing dans une boîte de LaTeX, on doit utiliser la clé
\Definition{box}. Cette clé prend comme valeur |c|, |t| ou |b| correspondant
-au paramètre de position verticale (comme dans un environnement |{minipage}| de LaTeX).
-La valeur par défaut est |c| (comme pour |{minipage}|).
+au paramètre de position verticale (comme dans un environnement |{minipage}| de LaTeX, qui
+crée aussi une boîte LaTeX). La valeur par défaut est |c| (comme pour |{minipage}|).
\smallskip
L'emploi de la clé |box| active |width=min| (sauf, bien sûr, si on utilise
@@ -1175,6 +1216,7 @@
return x*x
\end{Piton}
\hspace{1cm}
+\begin{Piton}
def cube(x):
return x*x*x
\end{Piton}
@@ -1205,6 +1247,7 @@
return x*x
\end{Piton}
\hspace{1cm}
+\begin{Piton}
def cube(x):
return x*x*x
\end{Piton}
@@ -1226,7 +1269,7 @@
\vspace{1cm}
-Voici un exemple avec la clé |max-width|.
+Voici un exemple avec la clé |max-width|, égale à 7~cm pour les deux listings.
\begin{Verbatim}
\begin{center}
@@ -1285,10 +1328,12 @@
la librairie |skins| de \pkg{tcolorbox} et activé la \emph{skin} |enhanced| pour avoir
une meilleure apparence au niveau du saut de page.
-\begin{Verbatim}[formatcom=\footnotesize\color{gray}]
+\begin{footnotesize}
+\begin{Verbatim}
\tcbuselibrary{skins,breakable} % dans le préambule
\tcbset{enhanced} % dans le préambule
\end{Verbatim}
+\end{footnotesize}
\smallskip
\begin{Verbatim}
@@ -1448,7 +1493,7 @@
return x*x
def carré(x):
"""Calcule le carré de x"""
- return x*x
+ return x*x
def carré(x):
"""Calcule le carré de x"""
return x*x
@@ -1460,8 +1505,9 @@
Si on souhaite que le résultat soit produit dans une boîte LaTeX (en dépit de son nom,
un environnement de \pkg{tcolorbox} n'est pas nécessairement une boîte LaTeX),
il suffit d'utiliser, conjointement avec la clé |tcolorbox|, la clé |box| fournie
-par \pkg{piton} (cf. p.~\pageref{box}). Bien sûr, la boîte ainsi créée ne sera \emph{pas}
-sécable par un saut de page.
+par \pkg{piton} (cf. p.~\pageref{box}). Bien sûr, la boîte LaTeX ainsi créée ne sera \emph{pas}
+sécable par un saut de page (comme toutes les boîtes de LaTeX), même si la clé |splittable|
+(cf.~p.~\pageref{splittable}) est active.
On rappelle que l'emploi de la clé |box| active |width=min| (sauf si on utilise
explicitement |width| ou |max-width|).
@@ -1581,7 +1627,8 @@
Supposons que le fichier à inclure contienne des solutions à des exercices de
programmation sur le modèle suivant :
-\begin{Verbatim}[formatcom=\small\color{gray}]
+\begin{small}
+\begin{Verbatim}
~#[Exercice 1] Version itérative
def fibo(n):
if n==0: return 0
@@ -1595,6 +1642,7 @@
return v
~#<Exercice 1>
\end{Verbatim}
+\end{small}
Les marqueurs de début de début et de fin sont les chaînes |#[Exercice 1]| et
|#<Exercice 1>|. La chaîne «|Exercice 1|» sera appelée le \emph{label} de l'exercice (ou
@@ -1683,9 +1731,8 @@
\label{line-breaks}
-Par défaut, les éléments produits par \pkg{piton} ne peuvent pas être coupés par une fin
-de ligne. Il existe néanmoins des clés pour autoriser de telles coupures (les points de
-coupure possibles sont les espaces, y compris les espaces qui sont dans les chaînes de
+Il existe des clés pour contrôler les coupures ligne (les points de coupure
+possibles sont les espaces, y compris les espaces qui sont dans les chaînes de
caractères des langages informatiques).
\begin{itemize}
\item \index{break-lines!break-lines-in-piton} Avec la clé
@@ -1765,6 +1812,7 @@
\subsubsection{Coupure des pages}
+\label{splittable}
\label{coupure-de-pages}
\index{splittable}
\index{splittable-on-empty-lines}
@@ -1893,6 +1941,7 @@
\label{split-on-empty-lines}
\index{split-separation}
\index{env-used-by-split}
+\index{add-to-split-separation}
L'exension \pkg{piton} fournit la clé \Definition{split-on-empty-lines}, qui ne doit pas
être confondue avec la clé |splittable-on-empty-lines| définie précédemment.
@@ -1914,10 +1963,15 @@
\item La valeur initiale de ce paramètre est |\vspace{\baselineskip}\vspace{-1.25pt}|, ce qui,
au final, correspond à une ligne vide dans le \textsc{pdf} produit (cet espace vertical
-est supprimé s'il tombe au niveau d'un saut de page).
+est supprimé s'il tombe au niveau d'un saut de page).
+
+\item L'extension \pkg{piton} propose en fait aussi la clé
+\Definition{add-to-split-separation} qui ajoute du contenu à droite de
+|split-separation|.
\end{itemize}
+
Chaque morceau du code informatique est formaté (de manière autonome) dans un
environnement dont le nom est donné par la clé \Definition{env-used-by-split}. La valeur
initiale de ce paramètre est, sans surprise, |Piton| et les différents morceaux sont donc
@@ -1959,7 +2013,45 @@
\end{Piton}
+\vspace{5mm}
+Si on souhaite au contraire une continuité de numérotation, on peut ajouter
+|\PitonOptions{resume}| au paramètre |split-separation| :
+
\bigskip
+\begin{Verbatim}
+\begin{Piton}[
+ split-on-empty-lines,
+ ~emphase#add-to-split-separation = \PitonOptions{resume}@ ,
+ background-color=gray!15,
+ line-numbers
+ ]
+def carré(x):
+ """Calcule le carré de x"""
+ return x*x
+
+def cube(x):
+ """Calcule le cube de x"""
+ return x*x*x
+\end{Piton}
+\end{Verbatim}
+
+\begin{Piton}[
+ split-on-empty-lines,
+ add-to-split-separation = \PitonOptions{resume} ,
+ background-color=gray!15,
+ line-numbers
+ ]
+def carré(x):
+ """Calcule le carré de x"""
+ return x*x
+
+def cube(x):
+ """Calcule le cube de x"""
+ return x*x*x
+\end{Piton}
+
+
+\bigskip
\textbf{Attention} : Comme chaque morceau est traité de manière indépendante, les
commandes spécifiées par |detected-commands| ou |raw-detected-commands|
(cf.~p.~\pageref{detected-commands}) et les commandes et environnements de Beamer
@@ -1967,6 +2059,7 @@
listing de départ.
+
\bigskip
\subsection{Mise en évidence d'identificateurs}
@@ -2220,31 +2313,33 @@
\end{itemize}
\medskip
-Dans l'exemple suivant, qui est une programmation récursive de la factorielle, on décide
-de surligner en jaune l'appel récursif. La commande |\highLight| de
-\pkg{lua-ul}\footnote{L'extension \pkg{lua-ul} requiert elle-même l'extension
- \pkg{luacolor}.} permet de le faire facilement.
+Dans l'exemple suivant, qui est une programmation récursive en C de la
+factorielle, on décide de surligner en jaune l'appel récursif. La commande
+|\highLight| de \pkg{lua-ul}\footnote{L'extension \pkg{lua-ul} requiert
+ elle-même l'extension \pkg{luacolor}.} permet de le faire facilement.
-\begin{Verbatim}[formatcom=\footnotesize\color{gray}]
+\begin{footnotesize}
+\begin{Verbatim}
\PitonOptions{~emphase#detected-commands@ = highLight} % dans le préambule
\end{Verbatim}
+\end{footnotesize}
\begin{Verbatim}
-\begin{Piton}
-def fact(n):
- if n==0:
- return 1
- else:
- ~emphase#\highLight@{return n*fact(n-1)}
+\begin{Piton}[language=C]
+int factorielle(int n)
+ {
+ if (n > 0) ~emphase#\highLight{return n * factorielle(n - 1)}@ ;
+ else return 1;
+ }
\end{Piton}
\end{Verbatim}
-\begin{Piton}
-def fact(n):
- if n==0:
- return 1
- else:
- \highLight{return n*fact(n-1)}
+\begin{Piton}[language=C]
+int factorielle(int n)
+ {
+ if (n > 0) \highLight{return n * factorielle(n - 1)} ;
+ else return 1;
+ }
\end{Piton}
\bigskip
@@ -2312,19 +2407,23 @@
\PitonOptions{vertical-detected-commands = newpage}
\end{Verbatim}
-et demander dans un listing un saut de page obligatoire par |\newpage{}| :
+et demander dans un listing un saut de page obligatoire par |\newpage{}| (la paire
+d'accolades |{}| est obligatoire car les commandes détectées par \pkg{piton} sont censées
+être des commandes LaTeX à un seul argument obligatoire).
-\begin{Verbatim}
+\medskip
+\begin{Code}
\begin{Piton}
def carré(x):
- return x*x ~emphase#\newpage{}@
+ return x*x \emph{\textbackslash{}newpage{}}
def cube(x):
return x*x*x
\end{Piton}
-\end{Verbatim}
+\end{Code}
+\medskip
+On peut aussi envisager de demander la détection de la commande |\vspace|.
-
\subsubsection{Le mécanisme «escape»}
\index{begin-escape}
@@ -2347,29 +2446,30 @@
comme précédemment mais on peut utiliser le mécanisme «escape» qui est plus général.
\smallskip
-On suppose que le préambule du document contient l'instruction :
-
+\begin{small}
\begin{Verbatim}
-\PitonOptions{~emphase#begin-escape=!,end-escape=!@}
+\PitonOptions{~emphase#begin-escape=!,end-escape=!@} % dans le préambule du document LaTeX
\end{Verbatim}
+\end{small}
-On peut alors écrire :
-\begin{Verbatim}
+\medskip
+\begin{Code}
\begin{Piton}
def fact(n):
if n==0:
return 1
else:
- ~emphase#!\highLight[LightPink]{!@return n*fact(n-1)~emphase#!}!@
+ ?\emph{?\highLight[LightPink]{?}?return n*fact(n-1)?\emph{?}?}?
\end{Piton}
-\end{Verbatim}
+\end{Code}
+\medskip
\begin{Piton}
def fact(n):
if n==0:
return 1
else:
- !\highLight[LightPink]{!return n*fact(n-1)!}!
+ ?\highLight[LightPink]{?return n*fact(n-1)?}?
\end{Piton}
@@ -2418,14 +2518,13 @@
\bigskip
Voici un exemple d'utilisation typique :
-\medskip
\begin{Verbatim}
\begin{Piton}[line-numbers]
def arctan(x,n=10):
- if ~emphase#\(x < 0\)@ :
- return ~emphase#\(-\arctan(-x)\)@
+ if ~emphase#\(x < 0\)@
+ return ~emphase#\(-\arctan(-x)\)@
elif ~emphase#\(x > 1\)@ :
- return ~emphase#\(\pi/2 - \arctan(1/x)\)@
+ return ~emphase#\(\pi/2 - \arctan(1/x)\)@
else:
s = ~emphase#\(0\)@
for ~emphase#\(k\)@ in range(~emphase#\(n\)@): s += ~emphase#\(\smash{\frac{(-1)^k}{2k+1} x^{2k+1}}\)@
@@ -2476,9 +2575,10 @@
\subsubsection{\{Piton\} et \textbackslash PitonInputFile sont ``overlay-aware''}
-Quand \pkg{piton} est utilisé avec Beamer, l'environnement |{Piton}| et la commande
-|\PitonInputFile| acceptent l'argument optionnel |<...>| de Beamer pour indiquer les
-«\emph{overlays}» concernés.
+Quand \pkg{piton} est utilisé avec Beamer, la command |\PitonInputFile| et
+l'environnement |{Piton}| (mais pas les environnements créés par
+|\NewPitonEnvironment|) acceptent l'argument optionnel |<...>| de Beamer pour
+indiquer les «\emph{overlays}» concernés.
On peut par exemple écrire :
@@ -2495,6 +2595,7 @@
\end{Verbatim}
+
\subsubsection{Commandes de Beamer reconnues dans \{Piton\} et \textbackslash PitonInputFile}
\index{detected-beamer-commands}
@@ -2534,7 +2635,9 @@
\medskip
Voici un exemple complet de fichier :
-\begin{Verbatim}[formatcom = \small\color{gray}]
+\medskip
+\begin{small}
+\begin{Code}
\documentclass{beamer}
\usepackage{piton}
\begin{document}
@@ -2542,16 +2645,18 @@
\begin{Piton}
def string_of_list(l):
"""Convertit une liste de nombres en chaîne"""
-~emphase# \only<2->{s = "{" + str(l[0])}@
-~emphase# \only<3->{for x in l[1:]: s = s + "," + str(x)}@
-~emphase# \only<4->{s = s + "}"}@
+ \emph{\only<2->{s = "{" + str(l[0])}}
+ \emph{\only<3->{for x in l[1:]: s = s + "," + str(x)}}
+ \emph{\only<4->{s = s + "}"}}
return s
\end{Piton}
\end{frame}
\end{document}
-\end{Verbatim}
+\end{Code}
+\end{small}
-Dans l'exemple précédent, les accolades des deux chaînes de caractères Python |"{"| et
+\medskip
+Dans cet exemple, les accolades des deux chaînes de caractères Python |"{"| et
|"}"| sont correctement interprétées (sans aucun caractère d'échappement).
@@ -2578,7 +2683,9 @@
\medskip
On peut par exemple écrire :
-\begin{Verbatim}[formatcom = \small\color{gray}]
+\medskip
+\begin{small}
+\begin{Code}
\documentclass{beamer}
\usepackage{piton}
\begin{document}
@@ -2586,16 +2693,16 @@
\begin{Piton}
def carré(x):
"""Calcule le carré de l'argument"""
- ~emphase#\begin{uncoverenv}<2>@
+\emph{\begin{uncoverenv}<2>}
return x*x
- ~emphase#\end{uncoverenv}@
+\emph{\end{uncoverenv}}
\end{Piton}
\end{frame}
\end{document}
-\end{Verbatim}
+\end{Code}
+\end{small}
-
\vspace{1cm}
\textbf{Remarque à propos de la commande \textbackslash alert et de
l'environnement \{alertenv\} de Beamer}
@@ -2928,6 +3035,40 @@
Par défaut, les numéros de ligne sont composés par \pkg{piton} en débordement à
gauche (en utilisant en interne la commande |\llap| de LaTeX).
+
+\begingroup
+\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+\begin{Verbatim}
+~emphase&\PitonOptions{background-color=gray!15, line-numbers}@
+\begin{Piton}
+def arctan(x,n=10):
+ if x < 0:
+ return -arctan(-x) #> (appel récursif)
+ elif x > 1:
+ return pi/2 - arctan(1/x) #> (autre appel récursif)
+ else:
+ return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+\end{Piton}
+\end{Verbatim}
+\endgroup
+
+
+
+\begingroup
+\PitonOptions{background-color=gray!15,line-numbers}
+\begin{Piton}
+def arctan(x,n=10):
+ if x < 0:
+ return -arctan(-x) #> (appel récursif)
+ elif x > 1:
+ return pi/2 - arctan(1/x) #> (autre appel récursif)
+ else:
+ return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+\end{Piton}
+\endgroup
+
+\bigskip
+
Si on ne veut pas de débordement, on peut utiliser l'option |left-margin=auto| qui va
insérer une marge adaptée aux numéros qui seront insérés (elle est plus large quand les
numéros dépassent 10).
@@ -3034,7 +3175,7 @@
\begingroup
-\PitonOptions{width = 9cm, background-color=gray!15}
+\PitonOptions{width = 9cm , background-color=gray!15}
\NewDocumentCommand{\MyLaTeXCommand}{m}{\hfill \normalfont\itshape\rlap{\quad #1}}
\SetPitonStyle{Comment.LaTeX = \MyLaTeXCommand}
\begin{Piton}
@@ -3061,7 +3202,7 @@
contenant du texte).
\medskip
-Cette commande |\rowcolor| peut-être utilisée dans un style, comme illustré à la
+Cette commande |\rowcolor| peut être utilisée dans un style, comme illustré à la
page~\pageref{rowcolor} mais on peut aussi envisager de l'utiliser directement
dans un listing. Il faudra néanmoins utiliser un des mécanismes d'échappement
vers LaTeX fournis par \pkg{piton}. Dans l'exemple suivant, on utilise la clé
@@ -3071,9 +3212,11 @@
|\rowcolor{[rgb]{0.8,1,0.8}}| (syntaxe acceptée par |\rowcolor|).
\nobreak
-\begin{Verbatim}[formatcom=\footnotesize\color{gray}]
+\begin{footnotesize}
+\begin{Verbatim}
\PitonOptions{raw-detected-commands = rowcolor} % dans le préambule
\end{Verbatim}
+\end{footnotesize}
\medskip
@@ -3215,9 +3358,11 @@
commandes LaTeX détectées par \pkg{piton} sont censées être des commandes à un argument
entre accolades.
-\begin{Verbatim}[formatcom = \footnotesize\color{gray}]
+\begin{footnotesize}
+\begin{Verbatim}
\PitonOptions{vertical-detected-commands = newpage} % dans le préambule
\end{Verbatim}
+\end{footnotesize}
\begin{Verbatim}
~emphase#\begin{Python}@{Mon exemple}
@@ -3379,24 +3524,22 @@
(avec \pkg{piton}) et qui affiche également dessous le résultat de l'exécution de ce code
avec Python.
-
-\begin{Verbatim}
-\NewPitonEnvironment{~emphase#PitonExecute@}{O{}}
+\medskip
+\begin{Code}
+\NewPitonEnvironment{\emph{PitonExecute}}{O{}}
{\PitonOptions{~#1}}
{\begin{center}
\directlua{pyluatex.execute(piton.get_last_code(), false, true, false, true)}%
- \end{center}
- \ignorespacesafterend}
-\end{Verbatim}
+ \end{center}}
+\end{Code}
+\medskip
\NewPitonEnvironment{PitonExecute}{O{}}
{\PitonOptions{#1}}
{\begin{center}
\directlua{pyluatex.execute(piton.get_last_code(), false, true, false, true)}%
- \end{center}
- \ignorespacesafterend}
+ \end{center}}
-
On a utilisé la fonction Lua |piton.get_last_code| fournie dans l'API de \pkg{piton} :
cf.~partie~\ref{API}, p.~\pageref{API}.
@@ -3404,10 +3547,11 @@
Cet environnement |{PitonExecute}| prend en argument optionnel (entre crochets) les
options proposées par la commande |\PitonOptions|.
+\medskip
\begin{Verbatim}
\begin{~emphase#PitonExecute@}[background-color=gray!15]
def carré(x):
- """Calcule le carré de l'argument"""
+ """Calcule le carré de x"""
return x*x
print(f'Le carré de 12 est {carré(12)}.')
\end{~emphase#PitonExecute@}
@@ -3417,7 +3561,7 @@
\medskip
\begin{PitonExecute}[background-color=gray!15]
def carré(x):
- """Calcule le carré de l'argument"""
+ """Calcule le carré de x"""
return x*x
print(f'Le carré de 12 est {carré(12)}.')
\end{PitonExecute}
@@ -3426,16 +3570,18 @@
On peut, dans cet environnement, utiliser les mécanismes d'échappement vers
LaTeX de la même manière que précédemment (cf. p.~\pageref{LaTeX-escapes}).
-
-\begin{Verbatim}[formatcom=\footnotesize\color{gray}]
+\begin{footnotesize}
+\begin{Verbatim}
\usepackage{luacolor,lua-ul} % dans le préambule
\PitonOptions{detected-commands = highLight} % dans le préambule
\end{Verbatim}
+\end{footnotesize}
+\medskip
\begin{Verbatim}
\begin{PitonExecute}[background-color=gray!15]
def carré(x):
- """Calcule le carré de l'argument"""
+ """Calcule le carré de x"""
~emphase#\highLight{return x*x}@
print(f'Le carré de 12 est {carré(12)}.')
\end{PitonExecute}
@@ -3444,7 +3590,7 @@
\medskip
\begin{PitonExecute}[background-color=gray!15]
def carré(x):
- """Calcule le carré de l'argument"""
+ """Calcule le carré de x"""
\highLight{return x*x}
print(f'Le carré de 12 est {carré(12)}.')
\end{PitonExecute}
@@ -3589,8 +3735,8 @@
L'exemple précédent donne alors :
\medskip
-\begin{Verbatim}
-~emphase#\begin{PitonREPL}@
+\begin{Code}
+\emph{\begin{PitonREPL}}
def valeur_absolue(x):
"""Renvoie la valeur absolue de x"""
if x > 0:
@@ -3601,8 +3747,8 @@
valeur_absolue(-3)
valeur_absolue(0)
valeur_absolue(5)
-~emphase#\end{PitonREPL}@
-\end{Verbatim}
+\emph{\end{PitonREPL}}
+\end{Code}
@@ -3663,7 +3809,7 @@
l'utilisateur n'a pas fixé ce style, ces éléments sont analysés et
formatés par \pkg{piton} au même titre que le reste du code. \\
Operator & les opérateurs suivants : \texttt{!= == << >> - \~{} + / * \% = < > \& .}
- \verb+|+ |@| \\
+ \verb+|+ |@| \\ % |
Operator.Word & les opérateurs suivants : |in|, |is|, |and|, |or| et |not| \\
Name.Builtin & la plupart des fonctions prédéfinies par Python \\
Name.Decorator & les décorateurs (instructions débutant par \verb|@|) \\
@@ -3748,6 +3894,21 @@
\end{tabularx}
\end{center}
+\vspace{1cm}
+
+Voici un exemple :
+
+\medskip
+\begin{Piton}[language = OCaml]
+let rec quick_sort lst = (* Tri par segmentation *)
+ match lst with
+ | [] -> []
+ | pivot :: rest ->
+ let left = List.filter (fun x -> x < pivot) rest in
+ let right = List.filter (fun x -> x >= pivot) rest in
+ quick_sort left @ [pivot] @ quick_sort right
+\end{Piton}
+
\newpage
\subsection[Le langage C (et C++)]{Le langage C (et \CC)}
@@ -3769,7 +3930,7 @@
String.Interpol & les éléments \texttt{\%d}, \texttt{\%i}, \texttt{\%f}, \texttt{\%c},
etc. dans les chaînes de caractères ; ce style hérite du style
|String.Long| \\
-Operator & les opérateurs suivants : \texttt{!= == << >> - \~{} + / * \% = < > \& .} \verb+|+ |@| \\
+Operator & les opérateurs suivants : \texttt{!= == << >> - \~{} + / * \% = < > \& .} \verb+|+ |@| \\ % |
Name.Type & les types prédéfinis suivants : |bool|, |char|, |char16_t|, |char32_t|,
|double|, |float|, |int|, |int8_t|, |int16_t|, |int32_t|, |int64_t|, |long|,
|short|, |signed|, |unsigned|, |void| et |wchar_t| \\
@@ -3905,7 +4066,8 @@
de la définition faite par \pkg{listings} (fichier |lstlang1.sty|).
\medskip
-\begin{Verbatim}[formatcom=\small]
+\begin{small}
+\begin{Verbatim}
\NewPitonLanguage{HTML}%
{morekeywords={A,ABBR,ACRONYM,ADDRESS,APPLET,AREA,B,BASE,BASEFONT,%
BDO,BIG,BLOCKQUOTE,BODY,BR,BUTTON,CAPTION,CENTER,CITE,CODE,COL,%
@@ -3934,8 +4096,8 @@
morestring=[d]",
}
\end{Verbatim}
+\end{small}
-
\newpage
\subsection{Le langage «minimal»}
Modified: trunk/Master/texmf-dist/doc/lualatex/piton/piton.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx
===================================================================
--- trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2025-08-30 19:46:54 UTC (rev 76188)
+++ trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2025-08-30 19:47:06 UTC (rev 76189)
@@ -9,7 +9,7 @@
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
-% http://www.latex-project.org/lppl.txt
+% http://www.latex-project.org/lppl.txti
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
@@ -88,12 +88,12 @@
% \iffalse
%<*STY>
% \fi
-\def\PitonFileVersion{4.8a}
-\def\PitonFileDate{2025/08/19}
+\def\PitonFileVersion{4.8b}
+\def\PitonFileDate{2025/08/30}
% \iffalse
%</STY>
%<*LUA>
-piton_version = "4.8a" -- 2025/08/19
+piton_version = "4.8b" -- 2025/08/30
%</LUA>
%\fi
%
@@ -112,12 +112,13 @@
%
%
% \section{Presentation}
+%
%
%
% The package \pkg{piton} uses the Lua library LPEG\footnote{LPEG is a
% pattern-matching library for Lua, written in C, based on \emph{parsing
% expression grammars}:
-% \url{http://www.inf.puc-rio.br/~roberto/lpeg/}} for parsing informatic
+% \url{http://www.inf.puc-rio.br/~roberto/lpeg/}} for parsing computer
% listings and typesets them with syntactic highlighting. Since it uses the Lua
% of LuaLaTeX, it works with |lualatex| only (and won't work with the other
% engines: |latex|, |pdflatex| and |xelatex|). It does not use external program
@@ -156,7 +157,7 @@
%
% \medskip
% The name of this extension (\pkg{piton}) has been chosen arbitrarily by
-% reference to the pitons used by the climbers in alpinism.
+% reference to the pitons used by the climbers in mountaineering.
%
%
% \section{Installation}
@@ -187,7 +188,7 @@
% \begin{itemize}
% \item the languages natively supported by \pkg{piton}, which are Python, OCaml,
% C~(in fact \CC), SQL and two special languages called |minimal| and |verbatim|;
-% \item the languages defined by the final user by using the built-in command
+% \item the languages defined by the end user by using the built-in command
% |\NewPitonLanguage| described p.~\pageref{NewPitonLanguage} (the parsers of
% those languages can't be as precise as those of the languages supported
% natively by \pkg{piton}).
@@ -236,7 +237,7 @@
% typeset multi-lines code. Since it takes its argument in a verbatim mode, it
% can't be used within the argument of a LaTeX command. For sake of
% customization, it's possible to define new environments similar to the
-% environment |{Piton}| with the command |\NewPitonEnvironment|:
+% environment |{Piton}| with the command |\NewPitonEnvironment| or its friends:
% cf.~\ref{NewPitonEnvironment} p.~\pageref{NewPitonEnvironment}.
%
% \item The command \DefinitionCommand{PitonInputFile} is used to insert and
@@ -278,7 +279,7 @@
%
% \item the LaTeX commands\footnote{That concerns the commands beginning with a
% backslash but also the active characters (with catcode equal to 13). } of the
-% argument are fully expanded and not executed,
+% argument are fully expanded (in the TeX meaning) and not executed,
%
% {\color{cyan} so, it's possible to use |\\| to insert a backslash}.
% \end{itemize}
@@ -371,7 +372,7 @@
% surprise, these instructions are not used for the so-called ``LaTeX comments'').
%
% The initial value is |\ttfamily| and, thus, \pkg{piton} uses by default the
-% current monospaced font.
+% current monospace font.
%
% \item \index{gobble}\label{gobble} The key \Definition{gobble} takes in as
% value a positive integer~$n$: the first $n$ characters are discarded (before
@@ -403,7 +404,7 @@
% which is the body without the overwritten LaTeX formatting instructions (cf.
% the part~\ref{API}, p.~\pageref{API}).} of the current environment in
% that file. At the first use of a file by \pkg{piton} (during a given
-% compilation done by LaTeX), it is erased. In fact, the file is written once at
+% compilation done by LuaLaTeX), it is erased. In fact, the file is written once at
% the end of the compilation of the file by LuaLaTeX.
%
% \item \index{path-write} The key \Definition{path-write} specifies a path
@@ -412,15 +413,13 @@
% \item The key \Definition{join} is similar to the key |write| but the files which
% are created are joined (as \emph{joined files}) in the \textsc{pdf}. Be
% careful: Some \textsc{pdf} readers don't provide any tool to access to these
-% joined files. Among the applications wich provide an access to those joined
-% files, we will mention the free application Foxit~PDF~Reader, which is
-% available on all the platforms.
+% joined files.
%
% \item \index{print}
% The key \Definition{print} controls whether the content of the environment is
% actually printed (with the syntactic formating) in the \textsc{pdf}. Of
% course, the initial value of |print| is |true|. However, it may be useful to
-% use |print=false| in some circonstancies (for example, when the key |write| or
+% use |print=false| in some circumstancies (for example, when the key |write| or
% the key |join| is used).
%
% \item \index{line-numbers} The key \Definition{line-numbers} activates the
@@ -479,6 +478,9 @@
% }
% \end{Verbatim}
%
+% Be careful : the previous code is not enough to print the numbers of lines.
+% For that, one also has to use the key |line-numbers| is a absolute way, that
+% is to say without value.
%
% \item \index{left-margin} The key \Definition{left-margin} corresponds to a
% margin on the left. That key may be useful in conjunction with the key
@@ -531,20 +533,24 @@
% continuation ``|...|'') characteristic of the Python consoles with
% \textsc{repl} (\emph{read-eval-print loop}).
%
+% The initial value is: |gray!15|
+%
% \item \index{width} \label{width} The key \Definition{width} fixes the width
% of the listing in the \textsc{pdf}. The initial value of that parameter
-% is the current value of |\linewidth|.
+% is the current value of |\linewidth| (LaTeX parameter which corresponds to the
+% width of the lines of text).
%
% That parameter is used for:
% \begin{itemize}
% \item the breaking the lines which are too long (except, of course, when the key
% |break-lines| is set to false: cf.~p.~\pageref{line-breaks});
-% \item the color of the backgrounds specified by the keys |background-color| and
+% \item the width of the backgrounds specified by the keys |background-color| and
% |prompt-background-color| described below;
-% \item the width of the LaTeX box created by the key |box| when that key is used
-% (cf. p.~\pageref{box});
-% \item the width of the graphical box created by the key |tcolorbox| when that
-% key is used (cf.~p.~\pageref{tcolorbox}).
+% \item the width fo the colored backgrounds added by |\rowcolor|
+% (cf.~p.~\pageref{rowcolor});
+% \item the width of the LaTeX box created by the key |box| (cf. p.~\pageref{box});
+% \item the width of the graphical box created by the key |tcolorbox|
+% (cf.~p.~\pageref{tcolorbox}).
% \end{itemize}
%
% \item \index{max-width} \colorbox{yellow!50}{\textbf{New 4.6}}
@@ -567,9 +573,9 @@
% particular, it does not apply for the \emph{doc strings}. In OCaml, that
% feature does not apply to the \emph{quoted strings}.} are replaced by the
% character~␣ (U+2423 : \textsc{open box}). Of course, that character~U+2423
-% must be present in the monospaced font which is used.\footnote{The initial
+% must be present in the monospace font which is used.\footnote{The initial
% value of |font-command| is |\ttfamily| and, thus, by default, \pkg{piton}
-% merely uses the current monospaced font.}
+% merely uses the current monospace font.}
%
% \nobreak
% \begingroup
@@ -587,7 +593,8 @@
%
% \bigskip
% \begingroup
-% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+% \small
+% \fvset{commandchars=\~\&\@}
% \begin{Verbatim}
% ~emphase&\begin{Piton}[language=C,line-numbers,gobble,background-color=gray!15@
% ~emphase& rounded-corners,width=min,splittable=4]@
@@ -648,7 +655,7 @@
%
% The package \pkg{piton} provides the command
% \DefinitionCommand{SetPitonStyle} to customize the different styles used to
-% format the syntactic elements of the informatic listings. The customizations done
+% format the syntactic elements of the computer listings. The customizations done
% by that command are limited to the current TeX group.\footnote{We remind that
% a LaTeX environment is, in particular, a TeX group.}
%
@@ -725,7 +732,7 @@
% the command |\NewPitonLanguage|).
%
% \bigskip
-% But it's also possible to define a style locally for a given informatic
+% But it's also possible to define a style locally for a given computer
% language by providing the name of that language as optional argument (between
% square brackets) to the command |\SetPitonStyle|.\footnote{We recall, that, in
% the package \pkg{piton}, the names of the computer languages are
@@ -823,8 +830,7 @@
%
% \medskip
% In the following example, we tune the styles |Name.Function| and |UserFunction|
-% so as to have clickable names of functions linked to the (informatic)
-% definition of the function.
+% so as to have clickable names of functions linked to the definition of the function.
%
% \begingroup
%
@@ -863,8 +869,8 @@
% \endgroup
%
% \medskip
-% (Some \textsc{pdf} viewers display a frame around the clickable word
-% |transpose| but other do not.)
+% The word |transpose| is in red because, in the document class \cls{l3doc} (used
+% in this document) the clickable words are in red.
%
% \PitonClearUserFunctions[Python]
%
@@ -874,7 +880,7 @@
% kept in the memory of LuaLaTeX (in a global way, that is to say independently
% of the TeX groups). The extension \pkg{piton} provides a command to clear that
% list : it's the command \DefinitionCommand{PitonClearUserFunctions}. When it
-% is used without argument, that command is applied to all the informatic
+% is used without argument, that command is applied to all the computer
% languages used by the user but it's also possible to use it with an optional
% argument (between square brackets) which is a list of computer languages to
% which the command will be applied.\footnote{We remind that, in \pkg{piton},
@@ -922,9 +928,11 @@
% If one wishes to format Python code in a box of \pkg{mdframed}, it's possible
% to define an environment |{Python}| with the following code.
%
-% \begin{Verbatim}[formatcom=\footnotesize\color{gray}]
+% \begin{footnotesize}
+% \begin{Verbatim}
% \usepackage[framemethod=tikz]{mdframed} % in the preamble
% \end{Verbatim}
+% \end{footnotesize}
%
%\begin{Verbatim}
% ~emphase#\NewPitonEnvironment@{Python}{}
@@ -966,7 +974,7 @@
% \index{listings@\pkg{listings} (extension)}
%
% \medskip
-% The package \pkg{listings} is a famous LaTeX package to format informatic
+% The package \pkg{listings} is a famous LaTeX package to format computer
% listings.
%
% That package provides a command |\lstdefinelanguage| which allows the user to
@@ -988,8 +996,9 @@
% \medskip
% For example, in the file |lstlang1.sty|, which is one of the definition files
% of \pkg{listings}, we find the following instructions (in version 1.10a).
-%
-%\begin{Verbatim}[formatcom=\small\color{gray}]
+%
+% \begin{small}
+% \begin{Verbatim}
% \lst~@definelanguage{Java}%
% {morekeywords={abstract,boolean,break,byte,case,catch,char,class,%
% const,continue,default,do,double,else,extends,false,final,%
@@ -1004,6 +1013,7 @@
% morestring=[b]',%
% }[keywords,comments,strings]
% \end{Verbatim}
+% \end{small}
%
% \medskip
% In order to define a language called |Java| for \pkg{piton}, one has only to
@@ -1011,7 +1021,8 @@
% |\lst at definelanguage|, between square brackets, has been discarded} (in fact,
% the symbols \verb+%+ may be deleted without any problem).
%
-% \begin{Verbatim}[formatcom=\small\color{gray}]
+% \begin{small}
+% \begin{Verbatim}
% ~emphase#\NewPitonLanguage@{Java}%
% {morekeywords={abstract,boolean,break,byte,case,catch,char,class,%
% const,continue,default,do,double,else,extends,false,final,%
@@ -1026,6 +1037,7 @@
% morestring=[b]',%
% }
% \end{Verbatim}
+% \end{small}
%
%
% \NewPitonLanguage{Java}
@@ -1126,11 +1138,11 @@
% \smallskip
% If one wishes to compose a listing in a box of LaTeX, he should use the key
% |box|. That key takes in as value |c|, |t| or |b| corresponding to the parameter
-% of vertical position (as for the envionment |{minipage}| of LaTeX). The default value
-% is |c| (as for |{minipage}|).
+% of vertical position (as for the envionment |{minipage}| of LaTeX which creates also
+% a LaTeX box). The default value is |c| (as for |{minipage}|).
%
% When the key |box| is used, |width=min| is activated (except, of course, when the
-% key |width| or the key |max-width| is explicitely used). For the keys |width| and
+% key |width| or the key |max-width| is explicitly used). For the keys |width| and
% |max-width|, cf.~p.~\pageref{width}.
%
%
@@ -1143,6 +1155,7 @@
% return x*x
% \end{Piton}
% \hspace{1cm}
+% \begin{Piton}
% def cube(x):
% return x*x*x
% \end{Piton}
@@ -1176,6 +1189,7 @@
% return x*x
% \end{Piton}
% \hspace{1cm}
+% \begin{Piton}
% def cube(x):
% return x*x*x
% \end{Piton}
@@ -1196,7 +1210,7 @@
% \end{center}
%
% \vspace{1cm}
-% Here is an exemple with the key |max-width|.
+% Here is an exemple with the key |max-width|, equal to 7~cm for both listings.
%
% \begin{Verbatim}
% \begin{center}
@@ -1234,7 +1248,7 @@
% The extension \pkg{piton} provides a key \Definition{tcolorbox} in order to
% ease the use of the extension \pkg{tcolorbox} in conjunction with the extension
% \pkg{piton}. However, the extension \pkg{piton} does not load \pkg{tcolorbox} and
-% the final user should have loaded it. Moreover, he must load the library |breakable|
+% the end user should have loaded it. Moreover, he must load the library |breakable|
% of \pkg{tcolorbox} with |\tcbuselibrary{breakable}| in the preamble of the LaTeX document.
% If this is not the case, an error will be raised at the first use of the key
% |tcolorbox|.
@@ -1254,10 +1268,12 @@
% ``\emph{skin}'' |enhanced|, in order to have a better appearance at the page break.
%
%
-% \begin{Verbatim}[formatcom = \footnotesize\color{gray}]
+% \begin{footnotesize}
+% \begin{Verbatim}
% \tcbuselibrary{skins,breakable} % in the preamble
% \tcbset{enhanced} % in the preamble
% \end{Verbatim}
+% \end{footnotesize}
%
% \begin{Verbatim}
% \begin{Piton}~emphase#[tcolorbox,splittable=3]@
@@ -1454,10 +1470,12 @@
% If we want an output composed in a LaTeX box (despites its name, an environment
% of \pkg{tcolorbox} does not always create a LaTeX box), we only have to use,
% in conjunction with the key |tcolorbox|, the key |box| provided by \pkg{piton}
-% (cf. p.~\pageref{box}). Of course, such LaTeX box can't be broken by a change of page.
+% (cf. p.~\pageref{box}). Of course, such LaTeX box, as all the LaTeX boxes, can't
+% be broken by a change of page, even if the key |splittable| (cf.~p.~\pageref{splittable})
+% is in force.
%
% We recall that, when the key |box| is used, |width=min| is activated (except,
-% when the key |width| or the key |max-width| is explicitely used).
+% when the key |width| or the key |max-width| is explicitly used).
%
%
% \smallskip
@@ -1514,7 +1532,7 @@
% the file to include has been found (letter~|T|) or not found (letter~|F|).
%
% \smallskip
-% The syntax for the pathes (absolute or relative) is the following one:
+% The syntax for the paths (absolute or relative) is the following one:
% \begin{itemize}
% \item The paths beginning by |/| are absolute.
%
@@ -1557,7 +1575,7 @@
% The command |\PitonInputFile| supports the keys \Definition{first-line} and
% \Definition{last-line} in order to insert only the part of file between the
% corresponding lines. Not to be confused with the key |line-numbers/start|
-% which fixes the first line number for the line numbering. In a sens,
+% which fixes the first line number for the line numbering. In one sense,
% |line-numbers/start| deals with the output whereas |first-line| and
% |last-line| deal with the input.
%
@@ -1579,9 +1597,10 @@
%
% \medskip
% We assume that the file to include contains solutions to exercises of
-% programmation on the following model.
+% programming on the following model.
%
-% \begin{Verbatim}[formatcom=\small\color{gray}]
+% \begin{small}
+% \begin{Verbatim}
% ~#[Exercise 1] Iterative version
% def fibo(n):
% if n==0: return 0
@@ -1595,6 +1614,7 @@
% return v
% ~#<Exercise 1>
% \end{Verbatim}
+% \end{small}
%
% The markers of the beginning and the end are the strings |#[Exercise 1]| and
% |#<Exercise 1>|. The string ``|Exercise 1|'' will be called the \emph{label}
@@ -1613,7 +1633,7 @@
% mathematical function which transforms the label (here |Exercise 1|) into the
% the beginning marker (in the example |#[Exercise 1]|). The string |#1|
% corresponds to the occurrences of the argument of that function, which the
-% classical syntax in TeX. Idem for |marker/end|.\footnote{In regard to LateX,
+% classical syntax in TeX. Idem for |marker/end|.\footnote{In regard to LaTeX,
% both functions must be \emph{fully expandable}.}
%
% \bigskip
@@ -1689,10 +1709,9 @@
%
% \label{line-breaks}
%
-% By default, the elements produced by \pkg{piton} can't be broken by an end on
-% line. However, there are keys to allow such breaks (the possible breaking
-% points are the spaces, even the spaces which appear in the strings of the
-% computer languages).
+% There are keys to control the line breaks (the possible breaking points are
+% the spaces, even the spaces which appear in the strings of the computer
+% languages).
% \begin{itemize}
% \item \index{break-lines!break-lines-in-piton} With the key
% \Definition{break-lines-in-piton}, the line breaks are allowed in the command
@@ -1715,7 +1734,7 @@
% \item \index{indent-broken-lines} With the key
% \Definition{indent-broken-lines}, the indentation of a
% broken line is respected at carriage return (on the condition that the used
-% font is a monospaced font and this is the case by default since the initial
+% font is a monospace font and this is the case by default since the initial
% value of |font-command| is |\ttfamily|).
%
% \item The key \Definition{end-of-broken-line} corresponds to the symbol placed
@@ -1769,6 +1788,7 @@
%
% \subsubsection{Page breaks}
% \label{page breaks}
+% \label{splittable}
% \index{splittable}
% \index{splittable-on-empty-lines}
%
@@ -1790,7 +1810,7 @@
% lines (when |split-on-empty-lines| is in force) may be broken anywhere with
% the restriction that no break will occur within the $n$ first lines of
% the listing or within the $n$ last lines.\footnote{Remark that we speak of the
-% lines of the original informatic listing and such line may be composed on
+% lines of the original computer listing and such line may be composed on
% several lines in the final \textsc{pdf} when the key |break-lines-in-Piton| is
% in force.}
%
@@ -1880,6 +1900,7 @@
% \index{split-on-empty-lines}
% \label{split-on-empty-lines}
% \index{split-separation}
+% \index{add-to-split-separation}
%
% The extension \pkg{piton} provides the key \Definition{split-on-empty-lines},
% which should not be confused with the key |splittable-on-empty-lines|
@@ -1887,8 +1908,8 @@
%
% \smallskip
% In order to understand the behaviour of the key |split-on-empty-lines|, one
-% should imagine that he has to compose an informatic listing which contains
-% several definitions of informatic functions. Usually, in the informatic
+% should imagine that he has to compose an computer listing which contains
+% several definitions of computer functions. Usually, in the computer
% languages, those definitions of functions are separated by empty lines.
%
% \smallskip
@@ -1905,10 +1926,14 @@
% empty line in the final \textsc{pdf} (this vertical space is deleted if it
% occurs on a page break). If the key |background-color| is in force, no
% background color is added to that empty line.
+%
+% \item In fact, the extension \pkg{piton} provides also the key
+% |add-to-split-separation| to add elements on the right of the parameter
+% |split-separation|.
% \end{itemize}
%
%
-% Each chunk of the informatic listing is composed in an environment whose name
+% Each chunk of the computer listing is composed in an environment whose name
% is given by the key \Definition{env-used-by-split}. The initial value of that
% parameter is, not surprisingly, |Piton| and, hence, the different chunks are
% composed in several environments |{Piton}|. If one decides to change the value
@@ -1916,7 +1941,7 @@
% |\NewPitonEnvironment| (cf.~part~\ref{NewPitonEnvironment},
% p.~\pageref{NewPitonEnvironment}).
%
-% Each chunk of the informatic listing is formated in its own environment.
+% Each chunk of the computer listing is formated in its own environment.
% Therefore, it has its own line numbering (if the key
% |line-numbers| is in force) and its own colored background (when the key
% |background-color| is in force), separated from the background color of the
@@ -1948,7 +1973,46 @@
% return x*x*x
% \end{Piton}
%
+%
% \bigskip
+% If we wish to have a continuity of the line numbers between the sublistings
+% it's possible to add |\PitonOptions{resume}| to the parameter |split-separation|.
+%
+% \bigskip
+% \begin{Verbatim}
+% \begin{Piton}[
+% split-on-empty-lines,
+% ~emphase#add-to-split-separation = \PitonOptions{resume}@ ,
+% background-color=gray!15,
+% line-numbers
+% ]
+% def carré(x):
+% """Calcule le carré de x"""
+% return x*x
+%
+% def cube(x):
+% """Calcule le cube de x"""
+% return x*x*x
+% \end{Piton}
+% \end{Verbatim}
+%
+% \begin{Piton}[
+% split-on-empty-lines,
+% add-to-split-separation = \PitonOptions{resume} ,
+% background-color=gray!15,
+% line-numbers
+% ]
+% def carré(x):
+% """Calcule le carré de x"""
+% return x*x
+%
+% def cube(x):
+% """Calcule le cube de x"""
+% return x*x*x
+% \end{Piton}
+%
+%
+% \bigskip
% \textbf{Caution}: Since each chunk is treated independently of the others, the
% commands specified by |detected-commands| or |raw-detected-commands|
% (cf.~p.~\pageref{detected-commands}) and the commands and environments of
@@ -1967,7 +2031,7 @@
% That command takes in three arguments:
%
% \begin{itemize}
-% \item The optional argument (within square brackets) specifies the informatic
+% \item The optional argument (within square brackets) specifies the computer
% language. If this argument is not present, the tunings done by
% |\SetPitonIdentifier| will apply to all the computer languages of
% \pkg{piton}.\footnote{We recall, that, in the package \pkg{piton}, the
@@ -2156,9 +2220,11 @@
% available only in the preamble of the document}.
%
% \nobreak
-% \begin{Verbatim}[formatcom=\footnotesize\color{gray}]
+% \begin{footnotesize}
+% \begin{Verbatim}
% \PitonOptions{math-comment} % in the preamble
% \end{Verbatim}
+% \end{footnotesize}
%
% \begin{Verbatim}
% \begin{Piton}
@@ -2192,7 +2258,7 @@
% backslash (eg. |detected-commands = { emph, textbf }|).
%
% \item These commands must be LaTeX commands with only one (mandatory) argument
-% between braces (and these braces must appear explicitly in the informatic
+% between braces (and these braces must appear explicitly in the computer
% listing).
%
% \item These commands must be \textbf{protected}\footnote{We recall that the
@@ -2204,32 +2270,34 @@
% \end{itemize}
%
% \bigskip
-% In the following example, which is a recursive programmation of the factorial
-% function, we decide to highlight the recursive call. The command |\highLight|
-% of \pkg{lua-ul}\footnote{The package \pkg{lua-ul} requires itself the package
-% \pkg{luacolor}.} directly does the job.
+% In the following example, which is a recursive programming in C of the
+% factorial function, we decide to highlight the recursive call. The command
+% |\highLight| of \pkg{lua-ul}\footnote{The package \pkg{lua-ul} requires itself
+% the package \pkg{luacolor}.} directly does the job.
%
-% \medskip
-% \begin{Verbatim}[formatcom=\footnotesize\color{gray}]
+% \medskip
+% \begin{footnotesize}
+% \begin{Verbatim}
% \PitonOptions{~emphase#detected-commands@ = highLight} % in the preamble
% \end{Verbatim}
+% \end{footnotesize}
%
% \begin{Verbatim}
-% \begin{Piton}
-% def fact(n):
-% if n==0:
-% return 1
-% else:
-% ~emphase#\highLight@{return n*fact(n-1)}
+% \begin{Piton}[language=C]
+% int factorielle(int n)
+% {
+% if (n > 0) ~emphase#\highLight{return n * factorielle(n - 1)}@ ;
+% else return 1;
+% }
% \end{Piton}
% \end{Verbatim}
%
-% \begin{Piton}
-% def fact(n):
-% if n==0:
-% return 1
-% else:
-% \highLight{return n*fact(n-1)}
+% \begin{Piton}[language=C]
+% int factorielle(int n)
+% {
+% if (n > 0) \highLight{return n * factorielle(n - 1)} ;
+% else return 1;
+% }
% \end{Piton}
%
% \bigskip
@@ -2294,7 +2362,9 @@
% \PitonOptions{vertical-detected-commands = newpage}
% \end{Verbatim}
%
-% and ask in a listing a mandatory break of page with |\newgage{}|:
+% and ask in a listing a mandatory break of page with |\newpage{}| (the pair of braces |{}|
+% is mandatory because the commands detected by \pkg{piton} are meant to be LaTeX commands
+% with one mandatory argument).
%
% \begin{Verbatim}
% \begin{Piton}
@@ -2304,12 +2374,15 @@
% return x*x*x
% \end{Piton}
% \end{Verbatim}
+%
+% \medskip
+% It would also be possible to require the detection of the command |\vspace|.
%
% \subsubsection{The mechanism ``escape''}
%
% \label{escape}
%
-% It's also possible to overwrite the informatic listings to insert LaTeX code
+% It's also possible to overwrite the computer listings to insert LaTeX code
% almost everywhere (but between lexical units, of course). By default,
% \pkg{piton} does not fix any delimiters for that kind of escape.
%
@@ -2319,7 +2392,7 @@
% in the preamble of the document}.
%
% \medskip
-% We consider once again the previous example of a recursive programmation of
+% We consider once again the previous example of a recursive programming of
% the factorial. We want to highlight in pink the instruction containing the
% recursive call. With the package \pkg{lua-ul}, we can use the syntax
% |\highLight[LightPink]{...}|. Because of the optional argument between square
@@ -2459,8 +2532,9 @@
% \subsubsection{\{Piton\} and \textbackslash PitonInputFile are
% ``overlay-aware''}
%
-% When \pkg{piton} is used in the class \cls{beamer}, the environment |{Piton}|
-% and the command |\PitonInputFile| accept the optional argument |<...>| of
+% When \pkg{piton} is used in the class \cls{beamer}, the command
+% |\PitonInputFile| and the environment |{Piton}| (but not the environments
+% created by |\NewPitonEnvironment|) accept the optional argument |<...>| of
% Beamer for the overlays which are involved.
%
% For example, it's possible to write:
@@ -2514,7 +2588,8 @@
% \medskip
% Here is a complete example of file:
%
-% \begin{Verbatim}[formatcom = \small\color{gray}]
+% \begin{small}
+% \begin{Verbatim}
% \documentclass{beamer}
% \usepackage{piton}
% \begin{document}
@@ -2530,6 +2605,7 @@
% \end{frame}
% \end{document}
% \end{Verbatim}
+% \end{small}
%
% In the previous example, the braces in the Python strings |"{"| and |"}"| are
% correctly interpreted (without any escape character).
@@ -2559,7 +2635,8 @@
%\medskip
% Here is an example:
%
-% \begin{Verbatim}[formatcom = \small\color{gray}]
+% \begin{small}
+% \begin{Verbatim}
% \documentclass{beamer}
% \usepackage{piton}
% \begin{document}
@@ -2567,13 +2644,14 @@
% \begin{Piton}
% def square(x):
% """Compure the square of its argument"""
-% ~emphase#\begin{uncoverenv}<2>@
+% ~emphase#\begin{uncoverenv}<2>@
% return x*x
-% ~emphase#\end{uncoverenv}@
+% ~emphase#\end{uncoverenv}@
% \end{Piton}
% \end{frame}
% \end{document}
% \end{Verbatim}
+% \end{small}
%
%
% \vspace{1cm}
@@ -2602,7 +2680,8 @@
% the package \pkg{luacolor}).
%
% \begingroup
-% \fvset{commandchars=\~\#\+,formatcom=\color{gray}}
+% \small
+% \fvset{commandchars=\~\#\+}
% \begin{Verbatim}
% \setbeamercolor{alerted text}{bg=yellow!50}
% \makeatletter
@@ -2647,7 +2726,7 @@
% \smallskip
% Caution: The packages \pkg{footnote} and \pkg{footnotehyper} are incompatible.
% The package \pkg{footnotehyper} is the successor of the package \pkg{footnote}
-% and should be used preferently. The package \pkg{footnote} has some drawbacks,
+% and should be used preferably. The package \pkg{footnote} has some drawbacks,
% in particular: it must be loaded after the package \pkg{xcolor} and it is not
% perfectly compatible with \pkg{hyperref}.
%
@@ -2674,7 +2753,8 @@
%
%
% \begingroup
-% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+% \small
+% \fvset{commandchars=\~\&\@}
% \begin{Verbatim}
% \PitonOptions{background-color=gray!15}
% \begin{Piton}
@@ -2711,7 +2791,8 @@
%
%
% \begingroup
-% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+% \small
+% \fvset{commandchars=\~\&\@}
% \begin{Verbatim}
% \PitonOptions{background-color=gray!15}
% ~emphase&\begin{minipage}{\linewidth}@
@@ -2750,7 +2831,7 @@
% \index{tab-size}
%
% \smallskip
-% Even though it's probably recommended to indent the informatics listings with
+% Even though it's probably recommended to indent the computers listings with
% spaces and not tabulations\footnote{For the language Python, see the note %
% PEP~8.}, \pkg{piton} accepts the characters of tabulation (that is to say the
% characters U+0009) at the beginning of the lines. Each character U+0009 is
@@ -2901,11 +2982,44 @@
% \index{numbers of the lines de code|emph}
%
% We remind that it's possible to have an automatic numbering of the lines in
-% the informatic listings by using the key |line-numbers| (used without value).
+% the computer listings by using the key |line-numbers| (used without value).
%
% By default, the numbers of the lines are composed by \pkg{piton} in an
% overlapping position on the left (by using internally the command |\llap| of LaTeX).
%
+% \begingroup
+% \small
+% \fvset{commandchars=\~\&\@}
+% \begin{Verbatim}
+% ~emphase&\PitonOptions{background-color=gray!15, line-numbers}@
+% \begin{Piton}
+% def arctan(x,n=10):
+% if x < 0:
+% return -arctan(-x) #> (recursive call)
+% elif x > 1:
+% return pi/2 - arctan(1/x) #> (other recursive call)
+% else:
+% return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+% \end{Piton}
+% \end{Verbatim}
+% \endgroup
+%
+%
+%
+% \begingroup
+% \PitonOptions{background-color=gray!15, line-numbers}
+% \begin{Piton}
+% def arctan(x,n=10):
+% if x < 0:
+% return -arctan(-x) #> (recursive call)
+% elif x > 1:
+% return pi/2 - arctan(1/x) #> (other recursive call)
+% else:
+% return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+% \end{Piton}
+% \endgroup
+%
+% \bigskip
% In order to avoid that overlapping, it's possible to use the option |left-margin=auto|
% which will insert automatically a margin adapted to the numbers of lines that
% will be written (that margin is larger when the numbers are greater than~10).
@@ -2912,7 +3026,8 @@
%
%
% \begingroup
-% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+% \small
+% \fvset{commandchars=\~\&\@}
% \begin{Verbatim}
% ~emphase&\PitonOptions{background-color=gray!15, left-margin = auto, line-numbers}@
% \begin{Piton}
@@ -2955,7 +3070,8 @@
%
%
% \begingroup
-% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+% \small
+% \fvset{commandchars=\~\&\@}
% \begin{Verbatim}
% \PitonOptions{background-color=gray!15}
% ~emphase&\SetPitonStyle{Comment.LaTeX = \hfill \normalfont\color{gray}}@
@@ -2991,7 +3107,8 @@
% by limiting the width of the listing with the key |width|.
%
% \begingroup
-% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+% \small
+% \fvset{commandchars=\~\&\@}
% \begin{Verbatim}
% \PitonOptions{background-color=gray!15, width=9cm}
% ~emphase&\NewDocumentCommand{\MyLaTeXCommand}{m}{\hfill \normalfont\itshape\rlap{\quad #1}}@
@@ -3051,9 +3168,11 @@
% allowed.
%
% \bigbreak
-% \begin{Verbatim}[formatcom=\footnotesize\color{gray}]
+% \begin{footnotesize}
+% \begin{Verbatim}
% \PitonOptions{raw-detected-commands = rowcolor} % in the preamble
% \end{Verbatim}
+% \end{footnotesize}
%
% \medskip
%
@@ -3192,15 +3311,17 @@
% In the following example of use, we have illustrated the fact that it is possible
% to impose a break of page in such environment with |\newpage{}| if we have required the
% detection of the LaTeX command |\newpage| with the key |vertical-detected-commands|
-% (cf.~p.~\pageref{vertical-detected-commands}) in the premable of the LaTeX document.
+% (cf.~p.~\pageref{vertical-detected-commands}) in the preamble of the LaTeX document.
%
% Remark that we must use |\newpage{}| and not |\newpage| because the LaTeX commands
% detected by \pkg{piton} are meant to be commands with one argument (between curly
% braces).
%
-% \begin{Verbatim}[formatcom=\footnotesize\color{gray}]
-% \PitonOptions{vertical-detected-commands = newpage} % in the premable
+% \begin{footnotesize}
+% \begin{Verbatim}
+% \PitonOptions{vertical-detected-commands = newpage} % in the preamble
% \end{Verbatim}
+% \end{footnotesize}
%
% \medskip
% \begin{Verbatim}
@@ -3373,8 +3494,7 @@
% {\PitonOptions{~#1}}
% {\begin{center}
% \directlua{pyluatex.execute(piton.get_last_code(), false, true, false, true)}%
-% \end{center}
-% \ignorespacesafterend}
+% \end{center}}
% \end{Verbatim}
%
% \medskip
@@ -3485,9 +3605,9 @@
% String.Short & the characters (between \texttt{'}) \\
% String.Long & the strings, between |"| but also the \emph{quoted-strings} \\
% String & that key fixes both |String.Short| and |String.Long| \\
-% Operator & les opérateurs, en particulier |+|, |-|, |/|, |*|, |@|, |!=|, |==|, |&&| \\
-% Operator.Word & les opérateurs suivants : |asr|, |land|, |lor|, |lsl|, |lxor|, |mod| et |or| \\
-% Name.Builtin & les fonctions |not|, |incr|, |decr|, |fst| et |snd| \\
+% Operator & the oporators, in particular: |+|, |-|, |/|, |*|, |@|, |!=|, |==|, |&&| \\
+% Operator.Word & the following operators: |asr|, |land|, |lor|, |lsl|, |lxor|, |mod| et |or| \\
+% Name.Builtin & the functions |not|, |incr|, |decr|, |fst| et |snd| \\
% Name.Type & the name of a type of OCaml \\
% Name.Field & the name of a field of a module \\
% Name.Constructor & the name of the constructors of types (which begins by a capital) \\
@@ -3515,6 +3635,22 @@
% \end{tabularx}
% \end{center}
%
+% \vspace{1cm}
+%
+% Here is an example:
+%
+% \medskip
+% \begin{Piton}[language = OCaml]
+% let rec quick_sort lst = (* Quick sort *)
+% match lst with
+% | [] -> []
+% | pivot :: rest ->
+% let left = List.filter (fun x -> x < pivot) rest in
+% let right = List.filter (fun x -> x >= pivot) rest in
+% quick_sort left @ [pivot] @ quick_sort right
+% \end{Piton}
+%
+%
% \newpage
%
% \subsection[The language C (and C++)]{The language C (and \CC)}
@@ -3542,8 +3678,8 @@
% |long|, |short|, |signed|, |unsigned|, |void| et |wchar_t| \\
% Name.Builtin & the following predefined functions: |printf|, |scanf|,
% |malloc|, |sizeof| and |alignof| \\
-% Name.Class & le nom des classes au moment de leur définition, c'est-à-dire
-% après le mot-clé \verb|class| \\
+% Name.Class & the names of the classes when they are defined, that is to say after
+% the keyword \verb|class| \\
% Name.Function & the name of the Python functions defined by the user \emph{at their
% point of definition} (with the keyword |let|) \\
% UserFunction & the name of the Python functions previously defined by the user
@@ -3665,7 +3801,8 @@
% adaptation of the definition done by \pkg{listings} (file |lstlang1.sty|).
%
% \medskip
-% \begin{Verbatim}[formatcom=\small]
+% \begin{small}
+% \begin{Verbatim}
% \NewPitonLanguage{HTML}%
% {morekeywords={A,ABBR,ACRONYM,ADDRESS,APPLET,AREA,B,BASE,BASEFONT,%
% BDO,BIG,BLOCKQUOTE,BODY,BR,BUTTON,CAPTION,CENTER,CITE,CODE,COL,%
@@ -3694,6 +3831,7 @@
% morestring=[d]",
% }
% \end{Verbatim}
+% \end{small}
%
%
%
@@ -3723,7 +3861,7 @@
% \end{center}
%
% \bigskip
-% That language is provided for the final user who might wish to add keywords in
+% That language is provided for the end user who might wish to add keywords in
% that language (with the command |\SetPitonIdentifier|: cf. \ref{SetPitonIdentifier},
% p.~\pageref{SetPitonIdentifier}) in order to create, for example, a language
% for pseudo-code.
@@ -3749,7 +3887,7 @@
% \end{tabularx}
% \end{center}
%
-% The language |verbatim| doen't provide any style and, thus, does not do any
+% The language |verbatim| doesn't provide any style and, thus, does not do any
% syntactic formating. However, it's possible to use the mechanism
% |detected-commands| (cf. part~\ref{detected-commands},
% p.~\pageref{detected-commands}) and the detection of the commands and
@@ -3824,49 +3962,49 @@
% \texttt{\textbackslash fbox}.}
%
% \texttt{\{
-% luatexbase.catcodetables.CatcodeTableOther\footnote{\texttt{luatexbase.catcodetables.CatcodeTableOther} is a mere number which corresponds to the ``catcode table'' whose all characters have the catcode ``other'' (which means that they will be typeset by LaTeX verbatim).}, "def" \} }
+% luatexbase.catcodetables.other\footnote{\texttt{luatexbase.catcodetables.other} is a mere number which corresponds to the ``catcode table'' whose all characters have the catcode ``other'' (which means that they will be typeset by LaTeX verbatim).}, "def" \} }
%
% |{ "}}" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, " " }|
+% |{ luatexbase.catcodetables.other, " " }|
%
% |{ "{\PitonStyle{Name.Function}{" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, "parity" }|
+% |{ luatexbase.catcodetables.other, "parity" }|
%
% |{ "}}" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, "(" }|
+% |{ luatexbase.catcodetables.other, "(" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, "x" }|
+% |{ luatexbase.catcodetables.other, "x" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, ")" }|
+% |{ luatexbase.catcodetables.other, ")" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, ":" }|
+% |{ luatexbase.catcodetables.other, ":" }|
%
% |{ "\\__piton_end_line: \\__piton_par: \\__piton_begin_line:" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, " " }|
+% |{ luatexbase.catcodetables.other, " " }|
%
% |{ "{\PitonStyle{Keyword}{" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, "return" }|
+% |{ luatexbase.catcodetables.other, "return" }|
%
% |{ "}}" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, " " }|
+% |{ luatexbase.catcodetables.other, " " }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, "x" }|
+% |{ luatexbase.catcodetables.other, "x" }|
%
% |{ "{\PitonStyle{Operator}{" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, "%" }|
+% |{ luatexbase.catcodetables.other, "%" }|
%
% |{ "}}" }|
%
% |{ "{\PitonStyle{Number}{" }|
%
-% |{ luatexbase.catcodetables.CatcodeTableOther, "2" }|
+% |{ luatexbase.catcodetables.other, "2" }|
%
% |{ "}}" }|
%
@@ -3907,7 +4045,7 @@
{piton}
{\PitonFileDate}
{\PitonFileVersion}
- {Highlight informatic listings with LPEG on LuaLaTeX}
+ {Highlight computer listings with LPEG on LuaLaTeX}
% \end{macrocode}
%
% \begin{macrocode}
@@ -3919,6 +4057,7 @@
% \end{macrocode}
%
% \begin{macrocode}
+\providecommand { \IfFormatAtLeastTF } { \@ifl at t@r \fmtversion }
\IfFormatAtLeastTF
{ 2023-11-01 }
{ }
@@ -3930,6 +4069,7 @@
% mathematical mode.
% \begin{macrocode}
\RequirePackage { amstext }
+\RequirePackage { transparent }
% \end{macrocode}
%
% \bigskip
@@ -3941,8 +4081,8 @@
\ProvideDocumentCommand { \IfPackageLoadedF } { m m }
{ \IfPackageLoadedTF { #1 } { } { #2 } }
-\ProvideDocumentCommand { \IfClassLoadedF } { m m }
- { \IfClassLoadedTF { #1 } { } { #2 } }
+\ProvideDocumentCommand { \IfClassLoadedT } { m m }
+ { \IfClassLoadedTF { #1 } { #2 } { } }
\ProvideDocumentCommand { \IfClassLoadedF } { m m }
{ \IfClassLoadedTF { #1 } { } { #2 } }
@@ -4011,6 +4151,11 @@
Since~you~use~Beamer,~don't~forget~to~use~piton~in~frames~with~
the~key~'fragile'.\\
}
+ \IfClassLoadedT { ltx-talk }
+ {
+ Since~you~use~'ltx-talk',~don't~forget~to~use~piton~in~
+ environments~'frame*'.\\
+ }
That~error~is~fatal.
}
\sys_if_engine_luatex:F { \@@_fatal:n { LuaLaTeX~mandatory } }
@@ -4103,12 +4248,9 @@
%
% \bigskip
% \begin{macrocode}
-\IfClassLoadedTF { beamer }
- { \bool_gset_true:N \g_@@_beamer_bool }
- {
- \IfPackageLoadedT { beamerarticle }
- { \bool_gset_true:N \g_@@_beamer_bool }
- }
+\IfClassLoadedT { beamer } { \bool_gset_true:N \g_@@_beamer_bool }
+\IfClassLoadedT { ltx-talk } { \bool_gset_true:N \g_@@_beamer_bool }
+\IfPackageLoadedT { beamerarticle } { \bool_gset_true:N \g_@@_beamer_bool }
% \end{macrocode}
%
% \begin{macrocode}
@@ -4221,15 +4363,13 @@
%
% \medskip
% The content of an environment such as |{Piton}| will be composed first in the
-% following box, but that box be \emph{unvboxed} at the end.
+% following box, but that box will (sometimes) be \emph{unvboxed} at the end.
+%
+% We need a global variable (see |\@@_add_backgrounds_to_output_box:|).
% \begin{macrocode}
\box_new:N \g_@@_output_box
% \end{macrocode}
%
-% \medskip
-% \begin{macrocode}
-\box_new:N \l_@@_line_box
-% \end{macrocode}
%
% The following string will contain the name of the computer language
% considered (the initial value is |python|).
@@ -4269,6 +4409,14 @@
% \end{macrocode}
%
% \medskip
+% When the key |tcolorbox| is used, you will have to take into account the width
+% of the graphical elements added by |tcolorbox| on both sides of the listing.
+% We will put that quantity in the following variable.
+% \begin{macrocode}
+\dim_new:N \l_@@_tcb_margins_dim
+% \end{macrocode}
+%
+% \medskip
% The following parameter corresponds to the key |box|.
% \begin{macrocode}
\str_new:N \l_@@_box_str
@@ -4332,7 +4480,7 @@
% \medskip
% When the key |split-on-empty-lines| will be in force, then the following token
% list will be inserted between the chunks of code (the computer listing provided
-% by the final user is split in chunks on the empty lines in the code).
+% by the end user is split in chunks on the empty lines in the code).
% \begin{macrocode}
\tl_new:N \l_@@_split_separation_tl
\tl_set:Nn \l_@@_split_separation_tl
@@ -4408,7 +4556,7 @@
%
% \medskip
% The parameter |\l_@@_join_str| corresponds to the key |join|. In fact, |\l_@@_join_str|
-% won't contain the exact value used the final user but its conversion in ``|utf16/hex|''.
+% won't contain the exact value used the end user but its conversion in ``|utf16/hex|''.
% \begin{macrocode}
\str_new:N \l_@@_join_str
% \end{macrocode}
@@ -4455,54 +4603,67 @@
% \begin{macrocode}
\bool_new:N \l_@@_break_lines_in_piton_bool
% \end{macrocode}
-%
+%
+% \medskip
+% The following flag will be raised when the key |max-width| is used (and
+% when |width| is used with the key |min|, which is equivalent to
+% |max-width=\linewidth|). Note also that the key |box| sets |width=min| (except
+% if |min| is used with a numerical value).
+% \begin{macrocode}
+\bool_new:N \l_@@_minimize_width_bool
+% \end{macrocode}
+%
% \bigskip
-% The following dimension will be the width of the listing constructed by
-% |{Piton}| or |\PitonInputFile|. If the user uses the key |width| of
-% |\PitonOptions| with a numerical value, that value will be stored in
-% |\l_@@_width_dim|.
-%
+% The following dimension corresponds to the key |width|. It's meant to be the whole width of
+% the environment (for instance, the width of the box of \pkg{tcolorbox} when the key
+% |tcolorbox| is used). The initial value is $0$~pt which means that the end user has not
+% used the key. In that case, it will be set equal to the current value of |\linewidth|
+% in |\@@_pre_composition:|.
+%
+% However if |max-width| is used (or |width=min| which is equivalent to
+% |max-width=\linewidth|), the actual width of the final environment in the \textsc{pdf}
+% may (potentially) be smaller.
% \begin{macrocode}
\dim_new:N \l_@@_width_dim
% \end{macrocode}
%
-% \bigskip
-% |\g_@@_width_dim| will be the width of the environment, after construction.
-% In particular, if |max-width| is used, |\g_@@_width_dim| has to be computed
-% from the actual content of the environment.
+% \medskip
+% |\l_@@_listing_width_dim| will be the width of the listing taking into account the
+% lines of code (of course) but also:
+% \begin{itemize}
+% \item |l_@@_left_margin_dim| (for the numbers of lines);
+% \item a small margin when |background-color| is in force\footnote{Remark that the mere
+% use of |\rowcolor| does not add those small margins.}).
+% \end{itemize}
% \begin{macrocode}
-\dim_new:N \g_@@_width_dim
+\dim_new:N \l_@@_listing_width_dim
% \end{macrocode}
-%
+% However, if |max-width| is used (or |width=min| which is equivalent to
+% |max-width=\linewidth|), that length will be computed once again in
+% |\@@_create_output_box:|
+%
% \medskip
-% We will also use another dimension called |\l_@@_code_width_dim|. That will
-% the width of the actual lines of code. That dimension may be lower than the
-% whole |\l_@@_width_dim| because we have to take into account the value of
-% |\l_@@_left_margin_dim| (for the numbers of lines when |line-numbers| is in
-% force) and another small margin when |background-color| is in
-% force\footnote{However, the mere use of |\rowcolor| does not add those small
-% margins.}).
+% |\l_@@_code_width_dim| will be the length of the lines of code, without the potential
+% margins (for the backgrounds and for |length-margin| for the number of lines).
+%
+% It will be computed in |\@@_compute_code_width:|.
% \begin{macrocode}
\dim_new:N \l_@@_code_width_dim
% \end{macrocode}
-%
+%
% \medskip
-% The following flag will be raised when the key |max-width| (and
-% when |width| is used with the key |min|, which is equivalent to
-% |max-width=\linewidth|).
% \begin{macrocode}
-\bool_new:N \l_@@_minimize_width_bool
+\box_new:N \l_@@_line_box
% \end{macrocode}
%
% \medskip
-% The following dimension corresponds to the key |left-margin| of |\PitonOptions|.
+% The following dimension corresponds to the key |left-margin|.
% \begin{macrocode}
\dim_new:N \l_@@_left_margin_dim
% \end{macrocode}
%
% \medskip
-% The following boolean will be set when the key |left-margin=auto|
-% is used.
+% The following boolean will be set when the key |left-margin=auto| is used.
% \begin{macrocode}
\bool_new:N \l_@@_left_margin_auto_bool
% \end{macrocode}
@@ -4662,7 +4823,7 @@
% \bigskip
% The following commands correspond to the keys |marker/beginning| and
% |marker/end|. The values of that keys are functions that will be applied to
-% the ``\emph{range}'' specified by the final user in an individual
+% the ``\emph{range}'' specified by the end user in an individual
% |\PitonInputFile|. They will construct the markers used to find textually in
% the external file loaded by \pkg{piton} the part which must be included (and
% formatted).
@@ -4680,7 +4841,6 @@
% |\@@_begin_line:|... |\@@_end_line:| and cleared at the end. It will be used
% by LPEG acting between the lines of the Python code in order to add
% instructions to be executed in vertical mode between the lines.
-%
% \begin{macrocode}
\tl_new:N \g_@@_after_line_tl
% \end{macrocode}
@@ -4849,7 +5009,7 @@
%
% |\regex_replace_all:nnN { \x20 } { \c { @@_breakable_space: } } \l_tmpa_tl|
%
-% but that programmation was certainly slow.
+% but that programming was certainly slow.
%
% Now, we use |\tl_replace_all:NVn| \emph{but}, in the styles
% |String.Long.Internal| we replace the spaces with
@@ -4892,8 +5052,7 @@
% \end{macrocode}
%
% \medskip
-% We put the potential number of line, the potential left margin and the
-% potential background.
+% We put the potential number of line, the potential left and right margins.
% \begin{macrocode}
\hbox_set:Nn \l_@@_line_box
{
@@ -4907,18 +5066,15 @@
{
\lua_now:e
{
- tex.sprint
+ tex.sprint
(
- luatexbase.catcodetables.expl ,
% \end{macrocode}
-% Since the argument of |tostring| will be a integer of Lua (\emph{integer} is a
+% The following expression gives a integer of Lua (\emph{integer} is a
% sub-type of \emph{number} introduced in Lua 5.3), the output will be of the
% form |"3"| (and not |"3.0"|) which is what we want for |\int_set:Nn|.
% \begin{macrocode}
- tostring
- ( piton.empty_lines
- [ \int_eval:n { \g_@@_line_int + 1 } ]
- )
+ piton.empty_lines
+ [ \int_eval:n { \g_@@_line_int + 1 } ]
)
}
}
@@ -4933,7 +5089,7 @@
}
% \end{macrocode}
% If there is a background, we must remind that there is a left margin of 0.5~em
-% for the background...
+% for the background (which will be added later).
% \begin{macrocode}
\int_compare:nNnT \l_@@_bg_colors_int > { \c_zero_int }
{
@@ -4957,7 +5113,7 @@
\@@_replace_spaces:n { #1 }
\strut \hfil
}
- \dim_compare:nNnTF { \box_wd:N \l_tmpa_box } < \l_@@_code_width_dim
+ \dim_compare:nNnTF { \box_wd:N \l_tmpa_box } < \l_@@_code_width_dim
{ \box_use:N \l_tmpa_box }
{ \@@_vtop_of_code:n { #1 } }
}
@@ -4973,10 +5129,6 @@
% \end{macrocode}
%
% \begin{macrocode}
- \dim_gset_eq:NN \g_@@_width_dim \l_@@_width_dim
-% \end{macrocode}
-%
-% \begin{macrocode}
\box_use_drop:N \l_@@_line_box
% \end{macrocode}
%
@@ -4988,6 +5140,7 @@
% \end{macrocode}
%
% \bigskip
+% The following command will be used in |\@@_begin_line:| … |\@@_end_line:|.
% \begin{macrocode}
\cs_new_protected:Npn \@@_vtop_of_code:n #1
{
@@ -5008,6 +5161,8 @@
% is used.
%
% The content of the line has been previously set in |\l_@@_line_box|.
+%
+% That command is used only once, in |\@@_add_backgrounds_to_output_box:|.
% \begin{macrocode}
\cs_new_protected:Npn \@@_add_background_to_line_and_use:
{
@@ -5019,9 +5174,9 @@
% \end{macrocode}
% The command |\@@_compute_and_set_color:| sets the current color but also sets the booleans
% |\g_@@_color_is_none_bool| and |\g_@@_next_color_is_none_bool|. It uses the
-% current value of |\l_@@_bg_color_clist|, the value of
-% |\g_@@_line_int| (the number of the current line) but also potential token lists
-% of the form |\g_@@_color_12_tl| if the final user has used the command |\rowcolor|.
+% current value of |\l_@@_bg_color_clist|, the value of |\g_@@_line_int| (the number of the
+% current line) but also potential token lists of the form |\g_@@_color_12_tl| if the end
+% user has used the command |\rowcolor|.
% \begin{macrocode}
\@@_compute_and_set_color:
% \end{macrocode}
@@ -5037,7 +5192,7 @@
% \begin{macrocode}
\bool_if:NTF \g_@@_color_is_none_bool
{ \dim_zero:N \l_tmpb_dim }
- { \dim_set_eq:NN \l_tmpb_dim \g_@@_width_dim }
+ { \dim_set_eq:NN \l_tmpb_dim \l_@@_listing_width_dim }
\dim_set:Nn \l_@@_tmpc_dim { \box_ht:N \l_@@_line_box }
% \end{macrocode}
% Now, the colored panel.
@@ -5085,9 +5240,10 @@
{ \skip_vertical:n { 2.5 pt } }
\skip_vertical:n { - \box_ht_plus_dp:N \l_@@_line_box }
\box_use_drop:N \l_@@_line_box
- }
+ }
}
% \end{macrocode}
+% End of |\@@_add_background_to_line_and_use:|
%
%
% \bigskip
@@ -5095,7 +5251,7 @@
% |\g_@@_color_is_none_bool| and |\g_@@_next_color_is_none_bool|. It uses the
% current value of |\l_@@_bg_color_clist|, the value of
% |\g_@@_line_int| (the number of the current line) but also potential token lists
-% of the form |\g_@@_color_12_tl| if the final user has used the command |\rowcolor|.
+% of the form |\g_@@_color_12_tl| if the end user has used the command |\rowcolor|.
% \begin{macrocode}
\cs_set_protected:Npn \@@_compute_and_set_color:
{
@@ -5180,7 +5336,7 @@
% finish and start paragraphs.
% \end{itemize}
% \begin{macrocode}
-\cs_new_protected:Npn \@@_par:
+\cs_new_protected:Npn \@@_par:
{
% \end{macrocode}
% We recall that |\g_@@_line_int| is \emph{not} used for the number of line
@@ -5256,7 +5412,6 @@
\bool_new:N \l_@@_skip_empty_lines_bool
\bool_set_true:N \l_@@_skip_empty_lines_bool
\bool_new:N \l_@@_line_numbers_absolute_bool
-\tl_new:N \l_@@_line_numbers_format_bool
\tl_new:N \l_@@_line_numbers_format_tl
\tl_set:Nn \l_@@_line_numbers_format_tl { \footnotesize \color { gray } }
\bool_new:N \l_@@_label_empty_lines_bool
@@ -5273,9 +5428,9 @@
% \begin{macrocode}
\keys_define:nn { PitonOptions / marker }
{
- beginning .code:n = \cs_set:Nn \@@_marker_beginning:n { #1 } ,
+ beginning .cs_set:Np = \@@_marker_beginning:n #1 ,
beginning .value_required:n = true ,
- end .code:n = \cs_set:Nn \@@_marker_end:n { #1 } ,
+ end .cs_set:Np = \@@_marker_end:n #1 ,
end .value_required:n = true ,
include-lines .bool_set:N = \l_@@_marker_include_lines_bool ,
include-lines .default:n = true ,
@@ -5346,24 +5501,6 @@
% \begin{macrocode}
\keys_define:nn { PitonOptions }
{
- rounded-corners .code:n =
- \IfPackageLoadedTF { tikz }
- { \dim_set:Nn \l_@@_rounded_corners_dim { #1 } }
- { \@@_err_rounded_corners_without_Tikz: } ,
- rounded-corners .default:n = 4 pt ,
- tcolorbox .code:n =
- \IfPackageLoadedTF { tcolorbox }
- {
- \pgfkeysifdefined { / tcb / libload / breakable }
- {
- \str_if_eq:eeTF { #1 } { true }
- { \bool_set_true:N \l_@@_tcolorbox_bool }
- { \bool_set_false:N \l_@@_tcolorbox_bool }
- }
- { \@@_error:n { library~breakable~not~loaded } }
- }
- { \@@_error:n { tcolorbox~not~loaded } } ,
- tcolorbox .default:n = true ,
box .choices:nn = { c , t , b , m }
{ \str_set_eq:NN \l_@@_box_str \l_keys_choice_tl } ,
box .default:n = c ,
@@ -5374,8 +5511,15 @@
% \end{macrocode}
% First, we put keys that should be available only in the preamble.
% \begin{macrocode}
- detected-commands .code:n =
- \clist_put_right:Nn \l_@@_detected_commands_clist { #1 } ,
+ detected-commands .code:n =
+ \clist_if_in:nnTF { #1 } { rowcolor }
+ {
+ \@@_error:n { rowcolor~in~detected-commands }
+ \clist_set:Nn \l_tmpa_clist { #1 }
+ \clist_remove_all:Nn \l_tmpa_clist { rowcolor }
+ \clist_put_right:No \l_@@_detected_commands_clist \l_tmpa_clist
+ }
+ { \clist_put_right:Nn \l_@@_detected_commands_clist { #1 } } ,
detected-commands .value_required:n = true ,
detected-commands .usage:n = preamble ,
vertical-detected-commands .code:n = \@@_vertical_commands:n { #1 } ,
@@ -5474,6 +5618,10 @@
split-separation .tl_set:N = \l_@@_split_separation_tl ,
split-separation .value_required:n = true ,
+
+ add-to-split-separation .code:n =
+ \tl_put_right:Nn \l_@@_split_separation_tl { #1 } ,
+ add-to-split-separation .value_required:n = true ,
marker .code:n =
\bool_lazy_or:nnTF
@@ -5491,6 +5639,9 @@
splittable .default:n = 1 ,
background-color .code:n =
\clist_set:Nn \l_@@_bg_color_clist { #1 }
+% \end{macrocode}
+% We keep the lenght of the clist |\l_@@_bg_color_clist| in a counter for efficiency only.
+% \begin{macrocode}
\int_set:Nn \l_@@_bg_colors_int { \clist_count:N \l_@@_bg_color_clist } ,
background-color .value_required:n = true ,
prompt-background-color .tl_set:N = \l_@@_prompt_bg_color_tl ,
@@ -5607,6 +5758,40 @@
}
% \end{macrocode}
%
+% \begin{macrocode}
+\hook_gput_code:nnn { begindocument } { . }
+ {
+ \keys_define:ne { PitonOptions }
+ {
+ \IfPackageLoadedTF { tikz }
+ {
+ rounded-corners .dim_set:N = \l_@@_rounded_corners_dim ,
+ rounded-corners .default:n = 4 pt
+ }
+ { rounded-corners .code:n = \@@_err_rounded_corners_without_Tikz: }
+ }
+ \IfPackageLoadedTF { tcolorbox }
+ {
+ \pgfkeysifdefined { / tcb / libload / breakable }
+ {
+ \keys_define:nn { PitonOptions }
+ {
+ tcolorbox .bool_set:N = \l_@@_tcolorbox_bool ,
+ tcolorbox .default:n = true
+ }
+ }
+ {
+ \keys_define:nn { PitonOptions }
+ { tcolorbox .code:n = \@@_error:n { library~breakable~not~loaded } }
+ }
+ }
+ {
+ \keys_define:nn { PitonOptions }
+ { tcolorbox .code:n = \@@_error:n { tcolorbox~not~loaded } }
+ }
+ }
+% \end{macrocode}
+%
% \bigskip
% \begin{macrocode}
\cs_new_protected:Npn \@@_err_rounded_corners_without_Tikz:
@@ -5678,15 +5863,17 @@
\cs_new_protected:Npn \@@_print_number:
{
\hbox_overlap_left:n
- {
- {
+ {
+ {
\l_@@_line_numbers_format_tl
% \end{macrocode}
% We put braces. Thus, the user may use the key |line-numbers/format| with a
% value such as |\fbox|.
% \begin{macrocode}
+ \pdfextension literal { /Artifact << /ActualText (\space) >> BDC }
{ \int_to_arabic:n \g_@@_visual_line_int }
- }
+ \pdfextension literal { EMC }
+ }
\skip_horizontal:N \l_@@_numbers_sep_dim
}
}
@@ -5695,7 +5882,7 @@
%
%
% \bigskip
-% \subsubsection{The main commands and environments for the final user}
+% \subsubsection{The main commands and environments for the end user}
%
% \bigskip
% \begin{macrocode}
@@ -5714,8 +5901,8 @@
% \end{macrocode}
%
% \bigskip
-% The following property list will contain the definitions of the informatic
-% languages as provided by the final user. However, if a language is defined
+% The following property list will contain the definitions of the computer
+% languages as provided by the end user. However, if a language is defined
% over another base language, the corresponding list will contain the \emph{whole}
% definition of the language.
% \begin{macrocode}
@@ -5752,7 +5939,7 @@
% \end{macrocode}
% We store in |\l_tmpa_tl| the name of the language with the potential dialect,
% that is to say, for example : |[AspectJ]{Java}|. We use |\tl_if_blank:nF|
-% because the final user may have written |\NewPitonLanguage[ ]{Java}{...}|.
+% because the end user may have written |\NewPitonLanguage[ ]{Java}{...}|.
% \begin{macrocode}
\tl_set:Ne \l_tmpa_tl
{
@@ -5796,7 +5983,7 @@
% \end{macrocode}
% We store in |\l_tmpa_tl| the name of the base language with the dialect, that
% is to say, for example : |[AspectJ]{Java}|. We use |\tl_if_blank:nF| because
-% the final user may have used |\NewPitonLanguage[Handel]{C}[ ]{C}{...}|
+% the end user may have used |\NewPitonLanguage[Handel]{C}[ ]{C}{...}|
% \begin{macrocode}
\tl_set:Ne \l_tmpa_tl
{
@@ -5804,7 +5991,7 @@
\str_lowercase:n { #4 }
}
% \end{macrocode}
-% We retrieve in |\l_tmpb_tl| the definition (as provided by the final user) of
+% We retrieve in |\l_tmpb_tl| the definition (as provided by the end user) of
% that base language. Caution: |\g_@@_languages_prop| does not contain all the
% languages provided by \pkg{piton} but only those defined by using
% |\NewPitonLanguage|.
@@ -5862,7 +6049,7 @@
% \end{macrocode}
% Remark that the argument of |\piton| (with the normal syntax) is expanded in
% the TeX sens, (see the |\tl_set:Ne| below) and that's why we can provide the
-% following escapes to the final user:
+% following escapes to the end user:
% \begin{macrocode}
\cs_set_eq:NN \\ \c_backslash_str
\cs_set_eq:NN \% \c_percent_str
@@ -5988,16 +6175,43 @@
% |\@@_pre_composition:| will be used both in |\PitonInputFile| and
% in the environments such as |{Piton}|.
% \begin{macrocode}
-\cs_new:Npn \@@_pre_composition:
+\cs_new_protected:Npn \@@_pre_composition:
{
- \legacy_if:nT { @inlabel } { \bool_set_true:N \l_@@_in_label_bool }
- \automatichyphenmode = 1
\dim_compare:nNnT \l_@@_width_dim = \c_zero_dim
{
\dim_set_eq:NN \l_@@_width_dim \linewidth
+% \end{macrocode}
+% When the key |box| is used, |width=min| is activated (except when
+% |width| has been used with a numerical value).
+% \begin{macrocode}
\str_if_empty:NF \l_@@_box_str
{ \bool_set_true:N \l_@@_minimize_width_bool }
}
+% \end{macrocode}
+% We compute |\l_@@_listing_width_dim|. However, if |max-width| is used (or
+% |width=min| which uses |max-width|), that length will be computed
+% again in |\@@_create_output_box:| but \textbf{even
+% in the case}, we have to compute that value now (because the maximal width set
+% by |max-width| may be reached by some lines of the listing---and those lines
+% would be wrapped).
+% \begin{macrocode}
+ \dim_set:Nn \l_@@_listing_width_dim
+ {
+ \bool_if:NTF \l_@@_tcolorbox_bool
+ {
+ \l_@@_width_dim -
+ ( \kvtcb at left@rule
+ + \kvtcb at leftupper
+ + \kvtcb at boxsep * 2
+ + \kvtcb at rightupper
+ + \kvtcb at right@rule )
+ }
+ { \l_@@_width_dim }
+ }
+% \end{macrocode}
+% \begin{macrocode}
+ \legacy_if:nT { @inlabel } { \bool_set_true:N \l_@@_in_label_bool }
+ \automatichyphenmode = 1
\bool_if:NF \l_@@_resume_bool { \int_gzero:N \g_@@_visual_line_int }
\g_@@_def_vertical_commands_tl
\int_gzero:N \g_@@_line_int
@@ -6004,7 +6218,12 @@
\int_gzero:N \g_@@_nb_lines_int
\dim_zero:N \parindent
\dim_zero:N \lineskip
+ \dim_zero:N \parskip
\cs_set_eq:NN \rowcolor \@@_rowcolor:n
+% \end{macrocode}
+%
+% For efficiency, we keep in |\l_@@_bg_colors_int| the length of |\l_@@_bg_color_clist|.
+% \begin{macrocode}
\int_compare:nNnT \l_@@_bg_colors_int > { \c_zero_int }
{ \bool_set_true:N \l_@@_bg_bool }
\bool_gset_false:N \g_@@_rowcolor_inside_bool
@@ -6016,7 +6235,6 @@
\cs_set_eq:NN \zlabel \@@_zlabel:n
}
{ \cs_set_eq:NN \label \@@_label:n }
- \dim_zero:N \parskip
\l_@@_font_command_tl
}
% \end{macrocode}
@@ -6023,70 +6241,70 @@
%
%
% \bigskip
-% If the final user has used both |left-margin=auto| and |line-numbers|, we have
+% If the end user has used both |left-margin=auto| and |line-numbers|, we have
% to compute the width of the maximal number of lines at the end of the
-% environment to fix the correct value to |left-margin|. The first argument of
-% the following function is the name of the Lua function that will be applied to
-% the second argument in order to count the number of lines.
+% environment to fix the correct value to |left-margin|.
% \begin{macrocode}
-\cs_new_protected:Npn \@@_compute_left_margin:nn #1 #2
+\cs_new_protected:Npn \@@_compute_left_margin:
{
- \bool_lazy_and:nnT \l_@@_left_margin_auto_bool \l_@@_line_numbers_bool
+ \use:e
{
- \hbox_set:Nn \l_tmpa_box
- {
- \l_@@_line_numbers_format_tl
- \bool_if:NTF \l_@@_skip_empty_lines_bool
- {
- \lua_now:n
- { piton.#1(token.scan_argument()) }
- { #2 }
- \int_to_arabic:n
- { \g_@@_visual_line_int + \l_@@_nb_non_empty_lines_int }
- }
- {
- \int_to_arabic:n
- { \g_@@_visual_line_int + \g_@@_nb_lines_int }
- }
- }
- \dim_set:Nn \l_@@_left_margin_dim
- { \box_wd:N \l_tmpa_box + \l_@@_numbers_sep_dim + 0.1 em }
+ \bool_if:NTF \l_@@_skip_empty_lines_bool
+ { \lua_now:n { piton.CountNonEmptyLines(token.scan_argument()) } }
+ { \lua_now:n { piton.CountLines(token.scan_argument()) } }
+ { \l_@@_listing_tl }
}
+ \hbox_set:Nn \l_tmpa_box
+ {
+ \l_@@_line_numbers_format_tl
+ \int_to_arabic:n
+ {
+ \g_@@_visual_line_int
+ +
+ \bool_if:NTF \l_@@_skip_empty_lines_bool
+ { \l_@@_nb_non_empty_lines_int }
+ { \g_@@_nb_lines_int }
+ }
+ }
+ \dim_set:Nn \l_@@_left_margin_dim
+ { \box_wd:N \l_tmpa_box + \l_@@_numbers_sep_dim + 0.1 em }
}
-\cs_generate_variant:Nn \@@_compute_left_margin:nn { n o }
% \end{macrocode}
%
%
% \bigskip
-% The following command computes |\g_@@_width_dim| and it will be used
-% when |max-width| or |width=min| is used.
+% The following command computes |\l_@@_listing_width_dim| and it will be used
+% when |max-width| (or |width=min|) is used. Remind that the key |box| sets |width=min|
+% (except when |width| is used with a numerical value).
+%
+% % It will be used only once in |\@@_create_output_box:|.
% \begin{macrocode}
-\cs_new_protected:Npn \@@_compute_width:
+\cs_new_protected:Npn \@@_recompute_listing_width:
{
- \dim_gset:Nn \g_@@_width_dim { \box_wd:N \g_@@_output_box }
+ \dim_set:Nn \l_@@_listing_width_dim { \box_wd:N \g_@@_output_box }
\int_compare:nNnTF \l_@@_bg_colors_int > { \c_zero_int }
{
- \dim_gadd:Nn \g_@@_width_dim { 0.5 em }
+ \dim_add:Nn \l_@@_listing_width_dim { 0.5 em }
\dim_compare:nNnTF \l_@@_left_margin_dim = \c_zero_dim
- { \dim_gadd:Nn \g_@@_width_dim { 0.5 em } }
- { \dim_gadd:Nn \g_@@_width_dim \l_@@_left_margin_dim }
+ { \dim_add:Nn \l_@@_listing_width_dim { 0.5 em } }
+ { \dim_add:Nn \l_@@_listing_width_dim \l_@@_left_margin_dim }
}
- { \dim_gadd:Nn \g_@@_width_dim \l_@@_left_margin_dim }
+ { \dim_add:Nn \l_@@_listing_width_dim \l_@@_left_margin_dim }
}
% \end{macrocode}
%
% \bigskip
-% Whereas |\l_@@_with_dim| is the width of the environment as specified by the key
-% |width| (except when |max-width| or |width=min| is used), |\l_@@_code_width_dim|
-% is the width of the lines of code without the potential margins for the numbers
-% of lines and the background.
+% The following command computes |\l_@@_code_width_dim|.
+%
+% It will be used only once in |\@@_create_output_box:|.
% \begin{macrocode}
\cs_new_protected:Npn \@@_compute_code_width:
{
- \dim_set_eq:NN \l_@@_code_width_dim \l_@@_width_dim
+ \dim_set_eq:NN \l_@@_code_width_dim \l_@@_listing_width_dim
\int_compare:nNnTF \l_@@_bg_colors_int > { \c_zero_int }
% \end{macrocode}
-% If there is a background, we subtract 0.5~em for the margin on the right.
+% If there is a background (even a background with only the color |none|),
+% we subtract 0.5~em for the margin on the right.
% \begin{macrocode}
{
\dim_sub:Nn \l_@@_code_width_dim { 0.5 em }
@@ -6110,35 +6328,18 @@
}
% \end{macrocode}
%
-%
-% \bigskip
-% For the following commands, the arguments are provided by curryfication.
-% \begin{macrocode}
-\NewDocumentCommand { \NewPitonEnvironment } { }
- { \@@_DefinePitonEnvironment:nnnnn { New } }
-% \end{macrocode}
%
% \begin{macrocode}
-\NewDocumentCommand { \DeclarePitonEnvironment } { }
- { \@@_DefinePitonEnvironment:nnnnn { Declare } }
+\cs_new_protected:Npn \@@_define_newpitonenvironment_old:
+ {
% \end{macrocode}
%
-% \begin{macrocode}
-\NewDocumentCommand { \RenewPitonEnvironment } { }
- { \@@_DefinePitonEnvironment:nnnnn { Renew } }
-% \end{macrocode}
-%
-% \begin{macrocode}
-\NewDocumentCommand { \ProvidePitonEnvironment } { }
- { \@@_DefinePitonEnvironment:nnnnn { Provide } }
-% \end{macrocode}
-%
% \bigskip
% The first argument of the following macro is one of the four strings:
% |New|, |Renew|, |Provide| and |Declare|.
% \begin{macrocode}
-\cs_new_protected:Npn \@@_DefinePitonEnvironment:nnnnn #1 #2 #3 #4 #5
- {
+ \cs_new_protected:Nn \@@_DefinePitonEnvironment:nnnnn
+ {
% \end{macrocode}
% We construct a TeX macro which will catch as argument all the tokens until
% |\end{|\texttt{\textsl{name_env}}|}| with, in that
@@ -6146,15 +6347,15 @@
% 12 (``\texttt{other}''). The latter explains why the definition of that
% function is a bit complicated.
% \begin{macrocode}
- \use:x
- {
- \cs_set_protected:Npn
- \use:c { _@@_collect_ #2 :w }
- ####1
- \c_backslash_str end \c_left_brace_str #2 \c_right_brace_str
- }
+ \use:x
{
- \group_end:
+ \cs_set_protected:Npn
+ \use:c { _@@_collect_ ##2 :w }
+ ########1
+ \c_backslash_str end \c_left_brace_str ##2 \c_right_brace_str
+ }
+ {
+ \group_end:
% \end{macrocode}
% Maybe, we should deactivate all the ``shorthands'' of \pkg{babel} (when
% \pkg{babel} is loaded) with the following instruction:
@@ -6165,40 +6366,41 @@
%
% \bigskip
% \begin{macrocode}
- \tl_set:Nn \l_@@_listing_tl { ##1 }
- \@@_composition:
+ \tl_set:Nn \l_@@_listing_tl { ####1 }
+ \@@_composition:
% \end{macrocode}
%
-% The following |\end{#2}| is only for the stack of environments of LaTeX.
+% The following |\end{##2}| is only for the stack of environments of LaTeX.
% \begin{macrocode}
- \end { #2 }
- }
+ \end { ##2 }
+ }
% \end{macrocode}
-%
-%
-%
+%
% \bigskip
% We can now define the new environment.
%
% We are still in the definition of the command |\NewPitonEnvironment|...
% \begin{macrocode}
- \use:c { #1 DocumentEnvironment } { #2 } { #3 }
- {
- \cs_set_eq:NN \PitonOptions \@@_fake_PitonOptions
- #4
- \@@_pre_composition:
- \int_compare:nNnT { \l_@@_number_lines_start_int } > { \c_zero_int }
- { \int_gset:Nn \g_@@_visual_line_int { \l_@@_number_lines_start_int - 1 } }
- \group_begin:
- \tl_map_function:nN
- { \ \\ \{ \} \$ \& \# \^ \_ \% \~ \^^I }
- \char_set_catcode_other:N
- \use:c { _@@_collect_ #2 :w }
- }
- {
- #5
- \ignorespacesafterend
- }
+ \use:c { ##1 DocumentEnvironment } { ##2 } { ##3 }
+ {
+ \cs_set_eq:NN \PitonOptions \@@_fake_PitonOptions
+ ##4
+ \@@_pre_composition:
+ \int_compare:nNnT { \l_@@_number_lines_start_int } > { \c_zero_int }
+ {
+ \int_gset:Nn \g_@@_visual_line_int
+ { \l_@@_number_lines_start_int - 1 }
+ }
+ \group_begin:
+ \tl_map_function:nN
+ { \ \\ \{ \} \$ \& \# \^ \_ \% \~ \^^I }
+ \char_set_catcode_other:N
+ \use:c { _@@_collect_ ##2 :w }
+ }
+ {
+ ##5
+ \ignorespacesafterend
+ }
% \end{macrocode}
%
% \medskip
@@ -6209,39 +6411,37 @@
% instance of the environment, a spurious space is inserted, probably because
% the |^^M| is converted to space).
% \begin{macrocode}
- \AddToHook { env / #2 / begin } { \char_set_catcode_other:N \^^M }
- }
+ \AddToHook { env / ##2 / begin } { \char_set_catcode_other:N \^^M }
+ }
+ }
% \end{macrocode}
-% This is the end of the definition of the command |\NewPitonEnvironment|.
%
-%
-% \bigskip
+%
% \begin{macrocode}
-\IfFormatAtLeastTF { 2025-06-01 }
+\cs_new_protected:Npn \@@_store_body:n #1
{
% \end{macrocode}
-% We will retrieve the body of the environment in |\l_@@_listing_tl|.
-% \begin{macrocode}
- \cs_new_protected:Npn \@@_store_body:n #1
- {
-% \end{macrocode}
% Now, we have to replace all the occurrences of |\obeyedline| by a character of
% end of line (|\r| in the strings of Lua).
% \begin{macrocode}
- \tl_set:Ne \obeyedline { \char_generate:nn { 13 } { 11 } }
- \tl_set:Ne \l_@@_listing_tl { #1 }
- \tl_set_eq:NN \ProcessedArgument \l_@@_listing_tl
- }
+ \tl_set:Ne \obeyedline { \char_generate:nn { 13 } { 11 } }
+ \tl_set:Ne \l_@@_listing_tl { #1 }
+ \tl_set_eq:NN \ProcessedArgument \l_@@_listing_tl
+ }
% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_define_newpitonenvironment_new:
+ {
% The first argument of the following macro is one of the four strings:
% |New|, |Renew|, |Provide| and |Declare|.
% \begin{macrocode}
- \cs_set_protected:Npn \@@_DefinePitonEnvironment:nnnnn #1 #2 #3 #4 #5
+ \cs_new_protected:Nn \@@_DefinePitonEnvironment:nnnnn
{
- \use:c { #1 DocumentEnvironment } { #2 } { #3 > { \@@_store_body:n } c }
+ \use:c { ##1 DocumentEnvironment } { ##2 } { ##3 > { \@@_store_body:n } c }
{
\cs_set_eq:NN \PitonOptions \@@_fake_PitonOptions
- #4
+ ##4
\@@_pre_composition:
\int_compare:nNnT { \l_@@_number_lines_start_int } > { \c_zero_int }
{
@@ -6248,28 +6448,59 @@
\int_gset:Nn \g_@@_visual_line_int
{ \l_@@_number_lines_start_int - 1 }
}
-% \end{macrocode}
-% Now, the main job.
-% \begin{macrocode}
+ \bool_if:NT \g_@@_beamer_bool
+ { \@@_translate_beamer_env:o { \l_@@_listing_tl } }
\bool_if:NT \g_@@_footnote_bool \savenotes
\@@_composition:
\bool_if:NT \g_@@_footnote_bool \endsavenotes
- #5
+ ##5
}
{ \ignorespacesafterend }
}
}
- { }
% \end{macrocode}
%
+%
+% \bigskip
% \begin{macrocode}
-\cs_new_protected:Npn \@@_detect_prompt:n #1
- {
-
- }
+\IfFormatAtLeastTF { 2025-06-01 }
+ { \@@_define_newpitonenvironment_new: }
+ { \@@_define_newpitonenvironment_old: }
% \end{macrocode}
%
+%
+% \bigskip
+% For the following commands, the arguments are provided by curryfication.
% \begin{macrocode}
+\NewDocumentCommand { \NewPitonEnvironment } { }
+ { \@@_DefinePitonEnvironment:nnnnn { New } }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentCommand { \DeclarePitonEnvironment } { }
+ { \@@_DefinePitonEnvironment:nnnnn { Declare } }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentCommand { \RenewPitonEnvironment } { }
+ { \@@_DefinePitonEnvironment:nnnnn { Renew } }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentCommand { \ProvidePitonEnvironment } { }
+ { \@@_DefinePitonEnvironment:nnnnn { Provide } }
+% \end{macrocode}
+%
+%
+% \bigskip
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_translate_beamer_env:n
+ { \lua_now:e { piton.TranslateBeamerEnv(token.scan_argument ( ) ) } }
+\cs_generate_variant:Nn \@@_translate_beamer_env:n { o }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
\cs_new_protected:Npn \@@_composition:
{
\str_if_empty:NT \l_@@_box_str
@@ -6278,16 +6509,13 @@
{ \bool_if:NF \l_@@_in_PitonInputFile_bool { \newline } }
}
% \end{macrocode}
-% The following line is only to compute |\l_@@_lines_int| which will be used
-% only when both |left-margin=auto| and |skip-empty-lines = false| are in force.
-% We should change that.
+%
% \begin{macrocode}
- \lua_now:e { piton.CountLines ( '\lua_escape:n{\l_@@_listing_tl}' ) }
+ \bool_lazy_and:nnT \l_@@_left_margin_auto_bool \l_@@_line_numbers_bool
+ { \@@_compute_left_margin: }
% \end{macrocode}
-% The first argument of the following function is the name of the Lua function
-% that will be applied to the second argument in order to count the number of lines.
+%
% \begin{macrocode}
- \@@_compute_left_margin:no { CountNonEmptyLines } { \l_@@_listing_tl }
\lua_now:e
{
piton.join = "\l_@@_join_str"
@@ -6301,7 +6529,8 @@
% When |split-on-empty-lines| is in force, each chunk will be formated by an
% environment |{Piton}| (or the environment specified by |env-used-by-split|).
% Within each of these environments, we will come back here (but, of course,
-% |split-on-empty-line| will have been set to |false|).
+% |split-on-empty-line| will have been set to |false|). The mechanism ``|retrieve|''
+% is mandatory.
% \begin{macrocode}
\bool_if:NTF \l_@@_split_on_empty_lines_bool
{ \par \@@_retrieve_gobble_split_parse:o \l_@@_listing_tl }
@@ -6308,7 +6537,7 @@
{
\@@_create_output_box:
% \end{macrocode}
-% Now, the listing has been composed in |\g_@@_output_box| and |\g_@@_width_dim|
+% Now, the listing has been composed in |\g_@@_output_box| and |\l_@@_listing_width_dim|
% contains the width of the listing (with the potential margin for the numbers of lines).
% \begin{macrocode}
\bool_if:NTF \l_@@_tcolorbox_bool
@@ -6418,6 +6647,7 @@
{ \mode_leave_vertical: }
}
}
+ \skip_vertical:n { 2.5 pt } % added
}
% \end{macrocode}
%
@@ -6431,25 +6661,40 @@
% because |\begin| is now protected by |\protected| (and not by |\protect|).
% \begin{macrocode}
\use:e { \exp_not:N \begin { minipage } [ \l_@@_box_str ] }
- { \g_@@_width_dim }
+ { \l_@@_listing_width_dim }
+% \end{macrocode}
+% Here, |\vbox_unpack:N|, instead of |\box_use:N| is mandatory for the vertical
+% position of the box.
+% \begin{macrocode}
\vbox_unpack:N \g_@@_output_box
+% \end{macrocode}
+% |\kern| is mandatory here (|\skip_vertical:n| won't work).
+% \begin{macrocode}
+ \kern 2.5 pt
\end { minipage }
}
% \end{macrocode}
%
% \bigskip
-% |\@@_composition_iii:| will be used when the key |tcolorbox| is in force.
+% |\@@_composition_iii:| will be used when the key |tcolorbox| is in force but
+% \emph{not} the key |box|.
% \begin{macrocode}
\cs_new_protected:Npn \@@_composition_iii:
{
- \bool_if:NT \l_@@_minimize_width_bool
- { \tcbset { text~width = \g_@@_width_dim } }
+ \use:e
+ {
+% \end{macrocode}
+% It will be possible to delete the |\exp_not:N| in TeXLive 2025
+% because |\begin| is now protected by |\protected| (and not by |\protect|).
+% \begin{macrocode}
+ \exp_not:N \begin { tcolorbox }
% \end{macrocode}
% Even though we use the key |breakable| of |{tcolorbox}|, our environment will be
% breakable only when the key |splittable| of \pkg{piton} is used.
% \begin{macrocode}
- \begin { tcolorbox } [ breakable ]
- \par
+ [ breakable , text~width = \l_@@_listing_width_dim ]
+ }
+ \par
\vbox_unpack:N \g_@@_output_box
\end { tcolorbox }
}
@@ -6460,13 +6705,16 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_composition_iv:
{
- \bool_if:NT \l_@@_minimize_width_bool
- { \tcbset { text~width = \g_@@_width_dim } }
\use:e
{
- \begin { tcolorbox }
+% \end{macrocode}
+% It will be possible to delete the |\exp_not:N| in TeXLive 2025
+% because |\begin| is now protected by |\protected| (and not by |\protect|).
+% \begin{macrocode}
+ \exp_not:N \begin { tcolorbox }
[
hbox ,
+ text~width = \l_@@_listing_width_dim ,
nobeforeafter ,
box~align =
\str_case:Nn \l_@@_box_str
@@ -6498,10 +6746,7 @@
\lua_now:e
{
tex.sprint
- (
- luatexbase.catcodetables.expl ,
- tostring ( piton.lines_status [ \int_use:N \g_@@_line_int ] )
- )
+ ( piton.lines_status [ \int_use:N \g_@@_line_int ] )
}
}
{ 1 { \penalty 100 } 2 \nobreak }
@@ -6509,14 +6754,16 @@
% \end{macrocode}
%
% \bigskip
+% |\@@_create_output_box:| is used only once, in |\@@_composition:|.
+%
+% It creates (and modify when there are backgrounds) |\g_@@_output_box|.
% \begin{macrocode}
\cs_new_protected:Npn \@@_create_output_box:
{
\@@_compute_code_width:
- \dim_gset_eq:NN \g_@@_width_dim \l_@@_width_dim
\vbox_gset:Nn \g_@@_output_box
{ \@@_retrieve_gobble_parse:o \l_@@_listing_tl }
- \bool_if:NT \l_@@_minimize_width_bool { \@@_compute_width: }
+ \bool_if:NT \l_@@_minimize_width_bool { \@@_recompute_listing_width: }
\bool_lazy_or:nnT
{ \int_compare_p:nNn \l_@@_bg_colors_int > { \c_zero_int } }
{ \g_@@_rowcolor_inside_bool }
@@ -6528,6 +6775,9 @@
% \bigskip
% We add the backgrounds after the composition of the box |\g_@@_output_box| by a
% loop over the lines in that box.
+% The backgrounds will have a width equal to |\l_@@_listing_width_dim|.
+%
+% That command will be used only once, in |\@@_create_output_box:|.
% \begin{macrocode}
\cs_new_protected:Npn \@@_add_backgrounds_to_output_box:
{
@@ -6554,7 +6804,7 @@
% \end{macrocode}
% In standard TeX (not LuaTeX), the only way to loop over the sub-boxes of a given
% box is to use the TeX primitive |\lastbox| (via |\box_set_to_last:N| of L3).
-% Of course, it would be interesting to replace that programmation by a programmation
+% Of course, it would be interesting to replace that programming by a programming
% in Lua of LuaTeX...
% \begin{macrocode}
\box_set_to_last:N \l_@@_line_box
@@ -6569,6 +6819,7 @@
% \end{macrocode}
% The command |\@@_add_background_to_line_and_use:| will add a background to
% the line (in |\l_@@_line_box|) but will also put the line in the current box.
+% The background will have a width equal to |\l_@@_listing_width_dim|.
% \begin{macrocode}
\@@_add_background_to_line_and_use:
\kern -2.5 pt
@@ -6583,7 +6834,7 @@
% \end{macrocode}
%
% \bigskip
-% The following will be used when the final user has used |print=false|.
+% The following will be used when the end user has used |print=false|.
% \begin{macrocode}
\cs_new_protected:Npn \@@_gobble_parse_no_print:n
{
@@ -6634,7 +6885,7 @@
{
\lua_now:e
{
- piton.RetrieveGobbleSplitParse
+ piton.RetrieveGobbleSplitParse
(
'\l_piton_language_str' ,
\int_use:N \l_@@_gobble_int ,
@@ -6648,9 +6899,8 @@
%
% \bigskip
% Now, we define the environment |{Piton}|, which is the main environment
-% provided by the package \pkg{piton}. Of course, you use
-% |\NewPitonEnvironment|.
-% \begin{macrocode}
+% provided by the package \pkg{piton}. Of course, you use |\NewPitonEnvironment|.
+% \begin{macrocode}
\bool_if:NTF \g_@@_beamer_bool
{
\NewPitonEnvironment { Piton } { d < > O { } }
@@ -6671,8 +6921,6 @@
%
%
% \bigskip
-% The code of the command |\PitonInputFile| is somewhat similar to the code of
-% the environment |{Piton}|.
% \begin{macrocode}
\NewDocumentCommand { \PitonInputFileTF } { d < > O { } m m m }
{
@@ -6795,17 +7043,8 @@
\int_compare:nNnT \g_@@_visual_line_int < \c_zero_int
{ \int_gzero:N \g_@@_visual_line_int }
% \end{macrocode}
-% We count with Lua the number of lines of the argument. The result will be
-% stored by Lua in |\g_@@_nb_lines_int|.
+%
% \begin{macrocode}
- \lua_now:e { piton.CountLinesFile ( '\l_@@_file_name_str' ) }
-% \end{macrocode}
-% The first argument of the following function is the name of the Lua function
-% that will be applied to the second argument in order to count the number of lines.
-% \begin{macrocode}
- \@@_compute_left_margin:no
- { CountNonEmptyLinesFile }
- { \l_@@_file_name_str }
\lua_now:e
{
% \end{macrocode}
@@ -6875,7 +7114,16 @@
% \end{macrocode}
%
% \medskip
+% The following variant will be rarely used. It applies only a local style
+% and only when that style exists (no error will be raised when the style does not
+% exist). That command will be used in particular for the language ``|expl|''.
% \begin{macrocode}
+\NewDocumentCommand { \OptionalLocalPitonStyle } { m }
+ { \cs_if_exist_use:c { pitonStyle _ \l_piton_language_str _ #1 } }
+% \end{macrocode}
+%
+% \medskip
+% \begin{macrocode}
\NewDocumentCommand { \SetPitonStyle } { O { } m }
{
\str_clear_new:N \l_@@_SetPitonStyle_option_str
@@ -6885,6 +7133,7 @@
\keys_set:nn { piton / Styles } { #2 }
}
% \end{macrocode}
+%
%
% \medskip
% \begin{macrocode}
@@ -6953,8 +7202,12 @@
% the syntax of \pkg{listings}.
% \begin{macrocode}
Directive
- }
-
+ }
+% \end{macrocode}
+%
+%
+%
+% \begin{macrocode}
\clist_map_inline:Nn \g_@@_styles_clist
{
\keys_define:nn { piton / Styles }
@@ -6978,13 +7231,43 @@
String .value_required:n = true ,
Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
Comment.Math .value_required:n = true ,
- unknown .code:n =
- \@@_error:n { Unknown~key~for~SetPitonStyle }
+ unknown .code:n = \@@_unknown_style:
}
% \end{macrocode}
%
% \bigskip
+% For the langage |expl|, it's possible to create ``on the fly'' some styles
+% of the form \texttt{Module.\textsl{name}} or \texttt{Type.\textsl{name}}.
+% For the other languages, it's not possible.
% \begin{macrocode}
+\cs_new_protected:Npn \@@_unknown_style:
+ {
+ \str_if_eq:eeTF \l_@@_SetPitonStyle_option_str { expl }
+ {
+ \seq_set_split:Nne \l_tmpa_seq { . } \l_keys_key_str
+ \seq_get_left:NN \l_tmpa_seq \l_tmpa_str
+% \end{macrocode}
+% Now, the first part of the key (before the first period) is stored in |\l_tmpa_str|.
+% \begin{macrocode}
+ \bool_lazy_and:nnTF
+ { \int_compare_p:nNn { \seq_count:N \l_tmpa_seq } > { 1 } }
+ {
+ \str_if_eq_p:Vn \l_tmpa_str { Module }
+ ||
+ \str_if_eq_p:Vn \l_tmpa_str { Type }
+ }
+% \end{macrocode}
+% Now, we will create a new style.
+% \begin{macrocode}
+ { \tl_set:co { pitonStyle _ expl _ \l_keys_key_str } \l_keys_value_tl }
+ { \@@_error:n { Unknown~key~for~SetPitonStyle } }
+ }
+ { \@@_error:n { Unknown~key~for~SetPitonStyle } }
+ }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
\SetPitonStyle[OCaml]
{
TypeExpression =
@@ -7171,7 +7454,70 @@
Discard = \use_none:n
}
% \end{macrocode}
+% \bigskip
+% \subsubsection{Styles specific to the language expl}
%
+% \begin{macrocode}
+\clist_new:N \g_@@_expl_styles_clist
+\clist_gset:Nn \g_@@_expl_styles_clist
+ {
+ Scope.l ,
+ Scope.g ,
+ Scope.c
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\clist_map_inline:Nn \g_@@_expl_styles_clist
+ {
+ \keys_define:nn { piton / Styles }
+ {
+ #1 .value_required:n = true ,
+ #1 .code:n =
+ \tl_set:cn
+ {
+ pitonStyle _
+ \str_if_empty:NF \l_@@_SetPitonStyle_option_str
+ { \l_@@_SetPitonStyle_option_str _ }
+ #1
+ }
+ { ##1 }
+ }
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\SetPitonStyle [ expl ]
+ {
+ Scope.l = ,
+ Scope.g = \bfseries ,
+ Scope.c = \slshape ,
+ Type.bool = \color [ HTML ] { AA6600} ,
+ Type.box = \color [ HTML ] { 267910 } ,
+ Type.clist = \color [ HTML ] { 309030 } ,
+ Type.fp = \color [ HTML ] { FF3300 } ,
+ Type.int = \color [ HTML ] { FF6600 } ,
+ Type.seq = \color [ HTML ] { 309030 } ,
+ Type.skip = \color [ HTML ] { 0CC060 } ,
+ Type.str = \color [ HTML ] { CC3300 } ,
+ Type.tl = \color [ HTML ] { AA2200 } ,
+ Module.bool = \color [ HTML ] { AA6600} ,
+ Module.box = \color [ HTML ] { 267910 } ,
+ Module.cs = \bfseries \color [ HTML ] { 006699 } ,
+ Module.exp = \bfseries \color [ HTML ] { 404040 } ,
+ Module.hbox = \color [ HTML ] { 267910 } ,
+ Module.prg = \bfseries ,
+ Module.clist = \color [ HTML ] { 309030 } ,
+ Module.fp = \color [ HTML ] { FF3300 } ,
+ Module.int = \color [ HTML ] { FF6600 } ,
+ Module.seq = \color [ HTML ] { 309030 } ,
+ Module.skip = \color [ HTML ] { 0CC060 } ,
+ Module.str = \color [ HTML ] { CC3300 } ,
+ Module.tl = \color [ HTML ] { AA2200 } ,
+ Module.vbox = \color [ HTML ] { 267910 }
+ }
+% \end{macrocode}
+%
% \medskip
% If the key |math-comments| has been used in the preamble of the LaTeX
% document, we change the style |Comment.Math| which should be considered only
@@ -7185,9 +7531,8 @@
}
% \end{macrocode}
%
+%
% \bigskip
-%
-% \bigskip
% \subsubsection{Highlighting some identifiers}
%
%
@@ -7235,7 +7580,7 @@
{
% \end{macrocode}
% First, the element is composed in the TeX flow with the style |Name.Function|
-% which is provided to the final user.
+% which is provided to the end user.
% \begin{macrocode}
{ \PitonStyle { Name.Function } { #1 } }
% \end{macrocode}
@@ -7332,11 +7677,28 @@
%
% \bigskip
% \begin{macrocode}
-\AtEndDocument
- { \lua_now:n { piton.join_and_write_files() } }
+\AtEndDocument { \lua_now:n { piton.join_and_write_files() } }
% \end{macrocode}
%
% \bigskip
+%
+% \subsubsection{Spaces of indentation}
+%
+% \bigskip
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_space_indentation:
+ {
+ \pdfextension literal { /Artifact << /ActualText (\space) >> BDC }
+ {
+ \color { white }
+ \transparent { 0 }
+ ␣ % U+2423
+ }
+ \pdfextension literal { EMC }
+ }
+% \end{macrocode}
+%
+% \bigskip
% \subsubsection{Security}
%
% \begin{macrocode}
@@ -7385,7 +7747,8 @@
breakable~not~loaded \\
You~can't~use~the~key~'tcolorbox'~because~
you~have~not~loaded~the~library~'breakable'~of~tcolorbox'. \\
- Use~\token_to_str:N \tcbuselibrary{breakable}. \\
+ Use~\token_to_str:N \tcbuselibrary{breakable}~in~the~preamble~
+ of~your~document.\\
If~you~go~on,~that~key~will~be~ignored.
}
% \end{macrocode}
@@ -7425,7 +7788,7 @@
\@@_msg_new:nn { Unknown~key~for~SetPitonStyle }
{
The~style~'\l_keys_key_str'~is~unknown.\\
- This~key~will~be~ignored.\\
+ This~setting~will~be~ignored.\\
The~available~styles~are~(in~alphabetic~order):~
\clist_use:Nnnn \g_@@_styles_clist { ~and~ } { ,~ } { ~and~ }.
}
@@ -7570,6 +7933,15 @@
However,~you~can~go~on.
}
% \end{macrocode}
+%
+% \begin{macrocode}
+\@@_msg_new:nn { rowcolor~in~detected-commands }
+ {
+ 'rowcolor'~forbidden~in~'detected-commands'.\\
+ You~should~put~'rowcolor'~in~'raw-detected-commands'.\\
+ That~key~will~be~ignored.
+ }
+% \end{macrocode}
%
% \begin{macrocode}
\@@_msg_new:nnn { Unknown~key~for~PitonOptions }
@@ -7581,6 +7953,7 @@
}
{
The~available~keys~are~(in~alphabetic~order):~
+ add-to-split-separation,~
auto-gobble,~
background-color,~
begin-range,~
@@ -7761,12 +8134,12 @@
% The function |Q| takes in as argument a pattern and returns a \textsc{lpeg}
% \emph{which does a capture} of the pattern. That capture will be sent to LaTeX
% with the catcode ``other'' for all the characters: it's suitable for elements
-% of the informatic listings that \pkg{piton} will typeset verbatim (thanks to the
+% of the computer listings that \pkg{piton} will typeset verbatim (thanks to the
% catcode ``other'').
% \begin{macrocode}
local Q
function Q ( pattern )
- return Ct ( Cc ( luatexbase.catcodetables.CatcodeTableOther ) * C ( pattern ) )
+ return Ct ( Cc ( luatexbase.catcodetables.other ) * C ( pattern ) )
end
% \end{macrocode}
%
@@ -7985,7 +8358,8 @@
% Remember that |\@@_leading_space:| does \emph{not} create a space, only an
% incrementation of the counter |\g_@@_indentation_int|.
% \begin{macrocode}
-local SpaceIndentation = Lc [[ \@@_leading_space: ]] * Q " "
+local SpaceIndentation
+ = Lc [[ \@@_leading_space: \@@_space_indentation: ]] * P " "
% \end{macrocode}
%
% \bigskip
@@ -8067,27 +8441,7 @@
end
% \end{macrocode}
%
-% \begin{macrocode}
-local beamerBeginEnvironments =
- ( space ^ 0 *
- L
- (
- P [[\begin{]] * beamerEnvironments * "}"
- * ( "<" * ( 1 - P ">" ) ^ 0 * ">" ) ^ -1
- )
- * "\r"
- ) ^ 0
-% \end{macrocode}
%
-% \begin{macrocode}
-local beamerEndEnvironments =
- ( space ^ 0 *
- L ( P [[\end{]] * beamerEnvironments * "}" )
- * "\r"
- ) ^ 0
-% \end{macrocode}
-%
-%
% \bigskip
% \paragraph{Several tools for the construction of the main LPEG}
%
@@ -8105,7 +8459,7 @@
% language-dependent. That's why we write a Lua function |Compute_braces| which
% will compute the pattern by taking in as argument a pattern for the strings of
% the language (at least the shorts strings). The argument of |Compute_braces|
-% must be a pattern \emph{which does no catching}.
+% must be a pattern \emph{which does no captures}.
% \begin{macrocode}
local Compute_braces
function Compute_braces ( lpeg_string ) return
@@ -8181,7 +8535,7 @@
%
% Remark that there is no \pkg{piton} style associated to a chunk of code which
% is analyzed by |ParseAgain|. If we wish a \pkg{piton} style available to the
-% final user (if he wish to format that element with a uniform font instead of
+% end user (if he wish to format that element with a uniform font instead of
% an analyze by |ParseAgain|), we have to use |\@@_piton:n|.
% \begin{macrocode}
local ParseAgain
@@ -8276,14 +8630,15 @@
% Now, the environments of Beamer.
% \begin{macrocode}
for _ , x in ipairs ( beamer_environments ) do
- lpeg = lpeg +
+ lpeg = lpeg +
Ct ( Cc "Open"
* C (
- P ( [[\begin{]] .. x .. "}" )
- * ( "<" * ( 1 - P ">") ^ 0 * ">" ) ^ -1
- )
- * Cc ( [[\end{]] .. x .. "}" )
- )
+ P ( [[\begin{]] .. x .. "}" )
+ * ( "<" * ( 1 - P ">") ^ 0 * ">" ) ^ -1
+ )
+ * space ^ 0 * ( P "\r" ) ^ 1 -- added 25/08/23
+ * Cc ( [[\end{]] .. x .. "}" )
+ )
* (
( ( 1 - P ( [[\end{]] .. x .. "}" ) ) ^ 0 )
/ ( function ( s )
@@ -8292,7 +8647,7 @@
end
end )
)
- * P ( [[\end{]] .. x .. "}" )
+ * P ( [[\end{]] .. x .. "}" )
* Ct ( Cc "Close" )
end
% \end{macrocode}
@@ -8322,7 +8677,7 @@
% \begin{macrocode}
local Prompt =
K ( 'Prompt' , ( P ">>>" + "..." ) * P " " ^ -1 )
- * Lc [[ \rowcolor { \l_@@_prompt_bg_color_tl } ]]
+ * Lc [[ \rowcolor { \l_@@_prompt_bg_color_tl } ]]
% \end{macrocode}
%
%
@@ -8335,35 +8690,8 @@
(
space ^ 0 * -1
+
-% \end{macrocode}
-% We recall that each line of the computer listing we have to parse will be sent
-% back to LaTeX between a pair |\@@_begin_line:| --
-% |\@@_end_line:|\footnote{Remember that the \texttt{\textbackslash
-% @@\_end\_line:} must be explicit because it will be used as marker in order to
-% delimit the argument of the command \texttt{\textbackslash @@\_begin\_line:}}.
-% \begin{macrocode}
- Ct (
- Cc "EOL"
- *
- Ct ( Lc [[ \@@_end_line: ]]
- * beamerEndEnvironments
- *
- (
-% \end{macrocode}
-% If the last line of the listing is the end of an environment of Beamer (eg.
-% |\end{uncoverenv}|), then, we don't open a new line. A token |\@@_end_line:|
-% will be added at the end of the environment but it will be no-op since we have
-% defined the macro |\@@_end_line:| to be no-op (even though it is also used as
-% a marker for the TeX delimited macro |\@@_begin_line:|).
-% \begin{macrocode}
- -1
- +
- beamerBeginEnvironments
- * Lc [[ \@@_par:\@@_begin_line: ]]
- )
- )
- )
- )
+ Cc "EOL"
+ )
* ( SpaceIndentation ^ 0 * # ( 1 - S " \r" ) ) ^ -1
% \end{macrocode}
%
@@ -8370,9 +8698,7 @@
%
% \bigskip
% The following \textsc{lpeg} |CommentLaTeX| is for what is called in that
-% document the ``LaTeX comments''. Since the elements that will be caught must
-% be sent to LaTeX with standard LaTeX catcodes, we put the capture (done by
-% the function~|C|) in a table (by using~|Ct|, which is an alias for |lpeg.Ct|).
+% document the ``LaTeX comments''.
% \begin{macrocode}
local CommentLaTeX =
P ( piton.comment_latex )
@@ -8858,7 +9184,7 @@
% \smallskip
% If the word |def| is not followed by an identifier and parenthesis, it will be
% caught as keyword by the \textsc{lpeg} |Keyword| (useful if, for example, the
-% final user wants to speak of the keyword \piton{def}).
+% end user wants to speak of the keyword \piton{def}).
%
%
% \paragraph{Miscellaneous}
@@ -8884,8 +9210,8 @@
+ Space
+ Tab
+ Escape + EscapeMath
+ + Beamer
+ CommentLaTeX
- + Beamer
+ DetectedCommands
+ Prompt
+ LongString
@@ -8925,7 +9251,6 @@
LPEG2.python =
Ct (
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -8940,7 +9265,7 @@
end
% \end{macrocode}
%
-% \bigskip
+%
% \subsubsection{The language Ocaml}
%
% We open a Lua local scope for the language OCaml (of course, there will be also
@@ -9438,7 +9763,7 @@
* Space
* (
% \end{macrocode}
-% You use here the argument |strict| in order to allow a correct analyse of
+% We use here the argument |strict| in order to allow a correct analyse of
% |let x = \uncover<2->{y}| (elsewhere, it's interpreted as a definition of a OCaml
% function).
% \begin{macrocode}
@@ -9618,7 +9943,6 @@
* K ( 'TypeExpression' , ( 1 - P "\r" ) ^ 0 )
+
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( ( space * Lc [[ \@@_trailing_space: ]] ) ^ 1 * -1
@@ -9842,7 +10166,6 @@
LPEG2.c =
Ct (
( space ^ 0 * P "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -9874,7 +10197,7 @@
Lc [[ {\PitonStyle{Keyword}{ ]]
* Q ( Cmt (
C ( letter * alphanum ^ 0 ) ,
- function ( s , i , a ) return string.upper ( a ) == name end
+ function ( _ , _ , a ) return a : upper ( ) == name end
)
)
* Lc "}}"
@@ -9961,7 +10284,7 @@
C ( identifier ) /
(
function ( s )
- if set_keywords[string.upper(s)] then return
+ if set_keywords [ s : upper ( ) ] then return
% \end{macrocode}
% Remind that, in Lua, it's possible to return \emph{several} values.
% \begin{macrocode}
@@ -9969,7 +10292,7 @@
{ luatexbase.catcodetables.other , s } ,
{ "}}" }
else
- if set_builtins[string.upper(s)] then return
+ if set_builtins [ s : upper ( ) ] then return
{ [[{\PitonStyle{Name.Builtin}{]] } ,
{ luatexbase.catcodetables.other , s } ,
{ "}}" }
@@ -10129,7 +10452,6 @@
LPEG2.sql =
Ct (
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -10218,7 +10540,6 @@
LPEG2.minimal =
Ct (
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -10292,7 +10613,6 @@
LPEG2.verbatim =
Ct (
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -10308,7 +10628,160 @@
end
% \end{macrocode}
%
+%
+% \subsubsection{The language expl}
+%
+% We open a Lua local scope for the language |expl| of LaTeX3 (of course, there
+% will be also global definitions).
+% \begin{macrocode}
+--EXPL expl
+do
+% \end{macrocode}
+%
+% \begin{macrocode}
+ local Comment =
+ WithStyle
+ ( 'Comment.Internal' ,
+ Q "%" * ( CommentMath + Q ( ( 1 - S "$\r" ) ^ 1 ) ) ^ 0 -- $
+ )
+ * ( EOL + -1 )
+% \end{macrocode}
+%
+% \medskip
+% First, we begin with a special function to analyse the ``keywords'', that is to
+% say the control sequences beginning by ``|\|''.
+% \begin{macrocode}
+ local analyze_cs
+ function analyze_cs ( s )
+ local i = s : find ( ":" )
+ if i then
+% \end{macrocode}
+% First, the case of what might be called a ``function'' in |expl|, for instance,
+% |\tl_set:Nn| or |\int_compare:nNnTF|.
+% \begin{macrocode}
+ local name = s : sub ( 2 , i - 1 )
+ local parts = name : explode ( "_" )
+ local module = parts[1]
+ if module == "" then module = parts[3] end
+% \end{macrocode}
+% Remind that, in Lua, we can return \emph{several} values.
+% \begin{macrocode}
+ return
+ { [[{\OptionalLocalPitonStyle{Module.]] .. module .. "}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ else
+% \end{macrocode}
+% \begin{macrocode}
+ local p = s : sub ( 1 , 3 )
+ if p == [[\l_]] or p == [[\g_]] or p == [[\c_]] then
+% \end{macrocode}
+% The case of what might be called a ``variable'', for instance,
+% |\l_tmpa_int| or |\g__module_text_tl|.
+% \begin{macrocode}
+ local scope = s : sub(2,2)
+ local parts = s : explode ( "_" )
+ local module = parts[2]
+ if module == "" then module = parts[3] end
+ local type = parts[#parts]
+ return
+ { [[{\OptionalLocalPitonStyle{Scope.]] .. scope .. "}{" } ,
+ { [[{\OptionalLocalPitonStyle{Module.]] .. module .. "}{" } ,
+ { [[{\OptionalLocalPitonStyle{Type.]] .. type .. "}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}}}}}" }
+ else
+% \end{macrocode}
+% We have a control sequence which is neither a ``function'' neither a ``variable''
+% of |expl|. It's a control sequence of standard LaTeX and we don't format it.
+% \begin{macrocode}
+ return { luatexbase.catcodetables.other , s }
+ end
+ end
+ end
+% \end{macrocode}
+%
% \bigskip
+% Here, we don't use |braces| as done with the other languages because we don't
+% have have to take into account the strings (there is no string in the langage
+% |expl|).
+% \begin{macrocode}
+ local braces =
+ P { "E" ,
+ E = ( "{" * V "E" * "}" + ( 1 - S "{}" ) ) ^ 0
+ }
+
+ if piton.beamer then Beamer = Compute_Beamer ( 'expl' , braces ) end
+
+ DetectedCommands =
+ Compute_DetectedCommands ( 'expl' , braces )
+ + Compute_RawDetectedCommands ( 'expl' , braces )
+
+ LPEG_cleaner.expl = Compute_LPEG_cleaner ( 'expl' , braces )
+% \end{macrocode}
+% \begin{macrocode}
+ local control_sequence = P "\\" * ( R "Az" + "_" + ":" + "@" ) ^ 1
+ local ControlSequence = C ( control_sequence ) / analyze_cs
+% \end{macrocode}
+%
+% \begin{macrocode}
+ local def_function
+ = P [[\cs_]]
+ * ( P "set" + "new")
+ * ( P "_protected" ) ^ -1
+ * P ":N" * ( P "p" ) ^ -1 * "n"
+% \end{macrocode}
+%
+% \begin{macrocode}
+ local DefFunction =
+ C ( def_function ) / analyze_cs
+ * Space
+ * Lc ( [[ {\PitonStyle{Name.Function}{ ]] )
+ * ControlSequence -- Q ( ControlSequence ) ?
+ * Lc "}}"
+% \end{macrocode}
+%
+% \begin{macrocode}
+ local Word = Q ( ( 1 - S " \r" ) ^ 1 )
+
+ local Main =
+ space ^ 0 * EOL
+ + Space
+ + Tab
+ + Escape + EscapeMath
+ + Beamer
+ + Comment
+ + DetectedCommands
+ + DefFunction
+ + ControlSequence
+ + Word
+% \end{macrocode}
+%
+% \bigskip
+% Here, we must not put |local|, of course.
+% \begin{macrocode}
+ LPEG1.expl = Main ^ 0
+
+ LPEG2.expl =
+ Ct (
+ ( space ^ 0 * "\r" ) ^ -1
+ * Lc [[ \@@_begin_line: ]]
+ * SpaceIndentation ^ 0
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
+ * -1
+ * Lc [[ \@@_end_line: ]]
+ )
+% \end{macrocode}
+%
+%
+% \bigskip
+% End of the Lua scope for the language |expl| of LaTeX3.
+% \begin{macrocode}
+end
+% \end{macrocode}
+%
+%
+% \bigskip
% \subsubsection{The function Parse}
%
% \medskip
@@ -10326,36 +10799,36 @@
% \begin{macrocode}
piton.language = language
local t = LPEG2[language] : match ( code )
- if t == nil then
+ if not t then
sprintL3 [[ \@@_error_or_warning:n { SyntaxError } ]]
return -- to exit in force the function
- end
+ end
local left_stack = {}
local right_stack = {}
- for _ , one_item in ipairs ( t ) do
- if one_item[1] == "EOL" then
- for _ , s in ipairs ( right_stack ) do
- tex.sprint ( s )
+ for _ , one_item in ipairs ( t ) do
+ if one_item == "EOL" then
+ for i = #right_stack, 1, -1 do
+ tex.sprint ( right_stack[i] )
end
- for _ , s in ipairs ( one_item[2] ) do
- tex.tprint ( s )
- end
- for _ , s in ipairs ( left_stack ) do
- tex.sprint ( s )
- end
- else
% \end{macrocode}
+% We remind that the |\@@_end_line:| must be explicit since it's the marker
+% of end of the command |\@@_begin_line:|.
+% \begin{macrocode}
+ sprintL3 ( [[ \@@_end_line: \@@_par: \@@_begin_line: ]] )
+ tex.sprint ( table.concat ( left_stack ) )
+ else
+% \end{macrocode}
%
% Here is an example of an item beginning with |"Open"|.
%
-% |{ "Open" , "\begin{uncover}<2>" , "\end{uncover}" }|
+% |{ "Open" , "\begin{uncoverenv}<2>" , "\end{uncoverenv}" }|
%
% In order to deal with the ends of lines, we have to close the environment
-% (|{uncover}| in this example) at the end of each line and reopen it at the
+% (|{uncoverenv}| in this example) at the end of each line and reopen it at the
% beginning of the new line. That's why we use two Lua stacks, called
% |left_stack| and |right_stack|. |left_stack| will be for the elements like
-% |\begin{uncover}<2>| and |right_stack| will be for the elements like
-% |\end{uncover}|.
+% |\begin{uncoverenv}<2>| and |right_stack| will be for the elements like
+% |\end{uncoverenv}|.
% \begin{macrocode}
if one_item[1] == "Open" then
tex.sprint ( one_item[2] )
@@ -10377,17 +10850,22 @@
%
% \bigskip
% There is the problem of the conventions of end of lines (|\n| in Unix and
-% Linux but |\r\n| in Windows). The function |cr_file_lines| will read a file
-% line by line after replacement of the |\r\n| by |\n|.
+% Linux but |\r\n| in Windows). The function |my_file_lines| will read a file
+% line by line after replacement of the potential |\r\n| by |\n| (that means that
+% we go the convention \textsc{unix}).
% \begin{macrocode}
-local cr_file_lines
-function cr_file_lines ( filename )
+local my_file_lines
+function my_file_lines ( filename )
local f = io.open ( filename , 'rb' )
local s = f : read ( '*a' )
f : close ( )
+% \end{macrocode}
+% À la fin, on doit bien mettre |(.-)| et pas |(.*)|.
+% \begin{macrocode}
return ( s .. '\n' ) : gsub( '\r\n?' , '\n') : gmatch ( '(.-)\n' )
end
% \end{macrocode}
+% Recall that, in Lua, |gmatch| returns an \emph{iterator}.
%
%
% \bigskip
@@ -10395,7 +10873,7 @@
function piton.ReadFile ( name , first_line , last_line )
local s = ''
local i = 0
- for line in cr_file_lines ( name ) do
+ for line in my_file_lines ( name ) do
i = i + 1
if i >= first_line then
s = s .. '\r' .. line
@@ -10404,20 +10882,18 @@
end
% \end{macrocode}
%
+% \bigskip
% We extract the BOM of utf-8, if present.
% \begin{macrocode}
- if string.byte ( s , 1 ) == 13 then
- if string.byte ( s , 2 ) == 239 then
- if string.byte ( s , 3 ) == 187 then
- if string.byte ( s , 4 ) == 191 then
- s = string.sub ( s , 5 , -1 )
- end
- end
- end
+ if s : sub ( 1 , 4 ) == string.char ( 13 , 239 , 187 , 191 ) then
+ s = s : sub ( 5 , -1 )
end
+% \end{macrocode}
+%
+% \begin{macrocode}
sprintL3 ( [[ \tl_set:Nn \l_@@_listing_tl { ]])
- tex.sprint ( luatexbase.catcodetables.CatcodeTableOther , s )
- sprintL3 ( [[ } ]] )
+ tex.sprint ( luatexbase.catcodetables.other , s )
+ sprintL3 ( "}" )
end
% \end{macrocode}
%
@@ -10440,6 +10916,8 @@
return piton.Parse ( lang , code : gsub ( '##' , '#' ) )
end
% \end{macrocode}
+% Of course, |gsub| spans the string only once for the substitutions, which
+% means that |####| will be replaced by |##| as expected and not by |#|.
%
% \bigskip
% The following command will be used when we have to parse some small chunks of
@@ -10515,17 +10993,6 @@
* Ct ( C " " ^ 0 * -1 ) / table.getn
% \end{macrocode}
%
-% \begin{macrocode}
-local remove_before_cr
-function remove_before_cr ( input_string )
- local match_result = ( P "\r" ) : match ( input_string )
- if match_result then return
- string.sub ( input_string , match_result )
- else return
- input_string
- end
-end
-% \end{macrocode}
%
% \bigskip
% The function |gobble| gobbles $n$ characters on the left of the code. The
@@ -10532,7 +10999,6 @@
% negative values of $n$ have special significations.
% \begin{macrocode}
function piton.Gobble ( n , code )
- code = remove_before_cr ( code )
if n == 0 then return
code
else
@@ -10576,7 +11042,6 @@
% \end{macrocode}
%
%
-% \bigskip
%
% \bigskip
% In the following code, |n| is the value of |\l_@@_gobble_int|.
@@ -10593,25 +11058,18 @@
% \begin{macrocode}
piton.CountLines ( piton.last_code )
piton.Parse ( lang , piton.last_code )
- sprintL3 [[ \vspace{2.5pt} ]]
-% \end{macrocode}
-% We finish the paragraph (each line of the listing is composed in a TeX box
-% --- with potentially several lines when |break-lines-in-Piton| is in force ---
-% put alone in a paragraph.
-% \begin{macrocode}
- sprintL3 [[ \par ]]
piton.join_and_write ( )
end
% \end{macrocode}
%
% \bigskip
-% The following function will be used when the final user has used the key |join|
+% The following function will be used when the end user has used the key |join|
% or the key |write|.
% The value of the key |join| has been written in the Lua variable |piton.join|.
% \begin{macrocode}
function piton.join_and_write ( )
if piton.join ~= '' then
- if piton.join_files [ piton.join ] == nil then
+ if not piton.join_files [ piton.join ] then
piton.join_files [ piton.join ] = piton.get_last_code ( )
else
piton.join_files [ piton.join ] =
@@ -10620,7 +11078,7 @@
end
% \end{macrocode}
%
-% Now, if the final user has used the key |write| to write the listing of the
+% Now, if the end user has used the key |write| to write the listing of the
% environment on an external file (on the disk).
%
% We have written the values of the keys |write| and |path-write| in the Lua
@@ -10665,7 +11123,7 @@
% files that we will write on the disk in the |\AtEndDocument|. They
% correspond to the use of the key |write| (and |path-write|).
% \begin{macrocode}
- if piton.write_files [ file_name ] == nil then
+ if not piton.write_files [ file_name ] then
piton.write_files [ file_name ] = piton.get_last_code ( )
else
piton.write_files [ file_name ] =
@@ -10677,7 +11135,7 @@
% \end{macrocode}
%
% \bigskip
-% The following command will be used when the final user has set |print=false|.
+% The following command will be used when the end user has set |print=false|.
% \begin{macrocode}
function piton.GobbleParseNoPrint ( lang , n , code )
piton.last_code = piton.Gobble ( n , code )
@@ -10749,7 +11207,7 @@
% \begin{macrocode}
piton.string_between_chunks =
[[ \par \l_@@_split_separation_tl \mode_leave_vertical: ]]
- .. [[ \int_gzero:N \g_@@_line_int ]]
+ .. [[ \global \g_@@_line_int = 0 ]]
% \end{macrocode}
% The counter |\g_@@_line_int| will be used to control the points where the code
% may be broken by a change of page (see the key |splittable|).
@@ -10759,7 +11217,7 @@
% \begin{macrocode}
function piton.get_last_code ( )
return LPEG_cleaner[piton.last_language] : match ( piton.last_code )
- : gsub('\r\n','\n') : gsub('\r','\n')
+ : gsub ( '\r\n?' , '\n' )
end
% \end{macrocode}
%
@@ -10767,18 +11225,51 @@
% \subsubsection{To count the number of lines}
%
% \begin{macrocode}
+local CountBeamerEnvironments
+function CountBeamerEnvironments ( code ) return
+ (
+ Ct (
+ (
+ P "\\begin{" * beamerEnvironments * ( 1 - P "\r" ) ^ 0 * C "\r"
+ +
+ ( 1 - P "\r" ) ^ 0 * "\r"
+ ) ^ 0
+ * ( 1 - P "\r" ) ^ 0
+ * -1
+ ) / table.getn
+ ) : match ( code )
+end
+% \end{macrocode}
+%
+% \bigskip
+% The following function counts the lines of |code| except the lines which
+% contains only instructions for the environements of Beamer.
+%
+% It is used in |GobbleParse| and at the beginning of |\@@_composition:| (in some
+% rare circumstancies).
+%
+% Be careful. We have tried a version with |string.gsub| without success.
+% \begin{macrocode}
function piton.CountLines ( code )
- local count = 0
+ local count
count =
( Ct ( ( ( 1 - P "\r" ) ^ 0 * C "\r" ) ^ 0
- * ( ( 1 - P "\r" ) ^ 1 * Cc "\r" ) ^ -1
+ *
+ (
+ space ^ 0 * ( 1 - P "\r" - space ) * ( 1 - P "\r" ) ^ 0 * Cc "\r"
+ + space ^ 0
+ ) ^ -1
* -1
) / table.getn
) : match ( code )
- sprintL3 ( string.format ( [[ \int_gset:Nn \g_@@_nb_lines_int { %i } ]] , count ) )
+ if piton.beamer then
+ count = count - 2 * CountBeamerEnvironments ( code )
+ end
+ sprintL3 ( [[ \int_gset:Nn \g_@@_nb_lines_int { ]] .. count .. "}" )
end
% \end{macrocode}
%
+%
% \bigskip
% The following function is only used once (in |piton.GobbleParse|). We have
% written an autonomous function only for legibility. The number of lines of the
@@ -10787,6 +11278,10 @@
% \begin{macrocode}
function piton.CountNonEmptyLines ( code )
local count = 0
+% \end{macrocode}
+% The following code is not clear. We should try to replace it by use of the |string|
+% library of Lua.
+% \begin{macrocode}
count =
( Ct ( ( P " " ^ 0 * "\r"
+ ( 1 - P "\r" ) ^ 0 * C "\r" ) ^ 0
@@ -10794,36 +11289,19 @@
* -1
) / table.getn
) : match ( code )
- sprintL3
- ( string.format ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { %i } ]] , count ) )
-end
+ count = count + 1
% \end{macrocode}
%
-% \bigskip
% \begin{macrocode}
-function piton.CountLinesFile ( name )
- local count = 0
- for line in io.lines ( name ) do count = count + 1 end
+ if piton.beamer then
+ count = count - 2 * CountBeamerEnvironments ( code )
+ end
sprintL3
- ( string.format ( [[ \int_gset:Nn \g_@@_nb_lines_int { %i } ]], count ) )
+ ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { ]] .. count .. "}" )
end
% \end{macrocode}
%
%
-% \bigskip
-% \begin{macrocode}
-function piton.CountNonEmptyLinesFile ( name )
- local count = 0
- for line in io.lines ( name ) do
- if not ( ( P " " ^ 0 * -1 ) : match ( line ) ) then
- count = count + 1
- end
- end
- sprintL3
- ( string.format ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { % i } ]] , count ) )
-end
-% \end{macrocode}
-%
%
% \bigskip
% The following function stores in |\l_@@_first_line_int| and
@@ -10832,17 +11310,17 @@
%
% |s| is the marker of the beginning and |t| is the marker of the end.
% \begin{macrocode}
-function piton.ComputeRange(s,t,file_name)
+function piton.ComputeRange ( s , t , file_name )
local first_line = -1
local count = 0
local last_found = false
for line in io.lines ( file_name ) do
if first_line == -1 then
- if string.sub ( line , 1 , #s ) == s then
+ if line : sub ( 1 , #s ) == s then
first_line = count
end
else
- if string.sub ( line , 1 , #t ) == t then
+ if line : sub ( 1 , #t ) == t then
last_found = true
break
end
@@ -10852,13 +11330,13 @@
if first_line == -1 then
sprintL3 [[ \@@_error_or_warning:n { begin~marker~not~found } ]]
else
- if last_found == false then
+ if not last_found then
sprintL3 [[ \@@_error_or_warning:n { end~marker~not~found } ]]
end
end
sprintL3 (
[[ \int_set:Nn \l_@@_first_line_int { ]] .. first_line .. ' + 2 }'
- .. [[ \int_set:Nn \l_@@_last_line_int { ]] .. count .. ' }' )
+ .. [[ \global \l_@@_last_line_int = ]] .. count )
end
% \end{macrocode}
%
@@ -10998,21 +11476,52 @@
piton.lines_status = lines_status
end
% \end{macrocode}
+%
+% \begin{macrocode}
+function piton.TranslateBeamerEnv ( code )
+ local s
+ s =
+ (
+ Ct (
+ (
+ space ^ 0
+ * C (
+ ( P "\\begin{" + "\\end{" )
+ * beamerEnvironments * "}" * ( 1 - P "\r" ) ^ 0 * "\r"
+ )
+ + C ( ( 1 - P "\r" ) ^ 0 * "\r" )
+ ) ^ 0
+ *
+ (
+ (
+ space ^ 0
+ * C (
+ ( P "\\begin{" + "\\end{" )
+ * beamerEnvironments * "}" * ( 1 - P "\r" ) ^ 0 * -1
+ )
+ + C ( ( 1 - P "\r" ) ^ 1 ) * -1
+ ) ^ -1
+ )
+ ) ^ -1 / table.concat
+ ) : match ( code )
+ sprintL3 ( [[ \tl_set:Nn \l_@@_listing_tl { ]] )
+ tex.sprint ( luatexbase.catcodetables.other , s )
+ sprintL3 ( "}" )
+end
+% \end{macrocode}
%
-
-%
% \bigskip
% \subsubsection{To create new languages with the syntax of listings}
%
% \begin{macrocode}
function piton.new_language ( lang , definition )
- lang = string.lower ( lang )
+ lang = lang : lower ( )
% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
local alpha , digit = lpeg.alpha , lpeg.digit
- local extra_letters = { "@" , "_" , "$" } -- $
+ local extra_letters = { "@" , "_" , "$" } --
% \end{macrocode}
%
%
@@ -11044,7 +11553,7 @@
% (In the following \textsc{lpeg} we have a problem when we try to add |{| and
% |}|).
% \begin{macrocode}
- local other = S ":_ at +-*/<>!?;.()[]~^=#&\"\'\\$" -- $
+ local other = S ":_ at +-*/<>!?;.()[]~^=#&\"\'\\$" --
local extra_others = { }
% \end{macrocode}
%
@@ -11069,7 +11578,7 @@
%
% \bigskip
% Now, the first transformation of the definition of the language, as provided
-% by the final user in the argument |definition| of |piton.new_language|.
+% by the end user in the argument |definition| of |piton.new_language|.
% \begin{macrocode}
local def_table
if ( S ", " ^ 0 * -1 ) : match ( definition ) then
@@ -11089,7 +11598,7 @@
def_table = cut_definition : match ( definition )
end
% \end{macrocode}
-% The definition of the language, provided by the final user of \pkg{piton} is
+% The definition of the language, provided by the end user of \pkg{piton} is
% now in the Lua table |def_table|. We will use it \emph{several times}.
%
% \medskip
@@ -11218,8 +11727,7 @@
function keyword_to_lpeg ( name ) return
Q ( Cmt (
C ( identifier ) ,
- function ( s , i , a ) return
- string.upper ( a ) == string.upper ( name )
+ function ( _ , _ , a ) return a : upper ( ) == name : upper ( )
end
)
)
@@ -11511,7 +12019,6 @@
LPEG2[lang] =
Ct (
( space ^ 0 * P "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \@@_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -11561,8 +12068,8 @@
LPEG2[lang] =
Ct (
( space ^ 0 * P "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \@@_begin_line: ]]
+ * Beamer
* SpaceIndentation ^ 0
* LPEG1[lang]
* -1
@@ -11583,7 +12090,7 @@
file : close ( )
else
sprintL3
- ( [[ \@@_error_or_warning:nn { FileError } { ]] .. file_name .. [[ } ]] )
+ ( [[ \@@_error_or_warning:nn { FileError } { ]] .. file_name .. "}" )
end
end
% \end{macrocode}
@@ -11592,7 +12099,7 @@
for file_name , file_content in pairs ( piton.join_files ) do
pdf.immediateobj("stream", file_content)
tex.print
- (
+ (
[[ \pdfextension annot width 0pt height 0pt depth 0pt ]]
..
% \end{macrocode}
@@ -11615,12 +12122,11 @@
% \begin{macrocode}
[[ /FS << /Type /Filespec /UF <]] .. file_name .. [[>]]
..
- [[ /EF << /F \pdffeedback lastobj 0 R >> >> } ]]
+ [[ /EF << /F \pdffeedback lastobj 0 R >> >> } ]]
)
end
end
-
%</LUA>
% \end{macrocode}
%
@@ -11629,7 +12135,14 @@
% \vspace{1cm}
% \section{History}
%
-% The successive versions of the file |piton.sty| provided by TeXLive are available on the
+%
+% The development of the extension \pkg{piton} is done on the following GitHub
+% repository:
+%
+% \verb|https://github.com/fpantigny/piton|
+%
+% \medskip
+% The successive versions of the file |piton.sty| provided by TeXLive are also available on the
% \textsc{svn} server of TeXLive:
%
% \nobreak
@@ -11639,12 +12152,7 @@
% \nolinkurl{https://tug.org/svn/texlive/trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty}
% }
%
-% \medskip
-% The development of the extension \pkg{piton} is done on the following GitHub
-% repository:
%
-% \verb|https://github.com/fpantigny/piton|
-%
% \subsection*{Changes between versions 4.7 and 4.8}
%
% New key |\rowcolor|
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2025-08-30 19:46:54 UTC (rev 76188)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2025-08-30 19:47:06 UTC (rev 76189)
@@ -20,7 +20,7 @@
-- -------------------------------------------
--
-- This file is part of the LuaLaTeX package 'piton'.
-piton_version = "4.8a" -- 2025/08/19
+piton_version = "4.8b" -- 2025/08/30
@@ -44,7 +44,7 @@
lpeg.locale(lpeg)
local Q
function Q ( pattern )
- return Ct ( Cc ( luatexbase.catcodetables.CatcodeTableOther ) * C ( pattern ) )
+ return Ct ( Cc ( luatexbase.catcodetables.other ) * C ( pattern ) )
end
local L
function L ( pattern ) return
@@ -136,7 +136,8 @@
local Punct = Q ( S ".,:;!" )
local Tab = "\t" * Lc [[ \__piton_tab: ]]
-local SpaceIndentation = Lc [[ \__piton_leading_space: ]] * Q " "
+local SpaceIndentation
+ = Lc [[ \__piton_leading_space: \__piton_space_indentation: ]] * P " "
local Delim = Q ( S "[({})]" )
local SpaceInString = space * Lc [[ \l__piton_space_in_string_tl ]]
@@ -160,20 +161,6 @@
for _ , x in ipairs ( beamer_environments ) do
beamerEnvironments = beamerEnvironments + P ( x )
end
-local beamerBeginEnvironments =
- ( space ^ 0 *
- L
- (
- P [[\begin{]] * beamerEnvironments * "}"
- * ( "<" * ( 1 - P ">" ) ^ 0 * ">" ) ^ -1
- )
- * "\r"
- ) ^ 0
-local beamerEndEnvironments =
- ( space ^ 0 *
- L ( P [[\end{]] * beamerEnvironments * "}" )
- * "\r"
- ) ^ 0
local LPEG0 = { }
local LPEG1 = { }
local LPEG2 = { }
@@ -275,10 +262,11 @@
lpeg = lpeg +
Ct ( Cc "Open"
* C (
- P ( [[\begin{]] .. x .. "}" )
- * ( "<" * ( 1 - P ">") ^ 0 * ">" ) ^ -1
+ P ( [[\begin{]] .. x .. "}" )
+ * ( "<" * ( 1 - P ">") ^ 0 * ">" ) ^ -1
)
- * Cc ( [[\end{]] .. x .. "}" )
+ * space ^ 0 * ( P "\r" ) ^ 1 -- added 25/08/23
+ * Cc ( [[\end{]] .. x .. "}" )
)
* (
( ( 1 - P ( [[\end{]] .. x .. "}" ) ) ^ 0 )
@@ -297,7 +285,7 @@
P "$" * K ( 'Comment.Math' , ( 1 - S "$\r" ) ^ 1 ) * P "$" -- $
local Prompt =
K ( 'Prompt' , ( P ">>>" + "..." ) * P " " ^ -1 )
- * Lc [[ \rowcolor { \l__piton_prompt_bg_color_tl } ]]
+ * Lc [[ \rowcolor { \l__piton_prompt_bg_color_tl } ]]
local EOL =
P "\r"
*
@@ -304,20 +292,7 @@
(
space ^ 0 * -1
+
- Ct (
- Cc "EOL"
- *
- Ct ( Lc [[ \__piton_end_line: ]]
- * beamerEndEnvironments
- *
- (
- -1
- +
- beamerBeginEnvironments
- * Lc [[ \__piton_par:\__piton_begin_line: ]]
- )
- )
- )
+ Cc "EOL"
)
* ( SpaceIndentation ^ 0 * # ( 1 - S " \r" ) ) ^ -1
local CommentLaTeX =
@@ -588,8 +563,8 @@
+ Space
+ Tab
+ Escape + EscapeMath
+ + Beamer
+ CommentLaTeX
- + Beamer
+ DetectedCommands
+ Prompt
+ LongString
@@ -615,7 +590,6 @@
LPEG2.python =
Ct (
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -1017,7 +991,6 @@
* K ( 'TypeExpression' , ( 1 - P "\r" ) ^ 0 )
+
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( ( space * Lc [[ \__piton_trailing_space: ]] ) ^ 1 * -1
@@ -1132,7 +1105,6 @@
LPEG2.c =
Ct (
( space ^ 0 * P "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -1147,7 +1119,7 @@
Lc [[ {\PitonStyle{Keyword}{ ]]
* Q ( Cmt (
C ( letter * alphanum ^ 0 ) ,
- function ( s , i , a ) return string.upper ( a ) == name end
+ function ( _ , _ , a ) return a : upper ( ) == name end
)
)
* Lc "}}"
@@ -1196,12 +1168,12 @@
C ( identifier ) /
(
function ( s )
- if set_keywords[string.upper(s)] then return
+ if set_keywords [ s : upper ( ) ] then return
{ [[{\PitonStyle{Keyword}{]] } ,
{ luatexbase.catcodetables.other , s } ,
{ "}}" }
else
- if set_builtins[string.upper(s)] then return
+ if set_builtins [ s : upper ( ) ] then return
{ [[{\PitonStyle{Name.Builtin}{]] } ,
{ luatexbase.catcodetables.other , s } ,
{ "}}" }
@@ -1297,7 +1269,6 @@
LPEG2.sql =
Ct (
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -1360,7 +1331,6 @@
LPEG2.minimal =
Ct (
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -1406,7 +1376,6 @@
LPEG2.verbatim =
Ct (
( space ^ 0 * "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -1414,10 +1383,99 @@
* Lc [[ \__piton_end_line: ]]
)
end
+--EXPL expl
+do
+ local Comment =
+ WithStyle
+ ( 'Comment.Internal' ,
+ Q "%" * ( CommentMath + Q ( ( 1 - S "$\r" ) ^ 1 ) ) ^ 0 -- $
+ )
+ * ( EOL + -1 )
+ local analyze_cs
+ function analyze_cs ( s )
+ local i = s : find ( ":" )
+ if i then
+ local name = s : sub ( 2 , i - 1 )
+ local parts = name : explode ( "_" )
+ local module = parts[1]
+ if module == "" then module = parts[3] end
+ return
+ { [[{\OptionalLocalPitonStyle{Module.]] .. module .. "}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}" }
+ else
+ local p = s : sub ( 1 , 3 )
+ if p == [[\l_]] or p == [[\g_]] or p == [[\c_]] then
+ local scope = s : sub(2,2)
+ local parts = s : explode ( "_" )
+ local module = parts[2]
+ if module == "" then module = parts[3] end
+ local type = parts[#parts]
+ return
+ { [[{\OptionalLocalPitonStyle{Scope.]] .. scope .. "}{" } ,
+ { [[{\OptionalLocalPitonStyle{Module.]] .. module .. "}{" } ,
+ { [[{\OptionalLocalPitonStyle{Type.]] .. type .. "}{" } ,
+ { luatexbase.catcodetables.other , s } ,
+ { "}}}}}}" }
+ else
+ return { luatexbase.catcodetables.other , s }
+ end
+ end
+ end
+ local braces =
+ P { "E" ,
+ E = ( "{" * V "E" * "}" + ( 1 - S "{}" ) ) ^ 0
+ }
+
+ if piton.beamer then Beamer = Compute_Beamer ( 'expl' , braces ) end
+
+ DetectedCommands =
+ Compute_DetectedCommands ( 'expl' , braces )
+ + Compute_RawDetectedCommands ( 'expl' , braces )
+
+ LPEG_cleaner.expl = Compute_LPEG_cleaner ( 'expl' , braces )
+ local control_sequence = P "\\" * ( R "Az" + "_" + ":" + "@" ) ^ 1
+ local ControlSequence = C ( control_sequence ) / analyze_cs
+ local def_function
+ = P [[\cs_]]
+ * ( P "set" + "new")
+ * ( P "_protected" ) ^ -1
+ * P ":N" * ( P "p" ) ^ -1 * "n"
+ local DefFunction =
+ C ( def_function ) / analyze_cs
+ * Space
+ * Lc ( [[ {\PitonStyle{Name.Function}{ ]] )
+ * ControlSequence -- Q ( ControlSequence ) ?
+ * Lc "}}"
+ local Word = Q ( ( 1 - S " \r" ) ^ 1 )
+
+ local Main =
+ space ^ 0 * EOL
+ + Space
+ + Tab
+ + Escape + EscapeMath
+ + Beamer
+ + Comment
+ + DetectedCommands
+ + DefFunction
+ + ControlSequence
+ + Word
+ LPEG1.expl = Main ^ 0
+
+ LPEG2.expl =
+ Ct (
+ ( space ^ 0 * "\r" ) ^ -1
+ * Lc [[ \__piton_begin_line: ]]
+ * SpaceIndentation ^ 0
+ * ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
+ * -1
+ * Lc [[ \__piton_end_line: ]]
+ )
+end
function piton.Parse ( language , code )
piton.language = language
local t = LPEG2[language] : match ( code )
- if t == nil then
+ if not t then
sprintL3 [[ \__piton_error_or_warning:n { SyntaxError } ]]
return -- to exit in force the function
end
@@ -1424,16 +1482,12 @@
local left_stack = {}
local right_stack = {}
for _ , one_item in ipairs ( t ) do
- if one_item[1] == "EOL" then
- for _ , s in ipairs ( right_stack ) do
- tex.sprint ( s )
+ if one_item == "EOL" then
+ for i = #right_stack, 1, -1 do
+ tex.sprint ( right_stack[i] )
end
- for _ , s in ipairs ( one_item[2] ) do
- tex.tprint ( s )
- end
- for _ , s in ipairs ( left_stack ) do
- tex.sprint ( s )
- end
+ sprintL3 ( [[ \__piton_end_line: \__piton_par: \__piton_begin_line: ]] )
+ tex.sprint ( table.concat ( left_stack ) )
else
if one_item[1] == "Open" then
tex.sprint ( one_item[2] )
@@ -1451,8 +1505,8 @@
end
end
end
-local cr_file_lines
-function cr_file_lines ( filename )
+local my_file_lines
+function my_file_lines ( filename )
local f = io.open ( filename , 'rb' )
local s = f : read ( '*a' )
f : close ( )
@@ -1461,7 +1515,7 @@
function piton.ReadFile ( name , first_line , last_line )
local s = ''
local i = 0
- for line in cr_file_lines ( name ) do
+ for line in my_file_lines ( name ) do
i = i + 1
if i >= first_line then
s = s .. '\r' .. line
@@ -1468,18 +1522,12 @@
end
if i >= last_line then break end
end
- if string.byte ( s , 1 ) == 13 then
- if string.byte ( s , 2 ) == 239 then
- if string.byte ( s , 3 ) == 187 then
- if string.byte ( s , 4 ) == 191 then
- s = string.sub ( s , 5 , -1 )
- end
- end
- end
+ if s : sub ( 1 , 4 ) == string.char ( 13 , 239 , 187 , 191 ) then
+ s = s : sub ( 5 , -1 )
end
sprintL3 ( [[ \tl_set:Nn \l__piton_listing_tl { ]])
- tex.sprint ( luatexbase.catcodetables.CatcodeTableOther , s )
- sprintL3 ( [[ } ]] )
+ tex.sprint ( luatexbase.catcodetables.other , s )
+ sprintL3 ( "}" )
end
function piton.RetrieveGobbleParse ( lang , n , splittable , code )
local s
@@ -1521,17 +1569,7 @@
local EnvGobbleLPEG =
( ( 1 - P "\r" ) ^ 0 * "\r" ) ^ 0
* Ct ( C " " ^ 0 * -1 ) / table.getn
-local remove_before_cr
-function remove_before_cr ( input_string )
- local match_result = ( P "\r" ) : match ( input_string )
- if match_result then return
- string.sub ( input_string , match_result )
- else return
- input_string
- end
-end
function piton.Gobble ( n , code )
- code = remove_before_cr ( code )
if n == 0 then return
code
else
@@ -1566,13 +1604,11 @@
piton.last_language = lang
piton.CountLines ( piton.last_code )
piton.Parse ( lang , piton.last_code )
- sprintL3 [[ \vspace{2.5pt} ]]
- sprintL3 [[ \par ]]
piton.join_and_write ( )
end
function piton.join_and_write ( )
if piton.join ~= '' then
- if piton.join_files [ piton.join ] == nil then
+ if not piton.join_files [ piton.join ] then
piton.join_files [ piton.join ] = piton.get_last_code ( )
else
piton.join_files [ piton.join ] =
@@ -1592,7 +1628,7 @@
end
end
if file_name ~= '' then
- if piton.write_files [ file_name ] == nil then
+ if not piton.write_files [ file_name ] then
piton.write_files [ file_name ] = piton.get_last_code ( )
else
piton.write_files [ file_name ] =
@@ -1648,20 +1684,41 @@
end
piton.string_between_chunks =
[[ \par \l__piton_split_separation_tl \mode_leave_vertical: ]]
- .. [[ \int_gzero:N \g__piton_line_int ]]
+ .. [[ \global \g__piton_line_int = 0 ]]
function piton.get_last_code ( )
return LPEG_cleaner[piton.last_language] : match ( piton.last_code )
- : gsub('\r\n','\n') : gsub('\r','\n')
+ : gsub ( '\r\n?' , '\n' )
end
+local CountBeamerEnvironments
+function CountBeamerEnvironments ( code ) return
+ (
+ Ct (
+ (
+ P "\\begin{" * beamerEnvironments * ( 1 - P "\r" ) ^ 0 * C "\r"
+ +
+ ( 1 - P "\r" ) ^ 0 * "\r"
+ ) ^ 0
+ * ( 1 - P "\r" ) ^ 0
+ * -1
+ ) / table.getn
+ ) : match ( code )
+end
function piton.CountLines ( code )
- local count = 0
+ local count
count =
( Ct ( ( ( 1 - P "\r" ) ^ 0 * C "\r" ) ^ 0
- * ( ( 1 - P "\r" ) ^ 1 * Cc "\r" ) ^ -1
+ *
+ (
+ space ^ 0 * ( 1 - P "\r" - space ) * ( 1 - P "\r" ) ^ 0 * Cc "\r"
+ + space ^ 0
+ ) ^ -1
* -1
) / table.getn
) : match ( code )
- sprintL3 ( string.format ( [[ \int_gset:Nn \g__piton_nb_lines_int { %i } ]] , count ) )
+ if piton.beamer then
+ count = count - 2 * CountBeamerEnvironments ( code )
+ end
+ sprintL3 ( [[ \int_gset:Nn \g__piton_nb_lines_int { ]] .. count .. "}" )
end
function piton.CountNonEmptyLines ( code )
local count = 0
@@ -1672,36 +1729,24 @@
* -1
) / table.getn
) : match ( code )
- sprintL3
- ( string.format ( [[ \int_set:Nn \l__piton_nb_non_empty_lines_int { %i } ]] , count ) )
-end
-function piton.CountLinesFile ( name )
- local count = 0
- for line in io.lines ( name ) do count = count + 1 end
- sprintL3
- ( string.format ( [[ \int_gset:Nn \g__piton_nb_lines_int { %i } ]], count ) )
-end
-function piton.CountNonEmptyLinesFile ( name )
- local count = 0
- for line in io.lines ( name ) do
- if not ( ( P " " ^ 0 * -1 ) : match ( line ) ) then
- count = count + 1
- end
+ count = count + 1
+ if piton.beamer then
+ count = count - 2 * CountBeamerEnvironments ( code )
end
sprintL3
- ( string.format ( [[ \int_set:Nn \l__piton_nb_non_empty_lines_int { % i } ]] , count ) )
+ ( [[ \int_set:Nn \l__piton_nb_non_empty_lines_int { ]] .. count .. "}" )
end
-function piton.ComputeRange(s,t,file_name)
+function piton.ComputeRange ( s , t , file_name )
local first_line = -1
local count = 0
local last_found = false
for line in io.lines ( file_name ) do
if first_line == -1 then
- if string.sub ( line , 1 , #s ) == s then
+ if line : sub ( 1 , #s ) == s then
first_line = count
end
else
- if string.sub ( line , 1 , #t ) == t then
+ if line : sub ( 1 , #t ) == t then
last_found = true
break
end
@@ -1711,13 +1756,13 @@
if first_line == -1 then
sprintL3 [[ \__piton_error_or_warning:n { begin~marker~not~found } ]]
else
- if last_found == false then
+ if not last_found then
sprintL3 [[ \__piton_error_or_warning:n { end~marker~not~found } ]]
end
end
sprintL3 (
[[ \int_set:Nn \l__piton_first_line_int { ]] .. first_line .. ' + 2 }'
- .. [[ \int_set:Nn \l__piton_last_line_int { ]] .. count .. ' }' )
+ .. [[ \global \l__piton_last_line_int = ]] .. count )
end
function piton.ComputeLinesStatus ( code , splittable )
local lpeg_line_beamer
@@ -1789,11 +1834,40 @@
end
piton.lines_status = lines_status
end
-
+function piton.TranslateBeamerEnv ( code )
+ local s
+ s =
+ (
+ Ct (
+ (
+ space ^ 0
+ * C (
+ ( P "\\begin{" + "\\end{" )
+ * beamerEnvironments * "}" * ( 1 - P "\r" ) ^ 0 * "\r"
+ )
+ + C ( ( 1 - P "\r" ) ^ 0 * "\r" )
+ ) ^ 0
+ *
+ (
+ (
+ space ^ 0
+ * C (
+ ( P "\\begin{" + "\\end{" )
+ * beamerEnvironments * "}" * ( 1 - P "\r" ) ^ 0 * -1
+ )
+ + C ( ( 1 - P "\r" ) ^ 1 ) * -1
+ ) ^ -1
+ )
+ ) ^ -1 / table.concat
+ ) : match ( code )
+ sprintL3 ( [[ \tl_set:Nn \l__piton_listing_tl { ]] )
+ tex.sprint ( luatexbase.catcodetables.other , s )
+ sprintL3 ( "}" )
+end
function piton.new_language ( lang , definition )
- lang = string.lower ( lang )
+ lang = lang : lower ( )
local alpha , digit = lpeg.alpha , lpeg.digit
- local extra_letters = { "@" , "_" , "$" } -- $
+ local extra_letters = { "@" , "_" , "$" } --
function add_to_letter ( c )
if c ~= " " then table.insert ( extra_letters , c ) end
end
@@ -1800,7 +1874,7 @@
function add_to_digit ( c )
if c ~= " " then digit = digit + c end
end
- local other = S ":_ at +-*/<>!?;.()[]~^=#&\"\'\\$" -- $
+ local other = S ":_ at +-*/<>!?;.()[]~^=#&\"\'\\$" --
local extra_others = { }
function add_to_other ( c )
if c ~= " " then
@@ -1902,8 +1976,7 @@
function keyword_to_lpeg ( name ) return
Q ( Cmt (
C ( identifier ) ,
- function ( s , i , a ) return
- string.upper ( a ) == string.upper ( name )
+ function ( _ , _ , a ) return a : upper ( ) == name : upper ( )
end
)
)
@@ -2109,7 +2182,6 @@
LPEG2[lang] =
Ct (
( space ^ 0 * P "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
* SpaceIndentation ^ 0
* ( space ^ 1 * -1 + space ^ 0 * EOL + Main ) ^ 0
@@ -2154,8 +2226,8 @@
LPEG2[lang] =
Ct (
( space ^ 0 * P "\r" ) ^ -1
- * beamerBeginEnvironments
* Lc [[ \__piton_begin_line: ]]
+ * Beamer
* SpaceIndentation ^ 0
* LPEG1[lang]
* -1
@@ -2171,7 +2243,7 @@
file : close ( )
else
sprintL3
- ( [[ \__piton_error_or_warning:nn { FileError } { ]] .. file_name .. [[ } ]] )
+ ( [[ \__piton_error_or_warning:nn { FileError } { ]] .. file_name .. "}" )
end
end
for file_name , file_content in pairs ( piton.join_files ) do
@@ -2186,7 +2258,7 @@
..
[[ /FS << /Type /Filespec /UF <]] .. file_name .. [[>]]
..
- [[ /EF << /F \pdffeedback lastobj 0 R >> >> } ]]
+ [[ /EF << /F \pdffeedback lastobj 0 R >> >> } ]]
)
end
end
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2025-08-30 19:46:54 UTC (rev 76188)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2025-08-30 19:47:06 UTC (rev 76189)
@@ -19,8 +19,8 @@
%% LaTeX version 2005/12/01 or later.
%% -------------------------------------------
%%
-\def\PitonFileVersion{4.8a}
-\def\PitonFileDate{2025/08/19}
+\def\PitonFileVersion{4.8b}
+\def\PitonFileDate{2025/08/30}
@@ -35,17 +35,19 @@
{piton}
{\PitonFileDate}
{\PitonFileVersion}
- {Highlight informatic listings with LPEG on LuaLaTeX}
+ {Highlight computer listings with LPEG on LuaLaTeX}
\msg_new:nnn { piton } { latex-too-old }
{
Your~LaTeX~release~is~too~old. \\
You~need~at~least~the~version~of~2023-11-01
}
+\providecommand { \IfFormatAtLeastTF } { \@ifl at t@r \fmtversion }
\IfFormatAtLeastTF
{ 2023-11-01 }
{ }
{ \msg_fatal:nn { piton } { latex-too-old } }
\RequirePackage { amstext }
+\RequirePackage { transparent }
\ProvideDocumentCommand { \IfPackageLoadedT } { m m }
{ \IfPackageLoadedTF { #1 } { #2 } { } }
@@ -52,8 +54,8 @@
\ProvideDocumentCommand { \IfPackageLoadedF } { m m }
{ \IfPackageLoadedTF { #1 } { } { #2 } }
-\ProvideDocumentCommand { \IfClassLoadedF } { m m }
- { \IfClassLoadedTF { #1 } { } { #2 } }
+\ProvideDocumentCommand { \IfClassLoadedT } { m m }
+ { \IfClassLoadedTF { #1 } { #2 } { } }
\ProvideDocumentCommand { \IfClassLoadedF } { m m }
{ \IfClassLoadedTF { #1 } { } { #2 } }
@@ -93,6 +95,11 @@
Since~you~use~Beamer,~don't~forget~to~use~piton~in~frames~with~
the~key~'fragile'.\\
}
+ \IfClassLoadedT { ltx-talk }
+ {
+ Since~you~use~'ltx-talk',~don't~forget~to~use~piton~in~
+ environments~'frame*'.\\
+ }
That~error~is~fatal.
}
\sys_if_engine_luatex:F { \__piton_fatal:n { LuaLaTeX~mandatory } }
@@ -135,12 +142,9 @@
That~key~will~be~ignored.
}
\ProcessKeyOptions
-\IfClassLoadedTF { beamer }
- { \bool_gset_true:N \g__piton_beamer_bool }
- {
- \IfPackageLoadedT { beamerarticle }
- { \bool_gset_true:N \g__piton_beamer_bool }
- }
+\IfClassLoadedT { beamer } { \bool_gset_true:N \g__piton_beamer_bool }
+\IfClassLoadedT { ltx-talk } { \bool_gset_true:N \g__piton_beamer_bool }
+\IfPackageLoadedT { beamerarticle } { \bool_gset_true:N \g__piton_beamer_bool }
\lua_now:e
{
piton = piton~or~{ }
@@ -197,7 +201,6 @@
\dim_new:N \l__piton_tmpc_dim
\tl_new:N \l__piton_listing_tl
\box_new:N \g__piton_output_box
-\box_new:N \l__piton_line_box
\str_new:N \l_piton_language_str
\str_set:Nn \l_piton_language_str { python }
\tl_new:N \g_piton_last_code_tl
@@ -204,6 +207,7 @@
\seq_new:N \l__piton_path_seq
\str_new:N \l__piton_path_write_str
\bool_new:N \l__piton_tcolorbox_bool
+\dim_new:N \l__piton_tcb_margins_dim
\str_new:N \l__piton_box_str
\bool_new:N \l__piton_in_PitonOptions_bool
\bool_new:N \l__piton_in_PitonInputFile_bool
@@ -241,10 +245,11 @@
\tl_new:N \l__piton_end_of_broken_line_tl
\tl_set:Nn \l__piton_end_of_broken_line_tl { \hspace* { 0.5em } \textbackslash }
\bool_new:N \l__piton_break_lines_in_piton_bool
+\bool_new:N \l__piton_minimize_width_bool
\dim_new:N \l__piton_width_dim
-\dim_new:N \g__piton_width_dim
+\dim_new:N \l__piton_listing_width_dim
\dim_new:N \l__piton_code_width_dim
-\bool_new:N \l__piton_minimize_width_bool
+\box_new:N \l__piton_line_box
\dim_new:N \l__piton_left_margin_dim
\bool_new:N \l__piton_left_margin_auto_bool
\dim_new:N \l__piton_numbers_sep_dim
@@ -412,11 +417,8 @@
{
tex.sprint
(
- luatexbase.catcodetables.expl ,
- tostring
- ( piton.empty_lines
- [ \int_eval:n { \g__piton_line_int + 1 } ]
- )
+ piton.empty_lines
+ [ \int_eval:n { \g__piton_line_int + 1 } ]
)
}
}
@@ -444,7 +446,7 @@
\__piton_replace_spaces:n { #1 }
\strut \hfil
}
- \dim_compare:nNnTF { \box_wd:N \l_tmpa_box } < \l__piton_code_width_dim
+ \dim_compare:nNnTF { \box_wd:N \l_tmpa_box } < \l__piton_code_width_dim
{ \box_use:N \l_tmpa_box }
{ \__piton_vtop_of_code:n { #1 } }
}
@@ -452,7 +454,6 @@
}
\box_set_dp:Nn \l__piton_line_box { \box_dp:N \l__piton_line_box + 1.25 pt }
\box_set_ht:Nn \l__piton_line_box { \box_ht:N \l__piton_line_box + 1.25 pt }
- \dim_gset_eq:NN \g__piton_width_dim \l__piton_width_dim
\box_use_drop:N \l__piton_line_box
\group_end:
\g__piton_after_line_tl
@@ -483,7 +484,7 @@
{ \dim_sub:Nn \l_tmpa_dim { 2.5 pt } }
\bool_if:NTF \g__piton_color_is_none_bool
{ \dim_zero:N \l_tmpb_dim }
- { \dim_set_eq:NN \l_tmpb_dim \g__piton_width_dim }
+ { \dim_set_eq:NN \l_tmpb_dim \l__piton_listing_width_dim }
\dim_set:Nn \l__piton_tmpc_dim { \box_ht:N \l__piton_line_box }
\dim_compare:nNnTF \l__piton_rounded_corners_dim > \c_zero_dim
{
@@ -528,7 +529,7 @@
{ \skip_vertical:n { 2.5 pt } }
\skip_vertical:n { - \box_ht_plus_dp:N \l__piton_line_box }
\box_use_drop:N \l__piton_line_box
- }
+ }
}
\cs_set_protected:Npn \__piton_compute_and_set_color:
{
@@ -618,7 +619,6 @@
\bool_new:N \l__piton_skip_empty_lines_bool
\bool_set_true:N \l__piton_skip_empty_lines_bool
\bool_new:N \l__piton_line_numbers_absolute_bool
-\tl_new:N \l__piton_line_numbers_format_bool
\tl_new:N \l__piton_line_numbers_format_tl
\tl_set:Nn \l__piton_line_numbers_format_tl { \footnotesize \color { gray } }
\bool_new:N \l__piton_label_empty_lines_bool
@@ -630,9 +630,9 @@
\bool_new:N \g__piton_label_as_zlabel_bool
\keys_define:nn { PitonOptions / marker }
{
- beginning .code:n = \cs_set:Nn \__piton_marker_beginning:n { #1 } ,
+ beginning .cs_set:Np = \__piton_marker_beginning:n #1 ,
beginning .value_required:n = true ,
- end .code:n = \cs_set:Nn \__piton_marker_end:n { #1 } ,
+ end .cs_set:Np = \__piton_marker_end:n #1 ,
end .value_required:n = true ,
include-lines .bool_set:N = \l__piton_marker_include_lines_bool ,
include-lines .default:n = true ,
@@ -691,24 +691,6 @@
}
\keys_define:nn { PitonOptions }
{
- rounded-corners .code:n =
- \IfPackageLoadedTF { tikz }
- { \dim_set:Nn \l__piton_rounded_corners_dim { #1 } }
- { \__piton_err_rounded_corners_without_Tikz: } ,
- rounded-corners .default:n = 4 pt ,
- tcolorbox .code:n =
- \IfPackageLoadedTF { tcolorbox }
- {
- \pgfkeysifdefined { / tcb / libload / breakable }
- {
- \str_if_eq:eeTF { #1 } { true }
- { \bool_set_true:N \l__piton_tcolorbox_bool }
- { \bool_set_false:N \l__piton_tcolorbox_bool }
- }
- { \__piton_error:n { library~breakable~not~loaded } }
- }
- { \__piton_error:n { tcolorbox~not~loaded } } ,
- tcolorbox .default:n = true ,
box .choices:nn = { c , t , b , m }
{ \str_set_eq:NN \l__piton_box_str \l_keys_choice_tl } ,
box .default:n = c ,
@@ -717,7 +699,14 @@
break-numbers-anywhere .bool_set:N = \l__piton_break_numbers_anywhere_bool ,
break-numbers-anywhere .default:n = true ,
detected-commands .code:n =
- \clist_put_right:Nn \l__piton_detected_commands_clist { #1 } ,
+ \clist_if_in:nnTF { #1 } { rowcolor }
+ {
+ \__piton_error:n { rowcolor~in~detected-commands }
+ \clist_set:Nn \l_tmpa_clist { #1 }
+ \clist_remove_all:Nn \l_tmpa_clist { rowcolor }
+ \clist_put_right:No \l__piton_detected_commands_clist \l_tmpa_clist
+ }
+ { \clist_put_right:Nn \l__piton_detected_commands_clist { #1 } } ,
detected-commands .value_required:n = true ,
detected-commands .usage:n = preamble ,
vertical-detected-commands .code:n = \__piton_vertical_commands:n { #1 } ,
@@ -802,6 +791,10 @@
split-separation .tl_set:N = \l__piton_split_separation_tl ,
split-separation .value_required:n = true ,
+ add-to-split-separation .code:n =
+ \tl_put_right:Nn \l__piton_split_separation_tl { #1 } ,
+ add-to-split-separation .value_required:n = true ,
+
marker .code:n =
\bool_lazy_or:nnTF
\l__piton_in_PitonInputFile_bool
@@ -918,6 +911,37 @@
\bool_set_true:N \l__piton_line_numbers_bool
\bool_set_false:N \l__piton_skip_empty_lines_bool ,
}
+\hook_gput_code:nnn { begindocument } { . }
+ {
+ \keys_define:ne { PitonOptions }
+ {
+ \IfPackageLoadedTF { tikz }
+ {
+ rounded-corners .dim_set:N = \l__piton_rounded_corners_dim ,
+ rounded-corners .default:n = 4 pt
+ }
+ { rounded-corners .code:n = \__piton_err_rounded_corners_without_Tikz: }
+ }
+ \IfPackageLoadedTF { tcolorbox }
+ {
+ \pgfkeysifdefined { / tcb / libload / breakable }
+ {
+ \keys_define:nn { PitonOptions }
+ {
+ tcolorbox .bool_set:N = \l__piton_tcolorbox_bool ,
+ tcolorbox .default:n = true
+ }
+ }
+ {
+ \keys_define:nn { PitonOptions }
+ { tcolorbox .code:n = \__piton_error:n { library~breakable~not~loaded } }
+ }
+ }
+ {
+ \keys_define:nn { PitonOptions }
+ { tcolorbox .code:n = \__piton_error:n { tcolorbox~not~loaded } }
+ }
+ }
\cs_new_protected:Npn \__piton_err_rounded_corners_without_Tikz:
{
\__piton_error:n { rounded-corners~without~Tikz }
@@ -949,7 +973,9 @@
{
{
\l__piton_line_numbers_format_tl
+ \pdfextension literal { /Artifact << /ActualText (\space) >> BDC }
{ \int_to_arabic:n \g__piton_visual_line_int }
+ \pdfextension literal { EMC }
}
\skip_horizontal:N \l__piton_numbers_sep_dim
}
@@ -1092,10 +1118,8 @@
\__piton_replace_spaces:o \l_tmpa_tl
\group_end:
}
-\cs_new:Npn \__piton_pre_composition:
+\cs_new_protected:Npn \__piton_pre_composition:
{
- \legacy_if:nT { @inlabel } { \bool_set_true:N \l__piton_in_label_bool }
- \automatichyphenmode = 1
\dim_compare:nNnT \l__piton_width_dim = \c_zero_dim
{
\dim_set_eq:NN \l__piton_width_dim \linewidth
@@ -1102,6 +1126,21 @@
\str_if_empty:NF \l__piton_box_str
{ \bool_set_true:N \l__piton_minimize_width_bool }
}
+ \dim_set:Nn \l__piton_listing_width_dim
+ {
+ \bool_if:NTF \l__piton_tcolorbox_bool
+ {
+ \l__piton_width_dim -
+ ( \kvtcb at left@rule
+ + \kvtcb at leftupper
+ + \kvtcb at boxsep * 2
+ + \kvtcb at rightupper
+ + \kvtcb at right@rule )
+ }
+ { \l__piton_width_dim }
+ }
+ \legacy_if:nT { @inlabel } { \bool_set_true:N \l__piton_in_label_bool }
+ \automatichyphenmode = 1
\bool_if:NF \l__piton_resume_bool { \int_gzero:N \g__piton_visual_line_int }
\g__piton_def_vertical_commands_tl
\int_gzero:N \g__piton_line_int
@@ -1108,6 +1147,7 @@
\int_gzero:N \g__piton_nb_lines_int
\dim_zero:N \parindent
\dim_zero:N \lineskip
+ \dim_zero:N \parskip
\cs_set_eq:NN \rowcolor \__piton_rowcolor:n
\int_compare:nNnT \l__piton_bg_colors_int > { \c_zero_int }
{ \bool_set_true:N \l__piton_bg_bool }
@@ -1120,49 +1160,47 @@
\cs_set_eq:NN \zlabel \__piton_zlabel:n
}
{ \cs_set_eq:NN \label \__piton_label:n }
- \dim_zero:N \parskip
\l__piton_font_command_tl
}
-\cs_new_protected:Npn \__piton_compute_left_margin:nn #1 #2
+\cs_new_protected:Npn \__piton_compute_left_margin:
{
- \bool_lazy_and:nnT \l__piton_left_margin_auto_bool \l__piton_line_numbers_bool
+ \use:e
{
- \hbox_set:Nn \l_tmpa_box
- {
- \l__piton_line_numbers_format_tl
- \bool_if:NTF \l__piton_skip_empty_lines_bool
- {
- \lua_now:n
- { piton.#1(token.scan_argument()) }
- { #2 }
- \int_to_arabic:n
- { \g__piton_visual_line_int + \l__piton_nb_non_empty_lines_int }
- }
- {
- \int_to_arabic:n
- { \g__piton_visual_line_int + \g__piton_nb_lines_int }
- }
+ \bool_if:NTF \l__piton_skip_empty_lines_bool
+ { \lua_now:n { piton.CountNonEmptyLines(token.scan_argument()) } }
+ { \lua_now:n { piton.CountLines(token.scan_argument()) } }
+ { \l__piton_listing_tl }
+ }
+ \hbox_set:Nn \l_tmpa_box
+ {
+ \l__piton_line_numbers_format_tl
+ \int_to_arabic:n
+ {
+ \g__piton_visual_line_int
+ +
+ \bool_if:NTF \l__piton_skip_empty_lines_bool
+ { \l__piton_nb_non_empty_lines_int }
+ { \g__piton_nb_lines_int }
}
- \dim_set:Nn \l__piton_left_margin_dim
- { \box_wd:N \l_tmpa_box + \l__piton_numbers_sep_dim + 0.1 em }
}
+ \dim_set:Nn \l__piton_left_margin_dim
+ { \box_wd:N \l_tmpa_box + \l__piton_numbers_sep_dim + 0.1 em }
}
-\cs_generate_variant:Nn \__piton_compute_left_margin:nn { n o }
-\cs_new_protected:Npn \__piton_compute_width:
+\cs_new_protected:Npn \__piton_recompute_listing_width:
{
- \dim_gset:Nn \g__piton_width_dim { \box_wd:N \g__piton_output_box }
+ \dim_set:Nn \l__piton_listing_width_dim { \box_wd:N \g__piton_output_box }
\int_compare:nNnTF \l__piton_bg_colors_int > { \c_zero_int }
{
- \dim_gadd:Nn \g__piton_width_dim { 0.5 em }
+ \dim_add:Nn \l__piton_listing_width_dim { 0.5 em }
\dim_compare:nNnTF \l__piton_left_margin_dim = \c_zero_dim
- { \dim_gadd:Nn \g__piton_width_dim { 0.5 em } }
- { \dim_gadd:Nn \g__piton_width_dim \l__piton_left_margin_dim }
+ { \dim_add:Nn \l__piton_listing_width_dim { 0.5 em } }
+ { \dim_add:Nn \l__piton_listing_width_dim \l__piton_left_margin_dim }
}
- { \dim_gadd:Nn \g__piton_width_dim \l__piton_left_margin_dim }
+ { \dim_add:Nn \l__piton_listing_width_dim \l__piton_left_margin_dim }
}
\cs_new_protected:Npn \__piton_compute_code_width:
{
- \dim_set_eq:NN \l__piton_code_width_dim \l__piton_width_dim
+ \dim_set_eq:NN \l__piton_code_width_dim \l__piton_listing_width_dim
\int_compare:nNnTF \l__piton_bg_colors_int > { \c_zero_int }
{
\dim_sub:Nn \l__piton_code_width_dim { 0.5 em }
@@ -1172,62 +1210,60 @@
}
{ \dim_sub:Nn \l__piton_code_width_dim \l__piton_left_margin_dim }
}
-\NewDocumentCommand { \NewPitonEnvironment } { }
- { \__piton_DefinePitonEnvironment:nnnnn { New } }
-\NewDocumentCommand { \DeclarePitonEnvironment } { }
- { \__piton_DefinePitonEnvironment:nnnnn { Declare } }
-\NewDocumentCommand { \RenewPitonEnvironment } { }
- { \__piton_DefinePitonEnvironment:nnnnn { Renew } }
-\NewDocumentCommand { \ProvidePitonEnvironment } { }
- { \__piton_DefinePitonEnvironment:nnnnn { Provide } }
-\cs_new_protected:Npn \__piton_DefinePitonEnvironment:nnnnn #1 #2 #3 #4 #5
+\cs_new_protected:Npn \__piton_define_newpitonenvironment_old:
{
- \use:x
+ \cs_new_protected:Nn \__piton_DefinePitonEnvironment:nnnnn
{
- \cs_set_protected:Npn
- \use:c { __piton_collect_ #2 :w }
- ####1
- \c_backslash_str end \c_left_brace_str #2 \c_right_brace_str
- }
+ \use:x
{
- \group_end:
- \tl_set:Nn \l__piton_listing_tl { ##1 }
- \__piton_composition:
- \end { #2 }
+ \cs_set_protected:Npn
+ \use:c { __piton_collect_ ##2 :w }
+ ########1
+ \c_backslash_str end \c_left_brace_str ##2 \c_right_brace_str
}
- \use:c { #1 DocumentEnvironment } { #2 } { #3 }
- {
- \cs_set_eq:NN \PitonOptions \__piton_fake_PitonOptions
- #4
- \__piton_pre_composition:
- \int_compare:nNnT { \l__piton_number_lines_start_int } > { \c_zero_int }
- { \int_gset:Nn \g__piton_visual_line_int { \l__piton_number_lines_start_int - 1 } }
- \group_begin:
- \tl_map_function:nN
- { \ \\ \{ \} \$ \& \# \^ \_ \% \~ \^^I }
- \char_set_catcode_other:N
- \use:c { __piton_collect_ #2 :w }
+ {
+ \group_end:
+ \tl_set:Nn \l__piton_listing_tl { ####1 }
+ \__piton_composition:
+ \end { ##2 }
+ }
+ \use:c { ##1 DocumentEnvironment } { ##2 } { ##3 }
+ {
+ \cs_set_eq:NN \PitonOptions \__piton_fake_PitonOptions
+ ##4
+ \__piton_pre_composition:
+ \int_compare:nNnT { \l__piton_number_lines_start_int } > { \c_zero_int }
+ {
+ \int_gset:Nn \g__piton_visual_line_int
+ { \l__piton_number_lines_start_int - 1 }
+ }
+ \group_begin:
+ \tl_map_function:nN
+ { \ \\ \{ \} \$ \& \# \^ \_ \% \~ \^^I }
+ \char_set_catcode_other:N
+ \use:c { __piton_collect_ ##2 :w }
+ }
+ {
+ ##5
+ \ignorespacesafterend
+ }
+ \AddToHook { env / ##2 / begin } { \char_set_catcode_other:N \^^M }
}
- {
- #5
- \ignorespacesafterend
- }
- \AddToHook { env / #2 / begin } { \char_set_catcode_other:N \^^M }
}
-\IfFormatAtLeastTF { 2025-06-01 }
+\cs_new_protected:Npn \__piton_store_body:n #1
{
- \cs_new_protected:Npn \__piton_store_body:n #1
+ \tl_set:Ne \obeyedline { \char_generate:nn { 13 } { 11 } }
+ \tl_set:Ne \l__piton_listing_tl { #1 }
+ \tl_set_eq:NN \ProcessedArgument \l__piton_listing_tl
+ }
+\cs_new_protected:Npn \__piton_define_newpitonenvironment_new:
+ {
+ \cs_new_protected:Nn \__piton_DefinePitonEnvironment:nnnnn
{
- \tl_set:Ne \obeyedline { \char_generate:nn { 13 } { 11 } }
- \tl_set:Ne \l__piton_listing_tl { #1 }
- \tl_set_eq:NN \ProcessedArgument \l__piton_listing_tl
- }
- \cs_set_protected:Npn \__piton_DefinePitonEnvironment:nnnnn #1 #2 #3 #4 #5
- {
- \use:c { #1 DocumentEnvironment } { #2 } { #3 > { \__piton_store_body:n } c }
+ \use:c { ##1 DocumentEnvironment } { ##2 } { ##3 > { \__piton_store_body:n } c }
{
\cs_set_eq:NN \PitonOptions \__piton_fake_PitonOptions
- #4
+ ##4
\__piton_pre_composition:
\int_compare:nNnT { \l__piton_number_lines_start_int } > { \c_zero_int }
{
@@ -1234,19 +1270,30 @@
\int_gset:Nn \g__piton_visual_line_int
{ \l__piton_number_lines_start_int - 1 }
}
+ \bool_if:NT \g__piton_beamer_bool
+ { \__piton_translate_beamer_env:o { \l__piton_listing_tl } }
\bool_if:NT \g__piton_footnote_bool \savenotes
\__piton_composition:
\bool_if:NT \g__piton_footnote_bool \endsavenotes
- #5
+ ##5
}
{ \ignorespacesafterend }
}
}
- { }
-\cs_new_protected:Npn \__piton_detect_prompt:n #1
- {
-
- }
+\IfFormatAtLeastTF { 2025-06-01 }
+ { \__piton_define_newpitonenvironment_new: }
+ { \__piton_define_newpitonenvironment_old: }
+\NewDocumentCommand { \NewPitonEnvironment } { }
+ { \__piton_DefinePitonEnvironment:nnnnn { New } }
+\NewDocumentCommand { \DeclarePitonEnvironment } { }
+ { \__piton_DefinePitonEnvironment:nnnnn { Declare } }
+\NewDocumentCommand { \RenewPitonEnvironment } { }
+ { \__piton_DefinePitonEnvironment:nnnnn { Renew } }
+\NewDocumentCommand { \ProvidePitonEnvironment } { }
+ { \__piton_DefinePitonEnvironment:nnnnn { Provide } }
+\cs_new_protected:Npn \__piton_translate_beamer_env:n
+ { \lua_now:e { piton.TranslateBeamerEnv(token.scan_argument ( ) ) } }
+\cs_generate_variant:Nn \__piton_translate_beamer_env:n { o }
\cs_new_protected:Npn \__piton_composition:
{
\str_if_empty:NT \l__piton_box_str
@@ -1254,8 +1301,8 @@
\mode_if_vertical:F
{ \bool_if:NF \l__piton_in_PitonInputFile_bool { \newline } }
}
- \lua_now:e { piton.CountLines ( '\lua_escape:n{\l__piton_listing_tl}' ) }
- \__piton_compute_left_margin:no { CountNonEmptyLines } { \l__piton_listing_tl }
+ \bool_lazy_and:nnT \l__piton_left_margin_auto_bool \l__piton_line_numbers_bool
+ { \__piton_compute_left_margin: }
\lua_now:e
{
piton.join = "\l__piton_join_str"
@@ -1333,19 +1380,23 @@
{ \mode_leave_vertical: }
}
}
+ \skip_vertical:n { 2.5 pt } % added
}
\cs_new_protected:Npn \__piton_composition_ii:
{
\use:e { \exp_not:N \begin { minipage } [ \l__piton_box_str ] }
- { \g__piton_width_dim }
+ { \l__piton_listing_width_dim }
\vbox_unpack:N \g__piton_output_box
+ \kern 2.5 pt
\end { minipage }
}
\cs_new_protected:Npn \__piton_composition_iii:
{
- \bool_if:NT \l__piton_minimize_width_bool
- { \tcbset { text~width = \g__piton_width_dim } }
- \begin { tcolorbox } [ breakable ]
+ \use:e
+ {
+ \exp_not:N \begin { tcolorbox }
+ [ breakable , text~width = \l__piton_listing_width_dim ]
+ }
\par
\vbox_unpack:N \g__piton_output_box
\end { tcolorbox }
@@ -1352,13 +1403,12 @@
}
\cs_new_protected:Npn \__piton_composition_iv:
{
- \bool_if:NT \l__piton_minimize_width_bool
- { \tcbset { text~width = \g__piton_width_dim } }
\use:e
{
- \begin { tcolorbox }
+ \exp_not:N \begin { tcolorbox }
[
hbox ,
+ text~width = \l__piton_listing_width_dim ,
nobeforeafter ,
box~align =
\str_case:Nn \l__piton_box_str
@@ -1380,10 +1430,7 @@
\lua_now:e
{
tex.sprint
- (
- luatexbase.catcodetables.expl ,
- tostring ( piton.lines_status [ \int_use:N \g__piton_line_int ] )
- )
+ ( piton.lines_status [ \int_use:N \g__piton_line_int ] )
}
}
{ 1 { \penalty 100 } 2 \nobreak }
@@ -1391,10 +1438,9 @@
\cs_new_protected:Npn \__piton_create_output_box:
{
\__piton_compute_code_width:
- \dim_gset_eq:NN \g__piton_width_dim \l__piton_width_dim
\vbox_gset:Nn \g__piton_output_box
{ \__piton_retrieve_gobble_parse:o \l__piton_listing_tl }
- \bool_if:NT \l__piton_minimize_width_bool { \__piton_compute_width: }
+ \bool_if:NT \l__piton_minimize_width_bool { \__piton_recompute_listing_width: }
\bool_lazy_or:nnT
{ \int_compare_p:nNn \l__piton_bg_colors_int > { \c_zero_int } }
{ \g__piton_rowcolor_inside_bool }
@@ -1576,10 +1622,6 @@
}
\int_compare:nNnT \g__piton_visual_line_int < \c_zero_int
{ \int_gzero:N \g__piton_visual_line_int }
- \lua_now:e { piton.CountLinesFile ( '\l__piton_file_name_str' ) }
- \__piton_compute_left_margin:no
- { CountNonEmptyLinesFile }
- { \l__piton_file_name_str }
\lua_now:e
{
piton.ReadFile(
@@ -1609,6 +1651,8 @@
\cs_if_exist_use:cF { pitonStyle _ \l_piton_language_str _ #1 }
{ \use:c { pitonStyle _ #1 } }
}
+\NewDocumentCommand { \OptionalLocalPitonStyle } { m }
+ { \cs_if_exist_use:c { pitonStyle _ \l_piton_language_str _ #1 } }
\NewDocumentCommand { \SetPitonStyle } { O { } m }
{
\str_clear_new:N \l__piton_SetPitonStyle_option_str
@@ -1672,7 +1716,6 @@
TypeExpression ,
Directive
}
-
\clist_map_inline:Nn \g__piton_styles_clist
{
\keys_define:nn { piton / Styles }
@@ -1696,9 +1739,26 @@
String .value_required:n = true ,
Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
Comment.Math .value_required:n = true ,
- unknown .code:n =
- \__piton_error:n { Unknown~key~for~SetPitonStyle }
+ unknown .code:n = \__piton_unknown_style:
}
+\cs_new_protected:Npn \__piton_unknown_style:
+ {
+ \str_if_eq:eeTF \l__piton_SetPitonStyle_option_str { expl }
+ {
+ \seq_set_split:Nne \l_tmpa_seq { . } \l_keys_key_str
+ \seq_get_left:NN \l_tmpa_seq \l_tmpa_str
+ \bool_lazy_and:nnTF
+ { \int_compare_p:nNn { \seq_count:N \l_tmpa_seq } > { 1 } }
+ {
+ \str_if_eq_p:Vn \l_tmpa_str { Module }
+ ||
+ \str_if_eq_p:Vn \l_tmpa_str { Type }
+ }
+ { \tl_set:co { pitonStyle _ expl _ \l_keys_key_str } \l_keys_value_tl }
+ { \__piton_error:n { Unknown~key~for~SetPitonStyle } }
+ }
+ { \__piton_error:n { Unknown~key~for~SetPitonStyle } }
+ }
\SetPitonStyle[OCaml]
{
TypeExpression =
@@ -1834,6 +1894,58 @@
Prompt = ,
Discard = \use_none:n
}
+\clist_new:N \g__piton_expl_styles_clist
+\clist_gset:Nn \g__piton_expl_styles_clist
+ {
+ Scope.l ,
+ Scope.g ,
+ Scope.c
+ }
+\clist_map_inline:Nn \g__piton_expl_styles_clist
+ {
+ \keys_define:nn { piton / Styles }
+ {
+ #1 .value_required:n = true ,
+ #1 .code:n =
+ \tl_set:cn
+ {
+ pitonStyle _
+ \str_if_empty:NF \l__piton_SetPitonStyle_option_str
+ { \l__piton_SetPitonStyle_option_str _ }
+ #1
+ }
+ { ##1 }
+ }
+ }
+\SetPitonStyle [ expl ]
+ {
+ Scope.l = ,
+ Scope.g = \bfseries ,
+ Scope.c = \slshape ,
+ Type.bool = \color [ HTML ] { AA6600} ,
+ Type.box = \color [ HTML ] { 267910 } ,
+ Type.clist = \color [ HTML ] { 309030 } ,
+ Type.fp = \color [ HTML ] { FF3300 } ,
+ Type.int = \color [ HTML ] { FF6600 } ,
+ Type.seq = \color [ HTML ] { 309030 } ,
+ Type.skip = \color [ HTML ] { 0CC060 } ,
+ Type.str = \color [ HTML ] { CC3300 } ,
+ Type.tl = \color [ HTML ] { AA2200 } ,
+ Module.bool = \color [ HTML ] { AA6600} ,
+ Module.box = \color [ HTML ] { 267910 } ,
+ Module.cs = \bfseries \color [ HTML ] { 006699 } ,
+ Module.exp = \bfseries \color [ HTML ] { 404040 } ,
+ Module.hbox = \color [ HTML ] { 267910 } ,
+ Module.prg = \bfseries ,
+ Module.clist = \color [ HTML ] { 309030 } ,
+ Module.fp = \color [ HTML ] { FF3300 } ,
+ Module.int = \color [ HTML ] { FF6600 } ,
+ Module.seq = \color [ HTML ] { 309030 } ,
+ Module.skip = \color [ HTML ] { 0CC060 } ,
+ Module.str = \color [ HTML ] { CC3300 } ,
+ Module.tl = \color [ HTML ] { AA2200 } ,
+ Module.vbox = \color [ HTML ] { 267910 }
+ }
\hook_gput_code:nnn { begindocument } { . }
{
\bool_if:NT \g__piton_math_comments_bool
@@ -1910,8 +2022,17 @@
\seq_map_function:NN \g__piton_languages_seq \__piton_clear_functions_i:n
\seq_gclear:N \g__piton_languages_seq
}
-\AtEndDocument
- { \lua_now:n { piton.join_and_write_files() } }
+\AtEndDocument { \lua_now:n { piton.join_and_write_files() } }
+\cs_new_protected:Npn \__piton_space_indentation:
+ {
+ \pdfextension literal { /Artifact << /ActualText (\space) >> BDC }
+ {
+ \color { white }
+ \transparent { 0 }
+ ␣ % U+2423
+ }
+ \pdfextension literal { EMC }
+ }
\AddToHook { env / piton / begin }
{ \__piton_fatal:n { No~environment~piton } }
@@ -1943,7 +2064,8 @@
breakable~not~loaded \\
You~can't~use~the~key~'tcolorbox'~because~
you~have~not~loaded~the~library~'breakable'~of~tcolorbox'. \\
- Use~\token_to_str:N \tcbuselibrary{breakable}. \\
+ Use~\token_to_str:N \tcbuselibrary{breakable}~in~the~preamble~
+ of~your~document.\\
If~you~go~on,~that~key~will~be~ignored.
}
\__piton_msg_new:nn { Language~not~defined }
@@ -1969,7 +2091,7 @@
\__piton_msg_new:nn { Unknown~key~for~SetPitonStyle }
{
The~style~'\l_keys_key_str'~is~unknown.\\
- This~key~will~be~ignored.\\
+ This~setting~will~be~ignored.\\
The~available~styles~are~(in~alphabetic~order):~
\clist_use:Nnnn \g__piton_styles_clist { ~and~ } { ,~ } { ~and~ }.
}
@@ -2069,6 +2191,12 @@
are~not~in~Beamer.\\
However,~you~can~go~on.
}
+\__piton_msg_new:nn { rowcolor~in~detected-commands }
+ {
+ 'rowcolor'~forbidden~in~'detected-commands'.\\
+ You~should~put~'rowcolor'~in~'raw-detected-commands'.\\
+ That~key~will~be~ignored.
+ }
\__piton_msg_new:nnn { Unknown~key~for~PitonOptions }
{
Unknown~key. \\
@@ -2078,6 +2206,7 @@
}
{
The~available~keys~are~(in~alphabetic~order):~
+ add-to-split-separation,~
auto-gobble,~
background-color,~
begin-range,~
More information about the tex-live-commits
mailing list.