texlive[72016] Master/texmf-dist: piton (12aug24)
commits+karl at tug.org
commits+karl at tug.org
Mon Aug 12 22:04:59 CEST 2024
Revision: 72016
https://tug.org/svn/texlive?view=revision&revision=72016
Author: karl
Date: 2024-08-12 22:04:59 +0200 (Mon, 12 Aug 2024)
Log Message:
-----------
piton (12aug24)
Modified Paths:
--------------
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/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 2024-08-12 20:04:42 UTC (rev 72015)
+++ trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex 2024-08-12 20:04:59 UTC (rev 72016)
@@ -15,7 +15,7 @@
end-escape = ! ,
begin-escape-math = \( ,
end-escape-math = \) ,
- detected-commands = highLight
+ detected-commands = { highLight , footnote }
}
@@ -380,9 +380,12 @@
\begin{itemize}
\item La clé \Definition{language} spécifie le langage informatique considéré (la casse
-n'est pas prise en compte). Cinq valeurs sont possibles : |Python|, |OCaml|, |C|, |SQL| et
-|minimal|. La valeur initiale est |Python|.
+n'est pas prise en compte). On peut choisir l'un des cinq langages prédéfinis (|Python|,
+|OCaml|, |C|, |SQL| et |minimal|) ou bien le nom d'un langage défini par l'utilisateur
+avec |\NewPitonLanguage| (voir partie~\ref{NewPitonLanguage}, p.~\pageref{NewPitonLanguage}).
+La valeur initiale est |Python|.
+
\item \index{path} La clé \Definition{path} indique un chemin où seront cherchés les fichiers inclus par
|\PitonInputFile|.
@@ -450,9 +453,12 @@
de lignes (insérés par |line-numbers|) et les lignes du code informatique. La valeur
initiale est 0.7~em.
-\item \colorbox{yellow!50}{\bfseries Nouveau 3.1}\enskip La clé
-\Definition{line-numbers/format} est une liste de tokens qui est insérée avant le numéro de
-ligne pour le formater. La valeur initiale est |\footnotesize \color{gray}|.
+\item \colorbox{yellow!50}{\bfseries Nouveau 3.1}\enskip
+La clé \Definition{line-numbers/format} est une liste de tokens qui est insérée avant le
+numéro de ligne pour le formater. Il est possible de mettre \emph{en dernière position} de
+cette liste une commande LaTeX à un argument comme |\fbox|.
+
+La valeur initiale est |\footnotesize \color{gray}|.
\end{itemize}
Pour la commodité, un dispositif de factorisation du préfixe |line-numbers| est
@@ -465,7 +471,8 @@
{
skip-empty-lines = false ,
label-empty-lines = false ,
- sep = 1 em
+ sep = 1 em ,
+ line-format = \footnotesize \color{blue}
}
}
\end{Verbatim}
@@ -493,6 +500,12 @@
\emph{Exemple} : |\PitonOptions{background-color = {gray!5,white}}|
+\smallskip
+Si la clé |split-on-empty-lines| est utilisée (voir la partie «Coupure de pages»,
+p.~\pageref{coupure-de-pages}), les lignes de séparation entre morceaux de code générés
+par cette clé n'ont pas de fond coloré (au moins avec la valeur initiale du paramètre
+|split-separation|).
+
\item \index{prompt-background-color} Avec la clé \Definition{prompt-background-color},
\pkg{piton} ajoute un fond coloré aux lignes débutant par le prompt «|>>>|» (et sa
continuation «|...|») caractéristique des consoles Python avec boucle \textsc{repl}
@@ -990,6 +1003,8 @@
\subsubsection{Coupure des pages}
+\label{coupure-de-pages}
+
\index{splittable}
\index{split-on-empty-lines}
\index{split-separation}
@@ -1010,11 +1025,16 @@
Quand la clé |split-on-empty-lines| est activée, le travail effectué va en fait un peu
plus loin : les lignes vides successives sont supprimées et remplacées par le contenu du
-paramètre correspondant à la clé \Definition{split-separation}.
+paramètre correspondant à la clé \Definition{split-separation}
+\begin{itemize}
+\item Ce paramètre doit contenir du matériel à insérer en \emph{mode vertical} de TeX. On
+peut, par exemple, mettre |\hrule|.
-La valeur initiale de ce paramètre est |\vspace{\baselineskip}\vspace{-1.25pt}|, ce qui,
+\item La valeur initiale de ce paramètre est |\vspace{\baselineskip}\vspace{-1.25pt}|, ce qui,
au final, correspond à une ligne vide dans le PDF produit (cet espace vertical est
-supprimé s'il tombe au niveau d'un saut de page).
+supprimé s'il tombe au niveau d'un saut de page). Si la clé |background-color| est
+utilisée, aucun fond n'est affiché au niveau de cette ligne de séparation.
+\end{itemize}
\medskip
\item La clé |split-on-empty-lines| peut bien sûr être insuffisante et c'est pourquoi
@@ -1030,6 +1050,8 @@
Employée sans argument, la clé |splittable| est équivalente à |splittable = 1|, et les
listings sont alors sécables n'importe où (ce n'est pas recommandable).
+La valeur initiale de la clé |splittable| vaut 100, ce qui fait que listings ne sont pas
+sécables.
\end{itemize}
\medskip
@@ -1841,6 +1863,7 @@
\label{footnote}
+\smallskip
Si vous voulez mettre des notes de pied de page dans un environnement de \pkg{piton} (ou
bien dans un listing produit par |\PitonInputFile|, bien que cela paraisse moins pertinent
dans ce cas-là) vous pouvez utiliser une paire |\footnotemark|--|\footnotetext|.
@@ -1866,11 +1889,97 @@
particulier, elle doit être chargée après l'extension \pkg{xcolor} et elle n'est pas
parfaitement compatible avec \pkg{hyperref}.
+
\medskip
+\textbf{Remarque importante} : Si vous utilisez Beamer, il faut savoir que Beamer a son
+propre système d'extraction des notes de pied de page et vous n'avez donc pas à charger
+\pkg{piton} avec la clé |footnote| ou bien la clé |footnotehyper|.
+
+\bigskip
+Par défaut, une commande |\footnote| ne peut apparaître que dans un «commentaire LaTeX».
+Mais on peut aussi ajouter la commande |\footnote| à la liste des
+``\emph{detected-commands}'' (cf.~partie~\ref{detected-commands},
+p.~\pageref{detected-commands}).
+
+\medskip
Dans ce document, l'extension \pkg{piton} a été chargée avec l'option |footnotehyper| et
-c'est pourquoi des notes peuvent être mises dans les environnements |{Piton}| : voir un
-exemple sur la première page de ce document.
+on rajouté la commande |\footnote| aux ``\emph{detected-commands}'' avec le code suivant
+dans la préambule du document LaTeX :
+\qquad \verb|\PitonOptions{detected-commands = footnote}|
+
+\begingroup
+\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+\begin{Verbatim}
+\PitonOptions{background-color=gray!10}
+\begin{Piton}
+def arctan(x,n=10):
+ if x < 0:
+ return -arctan(-x)~emphase&\footnote{Un premier appel récursif.}@
+ elif x > 1:
+ return pi/2 - arctan(1/x)~emphase&\footnote{Un deuxième 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!10}
+\begin{Piton}
+def arctan(x,n=10):
+ if x < 0:
+ return -arctan(-x)\footnote{Un premier appel récursif.}
+ elif x > 1:
+ return pi/2 - arctan(1/x)\footnote{Un deuxième appel récursif.}
+ else:
+ return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+\end{Piton}
+\endgroup
+
+
+\vspace{1cm}
+
+Si on utilise l'environnement |{Piton}| dans un environnement |{minipage}| de LaTeX, les
+notes sont, bien entendu, composées au bas de l'environnement |{minipage}|. Rappelons
+qu'une telle |{minipage}| ne peut être coupée par un saut de page.
+
+
+\begingroup
+\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+\begin{Verbatim}
+\PitonOptions{background-color=gray!10}
+\emphase\begin{minipage}{\linewidth}
+\begin{Piton}
+def arctan(x,n=10):
+ if x < 0:
+ return -arctan(-x)~emphase&\footnote{Un premier appel récursif.}@
+ elif x > 1:
+ return pi/2 - arctan(1/x)~emphase&\footnote{Un deuxième appel récursif.}@
+ else:
+ return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+\end{Piton}
+\end{minipage}
+\end{Verbatim}
+\endgroup
+
+\begingroup
+\PitonOptions{background-color=gray!10}
+\begin{minipage}{\linewidth}
+\begin{Piton}
+def arctan(x,n=10):
+ if x < 0:
+ return -arctan(-x)\footnote{Un premier appel récursif.}
+ elif x > 1:
+ return pi/2 - arctan(1/x)\footnote{Un deuxième appel récursif.}
+ else:
+ return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+\end{Piton}
+\end{minipage}
+\endgroup
+
+
+
\subsection{Tabulations}
\index{tabulations}
@@ -1938,7 +2047,7 @@
\index{numérotation des lignes de code|emph}
On rappelle que l'on peut demander la numérotation des lignes des listings avec la clé
-|line-numbers|.
+|line-numbers| (utilisée sans valeur).
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).
@@ -2071,92 +2180,6 @@
\bigskip
-\subsection{Notes dans les listings}
-
-\index{notes dans les listings|emph}
-
-Pour pouvoir extraire les notes (introduites par |\footnote|), l'extension |piton| doit
-être chargée, soit avec la clé |footnote|, soit avec la clé |footnotehyper|, comme
-expliqué à la section \ref{footnote} p.~\pageref{footnote}. Dans le présent document,
-l'extension \pkg{piton} a été chargée par la clé |footnotehyper|.
-
-Bien entendu, une commande |\footnote| ne peut apparaître que dans un commentaire LaTeX
-(qui débute par |#>|). Un tel commentaire peut se limiter à cette unique commande
-|\footnote|, comme dans l'exemple suivant.
-
-\begingroup
-\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
-\begin{Verbatim}
-\PitonOptions{background-color=gray!10}
-\begin{Piton}
-def arctan(x,n=10):
- if x < 0:
- return -arctan(-x)~emphase&#>\footnote{Un premier appel récursif.}]@
- elif x > 1:
- return pi/2 - arctan(1/x)~emphase&#>\footnote{Un deuxième 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!10}
-\begin{Piton}
-def arctan(x,n=10):
- if x < 0:
- return -arctan(-x)#>\footnote{Un premier appel récursif.}
- elif x > 1:
- return pi/2 - arctan(1/x)#>\footnote{Un deuxième appel récursif.}
- else:
- return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
-\end{Piton}
-\endgroup
-
-
-\vspace{1cm}
-
-Si on utilise l'environnement |{Piton}| dans un environnement |{minipage}| de LaTeX, les
-notes sont, bien entendu, composées au bas de l'environnement |{minipage}|. Rappelons
-qu'une telle |{minipage}| ne peut être coupée par un saut de page.
-
-
-\begingroup
-\fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
-\begin{Verbatim}
-\PitonOptions{background-color=gray!10}
-\emphase\begin{minipage}{\linewidth}
-\begin{Piton}
-def arctan(x,n=10):
- if x < 0:
- return -arctan(-x)~emphase&#>\footnote{Un premier appel récursif.}@
- elif x > 1:
- return pi/2 - arctan(1/x)~emphase&#>\footnote{Un deuxième appel récursif.}@
- else:
- return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
-\end{Piton}
-\end{minipage}
-\end{Verbatim}
-\endgroup
-
-\begingroup
-\PitonOptions{background-color=gray!10}
-\begin{minipage}{\linewidth}
-\begin{Piton}
-def arctan(x,n=10):
- if x < 0:
- return -arctan(-x)#>\footnote{Un premier appel récursif.}
- elif x > 1:
- return pi/2 - arctan(1/x)#>\footnote{Un deuxième appel récursif.}
- else:
- return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
-\end{Piton}
-\end{minipage}
-\endgroup
-
-
-\bigskip
-
\subsection{Un exemple de réglage des styles}
Les styles graphiques ont été présentés à la partie \ref{styles}, p.~\pageref{styles}.
@@ -2545,7 +2568,7 @@
Keyword & les mots-clés suivants :
\ttfamily assert, break, case, continue, del,
elif, else, except, exec, finally, for, from,
- global, if, import, lambda, non local,
+ global, if, import, in, lambda, non local,
pass, raise, return, try, while,
with, yield et yield from.\\
\bottomrule
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 2024-08-12 20:04:42 UTC (rev 72015)
+++ trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx 2024-08-12 20:04:59 UTC (rev 72016)
@@ -44,7 +44,7 @@
end-escape = ! ,
begin-escape-math = \( ,
end-escape-math = \) ,
- detected-commands = highLight
+ detected-commands = { highLight, footnote }
}
\parindent 0pt
@@ -79,12 +79,12 @@
% \iffalse
%<*STY>
% \fi
-\def\PitonFileVersion{3.1}
-\def\PitonFileDate{2024/07/30}
+\def\PitonFileVersion{3.1a}
+\def\PitonFileDate{2024/08/12}
% \iffalse
%</STY>
%<*LUA>
-piton_version = "3.1" -- 2024/07/30
+piton_version = "3.1a" -- 2024/08/12
%</LUA>
%\fi
%
@@ -361,8 +361,12 @@
%
% \begin{itemize}
% \item The key \Definition{language} specifies which computer language is
-% considered (that key is case-insensitive). Five values are allowed :
-% |Python|, |OCaml|, |C|, |SQL| and |minimal|. The initial value is |Python|.
+% considered (that key is case-insensitive). It's possible to use the name of
+% the five built-in languages (|Python|, |OCaml|, |C|, |SQL| and |minimal|) or
+% the name of the language defined by the user with |\NewPitonLanguage|
+% (cf.~part~\ref{NewPitonLanguage}, p.~\pageref{NewPitonLanguage}.
+%
+% The initial value is |Python|.
%
% \item \index{path} The key \Definition{path} specifies a path where the files
% included by |\PitonInputFile| will be searched.
@@ -433,8 +437,11 @@
% lines of code. The initial value is 0.7~em.
% \item \colorbox{yellow!50}{\bfseries New 3.1}\enskip The key
% \Definition{line-numbers/format} is a list of tokens which are inserted before
-% the number of line in order to format it. The initial value is
-% |\footnotesize\color{gray}|.
+% the number of line in order to format it. It's possible to put, \emph{at the
+% end} of the list, a LaTeX command with one argument, such as, for example,
+% |\fbox|.
+%
+% The initial value is |\footnotesize\color{gray}|.
% \end{itemize}
%
% For convenience, a mechanism of factorisation of the prefix |line-numbers| is
@@ -446,7 +453,8 @@
% {
% skip-empty-lines = false ,
% label-empty-lines = false ,
-% sep = 1 em
+% sep = 1 em ,
+% line-format = \footnotesize \color{blue}
% }
% }
% \end{Verbatim}
@@ -477,6 +485,12 @@
% The key |background-color| accepts a color defined «on the fly». For example,
% it's possible to write |background-color = [cmyk]{0.1,0.05,0,0}|.
%
+% \smallskip
+% When the key |split-on-empty-lines| is in force (see the part ``Page breaks'',
+% p.~\pageref{page breaks}), the empty lines generated by that key don't have
+% any background color (at least with the initial value of the parameter
+% |split-separation|).
+%
% \item \index{prompt-background-color} With the key
% \Definition{prompt-background-color}, \pkg{piton} adds a
% color background to the lines beginning with the prompt ``|>>>|'' (and its
@@ -980,6 +994,7 @@
% \label{breakable}
%
% \subsubsection{Page breaks}
+% \label{page breaks}
% \index{splittable}
%
% By default, the listings produced by the environment |{Piton}| and the command
@@ -998,10 +1013,17 @@
% In fact, when the key |split-on-empty-lines| is in force, the work goes a
% little further than merely allowing page breaks: several successive empty lines
% are deleted and replaced by the content of the parameter corresponding to the
-% key \Definition{split-separation}. The initial value of this parameter is
-% |\vspace{\baselineskip}\vspace{-1.25pt}| which corresponds eventually to an
+% key \Definition{split-separation}.
+% \begin{itemize}
+% \item That parameter must contain elements allowed to be inserted in
+% \emph{vertical mode} of TeX. For example, it's possible to put |\hrule|.
+%
+% \item The initial value of this parameter is
+% |\vspace{\baselineskip}\vspace{-1.25pt}| which corresponds eventually to an
% empty line in the final PDF (this vertical space is deleted if it occurs on a
-% page break).
+% page break). If the key |background-color| is in force, no background color is
+% added to that empty line.
+% \end{itemize}
%
% \item Of course, the key |split-on-empty-lines| may not be sufficient and
% that's why \pkg{piton} provides the key \Definition{splittable}.
@@ -1016,6 +1038,9 @@
% When used without value, the key |splittable| is equivalent to
% |splittable = 1| and the listings may be broken anywhere (it's probably
% not recommandable).
+%
+% The initial value of the key |splittable| is equal to 100 (by default, the
+% listings are not breakable at all).
% \end{itemize}
%
%
@@ -1832,11 +1857,99 @@
% in particular: it must be loaded after the package \pkg{xcolor} and it is not
% perfectly compatible with \pkg{hyperref}.
%
+%
+% \medskip
+% \textbf{Important remark} : If you use Beamer, you should know taht Beamer has
+% its own system to extract the footnotes. Therefore, \pkg{piton} must be loaded
+% in that class without the option |footnote| nor the option |footnotehyper|.
+%
+%
+% \bigskip
+% By default, in an environment |{Piton}|, a command |\footnote| may appear only
+% within a ``LaTeX comment''. But it's also possible to add the command
+% |\footnote| to the list of the ``\emph{detected-commands}''
+% (cf.~part~\ref{detected-commands}, p.~\pageref{detected-commands}).
+
% \medskip
% In this document, the package \pkg{piton} has been loaded with the
-% option |footnotehyper|. For examples of notes, cf. \ref{notes-examples},
-% p.~\pageref{notes-examples}.
+% option |footnotehyper| dans we added the command |\footnote| to the list of
+% the ``\emph{detected-commands}'' with the following instruction in the
+% preamble of the LaTeX document.
%
+% \qquad \verb|\PitonOptions{detected-commands = footnote}|
+%
+%
+% \begingroup
+% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+% \begin{Verbatim}
+% \PitonOptions{background-color=gray!10}
+% \begin{Piton}
+% def arctan(x,n=10):
+% if x < 0:
+% return -arctan(-x)~emphase&\footnote{First recursive call.}]@
+% elif x > 1:
+% return pi/2 - arctan(1/x)~emphase&\footnote{Second 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!10}
+% \begin{Piton}
+% def arctan(x,n=10):
+% if x < 0:
+% return -arctan(-x)\footnote{First recursive call.}
+% elif x > 1:
+% return pi/2 - arctan(1/x)\footnote{Second recursive call.}
+% else:
+% return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+% \end{Piton}
+% \endgroup
+%
+%
+% \vspace{1cm}
+%
+% If an environment |{Piton}| is used in an environment |{minipage}| of LaTeX,
+% the notes are composed, of course, at the foot of the environment
+% |{minipage}|. Recall that such |{minipage}| can't be broken by a page break.
+%
+%
+% \begingroup
+% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
+% \begin{Verbatim}
+% \PitonOptions{background-color=gray!10}
+% \emphase\begin{minipage}{\linewidth}
+% \begin{Piton}
+% def arctan(x,n=10):
+% if x < 0:
+% return -arctan(-x)~emphase&\footnote{First recursive call.}@
+% elif x > 1:
+% return pi/2 - arctan(1/x)~emphase&\footnote{Second recursive call.}@
+% else:
+% return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+% \end{Piton}
+% \end{minipage}
+% \end{Verbatim}
+% \endgroup
+%
+% \begingroup
+% \PitonOptions{background-color=gray!10}
+% \begin{minipage}{\linewidth}
+% \begin{Piton}
+% def arctan(x,n=10):
+% if x < 0:
+% return -arctan(-x)\footnote{First recursive call.}
+% elif x > 1:
+% return pi/2 - arctan(1/x)\footnote{Second recursive call.}
+% else:
+% return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
+% \end{Piton}
+% \end{minipage}
+% \endgroup
+%
+%
% \subsection{Tabulations}
%
% \index{tabulations}
@@ -1906,7 +2019,7 @@
% \index{numbers of the lines de code|emph}
%
% We remind that it's possible to have an automatic numbering of the lines in
-% the Python listings by using the key |line-numbers|.
+% the Python 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).
@@ -2039,96 +2152,9 @@
% \endgroup
%
%
-% \bigskip
-% \subsection{Notes in the listings}
-%
-% \label{notes-examples}
-% \index{notes in the listings}
%
-% In order to be able to extract the notes (which are typeset with the command
-% |\footnote|), the extension \pkg{piton} must be loaded with the key |footnote|
-% or the key |footenotehyper| as explained in the section \ref{footnote}
-% p.~\pageref{footnote}. In this document, the extension \pkg{piton} has been
-% loaded with the key |footnotehyper|.
%
-% Of course, in an environment |{Piton}|, a command |\footnote| may appear only
-% within a LaTeX comment (which begins with |#>|). It's possible to have comments
-% which contain only that command |\footnote|. That's the case in the following example.
%
-%
-%
-% \begingroup
-% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
-% \begin{Verbatim}
-% \PitonOptions{background-color=gray!10}
-% \begin{Piton}
-% def arctan(x,n=10):
-% if x < 0:
-% return -arctan(-x)~emphase&#>\footnote{First recursive call.}]@
-% elif x > 1:
-% return pi/2 - arctan(1/x)~emphase&#>\footnote{Second 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!10}
-% \begin{Piton}
-% def arctan(x,n=10):
-% if x < 0:
-% return -arctan(-x)#>\footnote{First recursive call.}
-% elif x > 1:
-% return pi/2 - arctan(1/x)#>\footnote{Second recursive call.}
-% else:
-% return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
-% \end{Piton}
-% \endgroup
-%
-%
-% \vspace{1cm}
-%
-% If an environment |{Piton}| is used in an environment |{minipage}| of LaTeX,
-% the notes are composed, of course, at the foot of the environment
-% |{minipage}|. Recall that such |{minipage}| can't be broken by a page break.
-%
-%
-% \begingroup
-% \fvset{commandchars=\~\&\@,formatcom=\small\color{gray}}
-% \begin{Verbatim}
-% \PitonOptions{background-color=gray!10}
-% \emphase\begin{minipage}{\linewidth}
-% \begin{Piton}
-% def arctan(x,n=10):
-% if x < 0:
-% return -arctan(-x)~emphase&#>\footnote{First recursive call.}@
-% elif x > 1:
-% return pi/2 - arctan(1/x)~emphase&#>\footnote{Second recursive call.}@
-% else:
-% return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
-% \end{Piton}
-% \end{minipage}
-% \end{Verbatim}
-% \endgroup
-%
-% \begingroup
-% \PitonOptions{background-color=gray!10}
-% \begin{minipage}{\linewidth}
-% \begin{Piton}
-% def arctan(x,n=10):
-% if x < 0:
-% return -arctan(-x)#>\footnote{First recursive call.}
-% elif x > 1:
-% return pi/2 - arctan(1/x)#>\footnote{Second recursive call.}
-% else:
-% return sum( (-1)**k/(2*k+1)*x**(2*k+1) for k in range(n) )
-% \end{Piton}
-% \end{minipage}
-% \endgroup
-%
-%
-%
% \bigskip
%
% \subsection{An example of tuning of the styles}
@@ -2321,7 +2347,7 @@
% Keyword & the following keywords:
% \ttfamily assert, break, case, continue, del,
% elif, else, except, exec, finally, for, from,
-% global, if, import, lambda, non local,
+% global, if, import, in, lambda, non local,
% pass, raise, return, try, while,
% with, yield et yield from.\\
% \bottomrule
@@ -2729,7 +2755,15 @@
% \end{macrocode}
%
% \bigskip
+% The command |\text| provided by the package \pkg{amstext} will be used to
+% allow the use of the command |\pion{...}| (with the standard syntax) in
+% mathematical mode.
% \begin{macrocode}
+\RequirePackage { amstext }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
\cs_new_protected:Npn \@@_error:n { \msg_error:nn { piton } }
\cs_new_protected:Npn \@@_warning:n { \msg_warning:nn { piton } }
\cs_new_protected:Npn \@@_error:nn { \msg_error:nnn { piton } }
@@ -2859,9 +2893,6 @@
beamer .bool_gset:N = \g_@@_beamer_bool ,
beamer .default:n = true ,
-
- math-comments .code:n = \@@_error:n { moved~to~preamble } ,
- comment-latex .code:n = \@@_error:n { moved~to~preamble } ,
unknown .code:n = \@@_error:n { Unknown~key~for~package }
}
@@ -2868,16 +2899,6 @@
% \end{macrocode}
%
%
-% \bigskip
-% \begin{macrocode}
-\@@_msg_new:nn { moved~to~preamble }
- {
- The~key~'\l_keys_key_str'~*must*~now~be~used~with~
- \token_to_str:N \PitonOptions`in~the~preamble~of~your~
- document.\\
- That~key~will~be~ignored.
- }
-% \end{macrocode}
%
% \begin{macrocode}
\@@_msg_new:nn { Unknown~key~for~package }
@@ -3034,20 +3055,23 @@
%
%
% \medskip
-% We will compute (with Lua) the numbers of lines of the Python code and store
+% We will compute (with Lua) the numbers of lines of the listings (or
+% \emph{chunks} of listings when |split-on-empty-lines| is in force) and store
% it in the following counter.
% \begin{macrocode}
\int_new:N \l_@@_nb_lines_int
% \end{macrocode}
%
-% The same for the number of non-empty lines of the Python codes.
+% The same for the number of non-empty lines of the listings.
% \begin{macrocode}
\int_new:N \l_@@_nb_non_empty_lines_int
% \end{macrocode}
%
% The following counter will be used to count the lines during the composition.
-% It will count all the lines, empty or not empty. It won't be used to print the
-% numbers of the lines.
+% It will take into account all the lines, empty or not empty. It won't be used
+% to print the numbers of the lines but will be used to allow or disallow line
+% breaks (when |splittable| is in force) and for the color of the background
+% (when |background-color| is used with a \emph{list} of colors).
% \begin{macrocode}
\int_new:N \g_@@_line_int
% \end{macrocode}
@@ -3054,7 +3078,8 @@
%
% \medskip
% The following token list will contain the (potential) information to write
-% on the |aux| (to be used in the next compilation).
+% on the |aux| (to be used in the next compilation). The technic of the
+% auxiliary file will be used when the key |width| is used with the value~|min|.
% \begin{macrocode}
\tl_new:N \g_@@_aux_tl
% \end{macrocode}
@@ -3062,26 +3087,31 @@
% \medskip
% The following counter corresponds to the key |splittable| of |\PitonOptions|.
% If the value of |\l_@@_splittable_int| is equal to $n$, then no line break can
-% occur within the first $n$~lines or the last $n$~lines of the listings.
+% occur within the first $n$~lines or the last $n$~lines of a listing (or a
+% \emph{chunk} of listings when the key |split-on-empty-lines| is in force).
% \begin{macrocode}
\int_new:N \l_@@_splittable_int
% \end{macrocode}
%
% \medskip
+% An initial value of |splittable| equal to 100 is equivalent to say that the
+% environments |{Piton}| are unbreakable.
+% \begin{macrocode}
+\int_set:Nn \l_@@_splittable_int { 100 }
+% \end{macrocode}
+%
+% \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 informatic code provided
-% by the final user is split in chunks on the empty lines in the code).
+% by the final 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 { \vspace{\baselineskip} \vspace{-1.25pt} }
+\tl_set:Nn \l_@@_split_separation_tl
+ { \vspace { \baselineskip } \vspace { -1.25pt } }
% \end{macrocode}
+% That parameter must contain elements to be inserted in \emph{vertical} mode by
+% TeX.
%
-% \medskip
-% An initial value of |splittable| equal to 100 is equivalent to say that the
-% environments |{Piton}| are unbreakable.
-% \begin{macrocode}
-\int_set:Nn \l_@@_splittable_int { 100 }
-% \end{macrocode}
%
%
% \medskip
@@ -3392,7 +3422,8 @@
% \bigskip
% \subsubsection{Treatment of a line of code}
%
-% The following command is only used once.
+% The following command is only used once. We have written an autonomous function
+% only for legibility.
% \begin{macrocode}
\cs_new_protected:Npn \@@_replace_spaces:n #1
{
@@ -3463,7 +3494,7 @@
{
\bool_if:nF
{
- \str_if_eq_p:nn { #1 } { \PitonStyle {Prompt}{} }
+ \str_if_eq_p:nn { #1 } { \PitonStyle { Prompt } { } }
&&
\l_@@_skip_empty_lines_bool
}
@@ -3470,7 +3501,7 @@
{ \int_gincr:N \g_@@_visual_line_int }
\bool_if:nT
{
- ! \str_if_eq_p:nn { #1 } { \PitonStyle {Prompt}{} }
+ ! \str_if_eq_p:nn { #1 } { \PitonStyle { Prompt } { } }
||
( ! \l_@@_skip_empty_lines_bool && \l_@@_label_empty_lines_bool )
}
@@ -3598,24 +3629,63 @@
% \end{macrocode}
%
% \bigskip
+% The command |\@@_newline:| will be inserted by Lua between two lines of the
+% informatic listing.
+% \begin{itemize}
+% \item In fact, it will be inserted between two commands
+% |\@@_begin_line:|...|\@@_end_of_line:|.
+% \item When the key |break-lines-in-Piton| is in force, a line of the
+% informatic code (the \emph{input}) may result in several lines in the PDF (the
+% \emph{output}).
+% \item |\@@_newline:| has a rather complex behaviour because it may close and
+% open |\vtop|s and finish and start paragraphs.
+% \end{itemize}
% \begin{macrocode}
\cs_new_protected:Npn \@@_newline:
{
+% \end{macrocode}
+% We recall that |\g_@@_line_int| is \emph{not} used for the number of line
+% printed in the PDF (when |line-numbers| is in force)...
+% \begin{macrocode}
\int_gincr:N \g_@@_line_int
+% \end{macrocode}
+% ... it will be used to allow or disallow page breaks (the final user controls
+% that behaviour with the key |splittable|).
+% \begin{macrocode}
\int_compare:nNnT \g_@@_line_int > { \l_@@_splittable_int - 1 }
{
\int_compare:nNnT
- { \l_@@_nb_lines_int - \g_@@_line_int } > \l_@@_splittable_int
+ { \l_@@_nb_lines_int - \g_@@_line_int + 1 } > \l_@@_splittable_int
+% \end{macrocode}
+% Now, we allow a page break after the current line of code.
+% \begin{macrocode}
{
\egroup
\bool_if:NT \g_@@_footnote_bool \endsavenotes
- \par \mode_leave_vertical:
+ \par
+% \end{macrocode}
+% Each non-splittable block of lines is composed in a |\vtop| of
+% TeX inserted in a paragraph of TeX.
+% \begin{itemize}
+% \item In the previous lines, we have closed a |\vtop| (with |\egroup|) and a
+% paragraph (with |\par|).
+% \item Now, we start a new paragraph (with |\mode_leave_vertical:|) and open a
+% |\vtop| (with |\vtop \bgroup|).
+% \end{itemize}
+% \begin{macrocode}
+ \mode_leave_vertical:
\bool_if:NT \g_@@_footnote_bool \savenotes
\vtop \bgroup
+% \end{macrocode}
+% And, in that |\vtop|, of course, we will put a box for each line of the
+% informatic listing (but a line of the informatic listing may be formatted as a
+% box of several lines when |break-lines-in-Piton| is in force).
+% \begin{macrocode}
}
}
}
% \end{macrocode}
+% After the command |\@@_newline:|, we will have a command |\@@_begin_line:|.
%
% \bigskip
% \begin{macrocode}
@@ -3688,12 +3758,8 @@
false .code:n = \bool_set_false:N \l_@@_line_numbers_bool ,
start .code:n =
- \bool_if:NTF \l_@@_in_PitonOptions_bool
- { Invalid~key }
- {
- \bool_set_true:N \l_@@_line_numbers_bool
- \int_set:Nn \l_@@_number_lines_start_int { #1 }
- } ,
+ \bool_set_true:N \l_@@_line_numbers_bool
+ \int_set:Nn \l_@@_number_lines_start_int { #1 } ,
start .value_required:n = true ,
skip-empty-lines .code:n =
@@ -3720,11 +3786,7 @@
{
\bool_set_true:N \l_@@_line_numbers_absolute_bool
\bool_set_false:N \l_@@_skip_empty_lines_bool
- }
- \bool_lazy_or:nnF
- \l_@@_in_PitonInputFile_bool
- \l_@@_in_PitonOptions_bool
- { \@@_error:n { Invalid~key } } ,
+ } ,
absolute .value_forbidden:n = true ,
resume .code:n =
@@ -3969,7 +4031,7 @@
% When using |\NewPitonEnvironment| a user may use |\PitonOptions| inside.
% However, the set of keys available should be different that in standard
% |\PitonOptions|. That's why we define a version of |\PitonOptions| with no
-% restrection on the set of available keys and we will link that version to
+% restriction on the set of available keys and we will link that version to
% |\PitonOptions| in such environment.
% \begin{macrocode}
\NewDocumentCommand \@@_fake_PitonOptions { }
@@ -3984,7 +4046,9 @@
%
% \medskip
% The following counter will be used to count the lines in the code when the
-% user requires the numbers of the lines to be printed (with |line-numbers|).
+% user requires the numbers of the lines to be printed (with |line-numbers|)
+% whereas the counter |\g_@@_line_int| previously defined is \emph{not} used for
+% that functionality.
%
% \begin{macrocode}
\int_new:N \g_@@_visual_line_int
@@ -4005,7 +4069,11 @@
{
{
\l_@@_line_numbers_format_tl
- \int_to_arabic:n \g_@@_visual_line_int
+% \end{macrocode}
+% We put braces. Thus, the user may use the key |line-numbers/format| with a
+% value such as |\fbox|.
+% \begin{macrocode}
+ { \int_to_arabic:n \g_@@_visual_line_int }
}
\skip_horizontal:N \l_@@_numbers_sep_dim
}
@@ -4193,18 +4261,29 @@
\NewDocumentCommand { \@@_piton_standard } { m }
{
\group_begin:
- \ttfamily
% \end{macrocode}
% The following tuning of LuaTeX in order to avoid all break of lines on the
% hyphens.
% \begin{macrocode}
\automatichyphenmode = 1
+% \end{macrocode}
+% Remark that the argument of |\piton| (with the normal syntax) is expanded in
+% the TeX sens, (see the |\tl_set:Nx| below) and that's why we can provide the
+% following escapes to the final user:
+% \begin{macrocode}
\cs_set_eq:NN \\ \c_backslash_str
\cs_set_eq:NN \% \c_percent_str
\cs_set_eq:NN \{ \c_left_brace_str
\cs_set_eq:NN \} \c_right_brace_str
\cs_set_eq:NN \$ \c_dollar_str
+% \end{macrocode}
+% The standard command |\␣| is \emph{not} expandable and we need here expandable
+% commands. With the following code, we define an expandable command.
+% \begin{macrocode}
\cs_set_eq:cN { ~ } \space
+% \end{macrocode}
+%
+% \begin{macrocode}
\cs_set_protected:Npn \@@_begin_line: { }
\cs_set_protected:Npn \@@_end_line: { }
\tl_set:Nx \l_tmpa_tl
@@ -4225,7 +4304,14 @@
\bool_if:NT \l_@@_break_lines_in_piton_bool
{ \regex_replace_all:nnN { \x20 } { \x20 } \l_tmpa_tl }
}
- \l_tmpa_tl
+% \end{macrocode}
+% The command |\text| is provided by the package \pkg{amstext} (loaded by \pkg{piton}).
+% \begin{macrocode}
+ \if_mode_math:
+ \text { \ttfamily \l_tmpa_tl }
+ \else:
+ \ttfamily \l_tmpa_tl
+ \fi:
\group_end:
}
% \end{macrocode}
@@ -4302,34 +4388,9 @@
\cs_new_protected:Npn \@@_piton_no_cr:n #1
{
\group_begin:
- \cs_set_protected:Npn \@@_begin_line: { }
- \cs_set_protected:Npn \@@_end_line: { }
- \cs_set:cpn { pitonStyle _ \l_piton_language_str _ Prompt } { }
- \cs_set:cpn { pitonStyle _ Prompt } { }
\cs_set_protected:Npn \@@_newline:
{ \msg_fatal:nn { piton } { cr~not~allowed } }
- \bool_lazy_or:nnTF
- \l_@@_break_lines_in_piton_bool
- \l_@@_break_lines_in_Piton_bool
- {
- \tl_set:Nx \l_tmpa_tl
- {
- \lua_now:e
- { piton.ParseTer('\l_piton_language_str',token.scan_string()) }
- { #1 }
- }
- }
- {
- \tl_set:Nx \l_tmpa_tl
- {
- \lua_now:e
- { piton.Parse('\l_piton_language_str',token.scan_string()) }
- { #1 }
- }
- }
- \bool_if:NT \l_@@_show_spaces_bool
- { \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423
- \l_tmpa_tl
+ \@@_piton:n { #1 }
\group_end:
}
% \end{macrocode}
@@ -4477,15 +4538,8 @@
}
{
\group_end:
- \mode_if_vertical:TF \mode_leave_vertical: \newline
+ \mode_if_vertical:TF { \noindent \mode_leave_vertical: } \newline
% \end{macrocode}
-% We count with Lua the number of lines of the argument. The result will be
-% stored by Lua in |\l_@@_nb_lines_int|. That information will be used to allow
-% or disallow page breaks. The use of |token.scan_argument| avoids problems with
-% the delimiters of the Lua string.
-% \begin{macrocode}
- \lua_now:n { piton.CountLines(token.scan_argument()) } { ##1 }
-% \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}
@@ -4492,7 +4546,8 @@
\@@_compute_left_margin:nn { CountNonEmptyLines } { ##1 }
\@@_compute_width:
\ttfamily
- \dim_zero:N \parskip
+ \dim_zero:N \parskip
+ \noindent % added 2024/08/07
% \end{macrocode}
%
% Now, the key |write|.
@@ -4574,7 +4629,7 @@
% \bigskip
% The following function will be used when the key |split-on-empty-lines| is not
% in force. It will gobble the spaces at the beginning of the lines and parse
-% the code. The argument is provided by curryfication.
+% the code. The argument is provided by curryfication.
% \begin{macrocode}
\cs_new_protected:Npn \@@_gobble_parse:n
{
@@ -4909,8 +4964,6 @@
{
String .meta:n = { String.Long = #1 , String.Short = #1 } ,
Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
- ParseAgain .tl_set:c = pitonStyle _ ParseAgain ,
- ParseAgain .value_required:n = true ,
ParseAgain.noCR .tl_set:c = pitonStyle _ ParseAgain.noCR ,
ParseAgain.noCR .value_required:n = true ,
unknown .code:n =
@@ -4978,13 +5031,12 @@
UserFunction = ,
Prompt = ,
ParseAgain.noCR = \@@_piton_no_cr:n ,
- ParseAgain = \@@_piton:n ,
Discard = \use_none:n
}
% \end{macrocode}
-% The last styles |ParseAgain.noCR| and |ParseAgain| should be considered as
+% The styles |ParseAgain.noCR| should be considered as
% ``internal style'' (not available for the final user). However, maybe we will
-% change that and document these styles for the final user (why not?).
+% change that and document that style for the final user.
%
% \medskip
% If the key |math-comments| has been used at load-time, we change the style
@@ -5243,8 +5295,11 @@
}
% \end{macrocode}
%
+% We don't give the name |syntax error| for the following error because you
+% should not give a name with a space because such space could be replaced by
+% U+2423 when the key |show-spaces| is in force in the command |\piton|.
% \begin{macrocode}
-\@@_msg_new:nn { syntax~error }
+\@@_msg_new:nn { SyntaxError }
{
Your~code~of~the~language~"\l_piton_language_str"~is~not~
syntactically~correct.\\
@@ -5461,19 +5516,7 @@
% \end{macrocode}
%
%
-% \bigskip
-% The following functions are an easy way to safely insert braces (|{| and |}|)
-% in the TeX flow.
% \begin{macrocode}
-function piton.open_brace ()
- tex.sprint("{")
-end
-function piton.close_brace ()
- tex.sprint("}")
-end
-% \end{macrocode}
-%
-% \begin{macrocode}
local function sprintL3 ( s )
tex.sprint ( luatexbase.catcodetables.expl , s )
end
@@ -5737,7 +5780,8 @@
% present in strings of the language. However, the syntax for the strings is
% 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 language (at least the shorts strings). The argument of |Compute_braces|
+% must be a pattern \emph{which does no catching}.
% \begin{macrocode}
local function Compute_braces ( lpeg_string ) return
P { "E" ,
@@ -5765,7 +5809,7 @@
* Cc "}"
)
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* P "}"
* Ct ( Cc "Close" )
end
@@ -5775,7 +5819,7 @@
% \begin{macrocode}
local function Compute_LPEG_cleaner ( lang , braces ) return
Ct ( ( piton.DetectedCommands * "{"
- * ( braces
+ * ( braces
/ ( function ( s )
if s ~= '' then return LPEG_cleaner[lang] : match ( s ) end end ) )
* "}"
@@ -5870,18 +5914,22 @@
% \end{macrocode}
%
% \bigskip
-% For |\\temporal|, the specification of the overlays (between angular brackets) is mandatory.
+% For |\\temporal|, the specification of the overlays (between angular brackets)
+% is mandatory.
% \begin{macrocode}
lpeg = lpeg +
L ( ( P "\\temporal" ) * "<" * ( 1 - P ">" ) ^ 0 * ">" * "{" )
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s )
+ if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}{" )
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s )
+ if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}{" )
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s )
+ if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}" )
% \end{macrocode}
%
@@ -6262,15 +6310,18 @@
% \bigskip
% \paragraph{Beamer}
%
+% The argument of |Compute_braces| must be a pattern \emph{which does no
+% catching} corresponding to the strings of the language.
+%
% \begin{macrocode}
local braces =
Compute_braces
(
- Q ( P "\"" + "r\"" + "R\"" + "f\"" + "F\"" )
- * ( "\"" * ( P "\\\"" + 1 - S "\"" ) ^ 0 * "\"" )
+ ( P "\"" + "r\"" + "R\"" + "f\"" + "F\"" )
+ * ( P "\\\"" + 1 - S "\"" ) ^ 0 * "\""
+
- Q ( P '\'' + 'r\'' + 'R\'' + 'f\'' + 'F\'' )
- * ( '\'' * ( P '\\\'' + 1 - S '\'' ) ^ 0 * '\'' )
+ ( P '\'' + 'r\'' + 'R\'' + 'f\'' + 'F\'' )
+ * ( P '\\\'' + 1 - S '\'' ) ^ 0 * '\''
)
if piton.beamer then Beamer = Compute_Beamer ( 'python' , braces ) end
% \end{macrocode}
@@ -6446,8 +6497,8 @@
* SkipSpace
* ( Q "->" * SkipSpace * K ( 'Name.Type' , identifier ) ) ^ -1
% \end{macrocode}
-% Here, we need a \pkg{piton} style |ParseAgain| which will be linked to
-% |\@@_piton:n| (that means that the capture will be parsed once again by
+% Here, we need a \pkg{piton} style |ParseAgain.noCR| which will be linked to
+% |\@@_piton_no_cr:n| (that means that the capture will be parsed once again by
% \pkg{piton}). We could avoid that kind of trick by using a non-terminal of a
% grammar but we have probably here a better legibility.
% \begin{macrocode}
@@ -6685,8 +6736,11 @@
% \paragraph{Beamer}
%
% \bigskip
+% The argument of |Compute_braces| must be a pattern \emph{which does no
+% catching} corresponding to the strings of the language.
+%
% \begin{macrocode}
-braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
+local braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
if piton.beamer then
Beamer = Compute_Beamer ( 'ocaml' , braces ) -- modified 2024/07/24
end
@@ -7044,8 +7098,10 @@
% \paragraph{Beamer}
%
% \bigskip
+% The argument of |Compute_braces| must be a pattern \emph{which does no
+% catching} corresponding to the strings of the language.
% \begin{macrocode}
-braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
+local braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
if piton.beamer then Beamer = Compute_Beamer ( 'c' , braces ) end
% \end{macrocode}
%
@@ -7240,8 +7296,11 @@
% \paragraph{Beamer}
%
% \bigskip
+% The argument of |Compute_braces| must be a pattern \emph{which does no
+% catching} corresponding to the strings of the language.
+%
% \begin{macrocode}
-braces = Compute_braces ( String )
+local braces = Compute_braces ( "'" * ( 1 - P "'" ) ^ 1 * "'" )
if piton.beamer then Beamer = Compute_Beamer ( 'sql' , braces ) end
% \end{macrocode}
%
@@ -7395,7 +7454,12 @@
* Q "\""
)
-braces = Compute_braces ( String )
+% \end{macrocode}
+% The argument of |Compute_braces| must be a pattern \emph{which does no
+% catching} corresponding to the strings of the language.
+% \begin{macrocode}
+local braces = Compute_braces ( P "\"" * ( P "\\\"" + 1 - P "\"" ) ^ 1 * "\"" )
+
if piton.beamer then Beamer = Compute_Beamer ( 'minimal' , braces ) end
DetectedCommands = Compute_DetectedCommands ( 'minimal' , braces )
@@ -7452,7 +7516,7 @@
local t = LPEG2[language] : match ( code )
if t == nil
then
- sprintL3 [[ \@@_error_or_warning:n { syntax~error } ]]
+ sprintL3 [[ \@@_error_or_warning:n { SyntaxError } ]]
return -- to exit in force the function
end
local left_stack = {}
@@ -7685,12 +7749,31 @@
piton.last_code = gobble ( n , code )
piton.last_language = lang
% \end{macrocode}
+% We count the number of lines of the informatic code. The result will be stored
+% by Lua in |\l_@@_nb_lines_int|. That information will be used to allow or
+% disallow page breaks (when |splittable| is in force).
% \begin{macrocode}
- sprintL3 [[ \bool_if:NT \g_@@_footnote_bool \savenotes \vtop \bgroup ]]
+ piton.CountLines ( piton.last_code )
+ sprintL3 [[ \bool_if:NT \g_@@_footnote_bool \savenotes ]]
+% \end{macrocode}
+% We begin a |\vtop| for an non-splittable block of lines.
+% \begin{macrocode}
+ sprintL3 [[ \vtop \bgroup ]]
piton.Parse ( lang , piton.last_code )
- sprintL3
- [[\vspace{2.5pt}\egroup\bool_if:NT\g_@@_footnote_bool\endsavenotes\par]]
% \end{macrocode}
+% We close the latest opened |\vtop| with the following |\egroup|. Be careful:
+% that |\vtop| is \emph{not} necessarily the |\vtop| opened two lines above
+% because the commands |\@@_newline:| inserted by Lua may open and close
+% |\vtop|s and start and finish paragraphs (when |splittable| is in force).
+% \begin{macrocode}
+ sprintL3 [[ \vspace{2.5pt} \egroup ]]
+ sprintL3 [[ \bool_if:NT \g_@@_footnote_bool \endsavenotes ]]
+% \end{macrocode}
+% We finish the paragraph (each block of non-splittable lines of code is
+% composed in a |\vtop| inserted in a paragraph).
+% \begin{macrocode}
+ sprintL3 [[ \par ]]
+% \end{macrocode}
%
% Now, if the final user has used the key |write| to write the code of the
% environment on an external file.
@@ -7707,7 +7790,9 @@
% The following function will be used when the key |split-on-empty-lines| is in
% force. With that key, the informatic code is split in chunks at the empty
% lines (usually between the informatic functions defined in the informatic
-% code). LaTeX will be able to change the page between the chunks.
+% code). LaTeX will be able to change the page between the chunks. The second
+% argument |n| corresponds to the value of the key |gobble| (number of spaces to
+% gobble).
% \begin{macrocode}
function piton.GobbleSplitParse ( lang , n , code )
P { "E" ,
@@ -7716,7 +7801,7 @@
/ ( function ( x ) sprintL3 [[ \@@_incr_visual_line: ]] end )
) ^ 1
/ ( function ( x )
- sprintL3 [[ \l_@@_split_separation_tl \int_gzero:N \g_@@_line_int ]]
+ sprintL3 ( piton.string_between_chunks )
end )
) ^ 0 * V "F" ,
% \end{macrocode}
@@ -7724,7 +7809,7 @@
% \begin{macrocode}
F = C ( V "G" ^ 0 )
% \end{macrocode}
-% The second argument of |.pitonGobbleParse| is the argument |gobble|: we put
+% The second argument of |piton.GobbleSplitParse| is the argument |gobble|: we put
% that argument to~$0$ because we will have gobbled previously the whole argument
% |code| (see below).
% \begin{macrocode}
@@ -7733,10 +7818,24 @@
% The non-terminal |G| corresponds to a non-empty line of code.
% \begin{macrocode}
G = ( 1 - P "\r" ) ^ 0 * "\r" - ( P " " ^ 0 * "\r" )
+ + ( ( 1 - P "\r" ) ^ 1 * -1 - ( P " " ^ 0 * -1 ) )
} : match ( gobble ( n , code ) )
end
% \end{macrocode}
%
+% \bigskip
+% The following Lua string will be inserted between the chunks of code created
+% when the key |split-on-empty-lines| is in force. It's used only once: you have
+% given a name to that Lua string only for legibily. The token list
+% |\l_@@_split_separation_tl| corresponds to the key |split-separation|. That
+% token list must contain elements inserted in \emph{vertical mode} of TeX.
+% \begin{macrocode}
+piton.string_between_chunks =
+ [[ \par \l_@@_split_separation_tl \mode_leave_vertical: ]]
+ .. [[ \int_gzero:N \g_@@_line_int ]]
+% \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|).
%
% \bigskip
% The following public Lua function is provided to the developer.
@@ -7751,14 +7850,23 @@
% \subsubsection{To count the number of lines}
%
% \medskip
+% 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
+% code will be stored in |\l_@@_nb_lines_int| and will be used to allow or
+% disallow line breaks (when |splittable| is in force).
% \begin{macrocode}
function piton.CountLines ( code )
local count = 0
for i in code : gmatch ( "\r" ) do count = count + 1 end
- sprintL3 ( [[ \int_set:Nn \l_@@_nb_lines_int { ]] .. count .. '}' )
+ sprintL3 ( string.format ( [[ \int_set:Nn \l_@@_nb_lines_int { % i } ]] , 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
+% code will be stored in |\l_@@_nb_non_empty_lines_int|. It will be used to
+% compute the largest number of lines to write (when |line-numbers| is in force).
% \begin{macrocode}
function piton.CountNonEmptyLines ( code )
local count = 0
@@ -7769,7 +7877,8 @@
* -1
) / table.getn
) : match ( code )
- sprintL3 ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { ]] .. count .. '}' )
+ sprintL3
+ ( string.format ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { % i } ]] , count ) )
end
% \end{macrocode}
%
@@ -7778,7 +7887,8 @@
function piton.CountLinesFile ( name )
local count = 0
for line in io.lines ( name ) do count = count + 1 end
- sprintL3 ( [[ \int_set:Nn \l_@@_nb_lines_int { ]] .. count .. '}' )
+ sprintL3
+ ( string.format ( [[ \int_set:Nn \l_@@_nb_lines_int { %i } ]], count))
end
% \end{macrocode}
%
@@ -7792,7 +7902,8 @@
count = count + 1
end
end
- sprintL3 ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { ]] .. count .. '}' )
+ sprintL3
+ ( string.format ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { % i } ]] , count ) )
end
% \end{macrocode}
%
@@ -8125,6 +8236,7 @@
% the strings.
% \begin{macrocode}
local long_string = P ( false )
+ local Long_string = P ( false )
local LongString = P (false )
local central_pattern = P ( false )
for _ , x in ipairs ( def_table ) do
@@ -8151,8 +8263,16 @@
else prefix = P ( true )
end
% \end{macrocode}
-% We can write the pattern which matches the string.
+% First, a pattern \emph{without captures} (needed to compute |braces|).
% \begin{macrocode}
+ long_string = long_string +
+ prefix
+ * arg3
+ * ( space + central_pattern ) ^ 0
+ * arg4
+% \end{macrocode}
+% Now a pattern \emph{with captures}.
+% \begin{macrocode}
local pattern =
prefix
* Q ( arg3 )
@@ -8159,10 +8279,9 @@
* ( VisualSpace + Q ( central_pattern ^ 1 ) + EOL ) ^ 0
* Q ( arg4 )
% \end{macrocode}
-% First, we create |long_string| because we need that \textsc{lpeg} in the
-% nested comments.
+% We will need |Long_string| in the nested comments.
% \begin{macrocode}
- long_string = long_string + pattern
+ Long_string = Long_string + pattern
LongString = LongString +
Ct ( Cc "Open" * Cc ( "{" .. arg2 .. "{" ) * Cc "}}" )
* pattern
@@ -8169,8 +8288,11 @@
* Ct ( Cc "Close" )
end
end
-
- local braces = Compute_braces ( String )
+% \end{macrocode}
+% The argument of |Compute_braces| must be a pattern \emph{which does no
+% catching} corresponding to the strings of the language.
+% \begin{macrocode}
+ local braces = Compute_braces ( long_string )
if piton.beamer then Beamer = Compute_Beamer ( lang , braces ) end
DetectedCommands = Compute_DetectedCommands ( lang , braces )
@@ -8403,7 +8525,7 @@
%
% \subsection*{Changes between versions 3.0 and 3.1}
%
-% New keys |line-numbers/format|, |detected-beamer-commands| and
+% Keys |line-numbers/format|, |detected-beamer-commands| and
% |detected-beamer-environments|.
%
%
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2024-08-12 20:04:42 UTC (rev 72015)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua 2024-08-12 20:04:59 UTC (rev 72016)
@@ -20,18 +20,13 @@
-- -------------------------------------------
--
-- This file is part of the LuaLaTeX package 'piton'.
-piton_version = "3.1" -- 2024/07/30
+piton_version = "3.1a" -- 2024/08/12
+
if piton.comment_latex == nil then piton.comment_latex = ">" end
piton.comment_latex = "#" .. piton.comment_latex
-function piton.open_brace ()
- tex.sprint("{")
-end
-function piton.close_brace ()
- tex.sprint("}")
-end
local function sprintL3 ( s )
tex.sprint ( luatexbase.catcodetables.expl , s )
end
@@ -150,13 +145,13 @@
* Cc "}"
)
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* P "}"
* Ct ( Cc "Close" )
end
local function Compute_LPEG_cleaner ( lang , braces ) return
Ct ( ( piton.DetectedCommands * "{"
- * ( braces
+ * ( braces
/ ( function ( s )
if s ~= '' then return LPEG_cleaner[lang] : match ( s ) end end ) )
* "}"
@@ -210,13 +205,16 @@
lpeg = lpeg +
L ( ( P "\\temporal" ) * "<" * ( 1 - P ">" ) ^ 0 * ">" * "{" )
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s )
+ if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}{" )
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s )
+ if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}{" )
* ( braces
- / ( function ( s ) if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
+ / ( function ( s )
+ if s ~= '' then return LPEG1[lang] : match ( s ) end end ) )
* L ( P "}" )
for _ , x in ipairs ( piton.beamer_environments ) do
lpeg = lpeg +
@@ -408,11 +406,11 @@
local braces =
Compute_braces
(
- Q ( P "\"" + "r\"" + "R\"" + "f\"" + "F\"" )
- * ( "\"" * ( P "\\\"" + 1 - S "\"" ) ^ 0 * "\"" )
+ ( P "\"" + "r\"" + "R\"" + "f\"" + "F\"" )
+ * ( P "\\\"" + 1 - S "\"" ) ^ 0 * "\""
+
- Q ( P '\'' + 'r\'' + 'R\'' + 'f\'' + 'F\'' )
- * ( '\'' * ( P '\\\'' + 1 - S '\'' ) ^ 0 * '\'' )
+ ( P '\'' + 'r\'' + 'R\'' + 'f\'' + 'F\'' )
+ * ( P '\\\'' + 1 - S '\'' ) ^ 0 * '\''
)
if piton.beamer then Beamer = Compute_Beamer ( 'python' , braces ) end
DetectedCommands = Compute_DetectedCommands ( 'python' , braces )
@@ -650,7 +648,7 @@
"Sys_blocked_io" + "Sys_error" + "Undefined_recursive_module" )
local Char =
K ( 'String.Short' , "'" * ( ( 1 - P "'" ) ^ 0 + "\\'" ) * "'" )
-braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
+local braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
if piton.beamer then
Beamer = Compute_Beamer ( 'ocaml' , braces ) -- modified 2024/07/24
end
@@ -857,7 +855,7 @@
) ^ 0
* Q "\""
)
-braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
+local braces = Compute_braces ( "\"" * ( 1 - S "\"" ) ^ 0 * "\"" )
if piton.beamer then Beamer = Compute_Beamer ( 'c' , braces ) end
DetectedCommands = Compute_DetectedCommands ( 'c' , braces )
LPEG_cleaner['c'] = Compute_LPEG_cleaner ( 'c' , braces )
@@ -964,7 +962,7 @@
end
)
local String = K ( 'String.Long' , "'" * ( 1 - P "'" ) ^ 1 * "'" )
-braces = Compute_braces ( String )
+local braces = Compute_braces ( "'" * ( 1 - P "'" ) ^ 1 * "'" )
if piton.beamer then Beamer = Compute_Beamer ( 'sql' , braces ) end
DetectedCommands = Compute_DetectedCommands ( 'sql' , braces )
LPEG_cleaner['sql'] = Compute_LPEG_cleaner ( 'sql' , braces )
@@ -1065,7 +1063,8 @@
* Q "\""
)
-braces = Compute_braces ( String )
+local braces = Compute_braces ( P "\"" * ( P "\\\"" + 1 - P "\"" ) ^ 1 * "\"" )
+
if piton.beamer then Beamer = Compute_Beamer ( 'minimal' , braces ) end
DetectedCommands = Compute_DetectedCommands ( 'minimal' , braces )
@@ -1110,7 +1109,7 @@
local t = LPEG2[language] : match ( code )
if t == nil
then
- sprintL3 [[ \__piton_error_or_warning:n { syntax~error } ]]
+ sprintL3 [[ \__piton_error_or_warning:n { SyntaxError } ]]
return -- to exit in force the function
end
local left_stack = {}
@@ -1244,10 +1243,13 @@
function piton.GobbleParse ( lang , n , code )
piton.last_code = gobble ( n , code )
piton.last_language = lang
- sprintL3 [[ \bool_if:NT \g__piton_footnote_bool \savenotes \vtop \bgroup ]]
+ piton.CountLines ( piton.last_code )
+ sprintL3 [[ \bool_if:NT \g__piton_footnote_bool \savenotes ]]
+ sprintL3 [[ \vtop \bgroup ]]
piton.Parse ( lang , piton.last_code )
- sprintL3
- [[\vspace{2.5pt}\egroup\bool_if:NT\g__piton_footnote_bool\endsavenotes\par]]
+ sprintL3 [[ \vspace{2.5pt} \egroup ]]
+ sprintL3 [[ \bool_if:NT \g__piton_footnote_bool \endsavenotes ]]
+ sprintL3 [[ \par ]]
if piton.write and piton.write ~= '' then
local file = assert ( io.open ( piton.write , piton.write_mode ) )
file:write ( piton.get_last_code ( ) )
@@ -1261,14 +1263,18 @@
/ ( function ( x ) sprintL3 [[ \__piton_incr_visual_line: ]] end )
) ^ 1
/ ( function ( x )
- sprintL3 [[ \l__piton_split_separation_tl \int_gzero:N \g__piton_line_int ]]
+ sprintL3 ( piton.string_between_chunks )
end )
) ^ 0 * V "F" ,
F = C ( V "G" ^ 0 )
/ ( function ( x ) piton.GobbleParse ( lang , 0 , x ) end ) ,
G = ( 1 - P "\r" ) ^ 0 * "\r" - ( P " " ^ 0 * "\r" )
+ + ( ( 1 - P "\r" ) ^ 1 * -1 - ( P " " ^ 0 * -1 ) )
} : match ( gobble ( n , code ) )
end
+piton.string_between_chunks =
+ [[ \par \l__piton_split_separation_tl \mode_leave_vertical: ]]
+ .. [[ \int_gzero:N \g__piton_line_int ]]
function piton.get_last_code ( )
return LPEG_cleaner[piton.last_language] : match ( piton.last_code )
end
@@ -1275,7 +1281,7 @@
function piton.CountLines ( code )
local count = 0
for i in code : gmatch ( "\r" ) do count = count + 1 end
- sprintL3 ( [[ \int_set:Nn \l__piton_nb_lines_int { ]] .. count .. '}' )
+ sprintL3 ( string.format ( [[ \int_set:Nn \l__piton_nb_lines_int { % i } ]] , count ) )
end
function piton.CountNonEmptyLines ( code )
local count = 0
@@ -1286,12 +1292,14 @@
* -1
) / table.getn
) : match ( code )
- sprintL3 ( [[ \int_set:Nn \l__piton_nb_non_empty_lines_int { ]] .. count .. '}' )
+ 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 ( [[ \int_set:Nn \l__piton_nb_lines_int { ]] .. count .. '}' )
+ sprintL3
+ ( string.format ( [[ \int_set:Nn \l__piton_nb_lines_int { %i } ]], count))
end
function piton.CountNonEmptyLinesFile ( name )
local count = 0
@@ -1300,7 +1308,8 @@
count = count + 1
end
end
- sprintL3 ( [[ \int_set:Nn \l__piton_nb_non_empty_lines_int { ]] .. count .. '}' )
+ sprintL3
+ ( string.format ( [[ \int_set:Nn \l__piton_nb_non_empty_lines_int { % i } ]] , count ) )
end
function piton.ComputeRange(marker_beginning,marker_end,file_name)
local s = ( Cs ( ( P '##' / '#' + 1 ) ^ 0 ) ) : match ( marker_beginning )
@@ -1477,6 +1486,7 @@
end
end
local long_string = P ( false )
+ local Long_string = P ( false )
local LongString = P (false )
local central_pattern = P ( false )
for _ , x in ipairs ( def_table ) do
@@ -1497,12 +1507,17 @@
then prefix = lpeg.B ( 1 - letter - ")" - "]" )
else prefix = P ( true )
end
+ long_string = long_string +
+ prefix
+ * arg3
+ * ( space + central_pattern ) ^ 0
+ * arg4
local pattern =
prefix
* Q ( arg3 )
* ( VisualSpace + Q ( central_pattern ^ 1 ) + EOL ) ^ 0
* Q ( arg4 )
- long_string = long_string + pattern
+ Long_string = Long_string + pattern
LongString = LongString +
Ct ( Cc "Open" * Cc ( "{" .. arg2 .. "{" ) * Cc "}}" )
* pattern
@@ -1509,8 +1524,7 @@
* Ct ( Cc "Close" )
end
end
-
- local braces = Compute_braces ( String )
+ local braces = Compute_braces ( long_string )
if piton.beamer then Beamer = Compute_Beamer ( lang , braces ) end
DetectedCommands = Compute_DetectedCommands ( lang , braces )
Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2024-08-12 20:04:42 UTC (rev 72015)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty 2024-08-12 20:04:59 UTC (rev 72016)
@@ -19,11 +19,12 @@
%% LaTeX version 2005/12/01 or later.
%% -------------------------------------------
%%
-\def\PitonFileVersion{3.1}
-\def\PitonFileDate{2024/07/30}
+\def\PitonFileVersion{3.1a}
+\def\PitonFileDate{2024/08/12}
+
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{l3keys2e}
\ProvidesExplPackage
@@ -31,6 +32,7 @@
{\PitonFileDate}
{\PitonFileVersion}
{Highlight informatic listings with LPEG on LuaLaTeX}
+\RequirePackage { amstext }
\cs_new_protected:Npn \__piton_error:n { \msg_error:nn { piton } }
\cs_new_protected:Npn \__piton_warning:n { \msg_warning:nn { piton } }
\cs_new_protected:Npn \__piton_error:nn { \msg_error:nnn { piton } }
@@ -96,18 +98,8 @@
beamer .bool_gset:N = \g__piton_beamer_bool ,
beamer .default:n = true ,
- math-comments .code:n = \__piton_error:n { moved~to~preamble } ,
- comment-latex .code:n = \__piton_error:n { moved~to~preamble } ,
-
unknown .code:n = \__piton_error:n { Unknown~key~for~package }
}
-\__piton_msg_new:nn { moved~to~preamble }
- {
- The~key~'\l_keys_key_str'~*must*~now~be~used~with~
- \token_to_str:N \PitonOptions`in~the~preamble~of~your~
- document.\\
- That~key~will~be~ignored.
- }
\__piton_msg_new:nn { Unknown~key~for~package }
{
Unknown~key.\\
@@ -185,9 +177,10 @@
\int_new:N \g__piton_line_int
\tl_new:N \g__piton_aux_tl
\int_new:N \l__piton_splittable_int
+\int_set:Nn \l__piton_splittable_int { 100 }
\tl_new:N \l__piton_split_separation_tl
-\tl_set:Nn \l__piton_split_separation_tl { \vspace{\baselineskip} \vspace{-1.25pt} }
-\int_set:Nn \l__piton_splittable_int { 100 }
+\tl_set:Nn \l__piton_split_separation_tl
+ { \vspace { \baselineskip } \vspace { -1.25pt } }
\clist_new:N \l__piton_bg_color_clist
\tl_new:N \l__piton_prompt_bg_color_tl
\str_new:N \l__piton_begin_range_str
@@ -312,7 +305,7 @@
{
\bool_if:nF
{
- \str_if_eq_p:nn { #1 } { \PitonStyle {Prompt}{} }
+ \str_if_eq_p:nn { #1 } { \PitonStyle { Prompt } { } }
&&
\l__piton_skip_empty_lines_bool
}
@@ -319,7 +312,7 @@
{ \int_gincr:N \g__piton_visual_line_int }
\bool_if:nT
{
- ! \str_if_eq_p:nn { #1 } { \PitonStyle {Prompt}{} }
+ ! \str_if_eq_p:nn { #1 } { \PitonStyle { Prompt } { } }
||
( ! \l__piton_skip_empty_lines_bool && \l__piton_label_empty_lines_bool )
}
@@ -392,11 +385,12 @@
\int_compare:nNnT \g__piton_line_int > { \l__piton_splittable_int - 1 }
{
\int_compare:nNnT
- { \l__piton_nb_lines_int - \g__piton_line_int } > \l__piton_splittable_int
+ { \l__piton_nb_lines_int - \g__piton_line_int + 1 } > \l__piton_splittable_int
{
\egroup
\bool_if:NT \g__piton_footnote_bool \endsavenotes
- \par \mode_leave_vertical:
+ \par
+ \mode_leave_vertical:
\bool_if:NT \g__piton_footnote_bool \savenotes
\vtop \bgroup
}
@@ -455,12 +449,8 @@
false .code:n = \bool_set_false:N \l__piton_line_numbers_bool ,
start .code:n =
- \bool_if:NTF \l__piton_in_PitonOptions_bool
- { Invalid~key }
- {
- \bool_set_true:N \l__piton_line_numbers_bool
- \int_set:Nn \l__piton_number_lines_start_int { #1 }
- } ,
+ \bool_set_true:N \l__piton_line_numbers_bool
+ \int_set:Nn \l__piton_number_lines_start_int { #1 } ,
start .value_required:n = true ,
skip-empty-lines .code:n =
@@ -487,11 +477,7 @@
{
\bool_set_true:N \l__piton_line_numbers_absolute_bool
\bool_set_false:N \l__piton_skip_empty_lines_bool
- }
- \bool_lazy_or:nnF
- \l__piton_in_PitonInputFile_bool
- \l__piton_in_PitonOptions_bool
- { \__piton_error:n { Invalid~key } } ,
+ } ,
absolute .value_forbidden:n = true ,
resume .code:n =
@@ -708,7 +694,7 @@
{
{
\l__piton_line_numbers_format_tl
- \int_to_arabic:n \g__piton_visual_line_int
+ { \int_to_arabic:n \g__piton_visual_line_int }
}
\skip_horizontal:N \l__piton_numbers_sep_dim
}
@@ -794,7 +780,6 @@
\NewDocumentCommand { \__piton_piton_standard } { m }
{
\group_begin:
- \ttfamily
\automatichyphenmode = 1
\cs_set_eq:NN \\ \c_backslash_str
\cs_set_eq:NN \% \c_percent_str
@@ -816,7 +801,11 @@
\bool_if:NT \l__piton_break_lines_in_piton_bool
{ \regex_replace_all:nnN { \x20 } { \x20 } \l_tmpa_tl }
}
- \l_tmpa_tl
+ \if_mode_math:
+ \text { \ttfamily \l_tmpa_tl }
+ \else:
+ \ttfamily \l_tmpa_tl
+ \fi:
\group_end:
}
\NewDocumentCommand { \__piton_piton_verbatim } { v }
@@ -872,34 +861,9 @@
\cs_new_protected:Npn \__piton_piton_no_cr:n #1
{
\group_begin:
- \cs_set_protected:Npn \__piton_begin_line: { }
- \cs_set_protected:Npn \__piton_end_line: { }
- \cs_set:cpn { pitonStyle _ \l_piton_language_str _ Prompt } { }
- \cs_set:cpn { pitonStyle _ Prompt } { }
\cs_set_protected:Npn \__piton_newline:
{ \msg_fatal:nn { piton } { cr~not~allowed } }
- \bool_lazy_or:nnTF
- \l__piton_break_lines_in_piton_bool
- \l__piton_break_lines_in_Piton_bool
- {
- \tl_set:Nx \l_tmpa_tl
- {
- \lua_now:e
- { piton.ParseTer('\l_piton_language_str',token.scan_string()) }
- { #1 }
- }
- }
- {
- \tl_set:Nx \l_tmpa_tl
- {
- \lua_now:e
- { piton.Parse('\l_piton_language_str',token.scan_string()) }
- { #1 }
- }
- }
- \bool_if:NT \l__piton_show_spaces_bool
- { \regex_replace_all:nnN { \x20 } { ␣ } \l_tmpa_tl } % U+2423
- \l_tmpa_tl
+ \__piton_piton:n { #1 }
\group_end:
}
\cs_new:Npn \__piton_pre_env:
@@ -979,12 +943,12 @@
}
{
\group_end:
- \mode_if_vertical:TF \mode_leave_vertical: \newline
- \lua_now:n { piton.CountLines(token.scan_argument()) } { ##1 }
+ \mode_if_vertical:TF { \noindent \mode_leave_vertical: } \newline
\__piton_compute_left_margin:nn { CountNonEmptyLines } { ##1 }
\__piton_compute_width:
\ttfamily
\dim_zero:N \parskip
+ \noindent % added 2024/08/07
\str_if_empty:NTF \l__piton_path_write_str
{ \lua_now:e { piton.write = "\l__piton_write_str" } }
{
@@ -1256,8 +1220,6 @@
{
String .meta:n = { String.Long = #1 , String.Short = #1 } ,
Comment.Math .tl_set:c = pitonStyle _ Comment.Math ,
- ParseAgain .tl_set:c = pitonStyle _ ParseAgain ,
- ParseAgain .value_required:n = true ,
ParseAgain.noCR .tl_set:c = pitonStyle _ ParseAgain.noCR ,
ParseAgain.noCR .value_required:n = true ,
unknown .code:n =
@@ -1303,7 +1265,6 @@
UserFunction = ,
Prompt = ,
ParseAgain.noCR = \__piton_piton_no_cr:n ,
- ParseAgain = \__piton_piton:n ,
Discard = \use_none:n
}
\AtBeginDocument
@@ -1446,7 +1407,7 @@
markers~and~explicit~number~of~lines.\\
Your~whole~file~'\l__piton_file_name_str'~will~be~included.
}
-\__piton_msg_new:nn { syntax~error }
+\__piton_msg_new:nn { SyntaxError }
{
Your~code~of~the~language~"\l_piton_language_str"~is~not~
syntactically~correct.\\
More information about the tex-live-commits
mailing list.