\primitive\pdfoutput cannot be queried
Hello,
AFAIK, an expression with \primitive will become expandable
if and only if the primitive is expandable.
(pdfTeX: \pdfprimitive)
The problem arises with \pdfoutput, a kind of count register.
Therefore it isn't expandable. This doesn't hurt, if \pdfoutput
is set. However it cannot get its value anymore:
\gdef\pdfoutput{\primitive\pdfoutput}
a) \ifcase\pdfoutput
fails with
! Missing number, treated as zero.
<to be read again>
\primitive
b) \ifcase\the\pdfoutput
fails with
! You can't use `\primitive' after \the.
c) \ifcase\number\pdfoutput
fails with
! Missing number, treated as zero.
<to be read again>
\primitive
d) \count0=\pdfoutput
fails with
! Missing number, treated as zero.
<to be read again>
\primitive
Yours sincerely
Heiko
Heiko Oberdiek wrote:
Hello,
AFAIK, an expression with \primitive will become expandable if and only if the primitive is expandable. (pdfTeX: \pdfprimitive)
I am thinking about this bug. Best wishes, Taco
Hi Heiko, Taco Hoekwater wrote:
Heiko Oberdiek wrote:
Hello,
AFAIK, an expression with \primitive will become expandable if and only if the primitive is expandable. (pdfTeX: \pdfprimitive)
I am thinking about this bug.
Please look at the attached patch against pdftex trunk. I have a similar
patch in luatex now, and it works ok for your example file as well as
some other stuff I tried.
The patch makes scan_something_internal (for \number and the other
convert commands) and scan_int (other places where numbers are needed)
skip over the unexpandable version of \primitive so that it looks at
the next token, and if that token is a primitive, it uses this instead.
If the next token is not a primitive at all, then a frozen \relax is
inserted, as that is probably the best thing to do. I have considered
reporting an error, but that is too unpredictable for my taste (and a
"Missing number" error will likely follow anyway).
Please check against any other tests you may have.
Best wishes,
Taco
Index: src/texk/web2c/pdftexdir/pdftex.web
===================================================================
--- src/texk/web2c/pdftexdir/pdftex.web (revision 546)
+++ src/texk/web2c/pdftexdir/pdftex.web (working copy)
@@ -8926,6 +8926,31 @@
end;
end
+@ This block deals with unexpandable \.{\\primitive} appearing at a spot where
+an integer or an internal values should have been found. It fetches the
+next token then resets |cur_cmd|, |cur_cs|, and |cur_tok|, based on the
+primitive value of that token. No expansion takes place, because the
+next token may be all sorts of things. This could trigger further
+expansion creating new errors.
+
+@
Hello Taco, On Sat, Apr 11, 2009 at 04:18:41PM +0200, Taco Hoekwater wrote:
Taco Hoekwater wrote:
Heiko Oberdiek wrote:
AFAIK, an expression with \primitive will become expandable if and only if the primitive is expandable. (pdfTeX: \pdfprimitive)
I am thinking about this bug.
Please look at the attached patch against pdftex trunk. I have a similar patch in luatex now, and it works ok for your example file as well as some other stuff I tried.
Yes, many thanks.
The patch makes scan_something_internal (for \number and the other convert commands) and scan_int (other places where numbers are needed) skip over the unexpandable version of \primitive so that it looks at the next token, and if that token is a primitive, it uses this instead.
If the next token is not a primitive at all, then a frozen \relax is inserted, as that is probably the best thing to do. I have considered reporting an error, but that is too unpredictable for my taste (and a "Missing number" error will likely follow anyway).
Please check against any other tests you may have.
If the next token is not a primitive, then it vanishes:
\def\sx{\immediate\write16{[\meaning\x]}}
% ok:
\edef\x{\pdfprimitive\pdfoutput}
\sx % [macro:->\pdfprimitive \pdfoutput ]
% token vanishes in the next cases:
\edef\x{\pdfprimitive0}
\sx % [macro:->]
\edef\x{\pdfprimitive123}
\sx % [macro:->23]
\expandafter\def\expandafter\x\expandafter{\pdfprimitive0}
\sx % [macro:->]
\edef\x{\pdfprimitive\Undefined}
\sx % [macro:->]
\edef\x{\pdfprimitive $}
\sx % [macro:->]
[\pdfprimitive 0] % []
% An error message I could trigger by:
\chardef\a=10 %
\pdfprimitive\a X
! Missing control sequence inserted.
<inserted text>
\inaccessible
<to be read again>
X
l.70 \pdfprimitive\a X
Yours sincerely
Heiko
Heiko Oberdiek wrote:
If the next token is not a primitive, then it vanishes:
Behaviour in that case is undefined at the moment. Perhaps I should just generate an error if the next token is not a primitive? Best wishes, Taco
On Wed, Apr 15, 2009 at 08:02:42PM +0200, Taco Hoekwater wrote:
Heiko Oberdiek wrote:
If the next token is not a primitive, then it vanishes:
Behaviour in that case is undefined at the moment. Perhaps I should just generate an error if the next token is not a primitive?
Yes, IMHO error message and ignoring itself (\pdfprimitive,
not the next token) as error recovery.
First I was unsure in the case of a command token. But if someone
uses \pdfprimitive\foobar, then his intention would be that
\foobar is a primitive of the engine. Otherwise \pdfprimitive
doesn't documentate or specify a useful behaviour.
Therefore the error message makes clear that his assumption
was wrong and he gets the error message at an earlier stage.
Yours sincerely
Heiko
Heiko Oberdiek wrote:
On Wed, Apr 15, 2009 at 08:02:42PM +0200, Taco Hoekwater wrote:
Heiko Oberdiek wrote:
If the next token is not a primitive, then it vanishes: Behaviour in that case is undefined at the moment. Perhaps I should just generate an error if the next token is not a primitive?
Yes, IMHO error message and ignoring itself (\pdfprimitive, not the next token) as error recovery.
Updated patch attached.
Best wishes,
Taco
Index: src/texk/web2c/pdftexdir/pdftex.web
===================================================================
--- src/texk/web2c/pdftexdir/pdftex.web (revision 546)
+++ src/texk/web2c/pdftexdir/pdftex.web (working copy)
@@ -8923,9 +8923,40 @@
p:=get_avail; info(p):=cs_token_flag+frozen_primitive;
link(p):=loc; loc:=p; start:=p;
end;
+ end
+else begin
+ print_err("Missing primitive name");
+ help2("The control sequence marked <to be read again> does not")@/
+ ("represent any known primitive.");
+ back_error;
end;
end
+@ This block deals with unexpandable \.{\\primitive} appearing at a spot where
+an integer or an internal values should have been found. It fetches the
+next token then resets |cur_cmd|, |cur_cs|, and |cur_tok|, based on the
+primitive value of that token. No expansion takes place, because the
+next token may be all sorts of things. This could trigger further
+expansion creating new errors.
+
+@
On Wed, Apr 15, 2009 at 09:53:22PM +0200, Taco Hoekwater wrote:
Heiko Oberdiek wrote:
On Wed, Apr 15, 2009 at 08:02:42PM +0200, Taco Hoekwater wrote:
Heiko Oberdiek wrote:
If the next token is not a primitive, then it vanishes: Behaviour in that case is undefined at the moment. Perhaps I should just generate an error if the next token is not a primitive?
Yes, IMHO error message and ignoring itself (\pdfprimitive, not the next token) as error recovery.
Updated patch attached.
Many thanks, my test file now runs fine with the expected error messages.
Yours sincerely
Heiko
participants (2)
-
Heiko Oberdiek
-
Taco Hoekwater