Skip to content

Commit

Permalink
Improve handling of \exp_not:n in \text_expand:n (fixes #875)
Browse files Browse the repository at this point in the history
  • Loading branch information
blefloch committed Apr 24, 2021
1 parent c76ca6c commit 30d827a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion l3kernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ this project uses date-based 'snapshot' version identifiers.
### Changed
- `\__kernel_file_name_sanitize:n` now uses a faster `\csname`-based
approach to expand the file name.
- `\pdf_version_gset:n` for `dvips`.
- `\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)
Expand Down
14 changes: 11 additions & 3 deletions l3kernel/l3text.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
}
{
Expand All @@ -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}
Expand Down Expand Up @@ -1050,6 +1057,7 @@
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}
% {
Expand Down
7 changes: 7 additions & 0 deletions l3kernel/testfiles/m3text001.lvt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions l3kernel/testfiles/m3text001.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ l. ... }
<recently read> }
l. ... }
============================================================
============================================================
TEST 8: Expansion noexpand
============================================================
> \abc \foo .
<recently read> }
l. ... }
> \foo .
<recently read> }
l. ... }
============================================================

0 comments on commit 30d827a

Please sign in to comment.