TeX line breaking algorithm in JavaScript (and HTML5 Canvas)
bramstein.com
bramstein.com
Both seem like pretty weak excuses to me.
The main real reason is likely that most users don’t care, and so they can get away with it.
One of the big points of competition between browsers these days is in speed. Part of the reason people switch from IE to one of the more modern browsers is because they are just that much snappier.
On a typical Amazon page the difference is going to be unnoticeable.
And your remark about real time: Even the old (and slow!) TeX can do linkebreaking for several hundred pages of text in a second. Including writing pdf. So you are probably right about real-time h&j even for quite large documents.
http://delivery.acm.org/10.1145/1610000/1600217/p99-hurst.pd...
Knuth-Plass takes O(kn) where n is the number of words and k the number of words per line. That’s definitely slower than the naive line-by-line method.
But the better algorithm can be supposedly improved with the method in this paper (I haven’t read it and don’t have time just now, so I’m not sure how much slower it would then be than the naive way).
http://delivery.acm.org/10.1145/150000/146656/p546-eppstein....
By “non-negligible” I meant something like 2–10 times slower (you’d have to test to be sure... I tried searching around but couldn’t find any direct speed comparisons). For typical pages it’s not going to matter, but if you have a page like the HTML5 spec, where it takes a half a second to resize a window now, it’s going to be noticeably slower using a more sophisticated paragraph composer.
Keep in mind, Safari doesn’t even do kerning, because they’re afraid it’d be too slow. (Also a ludicrous excuse for desktop hardware and typical web pages, IMO.)
And the Safari guys also use the same excuse (“it’s too slow”) for not doing real color management with CSS/HTML colors.
I would like to have two browsers of the same type, one with high(er) quality typography and one as it is now. And then compare the speed. That would be interesting.
I imagine it would have to make a fairly significant difference in rendering quality in order to make any speed losses worthwhile. Death by a thousand cuts and all that.
My email is on profile.
edit: I probably have access from academic network, but I am at home for a few days...
When I clicked again just now, I was able to download this paper... I still don't understand what has changed.
Thank you for your time.
EDIT: And thanks to cpach!
ssh -D 1080 unixhost.yourinstitution.edu
then set your browser’s SOCKS proxy to localhost:1080.I haven't really wrapped my head around the paper yet, but I think it only holds if you take out some of the elements of the original Knuth & Plass algorithm (the box, glue and penalty model.) Nevertheless, linear time seems possible for a total-fit algorithm if you're willing to give up that model.
There is also a Haskell and C++ implementation (with source code) available on the authors web page: http://progtools.comlab.ox.ac.uk/members/oege/publications/s...
In TeX the line breaking depends on the whole paragraph. I imagine it could be visually quite distracting if the line-wrapping jumped around in a WYSIWYG word processor as you added text to a paragraph.
Edit: ah. I see this is noted in the posted article’s To-do section:
Figure out how to deal with dynamic paragraphs (i.e. paragraphs being edited) as their ratios will change during editing and thus visibly move around.
I don’t actually use a WYSIWYG editor any more, so I’ll leave my speculation there.
Which is: Interpret your instructions very literally, so you still need to go over your document carefully to fix problems like urls running off the edge of the page?
Smart-arse joke aside, I agree with you that LaTeX is generally great, but it's not perfect, and sometimes it is difficult to make it do what you want.
Because word processor implementors are lazy and incompetent? ;-)
I think that probably most people don't realize there is something better, and can't even really tell the difference between typical word processor output and nice TeX-style optimal line breaks. It seems to me most people don't care that much about typography.
A document presented with good typography might be easier to read for lengthy periods without losing concentration. There might be fewer distractions, like rivers of space running through the text, hard-to-read shapes due to poor kerning, or chunky CAPITALS and long numbers where small caps and old-style figures would not have disrupted the flow. There might be subtle visual cues to help the reader understand the material more quickly, like moving captions and headings closer to the subject material or spacing out bullet lists a little so their items are clearly separated.
But in a world where most people using word processors don't know what a stylesheet is and emphasis tends to consist of centring text, setting it in bold, capitals, and double-underlined, and then hitting enter a few times either side to space it out a bit, I think we can safely assume that most people either don't know about the subtleties of good typography or just don't care. The world might be a slightly better place if leading word processors all adopted better typographical conventions by default, and a few of us would appreciate the ability to produce better quality results, but I'm afraid it's never going to be a selling point for most people.
The real problem with all of this is that everything is being done in a canvas element, which means no text selection, no searching, etc. etc.
The canvas is just a way to show the output of the line breaking algorithm. Earlier I had an example on my website of a dynamically created DOM paragraph using the Knuth & Plass algorithm. That way, the rendering was done by your browser (i.e. select, searching, etc. was possible) while the line breaks were handled by the algorithm. Unfortunately I haven't been able to get it reliable on all browsers, so I took it out before I posted this item. It's still on my Github repository: http://github.com/bramstein/javascript/tree/master/src/types...
http://en.wikipedia.org/wiki/River_(typography)
edit: re-reading this seems to follow naturally from reducing the size of the gaps between words, which the algorithm does.
Doesn't work in iPhone, sadly. Not sure why not, because Canvas is supported, I think.
Might be possible to make text selectable, but looks like a huge chore: http://stackoverflow.com/questions/1451635/how-to-make-canva...
I have a ­ hyphenator using Liang's algorithm as a YUI3 module if you're interested.
I just wish we could get 300dpi displays for our computers already, and stop worrying about the pixel grid. But, we're going to need some better techniques for resolution independent UIs before that happens. In particular, you will probably actually need better hinting for vector based UI graphics, so that the same vector graphics that can be used for high resolution displays can also be used for lower resolution displays while still looking good.
I would be very much interested in an open-source hyphenator (I'm aware of some other JavaScript implementations of Liang's algorithm) as I was planning to either use an existing one or to implement it myself.
I’m not sure too many people especially object to adjustments of 2-3% to inter-letter space or letter widths.
Another problem is ligatures. Where adjusting inter-letter spacing is possible, it usually needs to be applied uniformly across at least a whole word to work well. If you are writing the word "difficult", and the "ffi" is rendered using a ligature to avoid awkward clashes, then how do you adjust the spacing for that? You could keep the ligature, but then the inter-letter spacing isn't uniform across the whole word. Alternatively, you could break the ligature, but that could restore the undesirable clashes between the "f", "f" and "i" that the ligature was designed to prevent. To avoid that, you would have to open up the inter-letter spacing so much that the letters no longer clash, which is probably far too obvious in most fonts to be a useful effect.