[NTG-pdftex] [ pdftex-Bugs-437 ] two \immediate cancel itself

noreply at sarovar.org noreply at sarovar.org
Sat Oct 15 23:57:49 CEST 2005

Bugs item #437, was opened at 2005-10-15 23:57
You can respond by visiting: 

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Heiko Oberdiek (oberdiek)
Assigned to: Nobody (None)
Summary: two \immediate cancel itself

Initial Comment:

Vladimir Volovich found the following bug, I quote
his bug report from the ntg-pdftex list here:

> consider the following Plain TeX file:
> \immediate\immediate\openout1=test.out
> \immediate\write1 {line 1}
> \immediate\write1 {line 2}
> \immediate\closeout1
> \bye
> (it was reduced from a real-life example).
> if i process it with vanilla TeX engine (i.e. not
> with pdfetex, but with TeX), you get what i expect:
> two lines are written to the file test.out, and
> there are no pages of output (no DVI file generated).
> however, if i process this file with pdfetex, i do
> not get what i would expect: instead, the lines are
> written to terminal, test.out is created and is
> empty, and there is also a 1-page PDF file generated.
> the bug goes away if i remove the second \immediate,
> but as i said this is a simplified example converted
> from a real-life usage.

It is indeed a bug:

this is the original code of "Implement \immediate":

| begin get_x_token;
| if (cur_cmd=extension)and(cur_chr<=close_node) then
|   begin p:=tail; do_extension;{append a whatsit node}
|   out_what(tail); {do the action immediately}
|   flush_node_list(tail); tail:=p; link(p):=null;
|   end
| else back_input;
| end

A token is read. If the token hears to \immediate,
it is executed with the immediate setting.
Otherwise the token is just put back.
  Now pdfTeX has more commands that obey \immediate:

| begin get_x_token;
| if cur_cmd=extension then begin
|    if cur_chr<=close_node then
|       begin <<original action>> end
|     else case cur_chr of
|         pdf_obj_code: begin <<...>> end;
|         pdf_xform_code: begin <<...>> end;
|         pdf_ximage_code: begin <<...>> end;
|         end;
|     endcases;
| end 
| else
|     back_input;
| end

a) cur_cmd != extension
   --> nothing is changed (back_input)
b) cur_cmd == extension && cur_chr <= close_node
   --> nothing is changed (original action)
c) cur_cmd == extension
   && cur_chr in (pdf_{obj,xform,ximage}_code)
   --> new behaviour for pdfTeX
d) cur_cmd == extension && cur_chr > close_node
   && cur_chr not in (pdf_{obj,xform,ximage}_code)
   --> no action

Case d) is the bug. \immediate is an extension primitive
with cur_chr > close_node. Thus the second \immediate
is read, but then dropped. The effect is:
  \immediate\immediate\openout is same as \openout
Instead of "no action" there should be "back_input".
Before "endcases" the following line needs to be added:
    else case cur_chr of
      othercases back_input

I have attachted a diff file for pdftexdir/pdftex.ch.

Yours sincerely
  Heiko <oberdiek at uni-freiburg.de>


You can respond by visiting: 

More information about the ntg-pdftex mailing list