summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/lualatex/piton
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/lualatex/piton')
-rw-r--r--Master/texmf-dist/source/lualatex/piton/piton.dtx1384
-rw-r--r--Master/texmf-dist/source/lualatex/piton/piton.ins7
2 files changed, 1053 insertions, 338 deletions
diff --git a/Master/texmf-dist/source/lualatex/piton/piton.dtx b/Master/texmf-dist/source/lualatex/piton/piton.dtx
index 14263ecb56a..e6a78c709a5 100644
--- a/Master/texmf-dist/source/lualatex/piton/piton.dtx
+++ b/Master/texmf-dist/source/lualatex/piton/piton.dtx
@@ -1,4 +1,4 @@
-% \iffalse -*- coding: utf-8 ; -*- \fi \iffalse meta-comment
+% \iffalse -*- coding: utf-8 ; -*- \fi \iffalse meta-comment
%
% Copyright (C) 2023 by F. Pantigny
% -----------------------------------
@@ -15,10 +15,7 @@
%
% \fi
% \iffalse
-\def\myfileversion{2.0}
-\def\myfiledate{2023/08/01}
-%
-%
+%
%<*batchfile>
\begingroup
\input l3docstrip.tex
@@ -45,7 +42,13 @@ version 2005/12/01 or later.
%</batchfile>
%
%<@@=piton>
+%<*STY>
+\def\myfileversion{2.1}
+\def\myfiledate{2023/08/26}
+%</STY>
%<*driver>
+\def\myfileversion{2.1}
+\def\myfiledate{2023/08/26}
\documentclass{l3doc}
\usepackage{geometry}
\geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
@@ -56,7 +59,16 @@ version 2005/12/01 or later.
\fvset{commandchars=\~\#\@,formatcom=\color{gray}}
\captionsetup{labelfont = bf}
\usepackage{ragged2e}
-\usepackage[footnotehyper,escape-inside=$$,math-comments]{piton} % $$
+\usepackage[footnotehyper]{piton}
+\PitonOptions
+ {
+ splittable = 4 ,
+ math-comments,
+ begin-escape = ! ,
+ end-escape = ! ,
+ begin-escape-math = \( ,
+ end-escape-math = \)
+ }
\parindent 0pt
\skip\footins = 2\bigskipamount
@@ -68,6 +80,7 @@ version 2005/12/01 or later.
\EnableCrossrefs
\begin{document}
+
\DocInput{piton.dtx}
\end{document}
%</driver>
@@ -128,17 +141,17 @@ version 2005/12/01 or later.
% return s
% \end{Piton}
%
-%
-% \bigskip
-% The package \pkg{piton} is entirely contained in the file
-% |piton.sty|. This file may be put in the current directory or in a
-% |texmf| tree. However, the best is to install \pkg{piton} with a TeX
-% distribution such as MiKTeX, TeX Live or MacTeX.
%
+% \section{Installation}
+%
+% The package \pkg{piton} is contained in two files: |piton.sty| and |piton.lua|
+% (the LaTeX file |piton.sty| loaded by |\usepackage| will load the Lua file
+% |piton.lua|). Both files must be in a repertory where LaTeX will be able to
+% find them, for instance in a |texmf| tree. However, the best is to install
+% \pkg{piton} with a TeX distribution such as MiKTeX, TeX Live or MacTeX.
%
% \section{Use of the package}
%
-%
% \subsection{Loading the package}
%
% The package \pkg{piton} should be loaded with the classical command
@@ -193,11 +206,10 @@ version 2005/12/01 or later.
% cf.~\ref{NewPitonEnvironment} p.~\pageref{NewPitonEnvironment}.
%
% \item The command \colorbox{gray!20}{\ttfamily\textbackslash PitonInputFile}
-% is used to insert and typeset a whole external file.
+% is used to insert and typeset a external file.
%
-% That command takes in as optional argument (between square brackets) two keys
-% |first-line| and |last-line|: only the part between the corresponding lines
-% will be inserted.
+% It's possible to insert only a part of the file: cf.
+% part~\ref{part-of-a-file}, p.~\pageref{part-of-a-file}.
% \end{itemize}
%
% \subsection{The syntax of the command \textbackslash piton}
@@ -327,32 +339,63 @@ version 2005/12/01 or later.
% gobble is set by the position of the commands |\begin{Piton}| and
% |\end{Piton}| which delimit the current environment.
%
-% \item With the key \Definition{line-numbers}, the \emph{non empty} lines (and
-% all the lines of the \emph{docstrings}, even the empty ones) are numbered in
-% the environments |{Piton}| and in the listings resulting from the use of
+% \item The key \Definition{line-numbers} activates the line numbering. in the
+% environments |{Piton}| and in the listings resulting from the use of
% |\PitonInputFile|.
%
-% \item With the key \Definition{all-line-numbers}, \emph{all} the lines are numbered,
-% including the empty ones.
+% \colorbox{yellow!50}{\textbf{New 2.1}}\enskip In fact, the key |line-numbers| has
+% several subkeys.
+% \begin{itemize}
+% \item With the key \Definition{line-numbers/skip-empty-lines}, the empty lines
+% 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).}
+% \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|.
+% \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
+% file). That key may be useful when |\PitonInputFile| is used to insert only a
+% part of the file (cf. part~\ref{part-of-a-file}, p.~\pageref{part-of-a-file}).
+% The key |/absolute| is no-op in the environments |{Piton}|.
+% \item The key \Definition{line-numbers/start} requires that the line numbering
+% begins to the value of the key. That key is not available in |\PitonOptions|.
+% \item With the key \Definition{line-numbers/resume}, the counter of lines is
+% not set to zero at the beginning of each environment |{Piton}| or use of
+% |\PitonInputFile| as it is otherwise. That allows a numbering of the lines
+% across several environments.
+% \item The key \Definition{line-numbers/sep} is the horizontal distance between
+% the numbers of lines (inserted by |line-numbers|) and the beginning of the
+% lines of code. The initial value is 0.7~em.
+% \end{itemize}
%
-% \item The key \Definition{numbers-sep} is the horizontal distance between the
-% numbers of lines (inserted by |line-numbers| of |all-line-numbers|) and the
-% beginning of the lines of code. The initial value is 0.7~em.
+% For convenience, a mechanism of factorisation of the prefix |line-numbers| is
+% provided. That means that it is possible, for instance, to write:
+% \begin{Verbatim}
+% \PitonOptions
+% {
+% line-numbers =
+% {
+% skip-empty-lines = false ,
+% label-empty-lines = false ,
+% sep = 1 em
+% }
+% }
+% \end{Verbatim}
%
-% \item With the key \Definition{resume}, the counter of lines is not set to zero
-% at the beginning of each environment |{Piton}| or use of |\PitonInputFile| as
-% it is otherwise. That allows a numbering of the lines across several
-% environments.
%
% \item The key \Definition{left-margin} corresponds to a margin on the left.
-% That key may be useful in conjonction with the key |line-numbers| or the key
-% |line-all-numbers| if one does not want the numbers in an overlapping position
-% on the left.
+% That key may be useful in conjonction with the key |line-numbers| if one does
+% not want the numbers in an overlapping position on the left.
%
% It's possible to use the key |left-margin| with the value |auto|. With that
-% value, if the key |line-numbers| or the key |all-line-numbers| is used, a
-% margin will be automatically inserted to fit the numbers of lines. See an
-% example part \ref{example-numbering} on page~\pageref{example-numbering}.
+% value, if the key |line-numbers| is in force, a margin will be automatically
+% inserted to fit the numbers of lines. See an example part
+% \ref{example-numbering} on page~\pageref{example-numbering}.
%
% \item The key \Definition{background-color} sets the background color of the
% environments |{Piton}| and the listings produced by |\PitonInputFile| (it's
@@ -374,8 +417,8 @@ version 2005/12/01 or later.
% continuation ``|...|'') characteristic of the Python consoles with
% \textsc{repl} (\emph{read-eval-print loop}).
%
-% \item The key |width| will fix the width of the listing. That width applies to
-% the colored backgrounds specified by |background-color| and
+% \item The key \Definition{width} will fix the width of the listing. That width
+% applies to the colored backgrounds specified by |background-color| and
% |prompt-background-color| but also for the automatic breaking of the lines
% (when required by |break-lines|: cf.~\ref{line-breaks},
% p.~\pageref{line-breaks}).
@@ -627,6 +670,240 @@ version 2005/12/01 or later.
%
% \section{Advanced features}
%
+% \subsection{Page breaks and line breaks}
+%
+% \label{breakable}
+%
+% \subsubsection{Page breaks}
+%
+% 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.
+%
+% \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}
+%
+% \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}.}
+%
+% \subsubsection{Line breaks}
+%
+% \label{line-breaks}
+%
+% By default, the elements produced by \pkg{piton} can't be broken by an end on
+% line. However, there are keys to allow such breaks (the possible breaking
+% points are the spaces, even the spaces in the Python strings).
+% \begin{itemize}
+% \item With the key \Definition{break-lines-in-piton}, the line breaks are
+% allowed in the command |\piton{...}| (but not in the command
+% \verb+\piton|...|+, that is to say the command |\piton| in verbatim mode).
+% \item With the key \Definition{break-lines-in-Piton}, the line breaks are
+% allowed in the environment |{Piton}| (hence the capital letter |P| in the name) and in the
+% listings produced by |\PitonInputFile|.
+% \item The key \Definition{break-lines} is a conjonction of the two previous keys.
+% \end{itemize}
+%
+% \bigskip
+% The package \pkg{piton} provides also several keys to control the appearance
+% on the line breaks allowed by |break-lines-in-Piton|.
+%
+% \begin{itemize}
+% \item With the key \Definition{indent-broken-lines}, the indentation of a
+% broken line is respected at carriage return.
+%
+% \item The key \Definition{end-of-broken-line} corresponds to the symbol placed
+% at the end of a broken line. The initial value is:
+% |\hspace*{0.5em}\textbackslash|.
+%
+% \item The key \Definition{continuation-symbol} corresponds to the symbol
+% placed at each carriage return. The initial value is: |+\;| (the command |\;|
+% inserts a small horizontal space).
+%
+% \item The key \Definition{continuation-symbol-on-indentation} corresponds to
+% the symbol placed at each carriage return, on the position of the indentation
+% (only when the key |indent-broken-line| is in force). The initial value is:
+% |$\hookrightarrow\;$|.
+% \end{itemize}
+%
+%
+% \bigskip
+% The following code has been composed with the following tuning:
+%
+% \begin{Verbatim}
+% \PitonOptions{width=12cm,break-lines,indent-broken-lines,background-color=gray!15}
+% \end{Verbatim}
+%
+% \begin{center}
+% \PitonOptions{width=12cm,break-lines,indent-broken-lines,background-color=gray!15}
+% \begin{Piton}
+% def dict_of_list(l):
+% """Converts a list of subrs and descriptions of glyphs in a dictionary"""
+% our_dict = {}
+% for list_letter in l:
+% if (list_letter[0][0:3] == 'dup'): # if it's a subr
+% name = list_letter[0][4:-3]
+% print("We treat the subr of number " + name)
+% else:
+% name = list_letter[0][1:-3] # if it's a glyph
+% print("We treat the glyph of number " + name)
+% our_dict[name] = [treat_Postscript_line(k) for k in list_letter[1:-1]]
+% return dict
+% \end{Piton}
+% \end{center}
+%
+%
+% \bigskip
+% \subsection{Insertion of a part of a file}
+%
+% \label{part-of-a-file}
+%
+% The command |\PitonInputFile| inserts (with formating) the content of a file.
+% In fact, it's possible to insert only \emph{a part} of that file. Two
+% mechanisms are provided in this aim.
+% \begin{itemize}
+% \item It's possible to specify the part that we want to insert by the numbers
+% of the lines (in the original file).
+% \item \colorbox{yellow!50}{\textbf{New 2.1}}\enskip It's also possible to
+% specify the part to insert with textual markers.
+% \end{itemize}
+% In both cases, if we want to number the lines with the numbers of the
+% lines in the file, we have to use the key |line-numbers/absolute|.
+%
+% \subsubsection{With line numbers}
+%
+% The command |\PitonInputFile| supports the keys \Definition{first-line} and
+% \Definition{last-line} in order to insert only the part of file between the
+% corresponding lines. Not to be confused with the key |line-numbers/start|
+% which fixes the first line number for the line numbering. In a sens,
+% |line-numbers/start| deals with the output whereas |first-line| and
+% |last-line| deal with the input.
+%
+% \subsubsection{With textual markers}
+%
+% \colorbox{yellow!50}{\textbf{New 2.1}}
+%
+% In order to use that feature, we first have to specify the format of the
+% markers (for the beginning and the end of the part to include) with the keys
+% \Definition{marker-beginning} and \Definition{marker-end} (usually with the
+% command |\PitonOptions|).
+%
+%
+% \medskip
+% Let us take a practical example.
+%
+% \medskip
+% We assume that the file to include contains solutions to exercises of
+% programmation on the following model.
+%
+% \begin{Verbatim}[formatcom=\small\color{gray}]
+% ~#[Exercise 1] Iterative version
+% def fibo(n):
+% if n==0: return 0
+% else:
+% u=0
+% v=1
+% for i in range(n-1):
+% w = u+v
+% u = v
+% v = w
+% return v
+% ~#<Exercise 1>
+% \end{Verbatim}
+%
+% The markers of the beginning and the end are the strings |#[Exercise 1]| and
+% |#<Exercise 1>|. The string ``|Exercise 1|'' will be called the \emph{label}
+% of the exercise (or of the part of the file to be included).
+%
+% In order to specify such markers in \pkg{piton}, we will use the keys
+% |marker/beginning| and |marker/end| with the following instruction (the
+% character |#| of the comments of Python must be inserted with the protected
+% form |\#|).
+%
+% \begin{Verbatim}
+% \PitonOptions{ ~emphase#marker/beginning@ = \~#[~#1] , ~emphase#marker/end@ = \~#<~#1> }
+% \end{Verbatim}
+%
+% As one can see, |marker/beginning| is an expression corresponding to the
+% mathematical function which transforms the label (here |Exercise 1|) into the
+% the beginning marker (in the example |#[Exercise 1]|). The string |#1|
+% corresponds to the occurrences of the argument of that function, which the
+% classical syntax in TeX. Idem for |marker/end|.
+%
+% \bigskip
+% Now, you only have to use the key \Definition{range} of |\PitonInputFile| to
+% insert a marked content of the file.
+%
+% \smallskip
+% \begin{Verbatim}
+% \PitonInputFile[~emphase#range = Exercise 1@]{~textsl#file_name@}
+% \end{Verbatim}
+%
+% \medskip
+% \begin{Piton}
+% def fibo(n):
+% if n==0: return 0
+% else:
+% u=0
+% v=1
+% for i in range(n-1):
+% w = u+v
+% u = v
+% v = w
+% return v
+% \end{Piton}
+%
+% \vspace{1cm}
+% The key \Definition{marker/include-line} requires the insertion of the lines
+% containing the markers.
+%
+% \begin{Verbatim}
+% \PitonInputFile[~emphase#marker/include-lines@,range = Exercise 1]{~textsl#file_name@}
+% \end{Verbatim}
+%
+% \begin{Piton}
+% #[Exercise 1] Iterative version
+% def fibo(n):
+% if n==0: return 0
+% else:
+% u=0
+% v=1
+% for i in range(n-1):
+% w = u+v
+% u = v
+% v = w
+% return v
+% #<Exercise 1>
+% \end{Piton}
+%
+%
+% \bigskip
+% In fact, there exist also the keys \Definition{begin-range} and
+% \Definition{end-range} to insert several marked contents at the same time.
+%
+% For example, in order to insert the solutions of the exercises~3 to~5, we will
+% write (if the file has the correct structure!):
+%
+%
+% \begin{Verbatim}
+% \PitonInputFile[~emphase#begin-range = Exercise 3, end-range = Exercise 5@]{~textsl#file_name@}
+% \end{Verbatim}
+%
+%
+%
% \subsection{Highlighting some identifiers}
%
% It's possible to require a changement of formating for some identifiers with
@@ -639,17 +916,17 @@ version 2005/12/01 or later.
% instructions}| }|
%
% \begin{itemize}
-% \item \textsl{\ttfamily names} is a (comma-separated) list of identifiers
+% \item \textsl{\ttfamily names} is a (comma-separated) list of identifier
% names;
%
% \item \textsl{\ttfamily instructions} is a list of LaTeX instructions of the
-% same type that \pkg{piton} ``styles'' previously presented (cf~\ref{styles}
+% same type as \pkg{piton} ``styles'' previously presented (cf~\ref{styles}
% p.~\pageref{styles}).
% \end{itemize}
%
% \emph{Caution}: Only the identifiers may be concerned by that key. The
% keywords and the built-in functions won't be affected, even if their name is
-% in the list |\textsl{\ttfamily names}|.
+% in the list \textsl{\ttfamily names}.
%
% \begin{Verbatim}
% \PitonOptions
@@ -772,13 +1049,13 @@ version 2005/12/01 or later.
%
% \begin{itemize}
% \item It's possible to change the syntatic mark (which, by default, is |#>|).
-% For this purpose, there is a key |comment-latex| available at load-time (that
-% is to say at the |\usepackage|) which allows to choice the characters which,
+% For this purpose, there is a key |comment-latex| available only in the
+% preamble of the document, allows to choice the characters which,
% preceded by |#|, will be the syntatic marker.
%
-% For example, with the following loading:
+% For example, if the preamble contains the following instruction:
%
-% \quad \verb|\usepackage[comment-latex = LaTeX]{piton}|
+% \quad \verb|\PitonOptions{comment-latex = LaTeX}|
%
% the LaTeX comments will begin by |#LaTeX|.
%
@@ -804,8 +1081,7 @@ version 2005/12/01 or later.
% \end{itemize}
%
% \bigskip
-% If the user has required line numbers in the left margin (with the
-% key |line-numbers| or the key |all-line-numbers| of |\PitonOptions|), it's
+% If the user has required line numbers (with the key |line-numbers|), it's
% possible to refer to a number of line with the command |\label| used in a
% LaTeX comment.\footnote{That feature is implemented by using a redefinition of
% the standard command \texttt{\textbackslash label} in the environments
@@ -820,13 +1096,13 @@ version 2005/12/01 or later.
% composed in LaTeX mathematical mode (the other elements of the comment being
% composed verbatim).
%
-% That feature is activated by the key |math-comments| at load-time (that is to
-% say with the |\usepackage|).
+% That feature is activated by the key \Definition{math-comments}, which is
+% available only in the preamble of the document.
%
% \medskip
-% In the following example, we assume that the key |math-comments| has been used
-% when loading \pkg{piton}.
-%
+% Here is a example, where we have assumed that the preamble of the document
+% contains the instruction |\PitonOptions{math-comment}|:
+%
% \begin{Verbatim}
% \begin{Piton}
% def square(x):
@@ -839,23 +1115,23 @@ version 2005/12/01 or later.
% return x*x # compute $x^2$
% \end{Piton}
%
-% \subsubsection{The mechanism ``escape-inside''}
+% \subsubsection{The mechanism ``escape''}
%
% It's also possible to overwrite the Python listings to insert LaTeX code
% almost everywhere (but between lexical units, of course). By default,
-% \pkg{piton} does not fix any character for that kind of escape.
+% \pkg{piton} does not fix any delimiters for that kind of escape.
%
-% In order to use this mechanism, it's necessary to specify two characters which
+% In order to use this mechanism, it's necessary to specify the delimiters which
% will delimit the escape (one for the beginning and one for the end) by using
-% the key |escape-inside| at load-time (that is to say at the
-% |\begin{docuemnt}|).
+% the keys \Definition{begin-escape} and \Definition{end-escape}, available only
+% in the preamble of the document.
%
% \medskip
-% In the following example, we assume that the extension \pkg{piton} has been
-% loaded by the following instruction.
+% In the following example, we assume that the preamble of the document contains
+% the following instruction:
%
% \begin{Verbatim}
-% \usepackage[~emphase#escape-inside=$$@]{piton}
+% \PitonOptions{~emphase#begin-escape=!,end-escape=!@}
% \end{Verbatim}
%
% \medskip
@@ -869,7 +1145,7 @@ version 2005/12/01 or later.
% if n==0:
% return 1
% else:
-% ~emphase#$\highLight{$@return n*fact(n-1)~emphase#$}$@
+% ~emphase#!\highLight{!@return n*fact(n-1)~emphase#!}!@
% \end{Piton}
% \end{Verbatim}
%
@@ -878,7 +1154,7 @@ version 2005/12/01 or later.
% if n==0:
% return 1
% else:
-% $\highLight{$return n*fact(n-1)$}$
+% !\highLight{!return n*fact(n-1)!}!
% \end{Piton}
%
% \bigskip
@@ -902,7 +1178,7 @@ version 2005/12/01 or later.
% if n==0:
% return 1
% else:
-% ~emphase#$\Yellow$@return n*fact(n-1)
+% ~emphase#!\Yellow!@return n*fact(n-1)
% \end{Piton}
% \end{Verbatim}
%
@@ -916,17 +1192,81 @@ version 2005/12/01 or later.
% if n==0:
% return 1
% else:
-% $\Yellow$return n*fact(n-1)
+% !\Yellow!return n*fact(n-1)
% \end{Piton}
%
%
%
% \bigskip
-% \emph{Caution} : The escape to LaTeX allowed by the characters of
-% |escape-inside| is not active in the strings nor in the Python comments
-% (however, it's possible to have a whole Python comment composed in LaTeX by
-% beginning it with |#>|; such comments are merely called ``LaTeX comments'' in
-% this document).
+% \emph{Caution} : The escape to LaTeX allowed by the |begin-escape| and
+% |end-escape| is not active in the strings nor in the Python comments (however,
+% it's possible to have a whole Python comment composed in LaTeX by beginning it
+% with |#>|; such comments are merely called ``LaTeX comments'' in this
+% document).
+%
+%
+% \subsubsection{The mechanism ``escape-math''}
+%
+% The mechanism ``|escape-math|'' is very similar to the mechanism ``|escape|''
+% since the only difference is that the elements sent to LaTeX are composed in
+% the math mode of LaTeX.
+%
+% This mechanism is activated with the keys \Definition{begin-escape-math} and
+% \Definition{end-escape-math} (which are available only in the preamble of the
+% document).
+%
+% Despite the technical similarity, the use of the the mechanism
+% ``|escape-math|'' is in fact rather different from that of the mechanism
+% ``|escape|''. Indeed, since the elements are composed in a mathématical mode
+% of LaTeX, they are, in particular, composed within a TeX group and therefore,
+% they can't be used to change the formatting of other lexical units.
+%
+% In the langages where the character \verb|$| does not play a important role,
+% it's possible to activate that mechanism ``|escape-math|'' with the character
+% \verb|$|:
+% \begin{Verbatim}
+% \PitonOptions{~emphase#begin-escape-math=$,end-escape-math=$@}
+% \end{Verbatim}
+% Remark that the character \verb|$| must \emph{not} be protected by a backslash.
+%
+% \bigskip
+% However, it's probably more prudent to use |\(| et |\)|.
+% \begin{Verbatim}
+% \PitonOptions{~emphase#begin-escape-math=\(,end-escape-math=\)@}
+% \end{Verbatim}
+%
+% \bigskip
+% Here is an example of utilisation.
+%
+% \medskip
+% \begin{Verbatim}
+% \begin{Piton}[line-numbers]
+% def arctan(x,n=10):
+% if ~emphase#\(x < 0\)@ :
+% return ~emphase#\(-\arctan(-x)\)@
+% elif ~emphase#\(x > 1\)@ :
+% return ~emphase#\(\pi/2 - \arctan(1/x)\)@
+% else:
+% s = ~emphase#\(0\)@
+% for ~emphase#\(k\)@ in range(~emphase#\(n\)@): s += ~emphase#\(\smash{\frac{(-1)^k}{2k+1} x^{2k+1}}\)@
+% return s
+% \end{Piton}
+% \end{Verbatim}
+%
+%
+% \bigskip
+%
+% \begin{Piton}[line-numbers]
+% def arctan(x,n=10):
+% if \(x < 0\) :
+% return \(-\arctan(-x)\)
+% elif \(x > 1\) :
+% return \(\pi/2 - \arctan(1/x)\)
+% else:
+% s = \(0\)
+% for \(k\) in range(\(n\)): s += \(\smash{\frac{(-1)^k}{2k+1} x^{2k+1}}\)
+% return s
+% \end{Piton}
%
%
% \subsection{Behaviour in the class Beamer}
@@ -946,6 +1286,7 @@ version 2005/12/01 or later.
% \bigskip
% When the package \pkg{piton} is used within the class
% \cls{beamer}\footnote{The extension \pkg{piton} detects the class \cls{beamer}
+% and the package \pkg{beamerarticle} if it is loaded previously
% but, if needed, it's also possible to activate that mechanism with the key
% |beamer| provided by \pkg{piton} at load-time: |\textbackslash
% usepackage[beamer]\{piton\}|}, the behaviour of \pkg{piton} is slightly
@@ -1095,99 +1436,6 @@ version 2005/12/01 or later.
% environments |{Piton}| (we recall that the command |\alert| relies upon that
% environment |{alertenv}|).
%
-% \subsection{Page breaks and line breaks}
-%
-% \label{breakable}
-%
-% \subsubsection{Page breaks}
-%
-% 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.
-%
-% \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}
-%
-% \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}.}
-%
-% \subsubsection{Line breaks}
-%
-% \label{line-breaks}
-%
-% By default, the elements produced by \pkg{piton} can't be broken by an end on
-% line. However, there are keys to allow such breaks (the possible breaking
-% points are the spaces, even the spaces in the Python strings).
-% \begin{itemize}
-% \item With the key \Definition{break-lines-in-piton}, the line breaks are
-% allowed in the command |\piton{...}| (but not in the command
-% \verb+\piton|...|+, that is to say the command |\piton| in verbatim mode).
-% \item With the key \Definition{break-lines-in-Piton}, the line breaks are
-% allowed in the environment |{Piton}| (hence the capital letter |P| in the name) and in the
-% listings produced by |\PitonInputFile|.
-% \item The key \Definition{break-lines} is a conjonction of the two previous keys.
-% \end{itemize}
-%
-% \bigskip
-% The package \pkg{piton} provides also several keys to control the appearance
-% on the line breaks allowed by |break-lines-in-Piton|.
-%
-% \begin{itemize}
-% \item With the key \Definition{indent-broken-lines}, the indentation of a
-% broken line is respected at carriage return.
-%
-% \item The key \Definition{end-of-broken-line} corresponds to the symbol placed
-% at the end of a broken line. The initial value is:
-% |\hspace*{0.5em}\textbackslash|.
-%
-% \item The key \Definition{continuation-symbol} corresponds to the symbol
-% placed at each carriage return. The initial value is: |+\;|.
-%
-% \item The key \Definition{continuation-symbol-on-indentation} corresponds to
-% the symbol placed at each carriage return, on the position of the indentation
-% (only when the key |indent-broken-line| is in force). The initial value is:
-% |$\hookrightarrow\;$|.
-% \end{itemize}
-%
-%
-% \bigskip
-% The following code has been composed with the following tuning:
-%
-% \begin{Verbatim}
-% \PitonOptions{width=12cm,break-lines,indent-broken-lines,background-color=gray!15}
-% \end{Verbatim}
-%
-% \begin{center}
-% \PitonOptions{width=12cm,break-lines,indent-broken-lines,background-color=gray!15}
-% \begin{Piton}
-% def dict_of_list(l):
-% """Converts a list of subrs and descriptions of glyphs in a dictionary"""
-% our_dict = {}
-% for list_letter in l:
-% if (list_letter[0][0:3] == 'dup'): # if it's a subr
-% name = list_letter[0][4:-3]
-% print("We treat the subr of number " + name)
-% else:
-% name = list_letter[0][1:-3] # if it's a glyph
-% print("We treat the glyph of number " + name)
-% our_dict[name] = [treat_Postscript_line(k) for k in list_letter[1:-1]]
-% return dict
-% \end{Piton}
-% \end{center}
%
% \subsection{Footnotes in the environments of piton}
%
@@ -1247,7 +1495,7 @@ version 2005/12/01 or later.
% \label{example-numbering}
%
% We remind that it's possible to have an automatic numbering of the lines in
-% the Python listings by using the key |line-numbers| or the key |all-line-numbers|.
+% the Python listings by using the key |line-numbers|.
%
% By default, the numbers of the lines are composed by \pkg{piton} in an
% overlapping position on the left (by using internally the command |\llap| of LaTeX).
@@ -1802,7 +2050,7 @@ version 2005/12/01 or later.
%
% \section{Implementation}
%
-% % \medskip
+% \medskip
% The development of the extension \pkg{piton} is done on the following GitHub
% depot:
%
@@ -1936,6 +2184,7 @@ version 2005/12/01 or later.
%
% \subsubsection{Declaration of the package}
% \begin{macrocode}
+%<*STY>
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{l3keys2e}
\ProvidesExplPackage
@@ -1947,7 +2196,18 @@ version 2005/12/01 or later.
%
% \bigskip
% \begin{macrocode}
-\msg_new:nnn { piton } { LuaLaTeX~mandatory }
+\cs_new_protected:Npn \@@_error:n { \msg_error:nn { piton } }
+\cs_new_protected:Npn \@@_warning:n { \msg_warning:nn { piton } }
+\cs_new_protected:Npn \@@_error:nn { \msg_error:nnn { piton } }
+\cs_new_protected:Npn \@@_error:nnn { \msg_error:nnnn { piton } }
+\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 } }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\@@_msg_new:nn { LuaLaTeX~mandatory }
{
LuaLaTeX~is~mandatory.\\
The~package~'piton'~requires~the~engine~LuaLaTeX.\\
@@ -1962,32 +2222,48 @@ version 2005/12/01 or later.
% \begin{macrocode}
\RequirePackage { luatexbase }
% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\@@_msg_new:nn { piton.lua~not~found }
+ {
+ The~file~'piton.lua'~can't~be~found.\\
+ The package~'piton'~won't be loaded.
+ }
+% \end{macrocode}
%
% \bigskip
-% The boolean |\c_@@_footnotehyper_bool| will indicate if the option
+% \begin{macrocode}
+\file_if_exist:nF { piton.lua }
+ { \msg_critical:nn { piton } { piton.lua~not~found } }
+% \end{macrocode}
+%
+%
+% \bigskip
+% The boolean |\g_@@_footnotehyper_bool| will indicate if the option
% |footnotehyper| is used.
% \begin{macrocode}
-\bool_new:N \c_@@_footnotehyper_bool
+\bool_new:N \g_@@_footnotehyper_bool
% \end{macrocode}
%
% \medskip
-% The boolean |\c_@@_footnote_bool| will indicate if the option |footnote| is
+% The boolean |\g_@@_footnote_bool| will indicate if the option |footnote| is
% used, but quicky, it will also be set to |true| if the option |footnotehyper|
% is used.
% \begin{macrocode}
-\bool_new:N \c_@@_footnote_bool
+\bool_new:N \g_@@_footnote_bool
% \end{macrocode}
%
% \medskip
% The following boolean corresponds to the key |math-comments| (only at load-time).
% \begin{macrocode}
-\bool_new:N \c_@@_math_comments_bool
+\bool_new:N \g_@@_math_comments_bool
% \end{macrocode}
%
% \medskip
-% The following boolean corresponds to the key |beamer|.
% \begin{macrocode}
-\bool_new:N \c_@@_beamer_bool
+\bool_new:N \g_@@_beamer_bool
+\tl_new:N \g_@@_escape_inside_tl
% \end{macrocode}
%
% \bigskip
@@ -1995,56 +2271,66 @@ version 2005/12/01 or later.
% \begin{macrocode}
\keys_define:nn { piton / package }
{
- footnote .bool_set:N = \c_@@_footnote_bool ,
- footnotehyper .bool_set:N = \c_@@_footnotehyper_bool ,
- escape-inside .tl_set:N = \c_@@_escape_inside_tl ,
- escape-inside .initial:n = ,
- comment-latex .code:n = { \lua_now:n { comment_latex = "#1" } } ,
- comment-latex .value_required:n = true ,
- math-comments .bool_set:N = \c_@@_math_comments_bool ,
- math-comments .default:n = true ,
- beamer .bool_set:N = \c_@@_beamer_bool ,
- beamer .default:n = true ,
- unknown .code:n = \msg_error:nn { piton } { unknown~key~for~package }
+ footnote .bool_gset:N = \g_@@_footnote_bool ,
+ footnotehyper .bool_gset:N = \g_@@_footnotehyper_bool ,
+
+ beamer .bool_gset:N = \g_@@_beamer_bool ,
+ beamer .default:n = true ,
+
+ escape-inside .code:n = \@@_error:n { key-escape-inside-deleted } ,
+ math-comments .code:n = \@@_error:n { moved~to~preamble } ,
+ comment-latex .code:n = \@@_error:n { moved~to~preamble } ,
+
+ unknown .code:n = \@@_error:n { Unknown~key~for~package }
+ }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\@@_msg_new:nn { key-escape-inside-deleted }
+ {
+ The~key~'escape-inside'~has~been~deleted.~You~must~now~use~
+ the~keys~'begin-escape'~and~'end-escape'~in~
+ \token_to_str:N \PitonOptions.\\
+ That~key~will~be~ignored.
}
% \end{macrocode}
%
+% \bigskip
% \begin{macrocode}
-\msg_new:nnn { piton } { unknown~key~for~package }
+\@@_msg_new:nn { moved~to~preamble }
+ {
+ The~key~'\l_keys_key_str'~*must*~now~be~used~with~
+ \token_to_str:N \PitonOptions`in~the~preamble~of~your~
+ document.\\
+ That~key~will~be~ignored.
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\@@_msg_new:nn { Unknown~key~for~package }
{
Unknown~key.\\
You~have~used~the~key~'\l_keys_key_str'~but~the~only~keys~available~here~
- are~'beamer',~'comment-latex',~'escape-inside',~'footnote',~'footnotehyper'~and~
- 'math-comments'.~Other~keys~are~available~in~\token_to_str:N \PitonOptions.\\
+ are~'beamer',~'footnote',~'footnotehyper'.~Other~keys~are~available~in~
+ \token_to_str:N \PitonOptions.\\
That~key~will~be~ignored.
}
% \end{macrocode}
%
+%
% \bigskip
% We process the options provided by the user at load-time.
% \begin{macrocode}
\ProcessKeysOptions { piton / package }
% \end{macrocode}
%
-% \bigskip
-% \begin{macrocode}
-\begingroup
-\cs_new_protected:Npn \@@_set_escape_char:nn #1 #2
- {
- \lua_now:n { piton_begin_escape = "#1" }
- \lua_now:n { piton_end_escape = "#2" }
- }
-\cs_generate_variant:Nn \@@_set_escape_char:nn { x x }
-\@@_set_escape_char:xx
- { \tl_head:V \c_@@_escape_inside_tl }
- { \tl_tail:V \c_@@_escape_inside_tl }
-\endgroup
-% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
-\@ifclassloaded { beamer } { \bool_set_true:N \c_@@_beamer_bool } { }
-\bool_if:NT \c_@@_beamer_bool { \lua_now:n { piton_beamer = true } }
+\@ifclassloaded { beamer } { \bool_gset_true:N \g_@@_beamer_bool } { }
+\@ifpackageloaded { beamerarticle } { \bool_gset_true:N \g_@@_beamer_bool } { }
+\bool_if:NT \g_@@_beamer_bool { \lua_now:n { piton_beamer = true } }
% \end{macrocode}
%
% \bigskip
@@ -2058,7 +2344,7 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \begin{macrocode}
-\msg_new:nnn { piton } { xcolor~not~loaded }
+\@@_msg_new:nn { xcolor~not~loaded }
{
xcolor~not~loaded \\
The~package~'xcolor'~is~required~by~'piton'.\\
@@ -2068,7 +2354,7 @@ version 2005/12/01 or later.
%
%
% \begin{macrocode}
-\msg_new:nnn { piton } { footnote~with~footnotehyper~package }
+\@@_msg_new:nn { footnote~with~footnotehyper~package }
{
Footnote~forbidden.\\
You~can't~use~the~option~'footnote'~because~the~package~
@@ -2081,7 +2367,7 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \begin{macrocode}
-\msg_new:nnn { piton } { footnotehyper~with~footnote~package }
+\@@_msg_new:nn { footnotehyper~with~footnote~package }
{
You~can't~use~the~option~'footnotehyper'~because~the~package~
footnote~has~already~been~loaded.~
@@ -2094,14 +2380,14 @@ version 2005/12/01 or later.
%
% \medskip
% \begin{macrocode}
-\bool_if:NT \c_@@_footnote_bool
+\bool_if:NT \g_@@_footnote_bool
{
% \end{macrocode}
% The class \cls{beamer} has its own system to extract footnotes and that's why
% we have nothing to do if \cls{beamer} is used.
% \begin{macrocode}
\@ifclassloaded { beamer }
- { \bool_set_false:N \c_@@_footnote_bool }
+ { \bool_gset_false:N \g_@@_footnote_bool }
{
\@ifpackageloaded { footnotehyper }
{ \@@_error:n { footnote~with~footnotehyper~package } }
@@ -2111,25 +2397,30 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \begin{macrocode}
-\bool_if:NT \c_@@_footnotehyper_bool
+\bool_if:NT \g_@@_footnotehyper_bool
{
% \end{macrocode}
% The class \cls{beamer} has its own system to extract footnotes and that's why
% we have nothing to do if \cls{beamer} is used.
% \begin{macrocode}
\@ifclassloaded { beamer }
- { \bool_set_false:N \c_@@_footnote_bool }
+ { \bool_gset_false:N \g_@@_footnote_bool }
{
\@ifpackageloaded { footnote }
{ \@@_error:n { footnotehyper~with~footnote~package } }
{ \usepackage { footnotehyper } }
- \bool_set_true:N \c_@@_footnote_bool
+ \bool_gset_true:N \g_@@_footnote_bool
}
}
% \end{macrocode}
-% The flag |\c_@@_footnote_bool| is raised and so, we will only have to test
-% |\c_@@_footnote_bool| in order to know if we have to insert an environment
+% The flag |\g_@@_footnote_bool| is raised and so, we will only have to test
+% |\g_@@_footnote_bool| in order to know if we have to insert an environment
% |{savenotes}|.
+%
+% \bigskip
+% \begin{macrocode}
+\lua_now:n { piton = piton~or { } }
+% \end{macrocode}
%
% \bigskip
% \subsubsection{Parameters and technical definitions}
@@ -2142,6 +2433,20 @@ version 2005/12/01 or later.
\str_set:Nn \l_@@_language_str { python }
% \end{macrocode}
%
+% \medskip
+% In order to have a better control over the keys.
+% \begin{macrocode}
+\bool_new:N \l_@@_in_PitonOptions_bool
+\bool_new:N \l_@@_in_PitonInputFile_bool
+% \end{macrocode}
+%
+% \medskip
+% The following flag will be raised in the |\AtBeginDocument|.
+% \begin{macrocode}
+\bool_new:N \g_@@_in_document_bool
+% \end{macrocode}
+%
+% \medskip
% We will compute (with Lua) the numbers of lines of the Python code and store
% it in the following counter.
% \begin{macrocode}
@@ -2161,7 +2466,7 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \medskip
-% The following token list will contains the (potential) informations to write
+% The following token list will contain the (potential) informations to write
% on the |aux| (to be used in the next compilation).
% \begin{macrocode}
\tl_new:N \g_@@_aux_tl
@@ -2197,7 +2502,20 @@ version 2005/12/01 or later.
% \begin{macrocode}
\tl_new:N \l_@@_prompt_bg_color_tl
% \end{macrocode}
-%
+%
+% \medskip
+% The following parameters correspond to the keys |begin-range| and |end-range| of
+% the command |\PitonInputFile|.
+% \begin{macrocode}
+\str_new:N \l_@@_begin_range_str
+\str_new:N \l_@@_end_range_str
+% \end{macrocode}
+%
+% \medskip
+% The argument of |\PitonInputFile|.
+% \begin{macrocode}
+\str_new:N \l_@@_file_name_str
+% \end{macrocode}
%
% \medskip
% We will count the environments |{Piton}| (and, in fact, also the commands
@@ -2395,19 +2713,29 @@ version 2005/12/01 or later.
}
\@esphack
}
- { \msg_error:nn { piton } { label~with~lines~numbers } }
+ { \@@_error:n { label~with~lines~numbers } }
}
% \end{macrocode}
%
+% \bigskip
+% The following commands corresponds to the keys |marker/beginning| and
+% |marker/end|. The values of that keys are functions that will be applied to
+% the ``\emph{range}'' specified by the final user in an individual
+% |\PitonInputFile|. They will construct the markers used to find textually in
+% the external file loaded by \pkg{piton} the part which must be included (and
+% formatted).
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_marker_beginning:n #1 { }
+\cs_new_protected:Npn \@@_marker_end:n #1 { }
+% \end{macrocode}
+%
%
% \bigskip
% The following commands are a easy way to insert safely braces (|{| and |}|) in
% the TeX flow.
% \begin{macrocode}
-\cs_new_protected:Npn \@@_open_brace:
- { \directlua { piton.open_brace() } }
-\cs_new_protected:Npn \@@_close_brace:
- { \directlua { piton.close_brace() } }
+\cs_new_protected:Npn \@@_open_brace: { \directlua { piton.open_brace() } }
+\cs_new_protected:Npn \@@_close_brace: { \directlua { piton.close_brace() } }
% \end{macrocode}
%
% \bigskip
@@ -2504,12 +2832,22 @@ version 2005/12/01 or later.
\skip_horizontal:N \l_@@_left_margin_dim
\bool_if:NT \l_@@_line_numbers_bool
{
- \bool_if:NF \l_@@_all_line_numbers_bool
- { \tl_if_eq:nnF { #1 } { \PitonStyle {Prompt}{} } }
-% \end{macrocode}
-% Remember that |\@@_print_number:| always uses |\hbox_overlap_left:n|.
-% \begin{macrocode}
- \@@_print_number:
+ \bool_if:nF
+ {
+ \str_if_eq_p:nn { #1 } { \PitonStyle {Prompt}{} }
+ &&
+ \l_@@_skip_empty_lines_bool
+ }
+ { \int_gincr:N \g_@@_visual_line_int}
+
+ \bool_if:nT
+ {
+ ! \str_if_eq_p:nn { #1 } { \PitonStyle {Prompt}{} }
+ ||
+ ( ! \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
@@ -2588,7 +2926,7 @@ version 2005/12/01 or later.
{
\hbox_to_wd:nn \l_@@_line_width_dim
% \end{macrocode}
-% We unpack the bock in order to free the potential |\hfill| springs present in
+% We unpack the block in order to free the potential |\hfill| springs present in
% the LaTeX comments (cf. section~\ref{example-comments}, p.~\pageref{example-comments}).
% \begin{macrocode}
{ \hbox_unpack:N \l_tmpa_box \hfil }
@@ -2644,9 +2982,9 @@ version 2005/12/01 or later.
{ \l_@@_nb_lines_int - \g_@@_line_int } > \l_@@_splittable_int
{
\egroup
- \bool_if:NT \c_@@_footnote_bool { \end { savenotes } }
+ \bool_if:NT \g_@@_footnote_bool { \end { savenotes } }
\par \mode_leave_vertical: % \newline
- \bool_if:NT \c_@@_footnote_bool { \begin { savenotes } }
+ \bool_if:NT \g_@@_footnote_bool { \begin { savenotes } }
\vtop \bgroup
}
}
@@ -2687,17 +3025,90 @@ version 2005/12/01 or later.
% \subsubsection{PitonOptions}
%
% \medskip
-% The following parameters correspond to the keys |line-numbers| and
-% |all-line-numbers|.
% \begin{macrocode}
\bool_new:N \l_@@_line_numbers_bool
-\bool_new:N \l_@@_all_line_numbers_bool
+\bool_new:N \l_@@_skip_empty_lines_bool
+\bool_set_true:N \l_@@_skip_empty_lines_bool
+\bool_new:N \l_@@_line_numbers_absolute_bool
+\bool_new:N \l_@@_label_empty_lines_bool
+\bool_set_true:N \l_@@_label_empty_lines_bool
+\int_new:N \l_@@_number_lines_start_int
+\bool_new:N \l_@@_resume_bool
% \end{macrocode}
%
-% \medskip
-% The following flag corresponds to the key |resume|.
+%
+% \bigskip
% \begin{macrocode}
-\bool_new:N \l_@@_resume_bool
+\keys_define:nn { PitonOptions / marker }
+ {
+ beginning .code:n = \cs_set:Nn \@@_marker_beginning:n { #1 } ,
+ beginning .value_required:n = true ,
+ end .code:n = \cs_set:Nn \@@_marker_end:n { #1 } ,
+ end .value_required:n = true ,
+ include-lines .bool_set:N = \l_@@_marker_include_lines_bool ,
+ include-lines .default:n = true ,
+ unknown .code:n = \@@_error:n { Unknown~key~for~marker }
+ }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\keys_define:nn { PitonOptions / line-numbers }
+ {
+ true .code:n = \bool_set_true:N \l_@@_line_numbers_bool ,
+ false .code:n = \bool_set_false:N \l_@@_line_numbers_bool ,
+
+ start .code:n =
+ \bool_if:NTF \l_@@_in_PitonOptions_bool
+ { Invalid~key }
+ {
+ \bool_set_true:N \l_@@_line_numbers_bool
+ \int_set:Nn \l_@@_number_lines_start_int { #1 }
+ } ,
+ start .value_required:n = true ,
+
+ skip-empty-lines .code:n =
+ \bool_if:NF \l_@@_in_PitonOptions_bool
+ { \bool_set_true:N \l_@@_line_numbers_bool }
+ \str_if_eq:nnTF { #1 } { false }
+ { \bool_set_false:N \l_@@_skip_empty_lines_bool }
+ { \bool_set_true:N \l_@@_skip_empty_lines_bool } ,
+ skip-empty-lines .default:n = true ,
+
+ label-empty-lines .code:n =
+ \bool_if:NF \l_@@_in_PitonOptions_bool
+ { \bool_set_true:N \l_@@_line_numbers_bool }
+ \str_if_eq:nnTF { #1 } { false }
+ { \bool_set_false:N \l_@@_label_empty_lines_bool }
+ { \bool_set_true:N \l_@@_label_empty_lines_bool } ,
+ label-empty-lines .default:n = true ,
+
+ absolute .code:n =
+ \bool_if:NTF \l_@@_in_PitonOptions_bool
+ { \bool_set_true:N \l_@@_line_numbers_absolute_bool }
+ { \bool_set_true:N \l_@@_line_numbers_bool }
+ \bool_if:NT \l_@@_in_PitonInputFile_bool
+ {
+ \bool_set_true:N \l_@@_line_numbers_absolute_bool
+ \bool_set_false:N \l_@@_skip_empty_lines_bool
+ }
+ \bool_lazy_or:nnF
+ \l_@@_in_PitonInputFile_bool
+ \l_@@_in_PitonOptions_bool
+ { \@@_error:n { Invalid~key } } ,
+ absolute .value_forbidden:n = true ,
+
+ resume .code:n =
+ \bool_set_true:N \l_@@_resume_bool
+ \bool_if:NF \l_@@_in_PitonOptions_bool
+ { \bool_set_true:N \l_@@_line_numbers_bool } ,
+ resume .value_forbidden:n = true ,
+
+ sep .dim_set:N = \l_@@_numbers_sep_dim ,
+ sep .value_required:n = true ,
+
+ unknown .code:n = \@@_error:n { Unknown~key~for~line-numbers }
+ }
% \end{macrocode}
%
% \bigskip
@@ -2707,6 +3118,41 @@ version 2005/12/01 or later.
% \begin{macrocode}
\keys_define:nn { PitonOptions }
{
+% \end{macrocode}
+% First, we put keys that should be avalaible only in the preamble.
+% \begin{macrocode}
+ begin-escape .code:n =
+ \lua_now:e { piton.begin_escape = "\lua_escape:n{#1}" } ,
+ begin-escape .value_required:n = true ,
+ begin-escape .usage:n = preamble ,
+
+ end-escape .code:n =
+ \lua_now:e { piton.end_escape = "\lua_escape:n{#1}" } ,
+ end-escape .value_required:n = true ,
+ end-escape .usage:n = preamble ,
+
+ begin-escape-math .code:n =
+ \lua_now:e { piton.begin_escape_math = "\lua_escape:n{#1}" } ,
+ begin-escape-math .value_required:n = true ,
+ begin-escape-math .usage:n = preamble ,
+
+ end-escape-math .code:n =
+ \lua_now:e { piton.end_escape_math = "\lua_escape:n{#1}" } ,
+ end-escape-math .value_required:n = true ,
+ end-escape-math .usage:n = preamble ,
+
+ comment-latex .code:n = \lua_now:n { comment_latex = "#1" } ,
+ comment-latex .value_required:n = true ,
+ comment-latex .usage:n = preamble ,
+
+ math-comments .bool_set:N = \g_@@_math_comments_bool ,
+ math-comments .default:n = true ,
+ math-comments .usage:n = preamble ,
+% \end{macrocode}
+%
+% \bigskip
+% Now, general keys.
+% \begin{macrocode}
language .code:n =
\str_set:Nx \l_@@_language_str { \str_lowercase:n { #1 } } ,
language .value_required:n = true ,
@@ -2718,21 +3164,28 @@ version 2005/12/01 or later.
env-gobble .value_forbidden:n = true ,
tabs-auto-gobble .code:n = \int_set:Nn \l_@@_gobble_int { -3 } ,
tabs-auto-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 ,
- resume .bool_set:N = \l_@@_resume_bool ,
- resume .value_forbidden:n = true ,
+
+ marker .code:n =
+ \bool_lazy_or:nnTF
+ \l_@@_in_PitonInputFile_bool
+ \l_@@_in_PitonOptions_bool
+ { \keys_set:nn { PitonOptions / marker } { #1 } }
+ { \@@_error:n { Invalid~key } } ,
+ marker .value_required:n = true ,
+
+ line-numbers .code:n =
+ \keys_set:nn { PitonOptions / line-numbers } { #1 } ,
+ line-numbers .default:n = true ,
+
+
splittable .int_set:N = \l_@@_splittable_int ,
splittable .default:n = 1 ,
background-color .clist_set:N = \l_@@_bg_color_clist ,
background-color .value_required:n = true ,
prompt-background-color .tl_set:N = \l_@@_prompt_bg_color_tl ,
prompt-background-color .value_required:n = true ,
- width .code:n =
+
+ width .code:n =
\str_if_eq:nnTF { #1 } { min }
{
\bool_set_true:N \l_@@_width_min_bool
@@ -2742,7 +3195,8 @@ version 2005/12/01 or later.
\bool_set_false:N \l_@@_width_min_bool
\dim_set:Nn \l_@@_width_dim { #1 }
} ,
- width .value_required:n = true ,
+ width .value_required:n = true ,
+
left-margin .code:n =
\str_if_eq:nnTF { #1 } { auto }
{
@@ -2754,8 +3208,7 @@ version 2005/12/01 or later.
\bool_set_false:N \l_@@_left_margin_auto_bool
} ,
left-margin .value_required:n = true ,
- numbers-sep .dim_set:N = \l_@@_numbers_sep_dim ,
- numbers-sep .value_required:n = true ,
+
tab-size .code:n = \@@_set_tab_tl:n { #1 } ,
tab-size .value_required:n = true ,
show-spaces .bool_set:N = \l_@@_show_spaces_bool ,
@@ -2776,27 +3229,80 @@ version 2005/12/01 or later.
continuation-symbol .value_required:n = true ,
continuation-symbol-on-indentation .tl_set:N = \l_@@_csoi_tl ,
continuation-symbol-on-indentation .value_required:n = true ,
- unknown .code:n =
- \msg_error:nn { piton } { Unknown~key~for~PitonOptions }
+
+ first-line .code:n = \@@_in_PitonInputFile:n
+ { \int_set:Nn \l_@@_first_line_int { #1 } } ,
+ first-line .value_required:n = true ,
+
+ last-line .code:n = \@@_in_PitonInputFile:n
+ { \int_set:Nn \l_@@_last_line_int { #1 } } ,
+ last-line .value_required:n = true ,
+
+ begin-range .code:n = \@@_in_PitonInputFile:n
+ { \str_set:Nn \l_@@_begin_range_str { #1 } } ,
+ begin-range .value_required:n = true ,
+
+ end-range .code:n = \@@_in_PitonInputFile:n
+ { \str_set:Nn \l_@@_end_range_str { #1 } } ,
+ end-range .value_required:n = true ,
+
+ range .code:n = \@@_in_PitonInputFile:n
+ {
+ \str_set:Nn \l_@@_begin_range_str { #1 }
+ \str_set:Nn \l_@@_end_range_str { #1 }
+ } ,
+ range .value_required:n = true ,
+
+ resume .meta:n = line-numbers/resume ,
+
+ unknown .code:n = \@@_error:n { Unknown~key~for~PitonOptions } ,
+
+ % deprecated
+ all-line-numbers .code:n =
+ \bool_set_true:N \l_@@_line_numbers_bool
+ \bool_set_false:N \l_@@_skip_empty_lines_bool ,
+ all-line-numbers .value_forbidden:n = true ,
+
+ % deprecated
+ numbers-sep .dim_set:N = \l_@@_numbers_sep_dim ,
+ numbers-sep .value_required:n = true
}
% \end{macrocode}
%
+% \bigskip
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_in_PitonInputFile:n #1
+ {
+ \bool_if:NTF \l_@@_in_PitonInputFile_bool
+ { #1 }
+ { \@@_error:n { Invalid~key } }
+ }
+% \end{macrocode}
%
-% \bigskip
-%
+%
% \bigskip
-% The argument of |\PitonOptions| is provided by curryfication.
% \begin{macrocode}
-\NewDocumentCommand \PitonOptions { } { \keys_set:nn { PitonOptions } }
+\NewDocumentCommand \PitonOptions { m }
+ {
+ \bool_set_true:N \l_@@_in_PitonOptions_bool
+ \keys_set:nn { PitonOptions } { #1 }
+ \bool_set_false:N \l_@@_in_PitonOptions_bool
+ }
% \end{macrocode}
%
+%
+% \bigskip
+% \begin{macrocode}
+\hook_gput_code:nnn { begindocument } { . }
+ { \bool_gset_true:N \g_@@_in_document_bool }
+% \end{macrocode}
+%
% \bigskip
% \subsubsection{The numbers of the lines}
%
% \medskip
% The following counter will be used to count the lines in the code when the
-% user requires the numbers of the lines to be printed (with |line-numbers| or
-% |all-line-numbers|).
+% user requires the numbers of the lines to be printed (with |line-numbers|).
%
% \begin{macrocode}
\int_new:N \g_@@_visual_line_int
@@ -2806,10 +3312,13 @@ version 2005/12/01 or later.
% \begin{macrocode}
\cs_new_protected:Npn \@@_print_number:
{
- \int_gincr:N \g_@@_visual_line_int
\hbox_overlap_left:n
{
- { \color { gray } \footnotesize \int_to_arabic:n \g_@@_visual_line_int }
+ {
+ \color { gray }
+ \footnotesize
+ \int_to_arabic:n \g_@@_visual_line_int
+ }
\skip_horizontal:N \l_@@_numbers_sep_dim
}
}
@@ -3028,17 +3537,6 @@ version 2005/12/01 or later.
}
% \end{macrocode}
%
-% \bigskip
-% \begin{macrocode}
-\keys_define:nn { PitonInputFile }
- {
- first-line .int_set:N = \l_@@_first_line_int ,
- first-line .value_required:n = true ,
- last-line .int_set:N = \l_@@_last_line_int ,
- last-line .value_required:n = true ,
- }
-% \end{macrocode}
-%
%
% \bigskip
% If the final user has used both |left-margin=auto| and |line-numbers|, we have
@@ -3054,11 +3552,7 @@ version 2005/12/01 or later.
\hbox_set:Nn \l_tmpa_box
{
\footnotesize
- \bool_if:NTF \l_@@_all_line_numbers_bool
- {
- \int_to_arabic:n
- { \g_@@_visual_line_int + \l_@@_nb_lines_int }
- }
+ \bool_if:NTF \l_@@_skip_empty_lines_bool
{
\lua_now:n
{ piton.#1(token.scan_argument()) }
@@ -3066,6 +3560,10 @@ version 2005/12/01 or later.
\int_to_arabic:n
{ \g_@@_visual_line_int + \l_@@_nb_non_empty_lines_int }
}
+ {
+ \int_to_arabic:n
+ { \g_@@_visual_line_int + \l_@@_nb_lines_int }
+ }
}
\dim_set:Nn \l_@@_left_margin_dim
{ \box_wd:N \l_tmpa_box + \l_@@_numbers_sep_dim + 0.1 em }
@@ -3169,10 +3667,10 @@ version 2005/12/01 or later.
\ttfamily
\dim_zero:N \parskip % added 2023/07/06
% \end{macrocode}
-% |\c_@@_footnote_bool| is raised when the package \pkg{piton} has been load
+% |\g_@@_footnote_bool| is raised when the package \pkg{piton} has been load
% with the key |footnote| \emph{or} the key |footnotehyper|.
% \begin{macrocode}
- \bool_if:NT \c_@@_footnote_bool { \begin { savenotes } }
+ \bool_if:NT \g_@@_footnote_bool { \begin { savenotes } }
\vtop \bgroup
\lua_now:e
{
@@ -3186,7 +3684,7 @@ version 2005/12/01 or later.
{ ##1 }
\vspace { 2.5 pt }
\egroup
- \bool_if:NT \c_@@_footnote_bool { \end { savenotes } }
+ \bool_if:NT \g_@@_footnote_bool { \end { savenotes } }
% \end{macrocode}
% If the user has used the key |width| with the special value~|min|, we write on
% the |aux| file the value of |\l_@@_line_width_dim| (largest width of the lines
@@ -3211,6 +3709,8 @@ version 2005/12/01 or later.
{
#3
\@@_pre_env:
+ \int_compare:nNnT \l_@@_number_lines_start_int > 0
+ { \int_gset:Nn \g_@@_visual_line_int { \l_@@_number_lines_start_int - 1 } }
\group_begin:
\tl_map_function:nN
{ \ \\ \{ \} \$ \& \# \^ \_ \% \~ \^^I }
@@ -3238,19 +3738,20 @@ version 2005/12/01 or later.
% provided by the package \pkg{piton}. Of course, you use
% |\NewPitonEnvironment|.
% \begin{macrocode}
-\bool_if:NTF \c_@@_beamer_bool
+\bool_if:NTF \g_@@_beamer_bool
{
\NewPitonEnvironment { Piton } { d < > O { } }
{
- \PitonOptions { #2 }
+ \keys_set:nn { PitonOptions } { #2 }
\IfValueTF { #1 }
{ \begin { uncoverenv } < #1 > }
{ \begin { uncoverenv } }
}
{ \end { uncoverenv } }
}
- { \NewPitonEnvironment { Piton } { O { } }
- { \PitonOptions { #1 } }
+ {
+ \NewPitonEnvironment { Piton } { O { } }
+ { \keys_set:nn { PitonOptions } { #1 } }
{ }
}
% \end{macrocode}
@@ -3265,13 +3766,14 @@ version 2005/12/01 or later.
{
\file_if_exist:nTF { #3 }
{ \@@_input_file:nnn { #1 } { #2 } { #3 } }
- { \msg_error:nnn { piton } { unknown~file } { #3 } }
+ { \msg_error:nnn { piton } { Unknown~file } { #3 } }
}
% \end{macrocode}
%
% \begin{macrocode}
\cs_new_protected:Npn \@@_input_file:nnn #1 #2 #3
{
+ \str_set:Nn \l_@@_file_name_str { #3 }
% \end{macrocode}
% We recall that, if we are in Beamer, the command |\PitonInputFile| is
% ``overlay-aware'' and that's why there is an optional argument between angular
@@ -3279,23 +3781,65 @@ version 2005/12/01 or later.
% \begin{macrocode}
\tl_if_novalue:nF { #1 }
{
- \bool_if:NTF \c_@@_beamer_bool
+ \bool_if:NTF \g_@@_beamer_bool
{ \begin { uncoverenv } < #1 > }
- { \msg_error:nn { piton } { overlay~without~beamer } }
+ { \@@_error:n { overlay~without~beamer } }
}
\group_begin:
\int_zero_new:N \l_@@_first_line_int
\int_zero_new:N \l_@@_last_line_int
\int_set_eq:NN \l_@@_last_line_int \c_max_int
- \keys_set:nn { PitonInputFile } { #2 }
+ \bool_set_true:N \l_@@_in_PitonInputFile_bool
+ \keys_set:nn { PitonOptions } { #2 }
+ \bool_if:NT \l_@@_line_numbers_absolute_bool
+ { \bool_set_false:N \l_@@_skip_empty_lines_bool }
+ \bool_if:nTF
+ {
+ (
+ \int_compare_p:nNn \l_@@_first_line_int > 0
+ || \int_compare_p:nNn \l_@@_last_line_int < \c_max_int
+ )
+ && ! \str_if_empty_p:N \l_@@_begin_range_str
+ }
+ {
+ \@@_error:n { bad~range~specification }
+ \int_zero:N \l_@@_first_line_int
+ \int_set_eq:NN \l_@@_last_line_int \c_max_int
+ }
+ {
+ \str_if_empty:NF \l_@@_begin_range_str
+ {
+ \@@_compute_range:
+ \bool_lazy_or:nnT
+ \l_@@_marker_include_lines_bool
+ { ! \str_if_eq_p:NN \l_@@_begin_range_str \l_@@_end_range_str }
+ {
+ \int_decr:N \l_@@_first_line_int
+ \int_incr:N \l_@@_last_line_int
+ }
+ }
+ }
\@@_pre_env:
+ \bool_if:NT \l_@@_line_numbers_absolute_bool
+ { \int_gset:Nn \g_@@_visual_line_int { \l_@@_first_line_int - 1 } }
+ \int_compare:nNnT \l_@@_number_lines_start_int > 0
+ {
+ \int_gset:Nn \g_@@_visual_line_int
+ { \l_@@_number_lines_start_int - 1 }
+ }
+% \end{macrocode}
+% The following case arise 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 < 0
+ { \int_gzero:N \g_@@_visual_line_int }
\mode_if_vertical:TF \mode_leave_vertical: \newline
% \end{macrocode}
% We count with Lua the number of lines of the argument. The result will be
% stored by Lua in |\l_@@_nb_lines_int|. That information will be used to allow
% or disallow page breaks.
% \begin{macrocode}
- \lua_now:n { piton.CountLinesFile(token.scan_argument()) } { #3 }
+ \lua_now:e { piton.CountLinesFile('\l_@@_file_name_str') }
% \end{macrocode}
% The first argument of the following function is the name of the Lua function
% that will be applied to the second argument in order to count the number of lines.
@@ -3303,19 +3847,18 @@ version 2005/12/01 or later.
\@@_compute_left_margin:nn { CountNonEmptyLinesFile } { #3 }
\@@_compute_width:
\ttfamily
- \bool_if:NT \c_@@_footnote_bool { \begin { savenotes } }
+ \bool_if:NT \g_@@_footnote_bool { \begin { savenotes } }
\vtop \bgroup
\lua_now:e
{
piton.ParseFile(
- '\l_@@_language_str',
- token.scan_argument() ,
+ '\l_@@_language_str' ,
+ '\l_@@_file_name_str' ,
\int_use:N \l_@@_first_line_int ,
\int_use:N \l_@@_last_line_int )
}
- { #3 }
\egroup
- \bool_if:NT \c_@@_footnote_bool { \end { savenotes } }
+ \bool_if:NT \g_@@_footnote_bool { \end { savenotes } }
\bool_if:NT \l_@@_width_min_bool \@@_width_to_aux:
\group_end:
% \end{macrocode}
@@ -3324,11 +3867,39 @@ version 2005/12/01 or later.
% that we have opened at the beginning of the command.
% \begin{macrocode}
\tl_if_novalue:nF { #1 }
- { \bool_if:NT \c_@@_beamer_bool { \end { uncoverenv } } }
+ { \bool_if:NT \g_@@_beamer_bool { \end { uncoverenv } } }
\@@_write_aux:
}
% \end{macrocode}
%
+%
+% \bigskip
+% The following command computes the values of |\l_@@_first_line_int| and
+% |\l_@@_last_line_int| when |\PitonInputFile| is used with textual markers.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_compute_range:
+ {
+% \end{macrocode}
+% We store the markers in L3 strings (|str|) in order to do safely the following
+% replacement of |\#|.
+% \begin{macrocode}
+ \str_set:Nx \l_tmpa_str { \@@_marker_beginning:n \l_@@_begin_range_str }
+ \str_set:Nx \l_tmpb_str { \@@_marker_end:n \l_@@_end_range_str }
+% \end{macrocode}
+% We replace the sequences |\#| which may be present in the prefixes (and, more
+% unlikely, suffixes) added to the markers by the functions
+% |\@@_marker_beginning:n| and |\@@_marker_end:n|
+% \begin{macrocode}
+ \exp_args:NnV \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpa_str
+ \exp_args:NnV \regex_replace_all:nnN { \\\# } \c_hash_str \l_tmpb_str
+ \lua_now:e
+ {
+ piton.ComputeRange
+ ( '\l_tmpa_str' , '\l_tmpb_str' , '\l_@@_file_name_str' )
+ }
+ }
+% \end{macrocode}
+%
% \bigskip
% \subsubsection{The styles}
%
@@ -3406,7 +3977,7 @@ version 2005/12/01 or later.
ParseAgain.noCR .tl_set:c = pitonStyle ParseAgain.noCR ,
ParseAgain.noCR .value_required:n = true ,
unknown .code:n =
- \msg_error:nn { piton } { Unknown~key~for~SetPitonStyle }
+ \@@_error:n { Unknown~key~for~SetPitonStyle }
}
% \end{macrocode}
%
@@ -3425,7 +3996,7 @@ version 2005/12/01 or later.
{
\str_compare:nNnTF { #1 } < { #2 }
\sort_return_same:
- \sort_return_swapped:
+ \sort_return_swapped:
}
% \end{macrocode}
%
@@ -3480,7 +4051,7 @@ version 2005/12/01 or later.
% However, maybe we will document in a future version the possibility to write
% change the style \emph{locally} in a document)].
% \begin{macrocode}
-\bool_if:NT \c_@@_math_comments_bool { \SetPitonStyle { Comment.Math } }
+\bool_if:NT \g_@@_math_comments_bool { \SetPitonStyle { Comment.Math } }
% \end{macrocode}
%
% \bigskip
@@ -3592,7 +4163,7 @@ version 2005/12/01 or later.
%
%
% \begin{macrocode}
-\msg_new:nnn { piton } { Unknown~key~for~SetPitonStyle }
+\@@_msg_new:nn { Unknown~key~for~SetPitonStyle }
{
The~style~'\l_keys_key_str'~is~unknown.\\
This~key~will~be~ignored.\\
@@ -3601,8 +4172,53 @@ version 2005/12/01 or later.
}
% \end{macrocode}
%
+% \begin{macrocode}
+\@@_msg_new:nn { Invalid~key }
+ {
+ Wrong~use~of~key.\\
+ You~can't~use~the~key~'\l_keys_key_str'~here.\\
+ That~key~will~be~ignored.
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\@@_msg_new:nn { Unknown~key~for~line-numbers }
+ {
+ Unknown~key. \\
+ The~key~'line-numbers / \l_keys_key_str'~is~unknown.\\
+ The~available~keys~of~the~family~'line-numbers'~are~(in~
+ alphabetic~order):~
+ absolute,~false,~label-empty-lines,~resume,~skip-empty-lines,~
+ sep,~start~and~true.\\
+ That~key~will~be~ignored.
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\@@_msg_new:nn { Unknown~key~for~marker }
+ {
+ Unknown~key. \\
+ The~key~'marker / \l_keys_key_str'~is~unknown.\\
+ The~available~keys~of~the~family~'marker'~are~(in~
+ alphabetic~order):~ beginning,~end~and~include-lines.\\
+ That~key~will~be~ignored.
+ }
+% \end{macrocode}
+%
+%
+%
+% \begin{macrocode}
+\@@_msg_new:nn { bad~range~specification }
+ {
+ Incompatible~keys.\\
+ You~can't~specify~the~range~of~lines~to~include~by~using~both~
+ markers~and~explicit~number~of~lines.\\
+ Your~whole~file~'\l_@@_file_name_str'~will~be~included.
+ }
+% \end{macrocode}
+%
% \begin{macrocode}
-\msg_new:nnn { piton } { syntax~error }
+\@@_msg_new:nn { syntax~error }
{
Your~code~is~not~syntactically~correct.\\
It~won't~be~printed~in~the~PDF~file.
@@ -3611,11 +4227,42 @@ version 2005/12/01 or later.
%
% \begin{macrocode}
\NewDocumentCommand \PitonSyntaxError { }
- { \msg_error:nn { piton } { syntax~error } }
+ { \@@_error:n { syntax~error } }
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\@@_msg_new:nn { begin~marker~not~found }
+ {
+ Marker~not~found.\\
+ The~range~'\l_@@_begin_range_str'~provided~to~the~
+ command~\token_to_str:N \PitonInputFile\ has~not~been~found.~
+ The~whole~file~'\l_@@_file_name_str'~will~be~inserted.
+ }
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\@@_msg_new:nn { end~marker~not~found }
+ {
+ Marker~not~found.\\
+ The~marker~of~end~of~the~range~'\l_@@_end_range_str'~
+ provided~to~the~command~\token_to_str:N \PitonInputFile\
+ has~not~been~found.~The~file~'\l_@@_file_name_str'~will~
+ be~inserted~till~the~end.
+ }
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\NewDocumentCommand \PitonBeginMarkerNotFound { }
+ { \@@_error:n { begin~marker~not~found } }
+\NewDocumentCommand \PitonEndMarkerNotFound { }
+ { \@@_error:n { end~marker~not~found } }
% \end{macrocode}
%
% \begin{macrocode}
-\msg_new:nnn { piton } { unknown~file }
+\@@_msg_new:nn { Unknown~file }
{
Unknown~file. \\
The~file~'#1'~is~unknown.\\
@@ -3633,22 +4280,23 @@ version 2005/12/01 or later.
}
{
The~available~keys~are~(in~alphabetic~order):~
- all-line-numbers,~
auto-gobble,~
background-color,~
break-lines,~
break-lines-in-piton,~
break-lines-in-Piton,~
- continuation-symbol,~
+ continuation-symbol,~
continuation-symbol-on-indentation,~
end-of-broken-line,~
+ end-range,~
env-gobble,~
gobble,~
identifiers,~
indent-broken-lines,~
language,~
left-margin,~
- line-numbers,~
+ line-numbers/,~
+ marker/,~
prompt-background-color,~
resume,~
show-spaces,~
@@ -3661,18 +4309,17 @@ version 2005/12/01 or later.
%
% \bigskip
% \begin{macrocode}
-\msg_new:nnn { piton } { label~with~lines~numbers }
+\@@_msg_new:nn { label~with~lines~numbers }
{
You~can't~use~the~command~\token_to_str:N \label\
- because~the~key~'line-numbers'~(or~'all-line-numbers')~
- is~not~active.\\
+ because~the~key~'line-numbers'~is~not~active.\\
If~you~go~on,~that~command~will~ignored.
}
% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
-\msg_new:nnn { piton } { cr~not~allowed }
+\@@_msg_new:nn { cr~not~allowed }
{
You~can't~put~any~carriage~return~in~the~argument~
of~a~command~\c_backslash_str
@@ -3685,7 +4332,7 @@ version 2005/12/01 or later.
%
% \bigskip
% \begin{macrocode}
-\msg_new:nnn { piton } { overlay~without~beamer }
+\@@_msg_new:nn { overlay~without~beamer }
{
You~can't~use~an~argument~<...>~for~your~command~
\token_to_str:N \PitonInputFile\ because~you~are~not~
@@ -3696,19 +4343,25 @@ version 2005/12/01 or later.
%
% \bigskip
% \begin{macrocode}
-\msg_new:nnn { Piton } { Python~error }
+\@@_msg_new:nn { Python~error }
{ A~Python~error~has~been~detected. }
% \end{macrocode}
-%
+%
% \bigskip
-% \subsection{The Lua part of the implementation}
+% \subsubsection{We load piton.lua}
+%
%
% \bigskip
% \begin{macrocode}
-\ExplSyntaxOff
-\RequirePackage{luacode}
+\hook_gput_code:nnn { begindocument } { . }
+ { \lua_now:e { require("piton.lua") } }
+%</STY>
% \end{macrocode}
%
+% \bigskip
+% \subsection{The Lua part of the implementation}
+%
+%
%
% \bigskip
% The Lua code will be loaded via a |{luacode*}| environment. The environment
@@ -3716,13 +4369,9 @@ version 2005/12/01 or later.
% block. All the global functions (used by the L3 parts of the implementation)
% will be put in a Lua table |piton|.
%
-% \medskip
-% \begin{macrocode}
-\begin{luacode*}
-piton = piton or { }
-% \end{macrocode}
%
% \begin{macrocode}
+%<*LUA>
if piton.comment_latex == nil then piton.comment_latex = ">" end
piton.comment_latex = "#" .. piton.comment_latex
% \end{macrocode}
@@ -3773,7 +4422,7 @@ end
% with standard LaTeX catcodes for all the characters: the elements captured
% will be formatted as normal LaTeX codes. It's suitable for the ``LaTeX
% comments'' in the environments |{Piton}| and the elements beetween
-% ``|escape-inside|''. That function won't be much used.
+% |begin-escape| and |end-escape|. That function won't be much used.
% \begin{macrocode}
local function L(pattern)
return Ct ( C ( pattern ) )
@@ -3827,19 +4476,33 @@ end
%
% \bigskip
% The following \textsc{lpeg} catches the Python chunks which are in LaTeX
-% escapes (and that chunks will be considered as normal LaTeX constructions). We
-% recall that |piton.begin_espace| and |piton_end_escape| are Lua strings
-% corresponding to the key |escape-inside|\footnote{The \pkg{piton} key
-% |escape-inside| is available at load-time only.}. Since the elements that will
-% be catched must be sent to LaTeX with standard LaTeX catcodes, we put the
-% capture (done by the function |C|) in a table (by using |Ct|, which is an
-% alias for |lpeg.Ct|) without number of catcode table at the first component of
-% the table.
+% escapes (and that chunks will be considered as normal LaTeX constructions).
+% Since the elements that will be catched must be sent to LaTeX with standard
+% LaTeX catcodes, we put the capture (done by the function |C|) in a table (by
+% using |Ct|, which is an alias for |lpeg.Ct|) without number of catcode table
+% at the first component of the table.
+% \begin{macrocode}
+Escape = P ( false )
+if piton.begin_escape ~= nil
+then
+ Escape =
+ P(piton.begin_escape)
+ * L ( ( 1 - P(piton.end_escape) ) ^ 1 )
+ * P(piton.end_escape)
+end
+% \end{macrocode}
+%
% \begin{macrocode}
-local Escape =
- P(piton_begin_escape)
- * L ( ( 1 - P(piton_end_escape) ) ^ 1 )
- * P(piton_end_escape)
+EscapeMath = P ( false )
+if piton.begin_escape_math ~= nil
+then
+ EscapeMath =
+ P(piton.begin_escape_math)
+ * Lc ( "\\ensuremath{" )
+ * L ( ( 1 - P(piton.end_escape_math) ) ^ 1 )
+ * Lc ( "}" )
+ * P(piton.end_escape_math)
+end
% \end{macrocode}
%
% \vspace{1cm}
@@ -3907,13 +4570,11 @@ local Number =
%
% \bigskip
% We recall that |piton.begin_espace| and |piton_end_escape| are Lua strings
-% corresponding to the key |escape-inside|\footnote{The \pkg{piton} key
-% |escape-inside| is available at load-time only.}. Of course, if the final user
-% has not used the key |escape-inside|, these strings are empty.
+% corresponding to the keys |begin-escape| and |end-escape|.
% \begin{macrocode}
local Word
-if piton_begin_escape ~= ''
-then Word = Q ( ( ( 1 - space - P(piton_begin_escape) - P(piton_end_escape) )
+if piton.begin_escape ~= nil -- before : ''
+then Word = Q ( ( ( 1 - space - P(piton.begin_escape) - P(piton.end_escape) )
- S "'\"\r[()]" - digit ) ^ 1 )
else Word = Q ( ( ( 1 - space ) - S "'\"\r[()]" - digit ) ^ 1 )
end
@@ -4624,7 +5285,7 @@ local MainPython =
EOL
+ Space
+ Tab
- + Escape
+ + Escape + EscapeMath
+ CommentLaTeX
+ Beamer
+ LongString
@@ -5137,7 +5798,7 @@ MainOCaml =
EOL
+ Space
+ Tab
- + Escape
+ + Escape + EscapeMath
+ Beamer
+ TypeParameter
+ String + QuotedString + Char
@@ -5472,7 +6133,7 @@ local MainC =
EOL
+ Space
+ Tab
- + Escape
+ + Escape + EscapeMath
+ CommentLaTeX
+ Beamer
+ Preproc
@@ -5831,10 +6492,45 @@ function piton.CountNonEmptyLinesFile(name)
'\\int_set:Nn \\l_@@_nb_non_empty_lines_int {' .. count .. '}' )
end
% \end{macrocode}
+%
%
+% \bigskip
+% The following function stores in |\l_@@_first_line_int| and
+% |\l_@@_last_line_int| the numbers of lines of the file |file_name|
+% corresponding to the strings |marker_beginning| and |marker_end|.
% \begin{macrocode}
-\end{luacode*}
+function piton.ComputeRange(marker_beginning,marker_end,file_name)
+ local s = ( Cs ( ( P '##' / '#' + 1 ) ^ 0 ) ) : match ( marker_beginning )
+ local t = ( Cs ( ( P '##' / '#' + 1 ) ^ 0 ) ) : match ( marker_end )
+ local first_line = -1
+ local count = 0
+ local last_found = false
+ for line in io.lines(file_name)
+ do if first_line == -1
+ then if string.sub(line,1,#s) == s
+ then first_line = count
+ end
+ else if string.sub(line,1,#t) == t
+ then last_found = true
+ break
+ end
+ end
+ count = count + 1
+ end
+ if first_line == -1
+ then tex.sprint("\\PitonBeginMarkerNotFound")
+ else if last_found == false
+ then tex.sprint("\\PitonEndMarkerNotFound")
+ end
+ end
+ tex.sprint(
+ luatexbase.catcodetables.expl ,
+ '\\int_set:Nn \\l_@@_first_line_int {' .. first_line .. ' + 2 }'
+ .. '\\int_set:Nn \\l_@@_last_line_int {' .. count .. ' }' )
+end
+%</LUA>
% \end{macrocode}
+%
%
%
% \vspace{1cm}
@@ -5855,6 +6551,22 @@ end
%
% \verb|https://github.com/fpantigny/piton|
%
+% \subsection*{Changes between versions 2.0 and 2.1}
+%
+% The key |line-numbers| has now subkeys |line-numbers/skip-empty-lines|,
+% |line-numbers/label-empty-lines|, etc.
+%
+% The key |all-line-numbers| is deprecated: use
+% |line-numbers/skip-empty-lines=false|.
+%
+% New system to import, with |\PitonInputFile|, only a part (of the file)
+% delimited by textual markers.
+%
+% New keys |begin-escape|, |end-escape|, |begin-escape-math| and |end-escape-math|.
+%
+% The key |escape-inside| is deprecated: use |begin-escape| and |end-escape|.
+%
+%
% \subsection*{Changes between versions 1.6 and 2.0}
%
% The extension \pkg{piton} nows supports the computer languages OCaml and C
diff --git a/Master/texmf-dist/source/lualatex/piton/piton.ins b/Master/texmf-dist/source/lualatex/piton/piton.ins
index 70e62adb760..c51d4ea47f4 100644
--- a/Master/texmf-dist/source/lualatex/piton/piton.ins
+++ b/Master/texmf-dist/source/lualatex/piton/piton.ins
@@ -30,13 +30,16 @@ and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.
\endpreamble
-\generate{\file{piton.sty}{\from{piton.dtx}{package}}}
+\generate{\file{piton.sty}{\from{piton.dtx}{STY}}}
+\nopreamble
+\nopostamble
+\generate{\file{piton.lua}{\from{piton.dtx}{LUA}}}
\Msg{*********************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the}
\Msg{* following files into a directory searched by TeX:}
\Msg{*}
-\Msg{* \space\space piton.sty}
+\Msg{* \space\space piton.sty, piton.lua}
\Msg{*}
\Msg{* To produce the documentation run the file piton.dtx}
\Msg{* through LuaLaTeX.}