Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 11 down vote accepted

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

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

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

share|improve this answer
    
Ok, it seems one has to use \the in \message for counters and not \showthe. –  Uiy May 12 '12 at 6:51
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.