# How to print out to “log” without affecting anything else (lua print equiv)

lua's print is very effective for my debugging purposes but I can't easily use it in TeX because of all the macro expansion issues.

All it does is print the text to the window (console window or whatever; I use WinEdt) but doesn't effect output in any way.

I've tried \the, \showthe, and \message and none seem to work well.

Is there any easy way that will allow me to print macro and register values for debugging purposes?

-

If you want to display macro and register contents in the terminal and the log, then the two primitives you want are \show and \showthe. Macros are displayed using \show:

\def\foo{some tokens}
\show\foo


> \foo=macro:
->some tokens.
l.5 \show\foo


for example. If you try \show with a register it's not so helpful, with for example

\newcount\foo
\show\foo


giving

> \foo=\count201.
l.5 \show\foo


This is where \showthe comes in, as with

\newcount\foo
\foo 10\relax
\showthe\foo


you get

> 10.
l.7     \showthe\foo


The same applies to other register types (toks, dimens, skips).

\message writes the terminal and the log without interrupting the run and with expansion. So

\def\foo{bar}
\message{Hello world \foo}


writes

Hello world bar


to the terminal bu tdoes not stop the run. If you want to write the content of a register via \message you need to include \the:

\newtoks\foo
\foo{bar}
\message{Hello world \the\foo}


once again outputs

Hello world bar


Another useful primitive in this context is e-TeX's \showtokens, which can be used to show arbitrary tokens in the terminal and so is useful for constructing 'interactive' messages without issuing an error. The latter is carried out using \errmessage, which takes a little setting up if you want 'pretty printing' (see for example how this is handled by LaTeX2e in latex.ltx).

-
Ok, it seems one has to use \the in \message for counters and not \showthe. –  Uiy May 12 '12 at 6:51
The argument of \message is an expansion context: material is expanded but not executed. The \showthe primitive is not expandable (none of the write-like operations are), and so if you use \showthe inside \message you will get \showthe printed as part of the terminal output! –  Joseph Wright May 12 '12 at 7:04