[luatex] Strange behavior of tex.print.

Heiko Oberdiek heiko.oberdiek at googlemail.com
Fri Apr 29 12:36:08 CEST 2011

On Fri, Apr 29, 2011 at 09:46:27AM +0200, Paul Isambert wrote:

> Le 29/04/2011 09:25, Ulrike Fischer a écrit :
> >Am Fri, 29 Apr 2011 07:46:06 +0200 schrieb Patrick Gundlach:
> >
> >>Hi Paul,
> >
> >>>The manual states about tex.print(n,<strings>) that ``if n is
> >>>not a valid catcode table, then it is ignored, and the currently
> >>>active catcode regime is used instead.'' However (with catcode
> >>>table 1 not initialized):
> >>>tex.print(1, "a", "\relax")
> >
> >>>returns ``aflflelax'' (with the ``fl'' ligature, i.e. character
> >>>13 in CM). So: is that a bug, an inaccuracy in the manual, or
> >>>have I misunderstood something? My LuaTeX is v.0.66.
> >>I am not awake yet: isn't this due to the single backslash? \r =
> >>13 so that the chars 97,13,101,... get printed. I can't explain
> >>the f before the e, so my attempt is probably wrong.
> >The first "fl" is dued to the newline between the two strings, the
> >second to the carriage return "\r". But the question is why one
> >doesn't get the same results as with tex.print(-1,...):
> >
> >tex.print(-1, "a", "b")       --gives "a b"

Looks ok.

> >tex.print(-2, "a", "b")       --gives "ab"

The only exception of the documentation is the last string argument
that doesn't get the \endlinechar character appended. According
to the documentation the end of line character is inserted after
"a" with catcode 12 (or 10 if \endlinechar = 32).

> >tex.print(111, "a", "b")      --gives "aflb" why?

If 111 is not a valid catcode table, then the result
should use the current catcode regime with the same
result of tex.print(-1, "a", "b").

> >tex.print(-1, "c", "\relax")  --gives "c"

No. It gives "c \par". (Put \directlua{tex.print...)} in \edef).
There is a line end after "c" and by "\r".
  The documentation says, each line is treated as input line.
The string contains "\r" that happens to be the line terminator.
The behaviour seems to be unspecified, who takes care of the
part after the line end. It is thrown away by tex.print,
should it be parsed by TeX with the result of two lines, ...

> >tex.print(9, "c", "\relax")   --gives "cflflelax" why?
> Thanks Patrick and Ulrike, the second fl is indeed \r, I missed
> that; now the questions is: why are end-of-line characters printed
> as if they had catcode 12?

Perhaps in your case is \catcode\endlinechar=12?

Yours sincerely
  Heiko Oberdiek

More information about the luatex mailing list