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.

I am writing some macros for general debugging purposes (See Yiannis' question). I am basically expanding a given input step by step, and printing the result to the terminal and log. In order for this to happen step by step, I am using \show, which interrupts TeX and gives the user the opportunity to follow what is going on.

However, \show is quite verbose: at least six lines, most of which are useless. Can this number be reduced? (I don't mind dropping \show for a better alternative.)

Namely,

\documentclass{minimal}
\begin{document}
\errorcontextlines=-1\relax % attempt to have less lines
\def\deeper{\show\deepest...}
\def\deep{A \deeper macro}
\deep
\end{document}

writes the following to the terminal:

> \deepest=undefined.
\deeper ->\show \deepest 
                         ...
l.6     \deep

? 
share|improve this question
    
Is stopping the TeX run a key part of the question here, of is the main concern writing to the log? (For example would it be acceptable to write several lines to the log and only interrupt the run once?) –  Joseph Wright Feb 1 '11 at 20:04
    
@Joseph: the best would be to stop TeX, but not write anything else than the prompt "?" to the terminal. I don't care much about the log: it can be post-processed later if we need to extract information. –  Bruno Le Floch Feb 1 '11 at 20:09

1 Answer 1

up vote 13 down vote accepted

You can define your own \show using \message and \meaning. You can stop the compilation by reading some dummy input:

\def\myshow#1{%
    \message{\string#1=\meaning#1^^J?}%
    {\read-1 to \dummy}%
}

Example:

\def\example{Example macro}
\myshow\example

Results in:

\example=macro:->Example macro
?

See The TeXBook in Chapter 20: "Definitions (also called Macros)" on page 217 for more details.

share|improve this answer
    
thanks, \read0 to is exactly what I needed! (I already take care of finding the meaning etc., and outputting it using the hardwrap package) And \read also allows to take user input in a much cleaner way than \show (e.g., no need for I at the start). –  Bruno Le Floch Feb 1 '11 at 20:19
2  
Please note that I edited to \read-1 to suppress the prompt. I just had to look \read up in the TeXBook again to check how to do it. –  Martin Scharrer Feb 1 '11 at 20:21

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.