7

I'm currently reading the TeXbook, and I use \show a lot to see how Knuth defined plain-TeX macros in terms of TeX primitives. For instance, to have access to the definition of \centerline, I would write \show\centerline in my input file. When I compile that file with pdftex in interactive mode from the command line (a Unix terminal, in my case), TeX generates an error message that shows me the definition of \centerline in the terminal and offers me a menu of options (as described in Chapter 6: Running TeX in the TeXbook).

I understand that design choice by Knuth of having TeX generate an error message for each instance of \show: he probably wanted to leave the user some time to read what \show... prints in the terminal before letting TeX resume execution, instead of having to open the log file only after the end of the compilation.

However, instances of \show... in the input file have the undesirable side-effect of raising "errors" (false alarms, really) when pdftex is called from within an IDE such as TeXmaker with option -interaction=nonstopmode. For example,

\show\centerline
\bye

when compiled with pdftex -interaction=nonstopmode causes TeXmaker to report

enter image description here

Obviously, those false alarms prove really annoying when debugging. I always have to ask myself: Wait... are those errors due to instances of \show in my input file, or are they bona fide errors? On the other hand, my understanding is that you have to specify

-interaction=nonstopmode

if you want to call pdftex from within an IDE. Therefore, my question is:

Is there any way of preventing TeXmaker from reporting those "false alarms"?

Note: the problem I describe may be present in IDEs other than TeXmaker as well.

jub0bs
  • 58,916
  • 3
    \show uses the same routine as error messages. Use it only in interactive sessions. – egreg Nov 06 '13 at 17:51
  • @egreg It's too bad the errors generated by \show are indistinguishable from bona fide errors. I wish I could use \show in nonstopmode without having to deal with that problem. Oh well! I guess I can just use \meaning... – jub0bs Nov 06 '13 at 17:56
  • 2
    \texttt{\meaning\foo} prints (almost) the same information. But for looking at meanings I prefer running interactively, so I can add other commands to look at. Also texdef is good for this. However, error lines start with !, while \show lines start with >; if Texmaker doesn't distinguish between the two cases it's its fault. – egreg Nov 06 '13 at 18:03
  • 1
    @Jubobs: Try using \typeout{\meaning<cs>}. – Werner Nov 06 '13 at 18:03
  • 1
    Additional to the already mentioned tools, texdef and latexdef are very handy in a command line console. Ah, sorry already in egreg's comment! Besides with emacs/auctex there is no problem; only \showbox is truly a pain there. –  Nov 06 '13 at 18:22
  • @egreg Thanks for the tip. Since I'm working with tex, not latex, I guess you meant {\tt \meaning\foo}, though. – jub0bs Nov 06 '13 at 18:47
  • @Werner I'm working with tex. Isn't typeout a LaTeX macro? – jub0bs Nov 06 '13 at 18:49
  • @Jubobs: Okay, so \def\typeout{\immediate\write17} according to latex.ltx which you can define similarly I guess. – Werner Nov 06 '13 at 18:52
  • @Werner Great; thanks. Sorry about the noob questions: I haven't got through the whole TeXbook yet, so my knowledge of TeX is very limited at the moment... – jub0bs Nov 06 '13 at 18:59
  • @jfbu (and egreg) Wow! Thanks for telling me about texdef and latexdef. I didn't even know of their existence. Very useful indeed. – jub0bs Nov 06 '13 at 19:27
  • @egreg I think you should add bells and whistles to your first comment and post it as an answer... – jub0bs Nov 19 '13 at 16:33
  • 1
    Related (originally intended to address the "terminate TeX" part; but the typeout solution addresses both): expl3 - How can I make TeX stop on the first error, but do not stop on \show (or \tl_show:n)? - TeX - LaTeX Stack Exchange – user202729 Dec 10 '21 at 10:57

1 Answers1

7

\show uses the same internal routines that TeX employs for error messages. Judging now this may seem a design error, but one always has to keep in mind that TeX was released in 1982, when computer memory was quite scarcer than it is today.

A front-end like Texmaker could, in principle, distinguish between diagnostic messages given by \show (or \showthe) and real error messages, because the former start with >, while the latter start with !.

However, I find that using \show in a non interactive session is a waste of time, because you can't add other commands. If, for instance, you do \show\section, you'll be welcomed by

> \section=\long macro:
->\@startsection {section}{1}{\z@ }{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus .2ex}{\normalfont \Large \bfseries }.

which wouldn't tell much about the meaning and the syntax, unless you add, at the prompt,

i\makeatletter\show\@startsection

and then follow the other macros that appear. Just doing a compilation, looking at the log file and realizing that you need other \show commands is a very tedious procedure.

A very nice utility in this respect is texdef: calling

texdef -t latex -c article \section

you'd receive the same information; with

texdef -t latex -c article -s \section

you'd even get

% article.cls, line 312:
\newcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}

so also the place where the command is defined is shown (when possible).

Instead of \show you could use \meaning, that instead of interrupting the run will print the same information. It's probably better to enclose the call in a \texttt command, like

\texttt{\meaning\section}

(or {\tt\meaning\foo} in Plain TeX). However the same limitations as with \show apply.

egreg
  • 1,121,712