What is a new line for TeX in the following contexts:
- When reading from a file.
- When writing to a file.
- After having read a
%
character. - In a
\scantokens
.
I am asking in particular because the following code only typesets A
:
\documentclass{minimal}
\begin{document}
\catcode`\%=12
\def\foo{\scantokens{A%
B}}
\show\foo
\catcode`\%=14
\foo
\end{document}
So my main question is: how does %
know where to stop gobbling characters?
EDIT: Adding the two lines
\catcode`\^^M=12
\newlinechar`\^^M
before the definition of \foo
is instructive: then the definition actually contains new-lines, and the comment stops gobbling where we expect.
EDIT2: pdflatex
sets \newlinechar`\^^J
and \endlinechar`\^^M
(see Harald's concise answer below for what these are).
Best Answer
\endlinechar
.\newlinechar
will trigger the end of a line. Again, the exact result in the output file is hard coded, depending on your operating system.\scantokens
is treated as a single line. Thus a percent sign in the argument to\scantokens
will end input from this argument. However, any occurrences of the character whose number is\newlinechar
will be used to split the argument into several lines.To bring all these ideas together, consider the plain TeX file
which will typeset the text “abcdefX” .
(Edited to take into account what I learned about #4 from the comments.)