Coder Social home page Coder Social logo

Comments (4)

blefloch avatar blefloch commented on June 13, 2024

from latex-unravel.

PhelypeOleinik avatar PhelypeOleinik commented on June 13, 2024

I didn't put too much effort in minimising the code, sorry.

I tried changing

\tl_put_left:Nn \l__unravel_head_tl { \reverse_if:N }

into

\gtl_put_left:Nn \l__unravel_head_gtl { \reverse_if:N }

as you suggested and got a You can't use `\unless' before `\noexpand'.

Looking at \__unravel_test_two_chars:nn I discovered that the \l__unravel_head_tl at the end contained \reverse_if:N \exp_not:N \if \exp_not:N -, thus raising the error above. That stray \exp_not:N is added by \__unravel_test_two_chars_gtl:N. However removing the \exp_not:N from there makes \l__unravel_head_tl contain only \reverse_if:N \if -, which doesn't error but I think is not good either. Plus, there is a - missing from \l__unravel_head_tl so the test won't work. My brain didn't let me go any further. I couldn't unravel \unravel :(


Oh, wait, brain's back :D

I don't know about the correctness of this, but it seems to work:

First change \tl_put_left:Nn \l__unravel_head_tl { \reverse_if:N } into \gtl_put_left:Nn \l__unravel_head_gtl { \reverse_if:N } in \__unravel_unless:, as you said, then change \__unravel_test_two_chars:nn into (changes commented):

\cs_new_protected:Npn \__unravel_test_two_chars:nn #1
  {
    \__unravel_prev_input_gpush_gtl:N \l__unravel_head_gtl
    \__unravel_print_expansion:
    \__unravel_test_two_chars_get:n {#1}
    \__unravel_test_two_chars_get:n {#1}
    \__unravel_prev_input_gpop_gtl:N \l__unravel_head_gtl
    \__unravel_set_action_text:x { \gtl_to_str:N \l__unravel_head_gtl }
    \gtl_pop_left_item:NNTF \l__unravel_head_gtl \l__unravel_head_tl { } { }
    % First check if the token removed from \l__unravel_head_gtl is a \reverse_if:N
    \exp_after:wN
      \token_if_eq_meaning:NNT \l__unravel_head_tl \reverse_if:N
        {% If it is, pop the actual conditional and prepend it with \reverse_if:N
          \gtl_pop_left_item:NNTF \l__unravel_head_gtl \l__unravel_head_tl { } { }
          \tl_put_left:Nn \l__unravel_head_tl { \reverse_if:N }
        }
    \gtl_pop_left:NN \l__unravel_head_gtl \l__unravel_tmpb_gtl
    \__unravel_test_two_chars_gtl:N \l__unravel_tmpb_gtl
    \__unravel_test_two_chars_gtl:N \l__unravel_head_gtl
    \l__unravel_head_tl \scan_stop:
      \exp_after:wN \__unravel_cond_true:n
    \else:
      \exp_after:wN \__unravel_cond_false:n
    \fi:
  }

then the \l__unravel_head_tl will contain \reverse_if:N \if \exp_not:N -\exp_not:N - as it should :D

Both \if and \unless\if (and \ifcat) work with this change.

from latex-unravel.

PhelypeOleinik avatar PhelypeOleinik commented on June 13, 2024

Hm... Another issue that comes from this same part of the code is:

\RequirePackage{unravel}
\unravel{\if##\fi}
\stop

which also worked in TL 2018.

I tracked the issue down to the \tl_put_right:Nx in \__unravel_test_two_chars_gtl:N, which tries to expand the # after \gtl_head_do:NN does its thing. Since \gtl_head_do:NN is f-expandable I changed (in the definition of \__unravel_test_two_chars_gtl:N):

              { \exp_not:N \exp_not:N \gtl_head_do:NN #1 \exp_not:N }

to

              {
                \exp_not:N \exp_not:N
                \exp_not:f { \gtl_head_do:NN #1 \exp_not:N }
              }

and it seems to be working again :-)

If you'd like I can open a new issue for this.


Hm... Actually no. It makes this test:

\RequirePackage{unravel}
\def\test#1{\if\noexpand#1 \T\else\F\fi}
\unravel{\test{\test}}
\stop

take the true branch because the f expansion consumes the space and then the actual test done is \if \exp_not:N \test \exp_not:N \scan_stop:. Perhaps now that we have \expanded, \exp_not:e could be used...

from latex-unravel.

blefloch avatar blefloch commented on June 13, 2024

I had fixed the second issue with a variant of your fix, and now the first issue is fixed as well.

from latex-unravel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.