Live data from Hacker News

Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

news.ycombinator.com

11–20 of 58 posts

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#11
post #6

I'm surprised Pandoc didn't fit the bill. It's quite configurable with fenced attributes. I switched from using MD-->(Pandoc-->(latex))--> PDF to using MD-->(Pandoc-->(typst))--> PDF.

I read quite a few people gushing about Pandoc in a similar thread. I have to look into it, as I have similar needs as the OP.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#13
post #2

Does converting to HTML first and then to PDF help?

This is what I have done for a couple of books I wrote in Markdown ( https://deanebarker.net/books/ ). Convert to HTML, then use Prince ( https://www.princexml.com/ ) to style and convert to PDF.

Their licenses are pretty expensive. Any good free open source alternatives?

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#15
I worked on a 500+ page book[1] in Pandoc that included a bunch of code samples, math, a table of contents with working links and an index. (In hindsight, I wish we had thought about the index from the beginning rather than adding it after the fact.)

What worked well for me: Pandoc with a custom LaTeX template, and a decent amount of inline LaTeX to handle edge cases. We had a LaTeX theme to use from our publisher, but we also needed our own totally separate theme for the free version version of the book.

For one-off things like really long code lines, I found it best to manually figure out how to handle them. Sometimes there was a bit of TeX magic but, more often, I just rewrote or reorganized the code. I see the presentation and structure of code and math snippets as an integral part of how I'm communicating the underlying ideas, so manually changing things around to read better was fundamentally no different from going back and editing prose.

Unfortunately, this also means that the process was relatively hands-on. If you need something ≈completed automated, I expect Pandoc → LaTeX is going to fall a bit short. Edge cases need manual intervention, and it's easy for formatting errors to sneak in—the free version of our book has some formatting mistakes like code bleeding into the margin because I ran out of energy to fix all of them!

[1]: https://github.com/TikhonJelvis/RL-book

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#16
Typora is the best I've used. It's a GUI, but it's pretty fantastic for a GUI Markdown editor (especially an Electron one), and its PDF export is consistent and customizable with styles. Includes a few good ones out of the box. Plus an automated TOC.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#17
post #13

Earlier quoted context omitted.

This is what I have done for a couple of books I wrote in Markdown ( https://deanebarker.net/books/ ). Convert to HTML, then use Prince ( https://www.princexml.com/ ) to style and convert to PDF.

Their licenses are pretty expensive. Any good free open source alternatives?

If it looks correct in a browser, then chromium + playwright.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#19
post #9

I think you're overcomplicating it. I assume you created this markdown file and I assume you have a preview render that shows it the way you like it to be shown. So just hit the print button, and in the print dialog select save as PDF.

You are right if OP want to do this manually. If not I guess it is much more complicated, you would need some tool that allows you to print rendered markdown. Add one more step: convert print to PDF and effectively you have tool to convert markdown to PDF.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#20
Have you explored the AST (abstract syntax tree) tools yet, like Mdast and the related remark and micromark?

https://github.com/syntax-tree/mdast-util-from-markdown

It might work better if you parse it into an intermediary Mdast format first, do whatever processing you need to implement "pages" (not a part of any Markdown dialect I'm familiar with?" but it shouldn't be hard to write a custom parser for that in Mdast), output that to HTML (via https://github.com/syntax-tree/mdast-util-to-hast) and THEN convert the HTML to PDF.

The AST tools basically give you structured JSON that's much easier to work with programmatically than raw Markdown. Then you can render that semantic JSON into HTML or other outputs.

Post reply on HN