summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-09-19 20:28:42 +0000
committerKarl Berry <karl@freefriends.org>2022-09-19 20:28:42 +0000
commit3dfc7b446aa172f6643e8a654a351b1a49f673a5 (patch)
tree5b184e9fd159299b1b8b3247ec5cac073ad40b01 /Master/texmf-dist/tex
parent8e113c535e79ca3a2635bfefbaa29cd4b52a4410 (diff)
piton (19sep22)
git-svn-id: svn://tug.org/texlive/trunk@64446 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/lualatex/piton/piton.lua80
-rw-r--r--Master/texmf-dist/tex/lualatex/piton/piton.sty58
2 files changed, 94 insertions, 44 deletions
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 }