blefloch / latex-unravel

Watching TeX digest tokens
24 stars 1 forks source link

Cannot unravel `\use:x` #59

Closed muzimuzhi closed 6 months ago

muzimuzhi commented 8 months ago
\documentclass{article}
\usepackage{unravel}
\unravelsetup{max-action=1000}

\ExplSyntaxOn
\unravel{ \use:x {xxx} }

% equivalant to
% \unravel{\edef \l__exp_internal_tl {xxx} \l__exp_internal_tl }
\ExplSyntaxOff

\begin{document}
\end{document}

The problem starts at Step 4. The expected value of \l__exp_internal_tl is xxx, but an internal definition was used instead.

||
|> \use:x {xxx}

[===== Step 1 =====] \use:x = \protected\long macro:#1->\cs_set_nopar:Npx \l__exp_internal_tl {#1}\l__exp_internal_tl
||
|> \cs_set_nopar:Npx \l__exp_internal_tl {xxx}\l__exp_internal_tl

[===== Step 2 =====] \cs_set_nopar:Npx \l__exp_internal_tl {xxx}
|| \cs_set_nopar:Npx \l__exp_internal_tl {xxx}
|> \l__exp_internal_tl

[===== Step 3 =====] Set \l__exp_internal_tl=macro:->xxx
||
|> \l__exp_internal_tl

[===== Step 4 =====] \l__exp_internal_tl = macro:->\tl_gset:Nn \g__unravel_input_2_gtl {\s__gtl {}{}{}}
||
|> \tl_set:Nn \l__unravel_tmpa_tl {^}

[===== Step 5 =====] \tl_set:Nn = \protected\long macro:#1#2->\__kernel_tl_set:Ne #1{\__kernel_exp_not:w {#2}}
||
|> \__kernel_tl_set:Ne \l__unravel_tmpa_tl {\__kernel_exp_not:w {^}}

[===== Step 6 =====] \__kernel_exp_not:w = \unexpanded
|| \__kernel_tl_set:Ne \l__unravel_tmpa_tl {
|| \__kernel_exp_not:w
|> {^}}

[===== Step 7 =====] \__kernel_exp_not:w {^}
|| \__kernel_tl_set:Ne \l__unravel_tmpa_tl {^
|> }

[===== Step 8 =====] \__kernel_tl_set:Ne \l__unravel_tmpa_tl {^}
|| \__kernel_tl_set:Ne \l__unravel_tmpa_tl {^}
|>

[===== Step 9 =====] Set \l__unravel_tmpa_tl=macro:->^
||
|>

[===== End =====]
blefloch commented 6 months ago

This is fixed in the next version (hopefully sent today to CTAN and to here) by switching from x-type to e-type expansion everywhere in unravel, which means that the package does not affect \l__exp_internal_tl at all.

muzimuzhi commented 6 months ago

Thanks! I confirm it's resolved with gtl v0.6 (2024-01-04), containing https://github.com/blefloch/latex-gtl/commit/749a635296313ac17fcb23f7bdae99f696b7f546.

Update: Similar x- to e-type changes in unravel happened in https://github.com/blefloch/latex-unravel/commit/26d4f63c98b4ca90d8f32e2c902cc421084b8b51 and https://github.com/blefloch/latex-unravel/commit/67d6c5aaa675997346157d201f3e0377a6728bbd.