summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/piton/piton.dtx
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-03-31 03:00:49 +0000
committerNorbert Preining <norbert@preining.info>2024-03-31 03:00:49 +0000
commitd1109269e156ddc67b67f942a2e5aad3b37a40a6 (patch)
tree41f9af43bf0904dcbac73736c58ace6cc5e28f36 /macros/luatex/latex/piton/piton.dtx
parent16a9aadc4ae32ef5d7f20d62a3606b05e20f3405 (diff)
CTAN sync 202403310300
Diffstat (limited to 'macros/luatex/latex/piton/piton.dtx')
-rw-r--r--macros/luatex/latex/piton/piton.dtx440
1 files changed, 221 insertions, 219 deletions
diff --git a/macros/luatex/latex/piton/piton.dtx b/macros/luatex/latex/piton/piton.dtx
index e308e226b9..c8f13eabb5 100644
--- a/macros/luatex/latex/piton/piton.dtx
+++ b/macros/luatex/latex/piton/piton.dtx
@@ -72,12 +72,12 @@
% \iffalse
%<*STY>
% \fi
-\def\PitonFileVersion{2.7}
-\def\PitonFileDate{2024/03/24}
+\def\PitonFileVersion{2.7a}
+\def\PitonFileDate{2024/03/30}
% \iffalse
%</STY>
%<*LUA>
-piton_version = "2.7" -- 2024/03/24
+piton_version = "2.7a" -- 2024/03/30
%</LUA>
%\fi
%
@@ -359,9 +359,8 @@ piton_version = "2.7" -- 2024/03/24
% the part~\ref{API}, p.~\pageref{API}).} of the current environment in
% that file. At the first use of a file by \pkg{piton}, it is erased.
%
-% \item \index{path-write}\colorbox{yellow!50}{\bfseries New 2.5}\enskip The key
-% \Definition{path-write} specifies a path where the files written by the key
-% |write| will be written.
+% \item \index{path-write} The key \Definition{path-write} specifies a path
+% where the files written by the key |write| will be written.
%
% \item \index{line-numbers} The key \Definition{line-numbers} activates the
% line numbering in the environments |{Piton}| and in the listings resulting
@@ -371,14 +370,15 @@ piton_version = "2.7" -- 2024/03/24
% \begin{itemize}
% \item With the key \Definition{line-numbers/skip-empty-lines}, the empty lines
% (which contains only spaces) are considered as non existent for the line
-% numbering (if the key |/absolute| is in force, the key |/skip-empty-lines| is
-% no-op in |\PitonInputFile|). The initial value of that key is |true| (and not
-% |false|).\footnote{For the language Python, the empty lines in the docstrings
-% are taken into account (by design).}
+% numbering (if the key |/absolute|, described below, is in force, the key
+% |/skip-empty-lines| is no-op in |\PitonInputFile|). The initial value of that
+% key is |true| (and not |false|).\footnote{For the language Python, the empty
+% lines in the docstrings are taken into account (by design).}
% \item With the key \Definition{line-numbers/label-empty-lines}, the labels
% (that is to say the numbers) of the empty lines are displayed. If the key
% |/skip-empty-line| is in force, the clé |/label-empty-lines| is no-op. The
-% initial value of that key is~|true|.
+% initial value of that key is~|true|.\footnote{When the key
+% |split-on-empty-lines| is in force, the labels of the empty are never printed.}
% \item With the key \Definition{line-numbers/absolute}, in the listings
% generated in |\PitonInputFile|, the numbers of the lines displayed are
% \emph{absolute} (that is to say: they are the numbers of the lines in the
@@ -783,43 +783,51 @@ piton_version = "2.7" -- 2024/03/24
% By default, the listings produced by the environment |{Piton}| and the command
% |\PitonInputFile| are not breakable.
%
-% However, the command |\PitonOptions| provides the key \Definition{splittable}
-% to allow such breaks.
+% However, the command |\PitonOptions| provides the keys |split-on-empty-lines|
+% and |splittable| to allow such breaks.
%
% \begin{itemize}
-% \item If the key |splittable| is used without any value, the
-% listings are breakable everywhere.
-% \item If the key |splittable| is used with a numeric value~$n$ (which must be
-% a non-negative integer number), the listings are breakable but no break will
-% occur within the first $n$ lines and within the last $n$ lines. Therefore,
-% |splittable=1| is equivalent to |splittable|.
-% \end{itemize}
+% \item \colorbox{yellow!50}{\textbf{New 2.7}}\par\nobreak
+% The key \Definition{split-on-empty-lines} allows breaks on the empty
+% lines\footnote{The ``empty lines'' are the lines which contains only spaes.} in
+% the listing. In the informatic listings, the empty lines usually seperate the
+% definitions of the informatic functions and it's pertinent to allow breaks
+% between these functions.
+%
+% 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
+% empty line in the final PDF (this vertical space is deleted if it occurs on a
+% page break).
+%
+% \item Of course, the key |split-on-empty-lines| may not be sufficient and
+% that's why \pkg{piton} provides the key \Definition{splittable}.
+%
+% When the key |splittable| is used with the numeric value~$n$ (which must be a
+% positive integer) the listing, or each part of the listing delimited by empty
+% lines (when |split-on-empty-lines| is in force) may be broken anywhere with
+% the restriction that no break will occur within the $n$ first lines of
+% the listing or within the $n$ last lines. For example, a tuning with
+% |splittable = 4| may be a good choice.
+%
+% When used without value, the key |splittable| is equivalent to
+% |splittable = 1| and the listings may be broken anywhere (it's probably
+% not recommandable).
+% \end{itemize}
+%
+%
%
% \medskip
% Even with a background color (set by the key |background-color|), the pages
-% breaks are allowed, as soon as the key |splittable| is in force.\footnote{With
-% the key |splittable|, the environments \texttt{\{Piton\}} are breakable, even
-% within a (breakable) environment of \pkg{tcolorbox}. Remind that an
-% environment of \pkg{tcolorbox} included in another environment of
-% \pkg{tcolorbox} is \emph{not} breakable, even when both environments use the
-% key |breakable| of \pkg{tcolorbox}.}
-%
-% \bigskip
-% \colorbox{yellow!50}{\textbf{New 6.27}}\enskip The extension \pkg{piton}
-% provides a key \Definition{split-on-empty-lines}. When that key is in force,
-% the listings are split in chunks on the empty lines\footnote{The ``empty
-% lines'' are the lines which contain only spaces} of the code and each chunk is
-% treated by \pkg{piton} as an independent listing before being sent to LaTeX.
-% Thus, \textbf{LaTeX is able to add page breaks between the chunks}. If the key
-% |splittable| is used, it's active in each chunk. Of course, the utilisation of
-% both |split-on-empty-lines| and |splittable| makes sens if the key
-% |splittable| with a value different of 1 (for instance 4), so that the pages
-% breaks are prioritised on the empty lines of the original listing.
+% breaks are allowed, as soon as the key |split-on-empty-lines| or the key
+% |splittable| is in force.\footnote{With the key |splittable|, the environments
+% \texttt{\{Piton\}} are breakable, even within a (breakable) environment of
+% \pkg{tcolorbox}. Remind that an environment of \pkg{tcolorbox} included in
+% another environment of \pkg{tcolorbox} is \emph{not} breakable, even when both
+% environments use the key |breakable| of \pkg{tcolorbox}.}
%
-% \smallskip
-% The key \Definition{split-separation} specifies a list of LaTeX tokens that
-% will be inserted between the chunks. For example :
-% |\PitonOptions{split-separation = \hrule\goodbreak}|.
%
% \subsubsection{Line breaks}
%
@@ -2479,7 +2487,6 @@ piton_version = "2.7" -- 2024/03/24
\cs_new_protected:Npn \@@_fatal:n { \msg_fatal:nn { piton } }
\cs_new_protected:Npn \@@_fatal:nn { \msg_fatal:nnn { piton } }
\cs_new_protected:Npn \@@_msg_new:nn { \msg_new:nnn { piton } }
-\cs_new_protected:Npn \@@_msg_new:nnn { \msg_new:nnnn { piton } }
\cs_new_protected:Npn \@@_gredirect_none:n #1
{
\group_begin:
@@ -2489,6 +2496,40 @@ piton_version = "2.7" -- 2024/03/24
}
% \end{macrocode}
%
+% With Overleaf, by default, a document is compiled in non-stop mode. When there
+% is an error, there is no way to the user to use the key H in order to have
+% more information. That's why we decide to put that piece of information (for
+% the messages with such information) in the main part of the message when the
+% key |messages-for-Overleaf| is used (at load-time).
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_msg_new:nnn #1 #2 #3
+ {
+ \bool_if:NTF \g_@@_messages_for_Overleaf_bool
+ { \msg_new:nnn { piton } { #1 } { #2 \\ #3 } }
+ { \msg_new:nnnn { piton } { #1 } { #2 } { #3 } }
+ }
+% \end{macrocode}
+%
+% \bigskip
+% We also create a command which will generate usually an error but only a
+% warning on Overleaf. The argument is given by curryfication.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_error_or_warning:n
+ { \bool_if:NTF \g_@@_messages_for_Overleaf_bool \@@_warning:n \@@_error:n }
+% \end{macrocode}
+%
+% We try to detect whether the compilation is done on Overleaf. We use
+% |\c_sys_jobname_str| because, with Overleaf, the value of |\c_sys_jobname_str|
+% is always ``|output|''.
+% \begin{macrocode}
+\bool_new:N \g_@@_messages_for_Overleaf_bool
+\bool_gset:Nn \g_@@_messages_for_Overleaf_bool
+ {
+ \str_if_eq_p:on \c_sys_jobname_str { _region_ } % for Emacs
+ || \str_if_eq_p:on \c_sys_jobname_str { output } % for Overleaf
+ }
+% \end{macrocode}
+%
% \bigskip
% \begin{macrocode}
\@@_msg_new:nn { LuaLaTeX~mandatory }
@@ -2513,7 +2554,7 @@ piton_version = "2.7" -- 2024/03/24
\@@_msg_new:nnn { piton.lua~not~found }
{
The~file~'piton.lua'~can't~be~found.\\
- The~package~'piton'~won't~be~loaded.\\
+ This~eror~is~fatal.\\
If~you~want~to~know~how~to~retrieve~the~file~'piton.lua',~type~H~<return>.
}
{
@@ -2526,10 +2567,11 @@ piton_version = "2.7" -- 2024/03/24
% \bigskip
% \begin{macrocode}
\file_if_exist:nF { piton.lua }
- { \msg_critical:nn { piton } { piton.lua~not~found } }
+ { \msg_fatal:nn { piton } { piton.lua~not~found } }
% \end{macrocode}
%
%
+%
% \bigskip
% The boolean |\g_@@_footnotehyper_bool| will indicate if the option
% |footnotehyper| is used.
@@ -2707,7 +2749,7 @@ piton_version = "2.7" -- 2024/03/24
% \end{macrocode}
%
% \medskip
-% Each time the command |\PitonInputFile| or an environment of \pkg{piton} is
+% Each time the command |\PitonInputFile| of \pkg{piton} is
% used, the code of that environment will be stored in the following global string.
% \begin{macrocode}
\tl_new:N \g_piton_last_code_tl
@@ -2776,6 +2818,7 @@ piton_version = "2.7" -- 2024/03/24
% 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} }
% \end{macrocode}
%
% \medskip
@@ -3103,6 +3146,7 @@ piton_version = "2.7" -- 2024/03/24
% \bigskip
% \subsubsection{Treatment of a line of code}
%
+% The following command is only used once.
% \begin{macrocode}
\cs_new_protected:Npn \@@_replace_spaces:n #1
{
@@ -3178,7 +3222,6 @@ piton_version = "2.7" -- 2024/03/24
\l_@@_skip_empty_lines_bool
}
{ \int_gincr:N \g_@@_visual_line_int }
-
\bool_if:nT
{
! \str_if_eq_p:nn { #1 } { \PitonStyle {Prompt}{} }
@@ -3186,7 +3229,6 @@ piton_version = "2.7" -- 2024/03/24
( ! \l_@@_skip_empty_lines_bool && \l_@@_label_empty_lines_bool )
}
\@@_print_number:
-
}
% \end{macrocode}
% If there is a background, we must remind that there is a left margin of 0.5~em
@@ -3320,9 +3362,9 @@ piton_version = "2.7" -- 2024/03/24
{ \l_@@_nb_lines_int - \g_@@_line_int } > \l_@@_splittable_int
{
\egroup
- \bool_if:NT \g_@@_footnote_bool { \endsavenotes }
+ \bool_if:NT \g_@@_footnote_bool \endsavenotes
\par \mode_leave_vertical:
- \bool_if:NT \g_@@_footnote_bool { \savenotes }
+ \bool_if:NT \g_@@_footnote_bool \savenotes
\vtop \bgroup
}
}
@@ -3677,6 +3719,13 @@ piton_version = "2.7" -- 2024/03/24
\int_new:N \g_@@_visual_line_int
% \end{macrocode}
%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_incr_visual_line:
+ {
+ \bool_if:NF \l_@@_skip_empty_lines_bool
+ { \int_gincr:N \g_@@_visual_line_int }
+ }
+% \end{macrocode}
%
% \begin{macrocode}
\cs_new_protected:Npn \@@_print_number:
@@ -4058,7 +4107,8 @@ piton_version = "2.7" -- 2024/03/24
\lua_now:e
{ piton.write = "\l_@@_path_write_str / \l_@@_write_str" }
}
- \str_if_empty:NF \l_@@_write_str
+ \str_if_empty:NTF \l_@@_write_str
+ { \lua_now:n { piton.write = '' } }
{
\seq_if_in:NVTF \g_@@_write_seq \l_@@_write_str
{ \lua_now:n { piton.write_mode = "a" } }
@@ -4223,7 +4273,7 @@ piton_version = "2.7" -- 2024/03/24
{
\bool_if:NTF \g_@@_beamer_bool
{ \begin { uncoverenv } < #1 > }
- { \@@_error:n { overlay~without~beamer } }
+ { \@@_error_or_warning:n { overlay~without~beamer } }
}
\group_begin:
\int_zero_new:N \l_@@_first_line_int
@@ -4242,7 +4292,7 @@ piton_version = "2.7" -- 2024/03/24
&& ! \str_if_empty_p:N \l_@@_begin_range_str
}
{
- \@@_error:n { bad~range~specification }
+ \@@_error_or_warning:n { bad~range~specification }
\int_zero:N \l_@@_first_line_int
\int_set_eq:NN \l_@@_last_line_int \c_max_int
}
@@ -4268,7 +4318,7 @@ piton_version = "2.7" -- 2024/03/24
{ \l_@@_number_lines_start_int - 1 }
}
% \end{macrocode}
-% The following case arise when the code |line-numbers/absolute| is in force
+% The following case arises when the code |line-numbers/absolute| is in force
% without the use of a marked range.
% \begin{macrocode}
\int_compare:nNnT \g_@@_visual_line_int < \c_zero_int
@@ -4287,18 +4337,16 @@ piton_version = "2.7" -- 2024/03/24
\@@_compute_left_margin:no { CountNonEmptyLinesFile } \l_@@_file_name_str
\@@_compute_width:
\ttfamily
- \bool_if:NT \g_@@_footnote_bool { \savenotes }
- \vtop \bgroup
+ % \leavevmode
\lua_now:e
{
piton.ParseFile(
'\l_piton_language_str' ,
'\l_@@_file_name_str' ,
\int_use:N \l_@@_first_line_int ,
- \int_use:N \l_@@_last_line_int )
+ \int_use:N \l_@@_last_line_int ,
+ \bool_if:NTF \l_@@_split_on_empty_lines_bool { 1 } { 0 } )
}
- \egroup
- \bool_if:NT \g_@@_footnote_bool { \endsavenotes }
\bool_if:NT \l_@@_width_min_bool \@@_width_to_aux:
\group_end:
% \end{macrocode}
@@ -4567,39 +4615,6 @@ piton_version = "2.7" -- 2024/03/24
}
% \end{macrocode}
%
-% \bigskip
-% \begin{macrocode}
-\keys_define:nn { PitonOptions }
- { identifiers .code:n = \@@_set_identifiers:n { #1 } }
-% \end{macrocode}
-%
-% \bigskip
-% \begin{macrocode}
-\keys_define:nn { Piton / identifiers }
- {
- names .clist_set:N = \l_@@_identifiers_names_tl ,
- style .tl_set:N = \l_@@_style_tl ,
- }
-% \end{macrocode}
-%
-% \bigskip
-% \begin{macrocode}
-\cs_new_protected:Npn \@@_set_identifiers:n #1
- {
- \@@_error:n { key~identifiers~deprecated }
- \@@_gredirect_none:n { key~identifiers~deprecated }
- \clist_clear_new:N \l_@@_identifiers_names_tl
- \tl_clear_new:N \l_@@_style_tl
- \keys_set:nn { Piton / identifiers } { #1 }
- \clist_map_inline:Nn \l_@@_identifiers_names_tl
- {
- \tl_set_eq:cN
- { PitonIdentifier _ \l_piton_language_str _ ##1 }
- \l_@@_style_tl
- }
- }
-% \end{macrocode}
-%
%
% \bigskip
% In particular, we have an highlighting of the indentifiers which are the
@@ -4735,15 +4750,6 @@ piton_version = "2.7" -- 2024/03/24
}
% \end{macrocode}
%
-% \begin{macrocode}
-\@@_msg_new:nn { key~identifiers~deprecated }
- {
- The~key~'identifiers'~in~the~command~\token_to_str:N PitonOptions\
- is~now~deprecated:~you~should~use~the~command~
- \token_to_str:N \SetPitonIdentifier\ instead.\\
- However,~you~can~go~on.
- }
-% \end{macrocode}
%
% \begin{macrocode}
\@@_msg_new:nn { Unknown~key~for~SetPitonStyle }
@@ -4840,7 +4846,7 @@ piton_version = "2.7" -- 2024/03/24
% \end{macrocode}
%
% \begin{macrocode}
-\msg_new:nnnn { piton } { Unknown~key~for~PitonOptions }
+\@@_msg_new:nnn { Unknown~key~for~PitonOptions }
{
Unknown~key. \\
The~key~'\l_keys_key_str'~is~unknown~for~\token_to_str:N \PitonOptions.~
@@ -4939,7 +4945,6 @@ piton_version = "2.7" -- 2024/03/24
require ( "piton" )
tex.sprint ( luatexbase.catcodetables.CatcodeTableExpl ,
"\\@@_test_version:n {" .. piton_version .. "}" )
-
}
}
% \end{macrocode}
@@ -5001,6 +5006,12 @@ function piton.close_brace ()
end
% \end{macrocode}
%
+% \begin{macrocode}
+local function sprintL3 ( s )
+ tex.sprint ( luatexbase.catcodetables.expl , s )
+end
+% \end{uncoverenv}
+%
% \bigskip
% \subsubsection{Special functions dealing with LPEG}
%
@@ -6624,7 +6635,7 @@ LPEG2['c'] =
% \begin{macrocode}
local function LuaKeyword ( name )
return
- Lc "{\\PitonStyle{Keyword}{"
+ Lc [[{\PitonStyle{Keyword}{]]
* Q ( Cmt (
C ( identifier ) ,
function ( s , i , a ) return string.upper ( a ) == name end
@@ -6924,26 +6935,23 @@ function piton.Parse ( language , code )
local t = LPEG2[language] : match ( code )
if t == nil
then
- tex.sprint( luatexbase.catcodetables.CatcodeTableExpl,
- [[ \@@_error:n { syntax~error } ]] )
+ sprintL3 [[ \@@_error_or_warning:n { syntax~error } ]]
return -- to exit in force the function
end
local left_stack = {}
local right_stack = {}
- for _ , one_item in ipairs ( t )
- do
- if one_item[1] == "EOL"
- then
- for _ , s in ipairs ( right_stack )
- do tex.sprint ( s )
- end
- for _ , s in ipairs ( one_item[2] )
- do tex.tprint ( s )
- end
- for _ , s in ipairs ( left_stack )
- do tex.sprint ( s )
- end
- else
+ for _ , one_item in ipairs ( t ) do
+ if one_item[1] == "EOL" then
+ for _ , s in ipairs ( right_stack ) do
+ tex.sprint ( s )
+ end
+ for _ , s in ipairs ( one_item[2] ) do
+ tex.tprint ( s )
+ end
+ for _ , s in ipairs ( left_stack ) do
+ tex.sprint ( s )
+ end
+ else
% \end{macrocode}
%
% Here is an example of an item beginning with |"Open"|.
@@ -6957,22 +6965,20 @@ function piton.Parse ( language , code )
% |\begin{uncover}<2>| and |right_stack| will be for the elements like
% |\end{cover}|.
% \begin{macrocode}
- if one_item[1] == "Open"
- then
- tex.sprint( one_item[2] )
- table.insert ( left_stack , one_item[2] )
- table.insert ( right_stack , one_item[3] )
- else
- if one_item[1] == "Close"
- then
- tex.sprint ( right_stack[#right_stack] )
- left_stack[#left_stack] = nil
- right_stack[#right_stack] = nil
- else
- tex.tprint ( one_item )
- end
- end
- end
+ if one_item[1] == "Open" then
+ tex.sprint( one_item[2] )
+ table.insert ( left_stack , one_item[2] )
+ table.insert ( right_stack , one_item[3] )
+ else
+ if one_item[1] == "Close" then
+ tex.sprint ( right_stack[#right_stack] )
+ left_stack[#left_stack] = nil
+ right_stack[#right_stack] = nil
+ else
+ tex.tprint ( one_item )
+ end
+ end
+ end
end
end
% \end{macrocode}
@@ -6981,32 +6987,39 @@ end
%
% \bigskip
% The function |ParseFile| will be used by the LaTeX command |\PitonInputFile|.
-% That function merely reads the whole file (that is to say all its lines) and
+% That function merely reads the file (between |first_line| and |last_line|) and
% then apply the function~|Parse| to the resulting Lua string.
% \begin{macrocode}
-function piton.ParseFile ( language , name , first_line , last_line )
+function piton.ParseFile ( language , name , first_line , last_line , split )
local s = ''
local i = 0
- for line in io.lines ( name )
- do i = i + 1
- if i >= first_line
- then s = s .. '\r' .. line
- end
- if i >= last_line then break end
+ for line in io.lines ( name ) do
+ i = i + 1
+ if i >= first_line then
+ s = s .. '\r' .. line
+ end
+ if i >= last_line then break end
end
% \end{macrocode}
% We extract the BOM of utf-8, if present.
% \begin{macrocode}
- if string.byte ( s , 1 ) == 13
- then if string.byte ( s , 2 ) == 239
- then if string.byte ( s , 3 ) == 187
- then if string.byte ( s , 4 ) == 191
- then s = string.sub ( s , 5 , -1 )
- end
- end
- end
+ if string.byte ( s , 1 ) == 13 then
+ if string.byte ( s , 2 ) == 239 then
+ if string.byte ( s , 3 ) == 187 then
+ if string.byte ( s , 4 ) == 191 then
+ s = string.sub ( s , 5 , -1 )
+ end
+ end
+ end
+ end
+ if split == 1 then
+ piton.GobbleSplitParse ( language , 0 , s )
+ else
+ sprintL3 [[ \bool_if:NT \g_@@_footnote_bool \savenotes \vtop \bgroup ]]
+ piton.Parse ( language , s )
+ sprintL3
+ [[\vspace{2.5pt}\egroup\bool_if:NT\g_@@_footnote_bool\endsavenotes\par]]
end
- piton.Parse ( language , s )
end
% \end{macrocode}
%
@@ -7016,9 +7029,9 @@ end
% The following command will be used by the user command |\piton|.
% For that command, we have to undo the duplication of the symbols |#|.
% \begin{macrocode}
-function piton.ParseBis ( language , code )
+function piton.ParseBis ( lang , code )
local s = ( Cs ( ( P '##' / '#' + 1 ) ^ 0 ) ) : match ( code )
- return piton.Parse ( language , s )
+ return piton.Parse ( lang , s )
end
% \end{macrocode}
%
@@ -7029,10 +7042,14 @@ end
% element. In that case, you have to remove the potential |\@@_breakable_space:|
% that have been inserted when the key |break-lines| is in force.
% \begin{macrocode}
-function piton.ParseTer ( language , code )
- local s = ( Cs ( ( P [[ \@@_breakable_space: ]] / ' ' + 1 ) ^ 0 ) )
+function piton.ParseTer ( lang , code )
+% \end{macrocode}
+% Be careful: we have to write |[[\@@_breakable_space: ]]| with a space after
+% the name of the LaTeX command |\@@_breakable_space:|.
+% \begin{macrocode}
+ local s = ( Cs ( ( P [[\@@_breakable_space: ]] / ' ' + 1 ) ^ 0 ) )
: match ( code )
- return piton.Parse ( language , s )
+ return piton.Parse ( lang , s )
end
% \end{macrocode}
%
@@ -7090,11 +7107,10 @@ local EnvGobbleLPEG =
% \begin{macrocode}
local function remove_before_cr ( input_string )
local match_result = ( P "\r" ) : match ( input_string )
- if match_result
- then
- return string.sub ( input_string , match_result )
+ if match_result then
+ return string.sub ( input_string , match_result )
else
- return input_string
+ return input_string
end
end
% \end{macrocode}
@@ -7120,16 +7136,24 @@ local function gobble ( n , code )
end
end
% \end{macrocode}
+% We have a second test |if n == 0| because the, even if the key like
+% |auto-gobble| is in force, it's possible that, in fact, there is no space to gobble...
+% \begin{macrocode}
+ if n == 0 then
+ return code
+ else
+% \end{macrocode}
% We will now use a \textsc{lpeg} that we have to compute dynamically because it
% depends on the value of~$n$.
% \begin{macrocode}
- return
- ( Ct (
- ( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
- * ( C "\r" * ( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
- ) ^ 0 )
- / table.concat
- ) : match ( code )
+ return
+ ( Ct (
+ ( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
+ * ( C "\r" * ( 1 - P "\r" ) ^ (-n) * C ( ( 1 - P "\r" ) ^ 0 )
+ ) ^ 0 )
+ / table.concat
+ ) : match ( code )
+ end
end
end
% \end{macrocode}
@@ -7140,52 +7164,42 @@ end
% \bigskip
% In the following code, |n| is the value of |\l_@@_gobble_int|.
% \begin{macrocode}
-function piton.GobbleParse ( language , n , code )
+function piton.GobbleParse ( lang , n , code )
piton.last_code = gobble ( n , code )
- piton.last_language = language
+ piton.last_language = lang
% \end{macrocode}
% \begin{macrocode}
- tex.sprint(luatexbase.catcodetables.CatcodeTableExpl ,
- [[ \bool_if:NT \g_@@_footnote_bool \savenotes \vtop \bgroup ]] )
- piton.Parse ( language , piton.last_code )
- tex.sprint(luatexbase.catcodetables.CatcodeTableExpl ,
- [[ \vspace { 2.5 pt } \egroup \bool_if:NT \g_@@_footnote_bool \endsavenotes \par ]] )
+ sprintL3 [[ \bool_if:NT \g_@@_footnote_bool \savenotes \vtop \bgroup ]]
+ piton.Parse ( lang , piton.last_code )
+ sprintL3
+ [[\vspace{2.5pt}\egroup\bool_if:NT\g_@@_footnote_bool\endsavenotes\par]]
% \end{macrocode}
%
% Now, if the final user has used the key |write| to write the code of the
-% environment on an external file.
+% environment on an external file.
% \begin{macrocode}
- if piton.write ~= ''
- then local file = assert ( io.open ( piton.write , piton.write_mode ) )
- file:write ( piton.get_last_code ( ) )
- file:close ( )
+ if piton.write and piton.write ~= '' then
+ local file = assert ( io.open ( piton.write , piton.write_mode ) )
+ file:write ( piton.get_last_code ( ) )
+ file:close ( )
end
end
% \end{macrocode}
%
% \bigskip
-% The function |GobbleParsePar| is merely the function |GobbleParse| with the
-% insertion of a |\par| in the TeX flow after.
-% \begin{macrocode}
-local function GobbleParsePar ( language , n , code )
- piton.GobbleParse ( language , n , code )
- tex.sprint [[ \par ]]
-end
-% \end{macrocode}
-%
-% \bigskip
% 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.
% \begin{macrocode}
-function piton.GobbleSplitParse ( language , n , code )
+function piton.GobbleSplitParse ( lang , n , code )
P { "E" ,
E = ( V "F"
- * ( P " " ^ 0 * "\r" ) ^ 1
+ * ( P " " ^ 0 * "\r"
+ / ( function ( x ) sprintL3 [[ \@@_incr_visual_line: ]] end )
+ ) ^ 1
/ ( function ( x )
- tex.sprint ( luatexbase.catcodetables.expl ,
- [[ \l_@@_split_separation_tl ]] )
+ sprintL3 [[ \l_@@_split_separation_tl \int_gzero:N \g_@@_line_int ]]
end )
) ^ 0 * V "F" ,
% \end{macrocode}
@@ -7193,11 +7207,11 @@ function piton.GobbleSplitParse ( language , n , code )
% \begin{macrocode}
F = C ( V "G" ^ 0 )
% \end{macrocode}
-% The second argument of |GobbleParsePar| is the argument |gobble|: we put that
-% argument to~$0$ because we will have gobbled previously the whole argument
+% The second argument of |.pitonGobbleParse| is the argument |gobble|: we put
+% that argument to~$0$ because we will have gobbled previously the whole argument
% |code| (see below).
% \begin{macrocode}
- / ( function ( x ) GobbleParsePar ( language , 0 , x ) end ) ,
+ / ( function ( x ) piton.GobbleParse ( lang , 0 , x ) end ) ,
% \end{macrocode}
% The non-terminal |G| corresponds to a non-empty line of code.
% \begin{macrocode}
@@ -7224,9 +7238,7 @@ end
function piton.CountLines ( code )
local count = 0
for i in code : gmatch ( "\r" ) do count = count + 1 end
- tex.sprint (
- luatexbase.catcodetables.expl ,
- [[ \int_set:Nn \l_@@_nb_lines_int { ]] .. count .. '}' )
+ sprintL3 ( [[ \int_set:Nn \l_@@_nb_lines_int { ]] .. count .. '}' )
end
% \end{macrocode}
%
@@ -7240,9 +7252,7 @@ function piton.CountNonEmptyLines ( code )
* -1
) / table.getn
) : match ( code )
- tex.sprint(
- luatexbase.catcodetables.expl ,
- [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { ]] .. count .. '}' )
+ sprintL3 ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { ]] .. count .. '}' )
end
% \end{macrocode}
%
@@ -7250,11 +7260,8 @@ end
% \begin{macrocode}
function piton.CountLinesFile ( name )
local count = 0
- io.open ( name )
for line in io.lines ( name ) do count = count + 1 end
- tex.sprint (
- luatexbase.catcodetables.expl ,
- [[ \int_set:Nn \l_@@_nb_lines_int { ]] .. count .. '}' )
+ sprintL3 ( [[ \int_set:Nn \l_@@_nb_lines_int { ]] .. count .. '}' )
end
% \end{macrocode}
%
@@ -7264,13 +7271,11 @@ end
function piton.CountNonEmptyLinesFile ( name )
local count = 0
for line in io.lines ( name )
- do if not ( ( P " " ^ 0 * -1 ) : match ( line ) )
- then count = count + 1
+ do if not ( ( P " " ^ 0 * -1 ) : match ( line ) ) then
+ count = count + 1
end
end
- tex.sprint (
- luatexbase.catcodetables.expl ,
- [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { ]] .. count .. '}' )
+ sprintL3 ( [[ \int_set:Nn \l_@@_nb_non_empty_lines_int { ]] .. count .. '}' )
end
% \end{macrocode}
%
@@ -7299,15 +7304,12 @@ function piton.ComputeRange(marker_beginning,marker_end,file_name)
count = count + 1
end
if first_line == -1
- then tex.sprint ( luatexbase.catcodetables.expl ,
- [[ \@@_error:n { begin~marker~not~found } ]] )
+ then sprintL3 [[ \@@_error_or_warning:n { begin~marker~not~found } ]]
else if last_found == false
- then tex.sprint ( luatexbase.catcodetables.expl ,
- [[ \@@_error:n { end~marker~not~found } ]] )
+ then sprintL3 [[ \@@_error_or_warning:n { end~marker~not~found } ]]
end
end
- tex.sprint (
- luatexbase.catcodetables.expl ,
+ sprintL3 (
[[ \int_set:Nn \l_@@_first_line_int { ]] .. first_line .. ' + 2 }'
.. [[ \int_set:Nn \l_@@_last_line_int { ]] .. count .. ' }' )
end