bramstein / typeset

TeX line breaking algorithm in JavaScript
BSD 2-Clause "Simplified" License
990 stars 74 forks source link

Error in demerits calculation #12

Closed louridas closed 9 years ago

louridas commented 10 years ago

According to the TeX Book, p. 98, and Breaking Paragraphs into Lines, the demerits of a line with a penalty -10000 < penalty < 0 should be:

demerits = Math.pow(options.demerits.line + badness, 2) - Math.pow(node.penalty, 2);

instead of

demerits = Math.pow(options.demerits.line + badness - node.penalty, 2);

which is currently the case in:

https://github.com/bramstein/typeset/blob/master/src/linebreak.js#L168

bramstein commented 10 years ago

Thanks for this. I remember there being something about the demerits calculation in the addendum for the reproduction of "Breaking Paragraphs into Lines" in the "Digital Typography" book. I'm going to look it up and check the correctness when I have some time.

bramstein commented 9 years ago

Thanks, they were indeed incorrect. I've fixed it.