summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/regexpatch
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-07-15 14:45:37 +0000
committerKarl Berry <karl@freefriends.org>2012-07-15 14:45:37 +0000
commit4253f6c35ba914a69073485658b9ad82389c9faa (patch)
treecd7a73d5898f1e691a0ac1c5da263958e162e43b /Master/texmf-dist/source/latex/regexpatch
parent3a8d2268677f2d2f3320c4410d9c34f6e98241ac (diff)
regexpatch 0.1a (8jun12)
git-svn-id: svn://tug.org/texlive/trunk@27067 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/regexpatch')
-rw-r--r--Master/texmf-dist/source/latex/regexpatch/regexpatch.dtx139
1 files changed, 76 insertions, 63 deletions
diff --git a/Master/texmf-dist/source/latex/regexpatch/regexpatch.dtx b/Master/texmf-dist/source/latex/regexpatch/regexpatch.dtx
index 261bdcf3db2..b886de5f228 100644
--- a/Master/texmf-dist/source/latex/regexpatch/regexpatch.dtx
+++ b/Master/texmf-dist/source/latex/regexpatch/regexpatch.dtx
@@ -25,7 +25,7 @@
\newcommand{\sv}{[\texttt{*}]}
%</driver>
%<*driver|package>
-\GetIdInfo$Id: regexpatch.dtx 0.1dev 2012-04-15 12:00:00Z Enrico $
+\GetIdInfo$Id: regexpatch.dtx 0.1a 2012-06-07 12:00:00Z Enrico $
{Extending etoolbox patching commands}
%</driver|package>
%<*driver>
@@ -36,10 +36,11 @@
% \fi
%
% \title{^^A
-% The \textsf{regexpatch} package\\ Replacing \textsf{etoolbox} patching
-% commands^^A
-% \thanks{This file describes version \ExplFileVersion,
+% The \textsf{regexpatch} package^^A
+% \thanks{This file describes version \ExplFileVersion,
% last revised \ExplFileDate.}^^A
+% \\ {\normalsize Replacing \textsf{etoolbox} patching
+% commands}^^A
% }
%
% \author{^^A
@@ -54,6 +55,8 @@
%
% \maketitle
%
+% \changes{v0.1a}{2012/06/07}{Fixed bugs in success/failure code}
+% \changes{v0.1}{2012-04-15}{First public release}
% \begin{documentation}
%
% \begin{quotation}\small
@@ -211,6 +214,13 @@
% general. The next version will probably provide a new way for
% robustifying commands.
%
+% \section{Acknowledgment}
+%
+% This package would not exist without the \textsf{l3regex} package
+% and Bruno Le Floch. Some parts of \textsf{l3regex} were added just
+% because I asked for them while developing the present package.
+% Thanks also to Joseph Wright and all the \LaTeX3 team.
+%
%
% \section{Commands}
%
@@ -472,12 +482,17 @@
% \usepackage{etoolbox} % for \ifdef
% \ifdef{\H@old@part}
% {
-% \regexpatchcmd{\H@old@part}{$}{\c{gdef}\c{cont@name@part}\cB\{\cP\#2\cE\}}{}{}%
+% \regexpatchcmd{\H@old@part}
+% {$} % regex representing the end
+% {\c{gdef}\c{cont@name@part}\cB\{\cP\#2\cE\}} % replacement
+% {}{}%
% }
% {
-% \regexpatchcmd{\@part}{$}{\c{gdef}\c{cont@name@part}\cB\{\cP\#2\cE\}}{}{}%
+% \regexpatchcmd{\@part}
+% {$}
+% {\c{gdef}\c{cont@name@part}\cB\{\cP\#2\cE\}}
+% {}{}%
% }
-% \show\H@old@part
% \makeatother
%\end{verbatim}
% We want to add |\gdef\cont@name@part{#2}| at the end of the
@@ -568,7 +583,7 @@
}
\tex_endinput:D
}
-\RequirePackage{xparse,l3regex,etoolbox}
+\RequirePackage{xparse,l3regex}
% \end{macrocode}
%
% \subsection{Variables}
@@ -601,7 +616,7 @@
% A variant for checking a regex match so that we can give the second
% argument as a token list.
% \begin{macrocode}
-\cs_generate_variant:Nn \regex_match:nnT {nVT}
+\cs_generate_variant:Nn \regex_match:nnT {nV}
% \end{macrocode}
%
% \subsection{Functions}
@@ -653,7 +668,7 @@
% throw away everything except what's contained between the final pair
% of braces.
% \begin{macrocode}
-\cs_new:Npn \xpatch_main_check:N #1
+\cs_new_protected:Npn \xpatch_main_check:N #1
{
\bool_set_false:N \l_xpatch_protect_bool
\bool_set_false:N \l_xpatch_optional_bool
@@ -726,13 +741,13 @@
% execute is |#1|; |#2| is a function that gobbles the next items in
% case the macro's name is misspelled.
% \begin{macrocode}
-\cs_new:Npn \xpatch_main:NNN #1 #2 #3
+\cs_new_protected:Npn \xpatch_main:NNN #1 #2 #3
{
\cs_if_exist:NTF #3
{
\xpatch_main_check:N #3
\bool_if:NT \l_xpatch_tracing_bool
- { \xpatch_message_cstype:n #3 }
+ { \xpatch_message_cstype:N #3 }
\exp_after:wN #1 \cs:w \l_xpatch_name_tl \cs_end:
}
{
@@ -753,20 +768,14 @@
% will contain the prefix or parameter text or replacement text of
% |#1| first in `detokenized' and then in `tokenized' form.
% \begin{macrocode}
-\cs_new:Npn \xpatch_get_all:N #1
+\cs_new_protected:Npn \xpatch_get_all:N #1
{
- \exp_args:NNf \tl_set:Nn \l_xpatch_prefix_tl
- {\token_get_prefix_spec:N #1 }
- \exp_args:NNnx \tl_set_rescan:Nnn
- \l_xpatch_prefix_tl { } \l_xpatch_prefix_tl
- \exp_args:NNf \tl_set:Nn \l_xpatch_arg_tl
- {\token_get_arg_spec:N #1 }
- \exp_args:NNnx \tl_set_rescan:Nnn
- \l_xpatch_arg_tl { } \l_xpatch_arg_tl
- \exp_args:NNf \tl_set:Nn \l_xpatch_replacement_tl
- {\token_get_replacement_spec:N #1 }
- \exp_args:NNnx \tl_set_rescan:Nnn
- \l_xpatch_replacement_tl { } \l_xpatch_replacement_tl
+ \tl_set:Nf \l_xpatch_prefix_tl { \token_get_prefix_spec:N #1 }
+ \tl_set_rescan:Nnx \l_xpatch_prefix_tl { } \l_xpatch_prefix_tl
+ \tl_set:Nf \l_xpatch_arg_tl { \token_get_arg_spec:N #1 }
+ \tl_set_rescan:Nnx \l_xpatch_arg_tl { } \l_xpatch_arg_tl
+ \tl_set:Nf \l_xpatch_replacement_tl { \token_get_replacement_spec:N #1 }
+ \tl_set_rescan:Nnx \l_xpatch_replacement_tl { } \l_xpatch_replacement_tl
}
% \end{macrocode}
% After possible modifications to the replacement text, we can call
@@ -774,14 +783,16 @@
% it for checking if |#1| is patchable. Of course we need to use
% |\tex_def:D| at this point.
% \begin{macrocode}
-\cs_new:Npn \xpatch_rebuild:N #1
+\cs_new_protected:Npn \xpatch_rebuild:N #1
{
- \tl_clear:N \l_tmpa_tl
- \tl_put_right:NV \l_tmpa_tl \l_xpatch_prefix_tl
- \tl_put_right:Nn \l_tmpa_tl { \tex_def:D #1 }
- \tl_put_right:NV \l_tmpa_tl \l_xpatch_arg_tl
- \tl_put_right:No \l_tmpa_tl { \exp_after:wN {\l_xpatch_replacement_tl} }
- \tl_use:N \l_tmpa_tl
+ \use:x
+ {
+ \exp_not:V \l_xpatch_prefix_tl
+ \tex_def:D
+ \exp_not:N #1
+ \exp_not:V \l_xpatch_arg_tl
+ { \exp_not:V \l_xpatch_replacement_tl }
+ }
}
% \end{macrocode}
% To check if |#1| is patchable, we rebuild it as |\xpatch_tmpa:w| and
@@ -789,7 +800,7 @@
% the first thing to do, so we put |\xpatch_get_all:N| here; |#1| is
% the macro to patch.
% \begin{macrocode}
-\cs_new:Npn \xpatch_check_patchable:N #1
+\cs_new_protected:Npn \xpatch_check_patchable:N #1
{
\cs_if_exist:NTF #1
{
@@ -826,7 +837,7 @@
% easy: we check if the command is patchable and, if so, we prepend or append
% the second argument to the replacement text and rebuild the macro.
% \begin{macrocode}
-\cs_new:Npn \xpatch_pretocmd:Nnnn #1 #2 #3 #4
+\cs_new_protected:Npn \xpatch_pretocmd:Nnnn #1 #2 #3 #4
{
\xpatch_check_patchable:N #1
\bool_if:NTF \l_xpatch_patchable_bool
@@ -839,7 +850,7 @@
#4
}
}
-\cs_new:Npn \xpatch_apptocmd:Nnnn #1 #2 #3 #4
+\cs_new_protected:Npn \xpatch_apptocmd:Nnnn #1 #2 #3 #4
{
\xpatch_check_patchable:N #1
\bool_if:NTF \l_xpatch_patchable_bool
@@ -858,29 +869,32 @@
% conceptually different. First the internal version of
% |\regexpatchcmd(*)|: check if |#1| is patchable, do the replacement
% if possible; beware that characters in the replacement string are of
-% category 12 by default.
+% category 12 by default. We use |\regex_replace_all:nnNTF| and
+% |\regex_replace_once:nnNTF| in order to pass correctly the success
+% or failure arguments.
+% \changes{v0.1a}{2012/06/07}{Fixed bugs in success/failure code with regex...nnNTF}
% \begin{macrocode}
-\cs_new:Npn \xpatch_regexpatchcmd_all:Nnnnn #1 #2 #3 #4 #5
+\cs_new_protected:Npn \xpatch_regexpatchcmd_all:Nnnnn #1 #2 #3 #4 #5
{
\xpatch_check_patchable:N #1
\bool_if:NTF \l_xpatch_patchable_bool
{
- \regex_replace_all:nnN { #2 } { #3 } \l_xpatch_replacement_tl
- \xpatch_rebuild:N #1
- #4
+ \regex_replace_all:nnNTF { #2 } { #3 } \l_xpatch_replacement_tl
+ { \xpatch_rebuild:N #1 #4 }
+ { #5 }
}
{
#5
}
}
-\cs_new:Npn \xpatch_regexpatchcmd_once:Nnnnn #1 #2 #3 #4 #5
+\cs_new_protected:Npn \xpatch_regexpatchcmd_once:Nnnnn #1 #2 #3 #4 #5
{
\xpatch_check_patchable:N #1
\bool_if:NTF \l_xpatch_patchable_bool
{
- \regex_replace_once:nnN { #2 } { #3 } \l_xpatch_replacement_tl
- \xpatch_rebuild:N #1
- #4
+ \regex_replace_once:nnNTF { #2 } { #3 } \l_xpatch_replacement_tl
+ { \xpatch_rebuild:N #1 #4 }
+ { #5 }
}
{
#5
@@ -892,37 +906,37 @@
% directly the analog of |\patchcmd|, but also with a `replace all'
% version.
% \begin{macrocode}
-\cs_new:Npn \xpatch_patchcmd_once:Nnnnn #1 #2 #3 #4 #5
+\cs_new_protected:Npn \xpatch_patchcmd_once:Nnnnn #1 #2 #3 #4 #5
{
\xpatch_check_patchable:N #1
\bool_if:NTF \l_xpatch_patchable_bool
{
\tl_set:Nn \l_tmpa_tl { #2 }
\tl_set:Nn \l_tmpb_tl { #3 }
- \regex_replace_once:nnN
+ \regex_replace_once:nnNTF
{ \u{l_tmpa_tl} }
{ \u{l_tmpb_tl} }
\l_xpatch_replacement_tl
- \xpatch_rebuild:N #1
- #4
+ { \xpatch_rebuild:N #1 #4 }
+ { #5 }
}
{
#5
}
}
-\cs_new:Npn \xpatch_patchcmd_all:Nnnnn #1 #2 #3 #4 #5
+\cs_new_protected:Npn \xpatch_patchcmd_all:Nnnnn #1 #2 #3 #4 #5
{
\xpatch_check_patchable:N #1
\bool_if:NTF \l_xpatch_patchable_bool
{
\tl_set:Nn \l_tmpa_tl { #2 }
\tl_set:Nn \l_tmpb_tl { #3 }
- \regex_replace_all:nnN
+ \regex_replace_all:nnNTF
{ \u{l_tmpa_tl} }
{ \u{l_tmpb_tl} }
\l_xpatch_replacement_tl
- \xpatch_rebuild:N #1
- #4
+ { \xpatch_rebuild:N #1 #4 }
+ { #5 }
}
{
#5
@@ -932,14 +946,14 @@
%
% Now the tracing system.
% \begin{macrocode}
-\cs_new:Npn \xpatch_message:n #1
+\cs_new_protected:Npn \xpatch_message:n #1
{
\bool_if:NT \l_xpatch_tracing_bool
{
\msg_term:x { xpatch~message \\ #1 }
}
}
-\cs_new:Npn \xpatch_message_cstype:n #1
+\cs_new:Npn \xpatch_message_cstype:N #1
{
\prg_case_str:onn { \l_xpatch_type_tl }
{
@@ -1010,7 +1024,9 @@
% \subsection{The user level functions}
%
% Here are the functions for patching usual macros; the *-variants for
-% |\|$x$|patchcmd| do a `replace all'.
+% |\xpatchcmd| and |\regexpatchcmd| do a `replace all'.
+% \changes{v0.1a}{2012/06/07}{Fixed bug in success/failure code
+% (missing final \texttt{n})}
% \begin{macrocode}
\NewDocumentCommand{\xshowcmd} { s m }
{
@@ -1038,8 +1054,8 @@
\NewDocumentCommand{\xpatchcmd}{ s }
{
\IfBooleanTF{#1}
- { \xpatch_main:NNN \xpatch_patchcmd_all:Nnnnn \use_none:nn }
- { \xpatch_main:NNN \xpatch_patchcmd_once:Nnnnn \use_none:nn }
+ { \xpatch_main:NNN \xpatch_patchcmd_all:Nnnnn \use_none:nnn }
+ { \xpatch_main:NNN \xpatch_patchcmd_once:Nnnnn \use_none:nnn }
}
% \end{macrocode}
%
@@ -1154,18 +1170,15 @@
% Gather the prefix (it is |\protected| when |#1| has been defined
% with |\newrobustcmd|).
% \begin{macrocode}
- \exp_args:NNf \tl_set:Nn \l_xpatch_prefix_tl
- {\token_get_prefix_spec:N #1 }
+ \tl_set:Nf \l_xpatch_prefix_tl { \token_get_prefix_spec:N #1 }
\tl_clear:N \l_xpatch_prefix_tl
- \exp_args:NNnx \tl_set_rescan:Nnn
- \l_xpatch_prefix_tl { } \l_xpatch_prefix_tl
+ \tl_set_rescan:Nnx \l_xpatch_prefix_tl { } \l_xpatch_prefix_tl
% \end{macrocode}
% Get the replacement text in tokenized form: the control sequences
% have spaces in their names, so we can't rely on
% |\token_get_replacement_spec:N| because the spaces would be lost.
% \begin{macrocode}
- \exp_args:NNV \tl_set_eq:Nc \l_xpatch_replacement_tl
- { \l_xpatch_name_tl }
+ \tl_set_eq:Nc \l_xpatch_replacement_tl { \l_xpatch_name_tl }
% \end{macrocode}
% Now we have to change the last item in the token list: we just store
% the new optional argument in a token list variable and do a regex