Path: utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!cernvax!nath From: nath@cernvax.cern.ch (Alfred Nathaniel) Newsgroups: comp.text.tex Subject: TeX bug: optional spaces are mandatory Message-ID: <4117@cernvax.cern.ch> Date: 8 Feb 91 14:51:35 GMT Organization: CERN, European Laboratory for Particle Physics Lines: 108 I discovered a bug in TeX3.0. It also shows up in TeX2.9. Going through the change records I couldn't find any reference to it. So I suppose that it has been there for much longer. In sequences ...\counter=\ifnum\counter... and ...\counter=\fi \ifnum\counter... the \ifnum test fails if is not followed by a space. The problem is in this part of scan_int: ------------------------------------------------------------------------- @= loop@+ begin if (cur_tok=zero_token)and (cur_tok<=zero_token+9) then d:=cur_tok-zero_token else if radix=16 then if (cur_tok<=A_token+5)and(cur_tok>=A_token) then d:=cur_tok-A_token+10 else if (cur_tok<=other_A_token+5)and(cur_tok>=other_A_token) then d:=cur_tok-other_A_token+10 else goto done else goto done; vacuous:=false; if (cur_val>=m)and((cur_val>m)or(d>7)or(radix<>10)) then begin if OK_so_far then begin print_err("Number too big"); @.Number too big@> help2("I can only go up to 2147483647='17777777777=""7FFFFFFF,")@/ ("so I'm using that number instead of yours."); error; cur_val:=infinity; OK_so_far:=false; end; end else cur_val:=cur_val*radix+d; get_x_token; end; done: ------------------------------------------------------------------------- To look for another digit belonging to get_x_token is called. But if the next token is \ifnum the condition is evaluated before scan_int did realize that is complete and has to be stored in \counter. Here is an example where the bug occurs: ------------------------------------------------------------------------- \tracingcommands=2 % \count255=0 \count255=999\ifnum \count255=0 \message{[BOGUS: \the\count255<>0]} \fi % \count255=0 \ifnum 0=0 \count255=888\fi \ifnum \count255=0 \message{[BOGUS: \the\count255<>0]} \fi % \end ------------------------------------------------------------------------- This is TeX, C Version 3.0 (format=plain 91.1.28) 7 FEB 1991 16:23 **ifnumbug (ifnumbug.tex {vertical mode: \count} {\count} {\ifnum} {true} {\message} [BOGUS: 999<>0] {blank space } {\fi} {\count} {\ifnum} {true} {\count} {\fi} {\ifnum} {true} {\message} [BOGUS: 888<>0] {blank space } {\fi} {\end} ) No pages of output. ------------------------------------------------------------------------- Simply replacing get_x_token by get_token fixes this bug but the trip test falls flat on its face. I would classify it as category S according to "The Errors of TeX". A nasty feature is that it is a Heisenbug. If you look at it it goes away. Computing the absolute value of a macro argument: \counter=#1\ifnum\counter<0\counter=-\counter\fi may fail depending on the initial value of \counter while: \counter=#1\showthe\counter\ifnum\counter<0\counter=-\counter\fi always gives the correct result as does: \counter=#1 \ifnum\counter<0\counter=-\counter\fi The lesson I learned from this that when writing TeX macros optional spaces are sometimes mandatory. Is this the right channel for bug reports? If not could somebody who knows forward it or let me know where to send it to. Best regards, Alfred Nathaniel Internet: nath@cernvax.cern.ch = 128.141.1.74 nathanie@dxlmun.cern.ch = 128.141.1.121 Bitnet: nathanie@cernvm