11

Contrarily to pdfTeX and XeTeX, which send ^^M to the terminal for the character 13, LuaTeX sends the character 13 itself. This garbles the output of my terminal (bash under Ubuntu 10.04).

\edef\foo{\string\^^M}
\message{\meaning\foo ab}

gives

abcro:->\

i.e., the same as

macro:->\
ab 

but smashed into a single line. How can I tell LuaTeX to output ^^M instead?

3
  • This seems like a bug.
    – egreg
    Commented Jul 31, 2012 at 19:39
  • @egreg I had started to submit a bug report, but then had doubts on whether it was a bug or simply that I should change how ^^M was displayed in my particular terminal. I'll submit a bug report. Commented Jul 31, 2012 at 20:01
  • Bug report submitted. Commented Jul 31, 2012 at 20:10

2 Answers 2

11

As @egreg says, it looks like a bug to me. For writing to files you can modify a lua callback but unfortunately the callback (as documented) is not called when writing to the terminal.

\edef\foo{\string\^^M}

{\catcode`\^=12
\directlua{
callback.register(
"process_output_buffer",
function  (s)
snew, n =  string.gsub(s,"\string\r","^^M")
return snew
end)
}}


\message{\meaning\foo ab}
\newwrite\x
\immediate\openout\x=nnl.out
\immediate\write\x{\meaning\foo ab}

\stop

On the terminal you get

ab )o:->\

but in the file you get:

$ cat nnl.out
macro:->\^^Mab
1
  • I'll submit a bug report. Commented Jul 31, 2012 at 20:01
12

From LuaTeX Reference, beta 0.70.1, section 2.3 UNICODE text support:

Output to the terminal uses ^^ notation for the lower control range (c < 32), with the exception of ^^I, ^^J and ^^M. These are considered 'safe' and therefore print-as-is.

And in the manual are the terminal/log explicitely excluded for process_output_buffer:

4.1.3.2 process_output_buffer (0.43)
[…] It is only called for output to an actual file (that is, excluding the log, the terminal, and \write18 calls).

2
  • Ah, so that is not a bug, rather a bad feature. However, it leads to a garbled terminal output, so a work-around would be useful. Do you agree with David that there is no appropriate callback for this? Commented Jul 31, 2012 at 21:00
  • 3
    Not really, the output of the terminal/log is messed up anyway with much loss of information (catcodes, line breaks, &hellip;). If you are debugging such stuff, then you can use a decent editor &mdash; the data are not lost, even less shows me the ^^M as control character. Not having a callback has its advantages. The user knows, nobody has messed up with the output, showing beautiful things while doing malicious things. Commented Jul 31, 2012 at 21:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .