summaryrefslogtreecommitdiff
path: root/macros/luatex/latex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/latex')
-rw-r--r--macros/luatex/latex/piton/piton-french.pdfbin151124 -> 151584 bytes
-rw-r--r--macros/luatex/latex/piton/piton-french.tex7
-rw-r--r--macros/luatex/latex/piton/piton.dtx101
-rw-r--r--macros/luatex/latex/piton/piton.lua80
-rw-r--r--macros/luatex/latex/piton/piton.pdfbin223287 -> 227733 bytes
5 files changed, 130 insertions, 58 deletions
diff --git a/macros/luatex/latex/piton/piton-french.pdf b/macros/luatex/latex/piton/piton-french.pdf
index ef7a5a1964..5356daa678 100644
--- a/macros/luatex/latex/piton/piton-french.pdf
+++ b/macros/luatex/latex/piton/piton-french.pdf
Binary files differ
diff --git a/macros/luatex/latex/piton/piton-french.tex b/macros/luatex/latex/piton/piton-french.tex
index 5e9ee11c7a..3e70890e23 100644
--- a/macros/luatex/latex/piton/piton-french.tex
+++ b/macros/luatex/latex/piton/piton-french.tex
@@ -141,14 +141,14 @@ fonction (on peut néanmoins l'utiliser à l'intérieur d'un environnement).
\bigskip
Il est possible de composer des commentaires en LaTeX en commençant par |##| (c'est un échappement vers LaTeX). Les
-caractères |##| eux-mêmes ne seront pas imprimés.
+caractères |##| eux-mêmes ne seront pas imprimés et les espaces qui les suivent sont supprimés.
\section{Personnalisation}
\subsection{La commande \textbackslash PitonOptions}
-La commande |\PitonOptions| propose quatre clés : |gobble|, |auto-gobble|, |line-numbers| et |all-line-numbers|.
+La commande |\PitonOptions| propose cinq clés : |gobble|, |auto-gobble|, |env-gobble|, |line-numbers| et |all-line-numbers|.
\begin{itemize}
\item La clé |gobble| peut comme valeur un entier positif $n$ : les $n$ premiers caractères de chaque ligne sont
@@ -158,6 +158,9 @@ alors retirés (avant formatage du code) dans les environnements |{Piton}|.
d'espaces successifs débutant chaque ligne (non vide) de l'environnment |{Piton}| et applique |gobble| avec cette
valeur de~$n$.
+* Quand la clé |env-gobble| est activée, \pkg{piton} applique la clé |gobble| avec une valeur de $n$ égale au
+nombre d'espaces sur la ligne précédant le |\end{Piton}| (si cette ligne ne comporte que des espaces).
+
\item Avec la clé |line-numbers|, les lignes \emph{non vides} sont numérotées dans les environnements \verb|{Piton}|
et dans les listings produits par la commande |\PitonInputFile|.
diff --git a/macros/luatex/latex/piton/piton.dtx b/macros/luatex/latex/piton/piton.dtx
index 48e6f777e5..d7180b9fa3 100644
--- a/macros/luatex/latex/piton/piton.dtx
+++ b/macros/luatex/latex/piton/piton.dtx
@@ -15,8 +15,8 @@
%
% \fi
% \iffalse
-\def\myfileversion{0.6}
-\def\myfiledate{2022/09/14}
+\def\myfileversion{0.6a}
+\def\myfiledate{2022/09/19}
%
%
%<*batchfile>
@@ -159,25 +159,30 @@ def fact(n):
%
% \bigskip
% It's possible to compose comments in LaTeX by beginning with |##| (it's a
-% ``LaTeX escape''). The characters |##| themselves won't be printed.
+% ``LaTeX escape''). The characters |##| themselves won't be printed and the
+% spaces after |##| are removed.
%
% \section{Customization}
%
% \subsection{The command \textbackslash PitonOptions}
%
-% The command |\PitonOptions| provides four keys: |gobble|, |auto-gobble|,
-% |line-numbers| and |all-line-numbers|.
+% The command |\PitonOptions| provides five keys: |gobble|, |auto-gobble|,
+% |env-gobble|, |line-numbers| and |all-line-numbers|.
%
% \begin{itemize}
% \item The key |gobble| takes in as value a positive integer~$n$: the first $n$
% characters are discarded (before the process of hightlighning of the code) for
% each line of the environment |{Piton}|.
%
-% \item Then the key |auto-gobble| is in force, the extnsion \pkg{piton} compute
+% \item Then the key |auto-gobble| is in force, the extension \pkg{piton} computes
% the minimal value $n$ of the number of consecutives space beginning each (non
% empty) line of the environment |{Piton}| and applies |gobble| with that value
% of~$n$.
%
+% \item When the key |env-gobble| is in force, \pkg{piton} applies |gobble| with
+% a value of $n$ equal to the number of spaces before |\end{Piton}| on the last
+% line (if that line contains only spaces).
+%
% \item With the key |line-numbers|, the \emph{non empty} lines are numbered in
% the environments |{Piton}| and in the listings resulting from the use of
% |\PitonInputFile|.
@@ -388,6 +393,18 @@ def fact(n):
% \end{macrocode}
%
% \bigskip
+% \begin{macrocode}
+\msg_new:nnn { piton } { LuaLaTeX~mandatory }
+ { The~package~'piton'~must~be~used~with~LuaLaTeX.\\ It~won't~be~loaded. }
+\sys_if_engine_luatex:F { \msg_critical:nn { piton } { LuaLaTeX~mandatory } }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\RequirePackage { luatexbase }
+% \end{macrocode}
+%
+% \bigskip
% We define a set of keys |piton/package| for these options.
% \begin{macrocode}
\keys_define:nn { piton / package }
@@ -432,16 +449,24 @@ def fact(n):
\endgroup
% \end{macrocode}
%
-% \bigskip
-% \begin{macrocode}
-\msg_new:nnn { piton } { LuaLaTeX~mandatory }
- { The~package~'piton'~must~be~used~with~LuaLaTeX.\\ It~won't~be~loaded. }
-\sys_if_engine_luatex:F { \msg_critical:nn { piton } { LuaLaTeX~mandatory } }
-% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
-\RequirePackage { luatexbase }
+\AtBeginDocument
+ {
+ \@ifpackageloaded { xcolor }
+ { }
+ { \msg_fatal:nn { piton } { xcolor~not~loaded } }
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnn { piton } { xcolor~not~loaded }
+ {
+ xcolor~not~loaded \\
+ The~package~'xcolor'~is~required~by~'piton'.\\
+ This~error~is~fatal.
+ }
% \end{macrocode}
%
% \bigskip
@@ -477,7 +502,10 @@ def fact(n):
% \medskip
% \begin{macrocode}
\cs_new_protected:Npn \@@_print_number:
- { \bool_if:NT \l_@@_line_numbers_bool \@@_actually_print_number: }
+ {
+ \bool_if:NT \l_@@_line_numbers_bool
+ { \@@_actually_print_number: }
+ }
% \end{macrocode}
%
% \medskip
@@ -522,8 +550,8 @@ def fact(n):
%
% \bigskip
% \begin{macrocode}
-\cs_new_protected:Npn \@@_define_trim_syntax:n #1
- { \lua_now:n { define_trim_syntax(#1) } }
+\cs_new_protected:Npn \@@_define_gobble_syntax:n #1
+ { \lua_now:n { define_gobble_syntax(#1) } }
% \end{macrocode}
%
% \bigskip
@@ -561,26 +589,42 @@ def fact(n):
% \end{macrocode}
%
% \begin{macrocode}
-\keys_define:nn { piton / PitonOptions }
+\keys_define:nn { PitonOptions }
{
gobble .int_set:N = \l_@@_gobble_int ,
gobble .value_required:n = true ,
auto-gobble .code:n = \int_set:Nn \l_@@_gobble_int { -1 } ,
auto-gobble .value_forbidden:n = true ,
+ env-gobble .code:n = \int_set:Nn \l_@@_gobble_int { -2 } ,
+ env-gobble .value_forbidden:n = true ,
line-numbers .bool_set:N = \l_@@_line_numbers_bool ,
line-numbers .default:n = true ,
all-line-numbers .code:n =
\bool_set_true:N \l_@@_line_numbers_bool
\bool_set_true:N \l_@@_all_line_numbers_bool ,
- all-line-numbers .value_forbidden:n = true
+ all-line-numbers .value_forbidden:n = true ,
+ unknown .code:n =
+ \msg_error:nn { piton } { Unknown~key~for~PitonOptions }
}
% \end{macrocode}
%
+% \bigskip
+% \begin{macrocode}
+\msg_new:nnn { piton } { Unknown~key~for~PitonOptions }
+ {
+ Unknown~key \\
+ The~key~'\l_keys_key_str'~is~unknown~for~\token_to_str:N \PitonOptions.~The~
+ available~keys~are:~all-line-numbers,~auto-gobble,~env-gobble,~gobble~and~
+ line-numbers.\\
+ If~you~go~on,~that~key~will~be~ignored.
+ }
+% \end{macrocode}
+%
% \bigskip
% The argument of |\PitonOptions| is provided by currification.
% \begin{macrocode}
\NewDocumentCommand \PitonOptions { }
- { \keys_set:nn { piton / PitonOptions } }
+ { \keys_set:nn { PitonOptions } }
% \end{macrocode}
%
% \bigskip
@@ -621,9 +665,11 @@ def fact(n):
{ \lua_now:e { Parse(token.scan_argument()) } }
{ -1 }
{ \lua_now:e { AutoGobbleParse(token.scan_argument()) } }
+ { -2 }
+ { \lua_now:e { EnvGobbleParse(token.scan_argument()) } }
}
{
- \exp_args:NV \@@_define_trim_syntax:n \l_@@_gobble_int
+ \exp_args:NV \@@_define_gobble_syntax:n \l_@@_gobble_int
\lua_now:e { GobbleParse(token.scan_argument()) }
}
{ ##1 }
@@ -639,22 +685,25 @@ def fact(n):
%
%
% \bigskip
-% We can now define the new environment by defining the two TeX macros
-% characteristic to the LaTeX environment.
+% We can now define the new environment.
% \begin{macrocode}
- \NewDocumentEnvironment { #1 } { #2 }
+ \NewDocumentEnvironment { #1 } { #2 }
{
#3
\group_begin:
\tl_map_function:nN
- { \ \\ \{ \} \$ \& \# \^ \_ \% \~ \^^M }
+ { \ \\ \{ \} \$ \& \# \^ \_ \% \~ }
\char_set_catcode_other:N
- \use:c { __piton_collect_ #1 :w }
+ \use:c { __piton_collect_ #1 :w }
}
{ #4 }
+% \end{macrocode}
+%
+% \begin{macrocode}
+ \AddToHook { env / #1 / begin } { \char_set_catcode_other:N \^^M }
}
% \end{macrocode}
-%
+%
% \bigskip
% \begin{macrocode}
\NewPitonEnvironment { Piton } { } { } { }
diff --git a/macros/luatex/latex/piton/piton.lua b/macros/luatex/latex/piton/piton.lua
index 8ef48f45b1..2860246c4c 100644
--- a/macros/luatex/latex/piton/piton.lua
+++ b/macros/luatex/latex/piton/piton.lua
@@ -14,7 +14,7 @@
-- Latex version 2005/12/01 or later.
--- This file is part of the version 0.55 of the package 'piton'
+-- This file is part of the version 0.6a of the package 'piton'
local P, S, V , C , Ct, Cc, Cf = lpeg.P, lpeg.S, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cc, lpeg.Cf
@@ -315,7 +315,7 @@ local Comment = L ( "{\\pitonStyleComment {" )
local CommentLaTeX =
P "##"
- * L "{\\PitonStyle{Comment.LaTeX}{"
+ * L "{\\PitonStyle{Comment.LaTeX}{\\ignorespaces"
* Ct ( C ( ( 1 - P "\r" ) ^ 0 ) )
* L "}}"
* ( EOL + -1 )
@@ -347,32 +347,32 @@ local Operator = K ( P "!=" + P "==" + P "<<" + P ">>" + S "-~+/*%=<>&.@|" , 'Op
local OperatorWord = K ( P "in" + P "is" + P "and" + P "or" + P "not" , 'Operator.Word')
local SyntaxPython =
- ( ( space - P "\r" ) ^0 * P "\r" ) ^ -1 * space ^ -1 *
- ( ( space^1 * -1 )
- + EOL
- + Space
- + Escape
- + CommentLaTeX
- + LongString
- + Comment
- + ExceptionInConsole
- + Set
- + Delim
- + Class * ( Space + Punct + EOL )
- + Namespace * ( Space + Punct + EOL )
- + ImportAs
- + RaiseException
- + Keyword * ( Space + Punct + EOL )
- + DefFunction
- + ShortString
- + Decorator * ( Space + Punct + EOL )
- + Operator
- + OperatorWord * ( Space + Punct + EOL )
- + Builtin * ( Space + Punct + EOL )
- + Identifier
- + Number
- + Word
- ) ^0 * -1
+ ( ( space - P "\r" ) ^0 * P "\r" ) ^ -1 *
+ ( ( space^1 * -1 )
+ + EOL
+ + Space
+ + Escape
+ + CommentLaTeX
+ + LongString
+ + Comment
+ + ExceptionInConsole
+ + Set
+ + Delim
+ + Class * ( Space + Punct + EOL )
+ + Namespace * ( Space + Punct + EOL )
+ + ImportAs
+ + RaiseException
+ + Keyword * ( Space + Punct + EOL )
+ + DefFunction
+ + ShortString
+ + Decorator * ( Space + Punct + EOL )
+ + Operator
+ + OperatorWord * ( Space + Punct + EOL )
+ + Builtin * ( Space + Punct + EOL )
+ + Identifier
+ + Number
+ + Word
+ ) ^0 * -1
local MinimalSyntax =
@@ -397,6 +397,9 @@ function Parse(code)
end
end
+
+
+
function ParseFile(name)
s = ''
for line in io.lines(name) do s = s .. '\r' .. line end
@@ -449,8 +452,7 @@ AutoGobbleSyntax =
( Cf ( Cc(0) * ( P " " * Cc(1) ) ^ 0 , add )
* ( 1 - P " " ) * ( 1 - P "\r" ) ^ 0 ) ^ -1 ,
min
- )
-
+ )
function AutoGobbleParse(code)
local n = AutoGobbleSyntax:match(code)
@@ -462,6 +464,24 @@ function AutoGobbleParse(code)
end
+--[[ The following LPEG returns as capture the number of spaces at the last line,
+that is to say begin the \end{Piton} ]]
+
+EnvGobbleSyntax =
+ ( ( 1 - P "\r" ) ^ 0 * P "\r" ) ^ 0
+ * Cf ( Cc(0) * ( P " " * Cc(1) ) ^ 0 , add ) * -1
+
+function EnvGobbleParse(code)
+ local n = EnvGobbleSyntax:match(code)
+ if n==0
+ then Parse(code)
+ else define_gobble_syntax(n)
+ GobbleParse(code)
+ end
+end
+
+
+
diff --git a/macros/luatex/latex/piton/piton.pdf b/macros/luatex/latex/piton/piton.pdf
index 34024c336e..924373fc93 100644
--- a/macros/luatex/latex/piton/piton.pdf
+++ b/macros/luatex/latex/piton/piton.pdf
Binary files differ