Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

\output puzzle

39 views
Skip to first unread message

Carsten Heinz

unread,
Jan 5, 2001, 3:29:03 AM1/5/01
to
\documentclass{article}
\makeatletter
%
% With
%
\newbox\tempbox
\edef\originaloutput{\the\output}
%
% consider the following \output routine. We save
% box 255 and restore it after closing the group
% which is inserted by TeX when it calls \output.
%
\output{\global\setbox\tempbox\box\@cclv % save
\egroup
\setbox\@cclv\box\tempbox % restore
%
% Then we use the original output routine
%
\bgroup\originaloutput\egroup
%
% and insert \bgroup matching the } which TeX
% inserts at the end of the output routine.
%
\bgroup}
\makeatother
%
% This definition doesn't work: the first \egroup
% gives the error "unbalanced output routine".
%
% BUT: If we insert an \expandafter before that
% \egroup then all works well!
%
\begin{document}

Dummy text

\end{document}

Does someone know the implementation details of
TeX causing this effect, maybe the paragraph(s)
in "TeX - The Program"?

Happy new year!
Carsten


Sent via Deja.com
http://www.deja.com/

Heiko Oberdiek

unread,
Jan 5, 2001, 6:49:23 AM1/5/01
to
On Fri, 05 Jan 2001 08:29:03 GMT, Carsten Heinz <che...@gmx.de> wrote:

>\output{\global\setbox\tempbox\box\@cclv % save
> \egroup

It works with "\csname egroup\endcsname"
instead of "\egroup". (But I do not know
the reason. Perhaps TeX checks the group
levels before executing the output routine.)

Yours sincerely
Heiko <ober...@ruf.uni-freiburg.de>

Carsten Heinz

unread,
Jan 5, 2001, 4:03:12 PM1/5/01
to
In article <iibb5t00chaf5v7si...@4ax.com>,

Heiko Oberdiek <ober...@ruf.uni-freiburg.de> wrote:
> On Fri, 05 Jan 2001 08:29:03 GMT, Carsten Heinz <che...@gmx.de> wrote:
>
> >\output{\global\setbox\tempbox\box\@cclv % save
> > \egroup
>
> It works with "\csname egroup\endcsname"

Yet another work-around. So both

\csname egroup\endcsname
and \expandafter\egroup

do work. This puzzles me even more. First I thought
that it has something to do with the place where
\expandafter stores the token. But now with the
second \csname-trick, I don't know whether I know
TeX any more. Really strange.

> instead of "\egroup". (But I do not know
> the reason. Perhaps TeX checks the group
> levels before executing the output routine.)

Since it works with \expandafter, TeX should
complain about \egroup if it checks the group
levels before executing \output. But it doesn't.
So your and my theory above are some kind of
disproofed.

Best regards
Carsten

p.s.: I've forgotten to say that the described
\output-\expandafter\egroup-(or \csname)-trick
has an application. It solves a problem I've had
for about two years with the listings package.

Michael J Downes

unread,
Jan 9, 2001, 11:24:33 AM1/9/01
to
Carsten Heinz <che...@gmx.de> writes:

> Yet another work-around. So both
>
> \csname egroup\endcsname
> and \expandafter\egroup
>
> do work. This puzzles me even more. First I thought
> that it has something to do with the place where
> \expandafter stores the token. But now with the
> second \csname-trick, I don't know whether I know
> TeX any more.

I have not looked at the code but it seems pretty clear to me that the
lack of an error in the \expandafter and \csname cases is a TeX bug. It
should be giving an error message in all three cases.

I would guess that the easiest way to solve your original problem is

\expandafter\def\expandafter\originaloutput\the\output
%\show\originaloutput

\output{%
% My Before Code
\originaloutput
% My After Code
}

No special group tricks or saving/restoring box 255 is then necessary in
the before code or after code.

The only weird part is that no braces are needed when defining
\originaloutput because of the weird way that they are automatically
added by TeX to the contents of \output, unlike any other token
register.

Donald Arseneau

unread,
Jan 10, 2001, 11:34:13 PM1/10/01
to b...@ams.org
Carsten Heinz <che...@gmx.de> writes:

> \output{\global\setbox\tempbox\box\@cclv % save

> \egroup ...\bgroup}


> %
> % BUT: If we insert an \expandafter before that
> % \egroup then all works well!

My uneducated, untested, supposition is that this is a TeX bug
in the following:


@ When the user's output routine finishes, it has constructed a vlist
in internal vertical mode, and \TeX\ will do the following:

@<Resume the page builder after an output routine has come to an end@>=
begin if (loc<>null) or
((token_type<>output_text)and(token_type<>backed_up)) then
@<Recover from an unbalanced output routine@>;

which is part of the handle_right_brace routine.

The \expandafter sets the token_type of the right brace to backed_up
so the recovery is not executed. But I don't know why the test
(token_type<>backed_up) is there at all. Maybe it is to allow
valid \bgroup\expandafter\egroup constructions within the output
routine.

Donald Arseneau as...@triumf.ca

0 new messages