vincentdoerig / latex-css

LaTeX.css is a CSS library that makes your website look like a LaTeX document
https://latex.vercel.app
MIT License
2.76k stars 123 forks source link

Not properly typeset #10

Open purpleidea opened 4 years ago

purpleidea commented 4 years ago

Great idea, I love it! However the most important feature of LaTeX is proper typesetting, IOW, variable spaces, etc... Any way this can be implemented? I'm not sure how HTML would really support this. Perhaps that is an upstream browser issue that someone can fix first?

Cheers!

vincentdoerig commented 4 years ago

I agree, but I doubt there is a way to properly typeset HTML. Hyphenation is a mess and having text-align: justify; doesn't really help. Check out this comment from yesterday's HN thread.

The line-height, font-size and letter-spacing can probably be tweaked, but other than that there is not much that can be done using CSS only in terms of typesetting. Hopefully, the situation improves in the near future.

purpleidea commented 4 years ago

Yeah, I always hated reading on screens for exactly this purpose. Maybe it's time for HTML to grow up and grow proper type setting? Maybe you can use this issue to track links to upstream issue trackers? Maybe open an issue with w3c, firefox, chrome, and whatever M$ is doing these days?

Thanks for the nice idea, hopefully you can properly fix ugly text everywhere!

jotaf98 commented 4 years ago

Actually I don't think that's true anymore. Firefox apparently uses the same algorithm as TeX, see here:

https://github.com/mnater/Hyphenopoly/issues/116

So for the same font and geometry, the results should be the same.

The Hyphenopoly library could be used as a polyfill for the rare cases that don't support it, but with up-to-date browsers it's becoming less and less relevant.

purpleidea commented 4 years ago

@jotaf98 Hyphenation is only one aspect of typesetting. Open a LaTeX document and look put calipers up to your screen and measure the difference between the size of the space between two words, and the size of the space between two sentences. And there's much more...

jotaf98 commented 4 years ago

That's true -- it's a start, not a full solution.

Building on Hypohenopoly's example, which iterates the words and adds hyphens at strategic places, could it theoretically be possible to iterate the words and wrap them in <span> tags with custom left/right margins and letter-spacing, following TeX's spacing algorithm?

The CSS font ligatures handle quite a bit of odd inter-letter spacing. I wonder if the level of granularity of per-word letter-spacing plus inter-word margins would be enough to achieve an almost indistinguishable effect!

nvictor commented 3 years ago

Nice project guys,

I have had this link in my bookmarks for quite some time: https://github.com/bramstein/typeset

Would that help with the typesetting?

jotaf98 commented 3 years ago

Good find! @purpleidea and @vincentdoerig does this seem to address the issues you mentioned before?

purpleidea commented 3 years ago

@jotaf98 I don't have time to look into it, but I hope the state of the art gets better!

vincentdoerig commented 3 years ago

Thanks for the link @nvictor! The project looks very interesting. Unfortunately, I'm currently also busy and don't have time to explore it further. But it's definitely something I'd like to look at in the future 👍.