TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: What's the best way to write a book in Markdown?

27 pointsby JSLegendDevover 1 year ago
What are the best available tools to use if I want to write a book in markdown and export it as a pdf primarly?<p>It needs to handle displaying code well as I want to write a technical book.

16 comments

jjiceover 1 year ago
Sorry for the SO like answer, but id recommend not thinking very hard about PDF compilation of you&#x27;re writing in markdown, for now.<p>I&#x27;ve done something similar but I burnt so much time on configuring Pandoc, citations, formulas, and a compilation process, instead of writing the actual book. If you&#x27;re writing in Markdown, most of this process for you can be done at the end too.<p>With that said, Pandoc has been great. Gotta dive into some configuration to get things how you want for the finalized PDF, but it&#x27;s great.
评论 #38234439 未加载
评论 #38244676 未加载
sylvain_kerkourover 1 year ago
Hey,<p>I&#x27;ve wrote a few books (<a href="https:&#x2F;&#x2F;kerkour.com&#x2F;books" rel="nofollow noreferrer">https:&#x2F;&#x2F;kerkour.com&#x2F;books</a>) with only markdown, <a href="https:&#x2F;&#x2F;excalidraw.com" rel="nofollow noreferrer">https:&#x2F;&#x2F;excalidraw.com</a> and <a href="https:&#x2F;&#x2F;figma.com" rel="nofollow noreferrer">https:&#x2F;&#x2F;figma.com</a><p>I&#x27;ve detailed my complete setup and shared the Dockerfile that I use to convert the markdown into ebooks (EPUB, PDF and Kindle) on my blog: <a href="https:&#x2F;&#x2F;kerkour.com&#x2F;book-self-publishing-pandoc" rel="nofollow noreferrer">https:&#x2F;&#x2F;kerkour.com&#x2F;book-self-publishing-pandoc</a>
评论 #38242348 未加载
ThePhysicistover 1 year ago
I use Weasyprint [1] to generate a PDF from HTML, and I use a self-written static site generator based on Python &amp; Jinja2 to convert Markdown to HTML first [2] (note: that code is undocumented and only used by me). Weasyprint can handle code highlighting e.g. using Pygments or another static framework, the only downside is it can&#x27;t execute JS so if you e.g. want to dynamically generate content to render like SVGs you need to first pass your HTML through a headless browser, which is also possible though. There&#x27;s also paged.js [3] which is similar but runs in the browser, so it supports JS-generated content out of the box. And as others have mentioned Pandoc [4] is the Swiss army knife of converting between document formats.<p>1: <a href="https:&#x2F;&#x2F;weasyprint.org&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;weasyprint.org&#x2F;</a> 2: <a href="https:&#x2F;&#x2F;github.com&#x2F;adewes&#x2F;beam-up">https:&#x2F;&#x2F;github.com&#x2F;adewes&#x2F;beam-up</a> 3: <a href="https:&#x2F;&#x2F;pagedjs.org&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;pagedjs.org&#x2F;</a> 4: <a href="https:&#x2F;&#x2F;pandoc.org&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;pandoc.org&#x2F;</a>
softwaredougover 1 year ago
I have found that for the needs of typesetting, citations, and other typically more &quot;advanced&quot; needs Markdown is not quite enough.<p>I recently contributed several chapters to a book. Years ago I wrote a book in MS Word. But this time around we used AsciiDoc. RestructuredText is another option.<p>I used MS Code&#x27;s AsciiDoc support, and it worked generally great.
crimsoncastleover 1 year ago
I was using Typora, but now I use Zettlr. It&#x27;s free for every desktop platform and open source. You can even search multiple files in your directory from a sidebar while you type, it provides writing stats, has file tagging, exports to anything Pandoc supported, and it also has code highlighting. Zettlr is so good. I&#x27;m pretty sure it&#x27;s what you are looking for.
评论 #38238480 未加载
tizio13over 1 year ago
Obsidian for sure. You can export the pdf with the same styling you see on screen.<p>You can also use it to make your book a knowledge base.<p>Check out their docs for an example of what can be achieved.<p><a href="https:&#x2F;&#x2F;docs.obsidian.md&#x2F;Home" rel="nofollow noreferrer">https:&#x2F;&#x2F;docs.obsidian.md&#x2F;Home</a>
评论 #38236428 未加载
评论 #38235787 未加载
condwanalandover 1 year ago
I use Quarto with .qmd files. I use the plugin for VS Code but you can also do the rendering straight through the command line. Absolutely love it, didn&#x27;t need to configure much, it just worked out of the box.
评论 #38254489 未加载
lurn_morover 1 year ago
If you&#x27;re coming from MD to HTML&#x2F;CSS version, I&#x27;d recommend reviewing my CSS snippets for print from web tips, and it&#x27;ll help with formatting and (more importantly) page breaks in your final PDF: <a href="http:&#x2F;&#x2F;www.undr.com&#x2F;understatement&#x2F;2020&#x2F;the_one_where_we_begrudgingly_upgrade_our_print_stylesheet&#x2F;index.html" rel="nofollow noreferrer">http:&#x2F;&#x2F;www.undr.com&#x2F;understatement&#x2F;2020&#x2F;the_one_where_we_beg...</a>
mark_l_watsonover 1 year ago
I like leanpub.com, I have written several books on the platform.
评论 #38236250 未加载
juliangmpover 1 year ago
I like writing markdown docs with mdbook, though I&#x27;ve never used it for something to be printed physically so I dont know how good&#x2F;bad PDFs or epubs would come out.<p>What I like about it is that its easily extendable. You can write preprocessors to give yourself new features or an entire backend&#x2F;renderer to render the book differently. I&#x27;ve written a very simple one myself.
billconanover 1 year ago
I&#x27;m currently doing it using pandoc<p><a href="https:&#x2F;&#x2F;komsciguy.com&#x2F;misc&#x2F;write-a-programming-book-with-markdown-and-pandoc&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;komsciguy.com&#x2F;misc&#x2F;write-a-programming-book-with-mar...</a>
beezooover 1 year ago
I wrote my thesis using Bookdown, an RMarkdown package. It might be useful if you require e.g. Latex notation rendering.<p>My pipeline went via a custom latex template which unlocks all the formatting power of latex without having to deal with it for the content.
Symbioteover 1 year ago
Asciidoc (using Asciidoctor) has several book-like things built in compared to Markdown.<p><a href="https:&#x2F;&#x2F;asciidoctor.org&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;asciidoctor.org&#x2F;</a>
deadcoder0904over 1 year ago
it is extremely complicated when it shouldn&#x27;t be. maybe someday someone will make a saas to solve this problem once &amp; forever.<p>i&#x27;ve wrote custom code for it that i&#x27;ll share maybe 1 day but not yet.<p>what i did was use markdown with node.js &amp; wrote a script that all chapters are read from it.<p>it looks like this:<p>_book&#x2F; chapter1&#x2F; pic1.jpg index.md chapter2&#x2F; . . . chapter100&#x2F;<p>and then it uses princexml with 100 loc of css to output a beautiful pdf.<p>this should definitely be a saas though. it has massive potential.
chewzover 1 year ago
Typora.. <a href="https:&#x2F;&#x2F;typora.io&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;typora.io&#x2F;</a><p>And keep each chapter as separate file…
thangalinover 1 year ago
My Typesetting Markdown series[1] describes crafting shell scripts to cobble together pandoc, knitr, math, ConTeXt, and YAML-based interpolated variables to produce PDF files.<p>For my sci-fi novel, my character sheet was inside of a spreadsheet. It dawned on me that the character sheet could be replaced with a YAML file and integrated with a Markdown editor. I developed KeenWrite[2] to replace the scripts while allowing me to use interpolated variables and R inside of the prose.<p>My novel has two separate timelines and I wanted to make sure that dates lined up correctly without having to do the date math manually. I implemented a number date functions in R[3] based around an &quot;anchor&quot; date. As long as all my other dates are relative (in days) to the anchor date, all the math checks out. Possessives and pronouns are also handled in R (meaning I can change a character&#x27;s gender by changing a single variable, provided I haven&#x27;t referenced any sex-specific body parts or characteristics).<p>Also, I wanted a nice-looking PDF file to send to alpha readers (still looking, see profile). For that, I crafted KeenWrite Themes[4] along with a video tutorial series showing how all the software components work together.<p>On the technical side, Markdown lacks a standard syntax for citations and cross-references. I&#x27;ve written about this at length.[6] If flexmark-java were to get support, then it would help resolve a long-standing issue with KeenWrite.[7]<p>[1]: <a href="https:&#x2F;&#x2F;dave.autonoma.ca&#x2F;blog&#x2F;2019&#x2F;05&#x2F;22&#x2F;typesetting-markdown-part-1&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;dave.autonoma.ca&#x2F;blog&#x2F;2019&#x2F;05&#x2F;22&#x2F;typesetting-markdow...</a><p>[2]: <a href="https:&#x2F;&#x2F;keenwrite.com&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;keenwrite.com&#x2F;</a><p>[3]: <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;DaveJarvis&#x2F;KeenWrite&#x2F;-&#x2F;blob&#x2F;main&#x2F;R&#x2F;conversion.R?ref_type=heads#L52" rel="nofollow noreferrer">https:&#x2F;&#x2F;gitlab.com&#x2F;DaveJarvis&#x2F;KeenWrite&#x2F;-&#x2F;blob&#x2F;main&#x2F;R&#x2F;conver...</a><p>[4]: <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;DaveJarvis&#x2F;keenwrite-themes&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;gitlab.com&#x2F;DaveJarvis&#x2F;keenwrite-themes&#x2F;</a><p>[5]: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PLB-WIt1cZYLm1MMx2FBG9KWzPIoWZMKu_">https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PLB-WIt1cZYLm1MMx2FBG9...</a><p>[6]: <a href="https:&#x2F;&#x2F;talk.commonmark.org&#x2F;t&#x2F;cross-references-and-citations&#x2F;4013" rel="nofollow noreferrer">https:&#x2F;&#x2F;talk.commonmark.org&#x2F;t&#x2F;cross-references-and-citations...</a><p>[7]: <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;DaveJarvis&#x2F;KeenWrite&#x2F;-&#x2F;issues&#x2F;145" rel="nofollow noreferrer">https:&#x2F;&#x2F;gitlab.com&#x2F;DaveJarvis&#x2F;KeenWrite&#x2F;-&#x2F;issues&#x2F;145</a>