Skip to content

Instantly share code, notes, and snippets.

@eXeC64
Last active December 21, 2015 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eXeC64/6265134 to your computer and use it in GitHub Desktop.
Save eXeC64/6265134 to your computer and use it in GitHub Desktop.
Book formatting example
pandoc -S -o book.epub title.txt chapter01.md chapter02.md chapter03.md
pandoc --template=template.tex -o book.pdf title.text chapter01.md chapter02.md chapter03.md
Chapter 1's Title
=================
This is how the actual text of the book is written.
I put each sentence on a new line, but you don't have to.
The advantages of this are that it's really easy to reorder sentences or delete them.
New paragraphs are separated by an empty line.
So this would be yet another new paragraph.
I can italicise text by *surrounding* it with *asterisks*.
I can make it bold by using **two** asterisks.
I can underline it with _underscores_.
I could put all the chapters in a single file, by just creating another heading for a new chapter.
I prefer to have each chapter in a separate file though, it keeps things nice and tidy.
You can read more about markdown formatting and what pandoc supports on their website: http://johnmacfarlane.net/pandoc/index.html
More information
================
This is just another file, used as an example.
I'll take the opportunity to describe how LaTeX is used here.
LaTeX is a typesetting system that, while a little tricky to learn, generates really beautiful documents in the hands of an expert.
However, we don't need to be an expert to take advantage of it.
Pandoc can convert documents from many formats into many other formats, including markdown -> latex
With the correct software installed the latex file can be turned into a pdf.
I actually use Linux which makes this very easy, so I'm not sure what exactly you'll need to install to use latex on windows.
Pandoc's website ought to tell you.
template.tex is a file I wrote that acts as a template for pandoc when generating the latex file used to generate the pdf.
While not needed, I created one to set pagesize to a5 and use latex's book mode.
The template.tex I've included here is slightly simplified from the one I use, but will achieve the same effect.
Final notes
===========
Another thing worth mentioning is that pandoc can also create .doc and .docx files, if that's what your publisher demands.
It's a pretty nifty application, and free (as in free beer and freedom).
Oh, I almost forgot: title.txt is used to specify the book title and author, that's all.
What pandoc really does with the list of files provided is pretend they're all one long file, end on end, (so the order you give them in matters).
So title.txt is at the beginning, then there's each chapter file in turn, resulting in a continuous document that pandoc converts into other forms.chapter04.mdchapter04.mdchapter04.md
\documentclass[12pt,twoside,openany]{book}
\usepackage[a5paper]{geometry}
\usepackage[utf8]{inputenc}
\renewcommand*{\section}{\chapter}
\title{\textbf{$title$}}
\author{$author$}
\date{\today}
\begin{document}
\frontmatter
\maketitle
\mainmatter
$if(toc)$
\tableofcontents
$endif$
$body$
\end{document}
% Book Name Here
% Book Author
% Date, which is optional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment