texlib
texlib copied to clipboard
Should _BreakNode demerits be cumulative?
It seems that _BreakNode
only stores the demerits of the current breakpoint, instead of the cumulative (total) demerits.
Pseudo-code from the paper:
texlib:
if p[i] >= 0:
demerits = (1 + 100 * abs(r)**3 + p[i]) ** 3
elif self.is_forced_break(i):
demerits = (1 + 100 * abs(r)**3) ** 2 - p[i]**2
else:
demerits = (1 + 100 * abs(r)**3) ** 2
demerits += flagged_demerit * f[i] * f[A.position]
# Figure out the fitness class of this line (tight, loose,
# very tight or very loose).
if r < -.5: fitness_class = 0
elif r <= .5: fitness_class = 1
elif r <= 1: fitness_class = 2
else: fitness_class = 3
# If two consecutive lines are in very
# different fitness classes, add to the
# demerit score for this break.
if abs(fitness_class - A.fitness_class) > 1:
demerits += fitness_demerit
# Record a feasible break from A to B
brk = _BreakNode(position = i, line = A.line + 1,
fitness_class = fitness_class,
totalwidth = self.sum_width[i],
totalstretch = self.sum_stretch[i],
totalshrink = self.sum_shrink[i],
demerits = demerits,
previous = A)
breaks.append(brk)
Perhaps I'm missing something — the effect of this may not be immediately obvious. But if my suspicions are correct, texlib would be selecting the most optimal breaks based only on the demerits of the last line.