[comp.text.tex] Problem using \write

wester@ghostwheel.unm.edu (Michael Wester) (12/13/90)

I have been trying to understand the \length macro defined on page 219 of the
TeXbook.  All is well until I try to \write out a result.  In particular, I
TeX the following:

% Define \length, even to the point of using the same unreadable spacing as
% found in the TeXbook, just to be sure there that are no subtle errors.

\def\length#1{{\count0=0 \getlength#1\end \number\count0}}
\def\getlength#1{\ifx#1\end \let\next=\relax
  \else\advance\count0 by1 \let\next=\getlength\fi \next}

\def\qqq{\length{argument}}   % try out an example
\qqq                          % this causes an 8 to be written in the DVI file
\immediate\write16\qqq        % however, this causes an error

The error is
! Undefined control sequence.
\getlength ... etc.

Replacing \def by \edef causes the same problem.  I presume the \write causes
the same sort of expansion as \edef.  So, how does one view the result
interactively (if one is debugging on a non-graphics terminal and wishes to
avoid doing frequent octal dumps) and better, how can I make the \edef and/or
\write work?  A simple answer would be nice but from my experience so far, I
don't really expect TeX programming to be simple!
--
Michael Wester --- wester@ghostwheel.UNM.Edu (Internet), wester@unmb (BITNET)
Department of Mathematics, University of New Mexico, Albuquerque, New Mexico 

eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) (12/14/90)

wester@ghostwheel.unm.edu (Michael Wester) writes:

>\def\qqq{\length{argument}}   % try out an example
>\qqq                          % this causes an 8 to be written in the DVI file
>\immediate\write16\qqq        % however, this causes an error

>[...]  I presume the \write causes
>the same sort of expansion as \edef.  

Correct. And to add to your problems: the length macro uses
not only expansion, but also assignments, which are not
expandable.

You can view your results interactively but having the \write
*inside* the macro you are testing. Of course this is not what
you want.

This may be a silly solution, but I think it works:

\setbox0\hbox{\qqq}
\tracingonline=1
\showbox0

This shows you what's in box0 (without the \tracingonline you
get this only in your log file), in particular
the characters that have been typeset in it.

Victor.