View Issue Details

IDProjectCategoryView StatusLast Update
0000807luatexluatex bugpublic2015-10-21 11:56
ReporterTaco Assigned ToHans Hagen  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Summary0000807: Bad position equation number Lualatex
DescriptionAs reported here:

http://tex.stackexchange.com/questions/97819/bad-position-equation-number-lualatex
Steps To Reproduce
\hsize=2cm
$$a^2+b^2=c^2\eqno(1)$$
\bye

Ouput after compilation with luatex:

eqno in the left (should be on the right).
Additional InformationHendrik Vogt's analysis:

This appears to be a bug in the LuaTeX engine, see below. For a workaround, use align instead of equation; the align environment doesn't rely on the TeX engine for placement of the equation number. This fixes your problem (but can influence the vertical spacing for shorter equations).

I think I could locate the bug in texmath.w, lines 2220 to 2225. There it says

if ((eqno_box != null) && (eqno_w == 0) && !l) {
    tail_append(new_penalty(inf_penalty));
    shift_amount(eqno_box) = line_s;
    append_to_vlist(eqno_box);
    g2 = 0;
}

Of interest is the third line: the shift amount of the box containing the equation number is line_s, which previously was set to \displayindent (which usually is zero). Thus, the equation number is flush left.

Here's the corresponding lines from Knuth's tex.web, lines 22580 to 22585:

if (a<>null)and(e=0)and not l then
  begin tail_append(new_penalty(inf_penalty));
  shift_amount(a):=s+z-width(a);
  append_to_vlist(a);
  g2:=0;
  end;

You can see that this is the very same code in a different language, eqno_box != null translates to a<>null, and so on. Here, the shift amount of the box containing the equation number is s+z-width(a), where s is the same as line_s above, z is the line width and width(a), well, the width of the box a with the equation number. And this is the correct shift amount for having the equation number flush right!

Maybe I should explain the conditions in the first line of the code: the box with the equation number should be non-empty, it should have width 0(!), and we shouldn't be in the case of a left equation number as in \leqno. And why the width 0? This is the "flag" that was set before to indicate that the box should be placed in the next line because it didn't fit into the line with the equation.
TagsNo tags attached.

Activities

luigi scarso

2015-05-15 19:05

developer   ~0001375

It should be partially fixed in trunk, rev. 5244

Hans Hagen

2015-05-21 13:41

manager   ~0001381

And again fixed a bit better for r2l cases. A few node mem leaks were fixed too, as well as prev links.

Hans Hagen

2015-10-21 11:56

manager   ~0001456

there has been fixes to the eqno placement so it looks ok now

Issue History

Date Modified Username Field Change
2013-02-16 14:05 Taco New Issue
2015-05-15 19:05 luigi scarso Note Added: 0001375
2015-05-21 13:41 Hans Hagen Note Added: 0001381
2015-10-21 11:56 Hans Hagen Note Added: 0001456
2015-10-21 11:56 Hans Hagen Status new => closed
2015-10-21 11:56 Hans Hagen Assigned To => Hans Hagen
2015-10-21 11:56 Hans Hagen Resolution open => fixed