Live data from Hacker News

Using Web Technologies to Print a Book

richardmavis.info

61–69 of 69 posts

Re: Using Web Technologies to Print a Book

#61
post #58
post #41

Earlier quoted context omitted.

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.

There are a whole bunch of similar tools written in all sorts of languages, and OP just chose what he's most familiar with. It just happened to be different from your favorite toolchain.

It also looks like OP's book was split into several Markdown files, one for each chapter. So he would have needed some sort of build script anyway if he wanted to use texme on the combined document. He would also have needed more than a single line of code in the header, since he wanted some custom styling for blockquotes and code snippets.

Re: Using Web Technologies to Print a Book

#62
A random though, but you could use a horizontal rule (``) to split sections instead of the making a paragraph and filtering. They're part of the markdown syntax (using 3 or more hyphens, asterisks, or underscores) and you probably wouldn't even have to filter them out. Just use CSS. I'm actually pretty sure it's the semantic use case for them anyways. That's assuming, of course, that you don't use them elsewhere for other reasons.

Other than the unsolicited advise, I really like the workflow. I did something similar for almost all of my papers in college.

Re: Using Web Technologies to Print a Book

#63
post #10

GitBook PressBooks are also very affordable and great options that are built with web technologies and are slightly less manual. https://www.gitbook.com/ https://pressbooks.com/ GitBook is targeted at people creating technical documentation in Markdown. It has the advantage of git integration so it’s possible to branch & merge your way through a book project. Their GitHub account still hosts the legacy open source ed…

Pressbooks looks like the CDBaby or DistroKid of book publishing. Neat!

Re: Using Web Technologies to Print a Book

#64
post #14
post #4

This doesn't work for Linux, but for folks writing a novel, I can definitely recommend Scrivener (Mac and Windows). In addition to a powerful writing environment, it's "Compile" feature can output flexibly for print and ebooks. I generated hardcover, paperback, mobi, and epub, with enough customizability for me and no scripting required. Granted this is Hacker News and people here _like_ writing code (myself included…

I've not used it in years but I know there was a Linux version available for download from the support forums. It had a few issues but it worked really well when I tried it ~2 years ago on Ubuntu 14.04

It hasn't been updated in years and is broken on modern distros.

There's an open source clone called Manuskript though.

Re: Using Web Technologies to Print a Book

#66
post #28

Unsolicited code review: system("multimarkdown -s ../#{part}/story.md | sed -E 's/_([^_]+)_/ \\1 /g' | sed -E 's/ //g' | sed 's/ % / % /g' > output-#{part}.html") IMO: s_ % _ % _g is easier to read than: s/ % / % /g Any reason to keep the %-sign? Those sed commands could probably be reduced to one invocation of sed(1) instead of three. system("cat #{htmls} | #{wkhtmltopdf_cmd} --footer-html footer.html - body.pdf") N…

You're right -- good suggestions. Thanks.

Re: Using Web Technologies to Print a Book

#67

A random though, but you could use a horizontal rule (` `) to split sections instead of the making a paragraph and filtering. They're part of the markdown syntax (using 3 or more hyphens, asterisks, or underscores) and you probably wouldn't even have to filter them out. Just use CSS. I'm actually pretty sure it's the semantic use case for them anyways. That's assuming, of course, that you don't use them elsewhere for…

Great idea! Thanks.

Re: Using Web Technologies to Print a Book

#68
post #35
post #32

I clearly missed something, but why are you not going markdown -> PDF directly? That's what we use extensively in our operations playbooks at work and it gives something that looks like I'd get in a book - even more so after I tweaked the templates a little.

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.

> Because the user in question does not know {fill in the blank}

True.

> and is unwilling to learn how to design anything if it is not web technology.

False and does not follow.

Re: Using Web Technologies to Print a Book

#69
post #19

Earlier quoted context omitted.

Apache FOP[1] does[2] if you're willing to jump back in time to XHTML or use an HTML2FO converter. As always, Unicode is a problem. 1: https://xmlgraphics.apache.org/fop/ 2: https://xmlgraphics.apache.org/fop/0.95/hyphenation.html cf. https://wiki.apache.org/xmlgraphics-fop/HowTo/HtmlToPdf

That's Knuth-Liang hyphenation, which is something different from Knuth-Plass line breaking.

Oh, good catch, sorry about that.

Simon Pepping did some work done on Knuth-Plass in FO, but it's old and probably not quite as relevant now:

- https://web.archive.org/web/20070114211331/http://www.leverk...

- https://web.archive.org/web/20070128145517/http://www.leverk...

Post reply on HN