texlive[64446] Master/texmf-dist: piton (19sep22)

commits+karl at tug.org commits+karl at tug.org
Mon Sep 19 22:28:42 CEST 2022


Revision: 64446
          http://tug.org/svn/texlive?view=revision&revision=64446
Author:   karl
Date:     2022-09-19 22:28:42 +0200 (Mon, 19 Sep 2022)
Log Message:
-----------
piton (19sep22)

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	2022-09-19 20:28:15 UTC (rev 64445)
+++ trunk/Master/texmf-dist/doc/lualatex/piton/piton-french.tex	2022-09-19 20:28:42 UTC (rev 64446)
@@ -141,7 +141,7 @@
 
 \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}
@@ -148,7 +148,7 @@
 
 \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 @@
 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|.
 

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	2022-09-19 20:28:15 UTC (rev 64445)
+++ trunk/Master/texmf-dist/source/lualatex/piton/piton.dtx	2022-09-19 20:28:42 UTC (rev 64446)
@@ -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,14 +159,15 @@
 %
 % \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$
@@ -173,11 +174,15 @@
 % 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 @@
 %    \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,17 +449,25 @@
 \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
 %    \begin{macrocode}
@@ -477,7 +502,10 @@
 % \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 @@
 %
 % \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 @@
 %    \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 @@
                   { \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 @@
 % 
 % 
 % \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 } { } { } { }

Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua	2022-09-19 20:28:15 UTC (rev 64445)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.lua	2022-09-19 20:28:42 UTC (rev 64446)
@@ -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 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 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 @@
   end
 end
 
+
+
+
 function ParseFile(name)
   s = ''
   for line in io.lines(name) do s = s .. '\r' .. line end
@@ -449,9 +452,8 @@
            ( Cf ( Cc(0) * ( P " " * Cc(1) ) ^ 0 , add )
            * ( 1 - P " " ) * ( 1 - P "\r" ) ^ 0 ) ^ -1 ,
 	   min
-         ) 
+         )
 
-
 function AutoGobbleParse(code)
   local n = AutoGobbleSyntax:match(code)
   if n==0
@@ -462,6 +464,24 @@
 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
+
+
+
   
 
 

Modified: trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty	2022-09-19 20:28:15 UTC (rev 64445)
+++ trunk/Master/texmf-dist/tex/lualatex/piton/piton.sty	2022-09-19 20:28:42 UTC (rev 64446)
@@ -18,8 +18,8 @@
 %% and version 1.3 or later is part of all distributions of
 %% LaTeX version 2005/12/01 or later.
 %% 
-\def\myfileversion{0.6}
-\def\myfiledate{2022/09/14}
+\def\myfileversion{0.6a}
+\def\myfiledate{2022/09/19}
 
 
 \NeedsTeXFormat{LaTeX2e}
@@ -29,6 +29,10 @@
   {\myfiledate}
   {\myfileversion}
   {Highlight Python codes with LPEG on LuaLaTeX}
+\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 } }
+\RequirePackage { luatexbase }
 \keys_define:nn { piton / package }
   {
     escape-inside .tl_set:N = \c__piton_escape_inside_tl ,
@@ -54,10 +58,18 @@
   { \tl_head:V \c__piton_escape_inside_tl }
   { \tl_tail:V \c__piton_escape_inside_tl }
 \endgroup
-\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 } }
-\RequirePackage { luatexbase }
+\AtBeginDocument
+  {
+    \@ifpackageloaded { xcolor }
+      { }
+      { \msg_fatal:nn { piton } { xcolor~not~loaded } }
+  }
+\msg_new:nnn { piton } { xcolor~not~loaded }
+  {
+    xcolor~not~loaded \\
+    The~package~'xcolor'~is~required~by~'piton'.\\
+    This~error~is~fatal.
+  }
 \msg_new:nnn { piton } { piton.lua~not~found }
   {
     The~file~'piton.lua'~can't~be~found.\\
@@ -72,7 +84,10 @@
     \__piton_print_number:
   }
 \cs_new_protected:Npn \__piton_print_number:
-  { \bool_if:NT \l__piton_line_numbers_bool \__piton_actually_print_number: }
+  {
+    \bool_if:NT \l__piton_line_numbers_bool
+      { \__piton_actually_print_number: }
+  }
 \cs_new_protected:Npn \__piton_actually_print_number:
   {
     \bool_if:NF \l__piton_all_line_numbers_bool
@@ -90,8 +105,8 @@
   }
 \int_new:N \l__piton_lineno_int
 \int_new:N \l__piton_gobble_int
-\cs_new_protected:Npn \__piton_define_trim_syntax:n #1
-  { \lua_now:n { define_trim_syntax(#1) } }
+\cs_new_protected:Npn \__piton_define_gobble_syntax:n #1
+  { \lua_now:n { define_gobble_syntax(#1) } }
 \NewDocumentCommand { \piton } { v }
   {
     \group_begin:
@@ -113,21 +128,33 @@
   }
 \bool_new:N \l__piton_line_numbers_bool
 \bool_new:N \l__piton_all_line_numbers_bool
-\keys_define:nn { piton / PitonOptions }
+\keys_define:nn { PitonOptions }
   {
     gobble           .int_set:N         = \l__piton_gobble_int ,
     gobble           .value_required:n  = true ,
     auto-gobble      .code:n            = \int_set:Nn \l__piton_gobble_int { -1 } ,
     auto-gobble      .value_forbidden:n = true ,
+    env-gobble       .code:n            = \int_set:Nn \l__piton_gobble_int { -2 } ,
+    env-gobble       .value_forbidden:n = true ,
     line-numbers     .bool_set:N        = \l__piton_line_numbers_bool ,
     line-numbers     .default:n         = true ,
     all-line-numbers .code:n =
       \bool_set_true:N \l__piton_line_numbers_bool
       \bool_set_true:N \l__piton_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 }
   }
+\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.
+  }
 \NewDocumentCommand \PitonOptions { }
-  { \keys_set:nn { piton / PitonOptions } }
+  { \keys_set:nn { PitonOptions } }
 \NewDocumentCommand { \NewPitonEnvironment } { m m m m }
   {
     \use:x
@@ -154,9 +181,11 @@
                   { \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 \__piton_define_trim_syntax:n \l__piton_gobble_int
+                   \exp_args:NV \__piton_define_gobble_syntax:n \l__piton_gobble_int
                    \lua_now:e { GobbleParse(token.scan_argument()) }
                 }
               { ##1 }
@@ -169,11 +198,12 @@
         #3
         \group_begin:
         \tl_map_function:nN
-          { \ \\ \{ \} \$ \& \# \^ \_ \% \~ \^^M }
+          { \ \\ \{ \} \$ \& \# \^ \_ \% \~ }
           \char_set_catcode_other:N
         \use:c { __piton_collect_ #1 :w }
       }
       { #4 }
+    \AddToHook { env / #1 / begin } { \char_set_catcode_other:N \^^M }
   }
 \NewPitonEnvironment { Piton } { } { } { }
 \NewDocumentCommand { \PitonStyle } { m } { \csname pitonStyle#1\endcsname }



More information about the tex-live-commits mailing list.