[latex3-commits] [git/LaTeX3-latex3-latex3] master: Support for command replacement in text expansion (ba6af7823)
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Jan 22 12:56:32 CET 2020
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/ba6af782390809cf2f53fda9d59b15837e4a1652
>---------------------------------------------------------------
commit ba6af782390809cf2f53fda9d59b15837e4a1652
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Wed Jan 22 11:56:27 2020 +0000
Support for command replacement in text expansion
This is mainly needed for textcomp-like commands:
\T1-cmd, etc. otherwise loop infinitely.
>---------------------------------------------------------------
ba6af782390809cf2f53fda9d59b15837e4a1652
l3kernel/CHANGELOG.md | 3 +++
l3kernel/l3text.dtx | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 151ab19ad..73f8acdd5 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -7,6 +7,9 @@ this project uses date-based 'snapshot' version identifiers.
## [Unreleased]
+### Added
+- Support for command replacement in text expansion
+
### Changed
- Require key values for numerical key types (dim, int, etc.) (see #661)
diff --git a/l3kernel/l3text.dtx b/l3kernel/l3text.dtx
index 4cc60dcf5..bcc77afe5 100644
--- a/l3kernel/l3text.dtx
+++ b/l3kernel/l3text.dtx
@@ -77,6 +77,19 @@
% expansion
% \end{function}
%
+% \begin{function}[added = 2020-01-22]
+% {
+% \text_declare_expand_equivalent:Nn ,
+% \text_declare_expand_equivalent:cn
+% }
+% \begin{syntax}
+% \cs{text_declare_expand_equivalent:Nn} \meta{cmd} \Arg{replacement}
+% \end{syntax}
+% Declares that the \meta{replacement} tokens should be used whenever the
+% \meta{cmd} (a single token) is encountered. The \meta{replacement} tokens
+% should be expandable.
+% \end{function}
+%
% \subsection{Case changing}
%
% \begin{function}[EXP, added = 2019-11-20]
@@ -522,6 +535,8 @@
% }
% \begin{macro}[EXP]{\@@_expand_protect:nN}
% \begin{macro}[EXP]{\@@_expand_protect:Nw}
+% \begin{macro}[EXP]{\@@_expand_replace:N}
+% \begin{macro}[EXP]{\@@_expand_replace:n}
% \begin{macro}[EXP]{\@@_expand_cs_expand:N}
% After precautions against |&| tokens, start a simple loop: that of
% course means that \enquote{text} cannot contain the two recursion
@@ -834,7 +849,7 @@
{
\str_if_eq:nnTF {#1} { \protect }
{ \@@_expand_protect:N }
- { \@@_expand_cs_expand:N #1 }
+ { \@@_expand_replace:N #1 }
}
\cs_new:Npn \@@_expand_protect:N #1
{
@@ -855,6 +870,25 @@
\@@_expand_loop:w
}
% \end{macrocode}
+% See if there is a dedicated replacement, and if there is, insert it.
+% \begin{macrocode}
+\cs_new:Npn \@@_expand_replace:N #1
+ {
+ \bool_lazy_and:nnTF
+ { \cs_if_exist_p:c { l_@@_expand_ \token_to_str:N #1 _tl } }
+ {
+ \bool_lazy_or_p:nn
+ { \token_if_cs_p:N #1 }
+ { \token_if_active_p:N #1 }
+ }
+ {
+ \exp_args:Nv \@@_expand_replace:n
+ { l_@@_expand_ \token_to_str:N #1 _tl }
+ }
+ { \@@_expand_cs_expand:N #1 }
+ }
+\cs_new:Npn \@@_expand_replace:n #1 { \@@_expand_loop:w #1 }
+% \end{macrocode}
% Finally, expand any macros which can be: this then loops back around to
% deal with what they produce.
% \begin{macrocode}
@@ -893,6 +927,35 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}
+% {
+% \text_declare_expand_equivalent:Nn ,
+% \text_declare_expand_equivalent:cn
+% }
+% Create equivalents to allow replacement.
+% \begin{macrocode}
+\cs_new_protected:Npn \text_declare_expand_equivalent:Nn #1#2
+ {
+ \tl_clear_new:c { l_@@_expand_ \token_to_str:N #1 _tl }
+ \tl_set:cn { l_@@_expand_ \token_to_str:N #1 _tl } {#2}
+ }
+\cs_generate_variant:Nn \text_declare_expand_equivalent:Nn { c }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\@@_expand_textcomp:NN}
+% Filter out \pkg{textcomp}-like commands.
+% \begin{macrocode}
+%<*package>
+\cs_new:Npn \@@_expand_textcomp:NN #1#2 { \exp_not:n {#1} }
+\text_declare_expand_equivalent:cn { ?-cmd } { \@@_expand_textcomp:NN }
+\text_declare_expand_equivalent:cn { T1-cmd } { \@@_expand_textcomp:NN }
+\text_declare_expand_equivalent:cn { TS1-cmd } { \@@_expand_textcomp:NN }
+\text_declare_expand_equivalent:cn { TU-cmd } { \@@_expand_textcomp:NN }
+%</package>
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macrocode}
%</initex|package>
% \end{macrocode}
More information about the latex3-commits
mailing list