Hacker News new | ask | show | jobs
by vextea 560 days ago
So unfortunate that justified text in browsers looks awful compared to documents generated with LaTeX (usually)....
4 comments

I had a crack at a solution to this problem recently. It's pretty basic in terms of what it can do and not the most performant.

Code: https://github.com/tdjsnelling/microtype Demo: https://tdjsnelling.github.io/microtype/test/from-cdn/

Even better, there is the new CSS `hyphens: auto;`. Browser & language support is not yet 100% though.

https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens

Try to make a LaTeX document that automatically reflows based on screen size and you’ll see why it’s difficult.
A good example of this is Bertrand Russell's _Introduction to Mathematical Philosophy_:

https://courses.umass.edu/klement/imp/

which is available in a number of sizes _and_ has the LaTeX source available showing how the various sizes are arrived at.

The HTML version is quite nice. Do you know how they did the LaTeX to html conversion?
No idea. Ask the folks who manage that page?
It’s still just a few different sizes. A HTML website has to support every possible width.
The LaTeX source may be easily edited to impart any size/proportion desired --- not quite as straight-forward as re-sizing a browser window, but the same ultimate effect.
That is not what a latex document is for.

It's like talking about reflowing a physical page.

Instead, you change the document page size and render multiple versions and switch it out based on zoom level.

That’s the point. HTML has to support arbitrary screen sizes whereas LaTeX doesn’t, so the layout algorithms have to be more accomodating.
But the width of a PDF is still arbitrary isn't it? Can you just, recalculate for bigger widths?
Not really. It's fixed at "compile time". Eg "A4" or "Letter". I guess it "changes" according to zoom level, but that's just enlarging or shrinking - no reflow required.
You could apply the LaTeX algorithm to each rendering. The rendering might jump and it would be a change from before but it can be done.
For want of a "real" H&J algorithm, and having problematic lines identified as "overfull boxes" which need to be fixed.
All the print books on my bookshelf use fully justified text. In contrast, my preference for ebooks are to render them as left-justified. So I think I intuitively arrived at a practice that matches your conclusion about justified text in browsers.