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?

1 Answer 1


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}

leads to

> \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



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

This is where \showthe comes in, as with

\foo 10\relax

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

\message{Hello world \foo}


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:

\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, 2012 at 6:51
  • 3
    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, 2012 at 7:04
  • There is also \typeout{} that prints console messages
    – normanius
    Dec 15, 2022 at 17:15

You must log in to answer this question.

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