6

For example, with this code

%! TEX program = lualatex
\documentclass{article}
\begin{document}

\ExplSyntaxOn \char_set_catcode_other:N % \tl_set:Nn\var{%} \tl_analysis_show:N\var \ExplSyntaxOff

\end{document}

The output is

The token list \var contains the tokens:
>  % (the character %).

as expected, and it also works with all the other special characters. However when I try it with the newline character (which is encoded with the byte with value 10 on UNIX)

\char_set_catcode_other:n {10}
\tl_set:Nn\var{
}
\tl_analysis_show:N\var

the output is

The token list \var is empty

Why is that happening? (also ^^J or ^^M results in the same output, while a literal newline results in the output below)

The token list \var contains the tokens:
>    (the character  ).
user202729
  • 7,143

1 Answers1

6

Inside the scope of \ExplSyntaxOn the value of \endlinechar is set to 32 (space) and the category code of the space is set to 9 (ignored).

Thus your code is equivalent to \tl_set:Nn \var {} and the token list is indeed empty.

Setting the category code of the Unix newline (character 10) is irrelevant, because this character appears nowhere: when TeX reads a record (a line of input) it immediately discards the end-of-record operating system specific character and replaces it with the \endlinechar.

egreg
  • 1,121,712