Live data from Hacker News

Laying Out a Print Book with CSS

iangmcdowell.com

31–40 of 121 posts

Re: Laying Out a Print Book with CSS

#31
post #15

I would also recommend https://weasyprint.org if you are generating PDFs. Generating invoices, resumes, reports, flyers, etc. from plain Markdown is a two-line affair: https://taoofmac.com/space/notes/2023/03/19/1849#tuesday-202...

Thanks for the link, weasyprint for converting markdown to some presentation format looks cool, similar to pandoc but maybe more customizable?

Just to point out, in the original post, the author does end up using weasyprint, as the tools he began with did not support the required CSS features.

Re: Laying Out a Print Book with CSS

#32
post #24

For those interested in this topic, you might want to checked paged.js https://pagedjs.org/documentation/ It's an polyfil for the unimplemented CSS paged specification, which is exactly that is needed for laying out pages. https://www.w3.org/TR/css-page-3/

At the moment, the combo of pagedjs with a headless browser is my first recommendation when you need something to output pdf automatically.

Weasyprint looks nice, I have yet to use it. It probably has the advantage of not using an actual browser document (with all the relayouting problems), and may use fewer resources in terms of time and memory (I'd have to check though). The disadvantage is also it's not an actual browser document, meaning you need to render the html and css in some form before passing it to weasyprint.

Using a headless browser makes it easier in general to do some fancy stuff like music sheets or embed js chart libraries and so on.

Re: Laying Out a Print Book with CSS

#33

This article completely misses the point. Proper typesetting is about achieving a consistent appearance starting from ligatures and kerning, then word spacing and hyphenation, up to entire paragraphs and pages. Each character has to be typeset considering what character came before, how many words are in the same line and other lines in the same paragraph. The choice of font is also questionable, but not the main iss…

> Proper typesetting is about achieving a consistent appearance starting from ligatures and kerning, then word spacing and hyphenation, up to entire paragraphs and pages.

I looked into CSS hyphenation because I was curious about controlling hyphenation in ebooks. CSS hyphenation appears to be based around the principle that you manually insert HTML entities representing potential hyphen locations into every word, which is obviously insane.

    hy­phen­ation
    hy­phen­ation
    hy­phen­ation
    hy­phen­ation
The TeX way is to provide a set of hyphenation points once, such that, if a word needs to be hyphenated, that list can be consulted and the word can be hyphenated appropriately without each instance of it needing to be entered with several invisible HTML entities.

    \hyphenation{hy-phen-ation}
    hyphenation
    hyphenation
    hyphenation
    hyphenation
I can't think of any use case where I'd prefer what is apparently the only way to do it in CSS. Do epubs have a bespoke non-CSS way to handle this?

(I looked into this in the first place because the Kindle mobile app is godawful at hyphenating words, and I wanted to know what it would take to write an ebook that didn't have obvious howlers. The errors occur in foreign words, but they violate the rules of hyphenating English -- I've seen the app place a hyphen before the first vowel in a word, and I've seen it render "Qis-han", which is exactly equivalent to a hypothetical English "fis-hing" -- so it seems like they must be using a lookup table for all English words and falling back on something completely ridiculous for words that aren't in the table.)

Re: Laying Out a Print Book with CSS

#34
post #4

Interesting read, I find asciidoctor pdf and its theming guide extremely good to obtain nice results for books and articles, customizing it with CSS, fonts and more

I like asciidoctor because it is a text file and easy to version control, I have written couple of books with it and made into pdf, but I am still looking for actively maintained themes, so for self publishing and KDP, I am using pandoc and bunch of tools to convert it into various formats(docbook, md, docx etc). My current workflow is convert into docx which is imported in kindle create and optimise it with kindle previewer.

Re: Laying Out a Print Book with CSS

#35
I once had to generate about 170K+ pdf files from latex. Took a while (~5 hours) on a desktop, so had to get a server to do it and ran pdflatex with gnu parallel. The layout was a pain, since some strings in the databases were quite long.

Then I realized that I could just have generated HTML and printed it via some headless chrome script. The rendering was more consistent, and the printing was much faster (IIRC it took about 1/3 the time.)

Re: Laying Out a Print Book with CSS

#36
As a former freelance book compositor, I can say there are typically many more details that go into laying out a book. To take this layout up a notch, I would want to create a baseline grid (set the line heights and paragraph margins to align text of different sizes). I would also want to control widows and orphans, which is built into CSS.

Re: Laying Out a Print Book with CSS

#37
I had a fun time implementing shipping labels a few years ago. They were just a printable web page, rendered by Django. I was also able to fairly directly translate the sizes/padding in the spec to CSS using physical units. Surprisingly straightforward!

Re: Laying Out a Print Book with CSS

#38
post #29
post #17

One serious problem is that CSS do not support CMYK colors.

Might be a joke, humor can be difficult to convey in forum post form, And I am that stereotypical sort who often does not get humor. But I will bite. It is a printed book... there is no color in the process.

I don't think it's a joke, for the general case of print this is indeed a problem as the whole print industry runs on CMYK. You could go further and say that because CSS/Weasyprint doesn't have a Pantone plugin, it'll be difficult to control colour accuracy throughout the production process. You're right this isn't necessary for most novels, but it's a very real concern for print media.

Re: Laying Out a Print Book with CSS

#40
post #17

One serious problem is that CSS do not support CMYK colors.

CSS Color Module Level 5 https://drafts.csswg.org/css-color-5/> adds @color-profile for ICC profiles (which may cover CMYK), and device-cmyk() for uncalibrated CMYK colours.

Sure, browser support isn’t there yet, and this is still draft work, but it’s coming.

Post reply on HN