Skip to content

Instantly share code, notes, and snippets.

@tedhagos
Created May 5, 2012 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tedhagos/2600723 to your computer and use it in GitHub Desktop.
Save tedhagos/2600723 to your computer and use it in GitHub Desktop.
My Latex Book Template
# Workflow and tool chain for writing a book for PDF publishing
## Toolchain
1. Pandoc, install using the cabal installer, don't apt-get. On OSX, there is dmg, I think the dmg is best option for OSX, it is just too problematic to get 1.9.2 cabal using brew or macports. There was one option I tried and succeeded, that is to install the Haskell environment using a package installer, that contained the cabal installer. Then install pandoc using cabal. Don't forget that the executables are in ~/.cabal/bin, so you have to set the path
2. TexLive, get the full distribution. It will take sometime to download, so get some coffee and be prepared to waste time
3. A good texteditor. ia Writer on OSX, vi (all around). Recently though, TextMate 2.0 Alpha seems to be a pretty good editor of Markdown
## Workflow
1. Write the source files using Pandoc Markdown
2. Each chapter of the book is broken down into a markdown file
3. Write your own buildfile to consolidate each chapter into a single book
4. Chapter compilation can be done on the buildscript, but essentially it just contains
4.1 pandoc --chapters -o targetfile.tex sourcefile.md
4.2 cat and append content of preamble.doc to tempfile
4.3 cat and append content of targetfile.tex to tempfile
4.3 append the closing "\end{document} to tempfile
4.4 copy back tempfile to targetfile.tex
5. compile to pdf using "pdflatex targetfile.tex"
## Workarounds
Not everything in Pandoc works as advertised (even in 1.9.2), so you need to sidestep some items a little bit. These are some of the things.
1. Inclusion of source codes
~~~~{#thecode .java .numberLines}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This code block produces a \begin{Shades} environment, which becomes problematic if you output partially to latex. You will need to define the {Shades} environment, and I did not know how.
-------
\lstinputlisting{sourcode.java}
This works in Pandoc, this is good to use for longer source codes
-----
\begin{lstlisting}
\end{lstlisting}
This does not work in Pandoc, for some reason it stops processing, so side step
-----
~~~ {#code}
~~~
This works nicely in Pandoc, it produces an \begin{lstlisting} properly in latex, so use this for really short code snippets
## My Latex Preamble
1. Section headings
\usepackage{sectsty}
\allsectionsfont{\sffamily}
\subsectionfont{\mdseries}
\sectionfont{\rmfamily\Large}
\usepackage[Sonny]{fncychap}
\ChTitleVar{\raggedright\Huge\ttfamily\bfseries}
2. Paragraph skipping
\usepackage{parskip}
Don't mess with the \parskip variable anymore, the output is fine.
3. Change the main body font to Palatino
\usepackage{palatino}
4. Inclusion of graphics
\usepackage{graphicx}
5. Side notes in the margin
\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\raggedleft\footnotesize #1]%
{\raggedright\footnotesize #1}}
6. Ditch the fancy headings, use \pagestyle{myheadings}
\pagestyle{myheadings}
\markright{Introduction to Java}
-----------
7. Embedding line drawings
\begin{figure} [htpb]
\centering
\includegraphics[width=50mm]{source/18-database-programming/jdbc.pdf}
\caption{JDBC and your app}
\label{jdbc}
\end{figure}
PDF seems to work best. EPS doesn't work with my installation of pdflatex, pstricks also don't work. Anyway, PDF is fine.
\documentclass[14pt]{report}
\usepackage{palatino}
\usepackage{verbatim}
\usepackage{parskip}
\usepackage{enumerate}
\usepackage{minitoc}
\usepackage{todo}
\usepackage{marginnote}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{courier}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{sectsty}
\allsectionsfont{\sffamily}
\subsectionfont{\mdseries}
\sectionfont{\rmfamily\Large}
\usepackage[Sonny]{fncychap}
\ChTitleVar{\raggedright\Huge\ttfamily\bfseries}
\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\raggedleft\footnotesize #1]%
{\raggedright\footnotesize #1}}
\lstset{tabsize=2,numbers=left,language=java,basicstyle=\footnotesize\ttfamily,showstringspaces=false,xleftmargin=17pt,numberstyle=\tiny}
\usepackage[top=2cm, bottom=3.3cm, left=3.2cm, right=4cm]{geometry}
\linespread{1.1}
%\reversemarginpar
\begin{document}
\pagestyle{myheadings}
\markright{Introduction to Java}
\title{Java Core Programming}
\date{Nov 2011}
\author{Ted Hagos\\
\texttt {tedhagos@gmail.com}
}
\maketitle
\dominitoc
\tableofcontents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment