I'm trying to do this:
\documentclass{article}
\begin{document}
\message{Hello \\ world!}
\end{document}
However, the \\ is not printed as an end-of-line. I'm getting this in the console:
Hello \\ world!
What's the right syntax here?
This version works (I am assuming that priting end-of-line means for you going to the next line):
\documentclass{article}
\begin{document}
\message{Hello ^^J world!}
\end{document}
(^^J means newline character).
The (otherwise good) answer by Przemysław Scherwentke glosses over several details.
You cannot use \\ to separate lines in \message, because \\ is a typesetting instruction.
There is a general mechanism in TeX to produce new lines in \write or \message instructions, namely to use a character whose character code (the ASCII code) is the current value of the internal integer \newlinechar.
In the TeXbook we find (page 228)
The ⟨token list⟩ of a
\writeought to be rather short, since it makes one line of output. Some implementations of TeX are unable to write long lines; if you want to write a lot of stuff, just give several\writecommands. Alternatively, you can set TeX's\newlinecharparameter to the ASCII code number of some character that you want to stand for ”begin a new line”; then TeX will begin a new line whenever it would ordinarily output that character to a file. For example, one way to output two lines to the terminal in a single\writecommand is to say\newlinechar=`\^^J \immediate\write16{Two^^Jlines.}
It should be noted that plain TeX doesn't set a value for \newlinechar, so it keeps the default value −1.
To the contrary, LaTeX has always set \newlinechar=`\^^J, so you can always do something like
\documentclass{article}
\begin{document}
\message{Hello^^Jworld!}
\end{document}
Note that spaces around ^^J are preserved in the \message. This produces new lines in \message, \write and \typeout instructions.
\message also depends on the encoding of the shell and on character-translation/tcx. E.g., \newlinechar=-1 \catcode`\^^M=12 \catcode`\^^J=12 \message{Hello^^J^^Mworld!}\csname stop\endcsname\bye: pdftex: L1: "Hello", L2: "^^Mworld!" / xetex: "Hello^^J^^Mworld!" / luatex: L1: "Hello", L2: "world!" . The impact of char-translation can be seen with luatex when omitting ^^J(=line feed) where carriage return(input as ^^M) is not translated in terminal-output and thus executed by the shell which displays the message and does carriage-return but no linefeed.
– Ulrich Diez
Jan 08 '22 at 13:35
\^^Jis the value of the\newlinechar` parameter – plante Jan 08 '22 at 08:57