Live data from Hacker News

Writing a Book with Pandoc, Make, and Vim

keleshev.com

11–20 of 61 posts

Re: Writing a Book with Pandoc, Make, and Vim

#12
post #7

Can you refer to figures and have the name rendered? For instance, a piece of text referring to a figure and the figure’s label will both get rendered to “Figure 2.8” regardless of paragraph edits and figures inserted or delete before it?

So far, I got away with "In the following figure…"

Re: Writing a Book with Pandoc, Make, and Vim

#13
post #7

Can you refer to figures and have the name rendered? For instance, a piece of text referring to a figure and the figure’s label will both get rendered to “Figure 2.8” regardless of paragraph edits and figures inserted or delete before it?

For anything beyond the most basic document, use Acsiidoc rather than Markdown.

I prefer to use the Asciidoctor toolchain, but it's compatible with Acsiidoc.

Re: Writing a Book with Pandoc, Make, and Vim

#14
I was building a new API recently, and was looking for a good documentation solution.

The commercial cloud based solutions (Gitlab, Confluence, et al) are pretty good, but you have to keep paying or your documentation disappears. Self hosted Wiki or documentation solutions were also out, due to the pain of migrating content in and out.

We ended up with a very simple solution of Markdown + CSS + Pandoc + make. Pandoc takes the CSS and MD files as input, and outputs HTML. The MD files are in the API repository, deployment has been setup so that the latest documentation is deployed automatically with each API update.

Re: Writing a Book with Pandoc, Make, and Vim

#15
It's even possible to replace (Xe)LaTeX with weasy¹, a Python HTML-to-PDF converter. It supports two-colums via CSS, automatic CSS hypens, CSS page counters and embedding SVGs. I just needed an HTML header with CSS in the markdown file.

    $ pandoc --filter pandoc-citeproc --csl ieee.csl --bibliography=paper.bib --smart --normalize -f markdown+multiline_tables+inline_notes -t html5 -V margin-top:0.5in -V margin-bottom:0.5in -V margin-left:0.5in -V margin-right:0.5in -o output.html input.md
    $ python3 -c "from weasyprint import HTML; HTML('output.html').write_pdf('output.pdf', presentational_hints=True)"
For LaTeX-style math equations I added mathjax-pandoc-filter² as filter to the pandoc args:

    --filter ~/node_modules/.bin/mathjax-pandoc-filter -Mmathjax.centerDisplayMath -Mmathjax.noInlineSVG
¹ https://weasyprint.org/ ² https://github.com/lierdakil/mathjax-pandoc-filter

Re: Writing a Book with Pandoc, Make, and Vim

#16
Books are not files though!

Pandoc is great. make and vim are great too, but as you can see these tools will produce PDF files, HTML files, text files, markdown files and a lot jargon that the readers simply aren’t interested in. I mean normal readers here and not tech folks holed up inside a terminal with a homebrew theme.

Re: Writing a Book with Pandoc, Make, and Vim

#17
post #14

I was building a new API recently, and was looking for a good documentation solution. The commercial cloud based solutions (Gitlab, Confluence, et al) are pretty good, but you have to keep paying or your documentation disappears. Self hosted Wiki or documentation solutions were also out, due to the pain of migrating content in and out. We ended up with a very simple solution of Markdown + CSS + Pandoc + make. Pandoc…

Excuse me if this is a dumb question but did you consider swagger?

Re: Writing a Book with Pandoc, Make, and Vim

#18

It's even possible to replace (Xe)LaTeX with weasy¹, a Python HTML-to-PDF converter. It supports two-colums via CSS, automatic CSS hypens, CSS page counters and embedding SVGs. I just needed an HTML header with CSS in the markdown file. $ pandoc --filter pandoc-citeproc --csl ieee.csl --bibliography=paper.bib --smart --normalize -f markdown+multiline_tables+inline_notes -t html5 -V margin-top:0.5in -V margin-bottom:0…

This is a very interesting (open source) project that I didn’t know about; thank you for mentioning it.

But it doesn’t replace LaTeX, as it doesn’t produce the same results. A glance at the sample documents reveals the ugly typography resulting from the word-processing layout strategy employed in web browsers. This is confirmed in the documentation. So this could be useful if you have an existing set of HTML pages that you need to convert to PDFs, but, if you’re starting a project where you want to produce both HTML and PDF, this should not be part of the solution.

Re: Writing a Book with Pandoc, Make, and Vim

#19

It's even possible to replace (Xe)LaTeX with weasy¹, a Python HTML-to-PDF converter. It supports two-colums via CSS, automatic CSS hypens, CSS page counters and embedding SVGs. I just needed an HTML header with CSS in the markdown file. $ pandoc --filter pandoc-citeproc --csl ieee.csl --bibliography=paper.bib --smart --normalize -f markdown+multiline_tables+inline_notes -t html5 -V margin-top:0.5in -V margin-bottom:0…

Pandoc can even free you of the second step by using WeasyPrint as PDF engine:

    pandoc --pdf-engine=weasyprint -t html …

Re: Writing a Book with Pandoc, Make, and Vim

#20
Nice and thanks for sharing your setup. The footer is very informative, but I use GitHub style markdown, need to check if there's some workaround. For epub customization, this article [0] might help. Good luck for your book.

Here's how I generate PDF with pandoc+xelatex [1] I use gvim as my editor and have mapped a key (which then executes a shell script) to generate the book.

[0] https://cmichel.io/how-to-create-beautiful-epub-programming-...

[1] https://learnbyexample.github.io/tutorial/ebook-generation/c...

Post reply on HN