diff options
author | Karl Berry <karl@freefriends.org> | 2022-09-19 20:28:42 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-09-19 20:28:42 +0000 |
commit | 3dfc7b446aa172f6643e8a654a351b1a49f673a5 (patch) | |
tree | 5b184e9fd159299b1b8b3247ec5cac073ad40b01 /Master/texmf-dist | |
parent | 8e113c535e79ca3a2635bfefbaa29cd4b52a4410 (diff) |
piton (19sep22)
git-svn-id: svn://tug.org/texlive/trunk@64446 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/lualatex/piton/piton-french.pdf | bin | 151124 -> 151584 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/piton/piton-french.tex | 7 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/piton/piton.pdf | bin | 223287 -> 227733 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/lualatex/piton/piton.dtx | 101 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/piton/piton.lua | 80 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/piton/piton.sty | 58 |
6 files changed, 174 insertions, 72 deletions
diff --git a/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf b/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf Binary files differindex ef7a5a19649..5356daa6789 100644 --- a/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf +++ b/Master/texmf-dist/doc/lualatex/piton/piton-french.pdf diff --git a/Master/texmf-dist/doc/lualatex/piton/piton-french.tex b/Master/texmf-dist/doc/lualatex/piton/piton-french.tex index 5e9ee11c7a8..3e70890e234 100644 --- a/Master/texmf-dist/doc/lualatex/piton/piton-french.tex +++ b/Master/texmf-dist/doc/lualatex/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/Master/texmf-dist/doc/lualatex/piton/piton.pdf b/Master/texmf-dist/doc/lualatex/piton/piton.pdf Binary files differindex 34024c336e5..924373fc93d 100644 --- a/Master/texmf-dist/doc/lualatex/piton/piton.pdf +++ b/Master/texmf-dist/doc/lualatex/piton/piton.pdf diff --git a/Master/texmf-dist/source/lualatex/piton/piton.dtx b/Master/texmf-dist/source/lualatex/piton/piton.dtx index 48e6f777e50..d7180b9fa34 100644 --- a/Master/texmf-dist/source/lualatex/piton/piton.dtx +++ b/Master/texmf-dist/source/lualatex/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/Master/texmf-dist/tex/lualatex/piton/piton.lua b/Master/texmf-dist/tex/lualatex/piton/piton.lua index 8ef48f45b1f..2860246c4c3 100644 --- a/Master/texmf-dist/tex/lualatex/piton/piton.lua +++ b/Master/texmf-dist/tex/lualatex/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/Master/texmf-dist/tex/lualatex/piton/piton.sty b/Master/texmf-dist/tex/lualatex/piton/piton.sty index 5a3ac8cd0cb..3d128105017 100644 --- a/Master/texmf-dist/tex/lualatex/piton/piton.sty +++ b/Master/texmf-dist/tex/lualatex/piton/piton.sty @@ -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 } |