0

Looking at the code below, what would the setup in 6. have to be to return F? Also, why does 2. return F in other words how are \group_begin: and \c_group_begin_token different?

\begin{enumerate}
\item \tl_if_head_is_N_type:nTF{{foo}}{T}{F} % 1. F
\item \tl_if_head_eq_catcode:nNTF{{foo}}\group_begin:{T}{F} % 2. F
\item \tl_if_head_eq_catcode:nNTF{{foo}}\c_group_begin_token{T}{F} % 3. T
\item \token_if_group_begin:NTF\c_group_begin_token{T}{F} % 4. T
\item \tl_if_head_is_N_type:nTF{[foo]}{T}{F} % 5. T
\item \tl_if_head_is_N_type:nTF % 6. T
{\tl_rescan:nn
  {\char_set_catcode_group_begin:N [
      \char_set_catcode_group_end:N ]}
  {[foo]}}{T}{F}
\end{enumerate}

UPDATE:

What was lost on me the first time around is that using predicates such as \tl_if_head_eq_catcode:nNTF as second argument to\tl_rescan is a bad idea to detect any change to catcode specified in the setup as they are affected by the change themselves. That said, perhaps this new MWE explains better what I was trying to lead to. Also, [I'm now clear on\group_begin: vs \c_group_begin_token].

\char91 % [
\char93 % ]

\cctab_const:Nn \c__erw_setup_cctab
{
  \cctab_select:N \c_code_cctab
  \char_set_catcode:nn  {91}{1}
  \char_set_catcode:nn  {93}{2}
}

\tl_rescan:nn{\c__erw_setup_cctab}
{\tl_if_head_eq_catcode:nNTF {{foo}}
\c_group_begin_token{T}{F}} % T

\exp_args:Nnx
\tl_rescan:nn{\c__erw_setup_cctab}
{\tl_if_head_eq_catcode:nNTF {[foo]}
\c_group_begin_token{T}{F}} % F

PS: feel free to delete the question if it's still not clear.

3

TeX has two ways we can make a group: using \begingroup/\endgroup and using {/}. The latter can be achieved using a pair of tokens \let to {/}. In expl3 terms, \begingroup is \group_begin: and { is \c_group_begin_token. These are distinct ideas so come out differently when tested.

When you do \tl_if_head_is_N_type:nTF { \tl_rescan:nn ..., the argument is not expanded: you are asking if \tl_rescan:nn itself is N-type. It is, so the test is true: it does not matter what the output of the rescanning would be.

3
  • But if I expand with \exp_args:Nf the argument of \tl_if_head_is_N_type:nTF I get the same result.
    – Erwann
    May 12 at 18:58
  • @Erwann I'm really not sure what you mean - can you edit the question?
    – Joseph Wright
    May 13 at 13:14
  • Edit the question: I just did.
    – Erwann
    May 13 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.