Hi. In this post, I want to share how I use Markdown and Pandoc to write my first book in Competitive Programming (not published yet).
What is Markdown?
Markdown is a lightweight markup language with plain-text-formatting syntax created in 2004. The philosophy behind Markdown is that plain text documents should be readable without tags messing everything up, but there should still be ways to add text modifiers like lists, bold, italics, etc.
Markdown is a must-have skill nowadays. If you haven’t learned Markdown yet, you should do it now.
What is Pandoc?
Pandoc is a free and open-source document converter, widely used as a writing tool (especially by scholars) and as a basis for publishing workflows. It can take a document in one of the supported formats and convert only its markup to another format. It supports many different formats.
Why Markdown + Pandoc?
When I first thought about writing a book, two things came to my mind: Microsoft Word and LaTeX. Word is easier to use, but it lacks too many features (e.g. code syntax highlighting). In contrast, LaTeX has everything but takes way too much time to learn.
I want something that has the ease of use of Word and the flexibility of LaTeX. Markdown + Pandoc is the perfect choice. As I have been using Markdown for years, I can start writing my book immediately.
Pandoc allows you to customize your book with templates. The default template by Pandoc is not very good. After some searching, I found this wonderful post by Ryan Frazier. Based on his templates, I made some small changes to better suit my needs. You can find my template here.
Let’s start writing
Use whatever editor you want. I prefer Visual Studio Code.
There are scripts to output PDF, EPUB, and HTML. To compile your book, run:
For example, to output PDF, I would run: