[Tex/LaTex] plain TeX error. Undefined control sequence. \pgfutil@

luatextex-coretikz-pgf

I'm trying to compile the fix mentioned by egreg in this thread: Strange behaviour with PGF/TikZ and Plain TeX output routine

Here's the code:

\input pgf

\catcode`@=11
\newbox\pgfutil@@Output@Box
\def\shipout{%
  \ifhmode\hskip\else\vskip\fi 1sp 
  \afterassignment\pgfutil@@Delayed@EveryShipout@Test
  \setbox\pgfutil@@Output@Box=}
\def\pgfutil@@Delayed@EveryShipout@Test{%
  \ifdim\lastskip=\z@ % it was \shipout\vbox or \shipout\hbox
    \expandafter\aftergroup
  \fi
  \pgfutil@@EveryShipout@Test}
\def\pgfutil@@EveryShipout@Test{%
  \unskip % remove the skip used as signal
  \ifvoid\pgfutil@@Output@Box
    \expandafter\aftergroup
  \fi
  \pgfutil@EveryShipout@Output}
\def\pgfutil@EveryShipout@Output{%
  \setbox\pgfutil@@Output@Box=\vbox{
    \setbox\z@=\hbox{%
      \pgfutil@abe
      \unhbox\pgfutil@abb
      \pgfutil@abc
      \global\let\pgfutil@abc\pgfutil@empty
    }%
    \wd\z@=\z@\ht\z@=\z@\dp\z@=\z@\box\z@
    \ifhbox\pgfutil@@Output@Box\unhbox\else\unvbox\fi\pgfutil@@Output@Box
  }%
  \pgfutil@@EveryShipout@Org@Shipout\box\pgfutil@@Output@Box
}
\catcode`@=12

%\def\bxxx{\box255}\output={\shipout\bxxx}
%\output={\shipout\relax\box255}

\setbox0=\hbox{A}
\shipout\box0

Hello world
\bye

I get this error message every time I try:

! Undefined control sequence.
\pgfutil@EveryShipout@Output ...ipout@Org@Shipout 
                                                  \box \pgfutil@@Output@Box 
\plainoutput ...headline \pagebody \makefootline }
                                                  \advancepageno \ifnum \out...
<output> {\plainoutput 
              }
<to be read again> 
\pgfutil@origend 
l.42    \bye

? 
! Output loop---25 consecutive dead cycles.
<to be read again> 
\pgfutil@origend 
l.42    \bye

I can't figure out what's wrong.

Best Answer

The simple file

\input pgf

\show\shipout

produces different results when compiled using TeX Live 2012, with PGF version 2.10, or under TeX Live 2014, with PGF version 3.0.0

Version 2.1.0

> \shipout=macro:
->\afterassignment \pgfutil@@EveryShipout@Test \setbox 255= .

Version 3.0.0

> \shipout=macro:
->\edef \AtBegShi@GroupLevel {\number \currentgrouplevel }\afterassignment \AtBegShi@Test \setbox \AtBeginShipoutBox =.

The conclusion we can draw from this code is that the main error in PGF 2.10, which was doing \setbox255=... has been fixed. In my experiment, the example file you show (purged from the added code)

\input pgf

\setbox0=\hbox{A}
\shipout\box0

Hello world
\bye

compiles flawlessly and produces the expected result.