20101209

Commented Version of the LaTeX File to Create PDF ebooks and A6 Booklets

Below you can find a commented version of the LaTeX template I used to create two free ebooks and A6 booklets. Now you can tweak it as much as you like it!

The syntax highlighted TeX code comes from the htmlize package in emacs, to keep with my emacs 30 Day Challenge.

\documentclass[9pt,openany,final]{memoir}
% Set the font size with 9pt. Openany states that a chapter may start
% in either page (recto or verso in publishing language). Final is the
% way to say memoir to remove any comment crap we may have
\usepackage[pdftex]{graphicx}
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage[latin1]{inputenc}
\usepackage{wrapfig}
\usepackage{fix-cm}
% fix-cm is a package to use arbitrary font sizes. I wrote about it in
% http://www.mostlymaths.net/2009/03/big-fonts-in-latex.html
\usepackage[pdftex, colorlinks=true, linkcolor=black,
urlcolor=blue
]{hyperref}
% hyperref makes for clickable links inside a pdf and the table of
% contents. You can choose different colors as showed
\usepackage[activate={true,nocompatibility}]{microtype}
% Microtype allows you to make a lot of nasty things to typography:
% adjust kern spacing, font protrusion and font expansion. I think I
% don't use it here (I use the fix-cm version), but the original
% template I used did
\usepackage[paperwidth=9cm, paperheight=12cm, hmargin={1cm, 1cm},
vmargin={1.2cm, 0.8cm}
]{geometry}
% The geometry package allows you to set paper sizes. I tweaked it a
% little until the size looked good. You can leave it as is and tweak
% once you have everything written.
\widowpenalty 3999
\clubpenalty 3999
% Options for word and line breaking
\makeoddfoot{ruled}{}{}{}
\makeevenfoot{ruled}{}{}{}
% memoir options for footers. I leave them empty, with a ruled line
\makeevenhead{ruled}{\footnotesize
\emph{\rightmark}}{}{\footnotesize\scshape The Art of War, \thepage}
% Headings from memoir (even)
\makeoddhead{ruled}{\footnotesize
\emph{\rightmark}}{}{\footnotesize\scshape The Art of War, \thepage}
% Headings from memoir (odd)
\copypagestyle{chapter}{plain}
% This copies the page style from "plain" to the first page of a
% chapter. A hack in the memoir class, redefining chapter didn't work
\makeevenfoot{chapter}{}{}{}
\makeoddfoot{chapter}{}{}{}
% Clean footers for chapters
\pagestyle{ruled}
% I don't know why I state this, as all headings are already ruled.
\emergencystretch=\maxdimen
\hyphenpenalty=10
\hbadness=10000
% More options for line and word breaking
\setcounter{errorcontextlines}{999}
% I used this for debug purposes. Can be removed
\definecolor{gray}{gray}{0.77}
\definecolor{darkgray}{gray}{0.4}
\definecolor{black}{gray}{0}
% Color definitions in grayscale
\setlength\beforechapskip{-10pt}
\setlength\midchapskip{5pt}
\setlength\afterchapskip{10pt}
% These lengths are standard memoir names used for chapters. I just
% tweaked the values until I liked the result.

% Now I define a new chapter style, to be used through all the
% document. I think the commands are self-explanatory: I use
% renamecommand to change how the chapter will look like

\makechapterstyle{plroman}{
\renewcommand\chapterheadstart{\vspace*{\beforechapskip}
{
\color{darkgray}\centering\MakeUppercase
{
\fontsize{0.7in}{0.7in}\selectfont\romannumeral\thechapter}
\par\nobreak\vskip1\midchapskip\hrule\vskip0.5\midchapskip}\color{black}}
\renewcommand\chapternamenum{}
\renewcommand
\printchaptername{}
\renewcommand\printchapternum{\centering\MakeUppercase
{
\fontsize{1in}{2in}\selectfont\romannumeral\thechapter}}
\renewcommand\chaptitlefont{\huge\centering\color{black}
\vskip
0.5\midchapskip\vskip0.5\midchapskip}
\renewcommand\afterchapternum{}
\renewcommand\afterchaptertitle{\vskip0.5\midchapskip\vskip\midchapskip
\hrule
\vskip\midchapskip\vskip\midchapskip\vskip\midchapskip}
}
% Use this chapter style
\chapterstyle{plroman}
% Some more chapter & table of content redefinitions
\renewcommand{\cftchapterfont}{\scshape\mdseries}
\renewcommand{\cftchapterleader}{\dotfill}
\renewcommand{\cftchapterpagefont}{\scshape\mdseries}
\renewcommand{\chapternumberline}[1]{\hspace*{-5em}
\vbox{\hfil\hsize=7.5em\MakeUppercase
{\mdseries\romannumeral#1}.\
\hfilneg}}
\renewcommand
{\cftchapterbreak}{}

\begin{document}
% Now the content!
\include{taow}
\end{document}
Be sure to check the free ebooks I posted using this template: The Art of War and How to Live on 24 Hours a Day.

Related posts:
Written by Ruben Berenguel