TeX line breaking algorithm in JavaScript