[latex3-commits] [git/LaTeX3-latex3-latex3] gh875: Improve handling of \exp_not:n in \text_expand:n (fixes #875) (30d827a87)
Bruno Le Floch
blflatex at gmail.com
Sat Apr 24 23:42:43 CEST 2021
Repository : https://github.com/latex3/latex3
On branch : gh875
Link : https://github.com/latex3/latex3/commit/30d827a87be2524f61da42275e6315d3e345e140
>---------------------------------------------------------------
commit 30d827a87be2524f61da42275e6315d3e345e140
Author: Bruno Le Floch <blflatex at gmail.com>
Date: Sat Apr 24 23:42:43 2021 +0200
Improve handling of \exp_not:n in \text_expand:n (fixes #875)
>---------------------------------------------------------------
30d827a87be2524f61da42275e6315d3e345e140
l3kernel/CHANGELOG.md | 1 +
l3kernel/l3text.dtx | 14 +++++++++++---
l3kernel/testfiles/m3text001.lvt | 7 +++++++
l3kernel/testfiles/m3text001.tlg | 10 ++++++++++
4 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 055589332..fa3191dd5 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -16,6 +16,7 @@ this project uses date-based 'snapshot' version identifiers.
- `\__kernel_file_name_sanitize:n` now uses a faster `\csname`-based
approach to expand the file name.
- `\pdf_version_gset:n` for `dvips`.
+- Improve handling of `\exp_not:n` in `\text_expand:n` (issue #875)
### Fixed
- Evalutate integer constants only once (issue#861)
diff --git a/l3kernel/l3text.dtx b/l3kernel/l3text.dtx
index 7e994a683..b5133dacb 100644
--- a/l3kernel/l3text.dtx
+++ b/l3kernel/l3text.dtx
@@ -637,6 +637,7 @@
% \begin{macro}[EXP]{\@@_expand_replace:N}
% \begin{macro}[EXP]{\@@_expand_replace:n}
% \begin{macro}[EXP]{\@@_expand_cs_expand:N}
+% \begin{macro}[EXP]{\@@_expand_noexpand:w}
% \begin{macro}[EXP]{\@@_expand_noexpand:nn}
% After precautions against |&| tokens, start a simple loop: that of
% course means that \enquote{text} cannot contain the two recursion
@@ -996,14 +997,19 @@
% Finally, expand any macros which can be: this then loops back around to
% deal with what they produce. The only issue is if the token is
% \cs{exp_not:n}, as that must apply to the following balanced text.
-% There might be an \cs{exp_after:wN} there, so we check for it.
+% Expand everything that follows such an \cs{exp_not:n} (in principle
+% we should actually expand tokens and discard any spaces or \cs{scan_stop:},
+% but this is messy to ensure safely).
% \begin{macrocode}
\cs_new:Npn \@@_expand_cs_expand:N #1
{
\@@_if_expandable:NTF #1
{
\token_if_eq_meaning:NNTF #1 \exp_not:n
- { \@@_expand_noexpand:w }
+ {
+ \exp_after:wN \@@_expand_noexpand:w
+ \exp:w \exp_end_continue_f:w
+ }
{ \exp_after:wN \@@_expand_loop:w #1 }
}
{
@@ -1015,7 +1021,8 @@
{ \@@_expand_noexpand:nn {#1} }
\cs_new:Npn \@@_expand_noexpand:nn #1#2
{
- #1 \@@_expand_store:n #1 {#2}
+ \exp_after:wN \@@_expand_store:n \exp_after:wN
+ { \__kernel_exp_not:w #1 {#2} }
\@@_expand_loop:w
}
% \end{macrocode}
@@ -1050,6 +1057,7 @@
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
%
% \begin{macro}
% {
diff --git a/l3kernel/testfiles/m3text001.lvt b/l3kernel/testfiles/m3text001.lvt
index 40225c2b6..1b328c16c 100644
--- a/l3kernel/testfiles/m3text001.lvt
+++ b/l3kernel/testfiles/m3text001.lvt
@@ -43,6 +43,7 @@
\text_expand:n { Some~text~$y~=~\sin \theta$ }
\NEWLINE
\text_expand:n { Opps~not~close~token~in~$y~=~\sin \theta }
+ % $ % make some code-highlighters happy
}
\TESTEXP { Letter-like~commands }
@@ -82,4 +83,10 @@
{ \text_expand:n { \tl_map_tokens:nn { { \NoCaseChange { c } } } { tokens } } }
}
+\TEST { Expansion~noexpand }
+ {
+ \tl_show:x { \text_expand:n { \exp_not:n { ~ \abc \foo } } }
+ \tl_show:x { \text_expand:n { \tl_tail:n { ~ \abc \foo } } }
+ }
+
\END
diff --git a/l3kernel/testfiles/m3text001.tlg b/l3kernel/testfiles/m3text001.tlg
index a0193a95d..b6a56f57d 100644
--- a/l3kernel/testfiles/m3text001.tlg
+++ b/l3kernel/testfiles/m3text001.tlg
@@ -51,3 +51,13 @@ l. ... }
<recently read> }
l. ... }
============================================================
+============================================================
+TEST 8: Expansion noexpand
+============================================================
+> \abc \foo .
+<recently read> }
+l. ... }
+> \foo .
+<recently read> }
+l. ... }
+============================================================
More information about the latex3-commits
mailing list.