Live data from Hacker News

Using Web Technologies to Print a Book

richardmavis.info

51–60 of 69 posts

Re: Using Web Technologies to Print a Book

#51

Earlier quoted context omitted.

WeasyPrint looks to have progressed a lot since last I looked at it (when there was no way I could use it at all, though I can’t remember the reason), but looks to still be quite limited. A couple of things that spring to my attention immediately: no flexbox, and no CSSOM (so that you can’t adjust the document based on layout at all unless you can do it in straight CSS). Still, in practice probably usable for what I…

One of the problem with CSSOM and similar things is the problem of iterative layout: Let's say you have a list which should be split automatically on two pages. You also want to add a table header on the second page. But now the second part of the list doesn't fit on the page anymore. So you need to split the list further, and add another header. Basically every change to the CSS or DOM requires a reflow (or clever o…

That’s no different from what browsers do at present.

Yes, modifications may cause a reflow. So? That just means that it’s slow. That’s not a problem.

That’s how you implement such things. The initial implementation throws away all layout information as soon as you modify any CSSOM property, and recalculates it. You release that to people saying “it can now do this, but it’ll be extremely slow; let us know what sorts of things you do with it and when you find particularly awful performance cases, and then we’ll look into speeding it up”. Then, as people try using it, you determine where it’s worth putting effort into speeding it up. This is exactly what Michael Day of Prince said they’d do if/when they implemented CSSOM, when I asked him about whether it might come, several years ago. This is an entirely reasonable approach.

Re: Using Web Technologies to Print a Book

#52
post #33

Earlier quoted context omitted.

One of the problem with CSSOM and similar things is the problem of iterative layout: Let's say you have a list which should be split automatically on two pages. You also want to add a table header on the second page. But now the second part of the list doesn't fit on the page anymore. So you need to split the list further, and add another header. Basically every change to the CSS or DOM requires a reflow (or clever o…

I have a theory how this should be solved in web standard, which in turn has other uses besides printing, but well, I don't feel like I can affect web standard in any meaningful sense. The basic idea is to add (placeholder name) stopUpdating/resumeUpdating to window, which can be polyfilled as no-op. The semantics is that CSSOM view methods are allowed to return the value when update was not stopped, or any later val…

So long as you don’t read layout information in between, you can already batch your modifications just fine. All it takes is care in how you structure and implement things, and you’re fine. And before you object, your proposed solution would require almost as much care, have more hazards to trip over, and require opting in in a way that few would—and those that would, already know how to be careful. I suspect it would also increase complexity and possibly memory usage in the browser.

If you were designing something from scratch, such approaches would be worthwhile considering, but I think that boat has sailed, and the architecture would fight against you.

Then again, I believe it was generally accepted that web browsers were stuck with UTF-16, until Simon introduced WTF-8 for Servo.

Re: Using Web Technologies to Print a Book

#53
post #49
post #48

Earlier quoted context omitted.

Wrapping sentences into short functional parts (motivated by more or less arbitrary limits like 80 characters) helps having easily editable and readable text.

Apologies but I'm not sure I understand your point. Are you able to elaborate?

Hitting enter at the end of a line lets you manually wrap paragraphs in a way that will fit into an 80 or 120-char wide terminal.

Ignoring those line breaks is desirable when reflowing the text into e.g. HTML output

Re: Using Web Technologies to Print a Book

#54
post #43

You are on linux. You want to typeset a book. Why not use (pdf)LaTeX?

Latex is really good if someone needs lots of math, references and so on. It's really par none when it comes to technical writing. But it's so clunky in some ways it's more of a precision tool for this particular task than a generic layout software. I'm saying this as person who's in his past lives written scientific material using LaTeX and done semi-professional graphic design and layout work as well. Oh god, I in…

There's a lot more to LaTeX than just equations though. There are packages for handling lots of things the humanities need too. Egyptian Hieroglyphs? Use HieroTeX. Music? Use Musixtex. Really, think of anything that would be hard to typeset manually and somebody's likely to have already created a LaTeX package for it.

Re: Using Web Technologies to Print a Book

#55
post #33

Earlier quoted context omitted.

I have a theory how this should be solved in web standard, which in turn has other uses besides printing, but well, I don't feel like I can affect web standard in any meaningful sense. The basic idea is to add (placeholder name) stopUpdating/resumeUpdating to window, which can be polyfilled as no-op. The semantics is that CSSOM view methods are allowed to return the value when update was not stopped, or any later val…

I think the approach of WeasyPrint and Prince, implementing a dedicated layout engine for paged media, is better than making these things work in Browser engines. In any case, html/css for paged media should be mostly separate from website code. "Printing out" web pages works in many cases, but it's crappy.

The only two reasons why printing web pages out is lousy are because web developers put little to no effort into it, and because the browser manufacturers put little to no effort into it. I would love the likes of WeasyPrint and Prince to be rendered obsolete by one or more mainstream web browsers. If any of them decided that it was a strategic priority, they’d get a lot done very quickly. It’s just that there’s no compelling reason for them to, while there is for the people behind engines with a specific purpose—and so Prince is pretty safe in its position.

Re: Using Web Technologies to Print a Book

#56
post #43

Earlier quoted context omitted.

Latex is really good if someone needs lots of math, references and so on. It's really par none when it comes to technical writing. But it's so clunky in some ways it's more of a precision tool for this particular task than a generic layout software. I'm saying this as person who's in his past lives written scientific material using LaTeX and done semi-professional graphic design and layout work as well. Oh god, I in…

There's a lot more to LaTeX than just equations though. There are packages for handling lots of things the humanities need too. Egyptian Hieroglyphs? Use HieroTeX. Music? Use Musixtex. Really, think of anything that would be hard to typeset manually and somebody's likely to have already created a LaTeX package for it.

> and somebody's likely to have already created a LaTeX package for it

... or a dozen, each with different features, like tables.

Re: Using Web Technologies to Print a Book

#57
post #49
post #48

Earlier quoted context omitted.

Wrapping sentences into short functional parts (motivated by more or less arbitrary limits like 80 characters) helps having easily editable and readable text.

Apologies but I'm not sure I understand your point. Are you able to elaborate?

As others, I've grown accustomed to wrapping lines to fit in small terminals, and I started avoiding breaking the line randomly. Instead I try to break after self-sufficient parts of sentences so that lines flow naturally after one another. That usually means after a comma, before a connector word, or after an enumeration. It's not always possible, but I find that when I need to rewrite a sentence to be naturally breakable it usually reads better. Furthermore, each line often ends up expressing a whole idea, which means working on that idea usually translates to simple line operations, which fits nicely in an expressive text editor like Vim.

Re: Using Web Technologies to Print a Book

#58
post #41
post #35

Earlier quoted context omitted.

Because the user in question does not know and is unwilling to learn how to design anything if it is not web technology. That is, you probably want to design PDF output. Some users prefer to do any design work whatsoever using web technology. Therefore, PDF needs to be generated from HTML.

If OP is used to working with HTML/CSS, it will probably save him a lot of time and energy to do basic formatting in HTML/CSS than to learn how to design a professional-looking PDF document. He's a programmer and novelist, not a designer. In fact, he's not even aiming to design a professional-looking PDF document, just a throwaway printout for proofreaders who don't know how to parse Markdown.

Why not use something like http://github.com/susam/texme as a starting point? Really easy to turn any Markdown document into a rendered HTML with a single line of code in the header.

This rendered HTML could be converted to PDF and printed or the self-rendered HTML itself could be printed directly.

Re: Using Web Technologies to Print a Book

#60
post #47

You are on linux. You want to typeset a book. Why not use (pdf)LaTeX?

Because there is more to a book than type-setting and anything like putting images where you want them or specific whitespace aesthetics is a major pain to do in LaTex.

What's so painful about whitespace in LaTeX? hspace is horizontal space. vspace is vertical space. I mean, you should use smallskip, bigskip, etc., but if you want specific length, hspace/vspace work.
Post reply on HN