Saturday, December 23, 2017

Formatted pdf output with MarkDown, Pandoc, and Latex.

I needed to create a document in a text format that would allow me to build a pdf that can be printed in a nice manner. I chose pandoc and markdown for the primary text file. I've managed to get it looking in the way that I want it, mostly.

The following header in my makdown file setups a twosided document with inner margin of 1.5in and the top, bottom, outer of 1.0in. The H1 and H2 sections (section/subsection) are using a different sized font and are centered on the page. I've needed to do multicolumn layout in a few places so there is a new command that does that for pandoc. The font is set for times and the default size is 12pt. The downside to this is that I've not been able to get the PDF bookmarks to have the correct page numbers yet. This prints nicely though.

I pulled all of this together from a bunch of StackOverflow/StackExchange question/answer.


---
subparagraph: yes
documentclass: article
fontfamily: times
fontsize: 12pt
geometry: twoside, outer=1.0in, inner=1.5in, top=1.0in, bottom=1.0in
header-includes:
 - \usepackage{titlesec}
 - \usepackage{multicol}
 - \usepackage{bookmark}
 - \titleformat*{\section}{\fontsize{16}{20}\filcenter\selectfont}
 - \titleformat*{\subsection}{\fontsize{13}{15}\filcenter\selectfont}
 - \newcommand{\hideFromPandoc}[1]{#1}
     \hideFromPandoc{
       \let\Begin\begin
       \let\End\end
     }
---

\pagenumbering{gobble}

Some text on an intro page

\newpage

   

\pagebreak

\pagenumbering{arabic}

# Begin header of page 1 of the new document

Multicols are done in the following manner. If doing a list use make sure the blank line is there after/before \Begin/\End. They won't format properly otherwise.


\Begin{multicols}{2}

1. Item 1
2. Item 2
3. Item 3
4. Item 4
5. Item 5

\End{multicols}

Here's the makefile that I created to build the document.
output.pdf: input.md
 pandoc -f markdown -t latex -o $@  $^

clean:
 rm -f *.pdf *~


No comments: