When using print from lua, if the log file's current line has not been terminated then the lua tex will not start on a new line. This is very annoying because many times I search for some debug string being printed and it is not on a new line but at the end of some rather long line printed from TeX.
e.g.,
Printing some debug string 1
[1{C:/Users/Administrator/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]
[2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]Printing another debug string 2
[14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27]`
Instead of
Printing some debug string 1
[1{C:/Users/Administrator/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]
Printing another debug string 2
[14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27]
The 2nd one is the preferred case but if I print a newline, \n
, then I'll get unnecessary empty lines I do not want.
Is there any way to fix this? Basically on every entry of \directlua
or whatever is used I want to print a new line ONLY if something is actually printed(so I don't get a bunch of blank lines) and, even better, only if the log file does not also end on a new line.
Best Answer
Use
texio.write_nl(...)
:gives
In one project I have defined a helper function:
so that I can easily use formatted strings: