%%% MEMOIR CLASS %%%
\documentclass[twoside,12pt,openright,final,english]{memoir}
% Memoir Divisions: \book, \part, \chapter, \section, \subsection
% Fine divisions:   \subsubsection, \paragraph \subparagraph.
%%% END MEMOIR CLASS %%%

\usepackage{graphicx}
% For full size print graphics
%\graphicspath{{./images-original/}}
% For web quality out
\graphicspath{{./images-1600x1200/}}

\makeindex
\makeglossary
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

%%% PAGE, STOCK, AND MARGIN SIZE %%%
%\setstocksize{18.5cm}{12.5cm} % { height }{ width }
%\setstocksize{22.86cm}{15.24cm} % { height }{ width }
% Lulu 7.44 x 9.68"   18.90 x 24.58cm
\setstocksize{24.58cm}{18.90cm} % { height }{ width }
\settrimmedsize{\stockheight}{\stockwidth}{*}

%\settypeblocksize{ height }{ width }{ ratio }
\settypeblocksize{19.0cm}{*}{*}

%\setlrmarginsandblock{ spine }{ edge }{ ratio }
% make the spine have more space than outer edge
\setlrmarginsandblock{*}{2.5cm}{1.2}

% The command \setulmargins can be used to specify the upper and lower mar-
% gins where the heights of the page and the typeblock are fixed.
% \setulmargins{ upper }{ lower }{ ratio }
\setulmargins{2.0cm}{*}{*}

% \setheadfoot{ headheight }{ footskip }
\setheadfoot{12pt}{2cm}

%\isopage
%\checkandfixthelayout
\checkandfixthelayout[fixed]
%%% END PAGE, STOCK, AND MARGIN SIZE %%%

%%% INCLUDED FILES %%%
% select which chapters to render:
\newif\iftitle\titletrue
\newif\ifcopyright\copyrighttrue
\newif\ifwarnings\warningstrue
\newif\ifunpacking\unpackingtrue
\newif\ifsetup\setuptrue
\newif\ifsoftware\softwaretrue
\newif\iffilament\filamenttrue
\newif\iffirstprint\firstprinttrue
\newif\ifmaintenance\maintenancetrue
\newif\ifadvanced\advancedtrue
\newif\iffaq\faqfalse
\newif\iftroubleshooting\troubleshootingfalse
\newif\ifsource\sourcetrue
\newif\ifsupport\supporttrue
\newif\ifcontact\contacttrue
\newif\ifcolophon\colophontrue
%% or just render everything:
\newif\ifrendereverything\rendereverythingfalse
\ifrendereverything \titletrue \copyrighttrue \warningstrue \unpackingtrue \setuptrue \softwaretrue \filamenttrue \firstprinttrue \maintenancetrue \advancedtrue \faqtrue \troubleshootingtrue \colophontrue \fi
%%% END INCLUDED FILES %%%

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\usepackage[english]{babel}

% WTF?
\usepackage{ucs}

%%% PDFLATEX %%%
% fixes "no room for a new \count" error
\usepackage{etex}

\usepackage[protrusion,expansion,spacing,kerning,babel,final]{microtype}
\usepackage[utf8x]{inputenc}

%%% FONT FONT FONT %%%
% Set default fontsize to 12.5pt and baseline to 15pt
%\renewcommand{\normalsize}{\fontsize{12.5pt}{15pt}}
% LY1 Encoding, per otftotfm

%\usepackage[LY1]{fontenc}
%\renewcommand{\rmdefault}{IM_FELL_DW_Pica_PRO}
%\renewcommand{\bfdefault}{b}

%\defaultfontfeatures{Numbers=OldStyle}
%%% END FONT FONT FONT %%%

%%% LEDMAC %%%
\usepackage{ledmac}
%%% END LEDMAC %%%

%%% PAGE STYLE %%%
\makepagestyle{jebstyle}
\pagestyle{jebstyle}
% HEADER
\makeevenhead{jebstyle}{}{\hspace{2em}\itshape\small\leftmark}{} % KLUDGE
\makeoddhead{jebstyle}{}{\scshape\small\rightmark}{}
% FOOTER
\makeevenfoot{jebstyle}{}{\hspace{2em}\thepage}{} % KLUDGE
\makeoddfoot{jebstyle}{}{\thepage}{}
%%% END 

%%% jebinski CHAPTER STYLE %%%
\makechapterstyle{jebinski}{%
% Clear out the chapter name (e.g. capítulo)
  \renewcommand*{\printchaptername}{}
% Clear out the chapter number
  \renewcommand*{\printchapternum}{}
% Set chapter font
  \renewcommand*{\chaptitlefont}{\normalfont\large\scshape}
  \renewcommand*{\printchaptertitle}[1]{%
     \hrule\vskip\onelineskip \centering \chaptitlefont{##1}\par}
  \renewcommand*{\afterchaptertitle}{\vskip\onelineskip \hrule\vskip
     \afterchapskip}
}
%%% END jebinski CHAPTER STYLE %%%

%%% FORMATTING KLUDGES %%%
% fewer overfull lines compared with \fussy and fewer obvious
% large interword spaces than with \sloppy.
\midsloppy
% "fix" for Overfull \hbox
%\emergencystretch=8pt
\setlength{\emergencystretch}{3em}  % 3em
% Prints out a block on overfull hbox lines
%\overfullrule=5pt
%
% \tolerance is a paragraph parameter, probably ignored here
\tolerance=5000 % allow looser spacing 
%\tolerance=95000 % allow waaay looser spacing 
%
% 10000 almost prevents hyphenation. What's default?
\hyphenpenalty=500 % 500 seems reasonable
%
%the default \flushbottom
%\sloppypar
\setlength{\topskip}{1.6\topskip}
\checkandfixthelayout
%\sloppybottom
\raggedbottom

%%%%%%%% WIDOWS AND ORPHANS %%%%%%%%%%%
\widowpenalty=10000
\clubpenalty=10000
%%%%%%%% END WIDOWS AND ORPHANS %%%%%%%%%%%


%%% END FORMATTING KLUDGES %%%

%%% FOOTNOTES %%%
% no horizontal rule before footnotes:
\let\oldfootnoterule\footnoterule
\renewcommand*{\footnoterule}{}
% This indents the footnote, or it lines up too far to the
% left on the spanish side. The right page note should really
% move over more to the left
% KLUDGE
\setlength{\footmarkwidth}{3.5em}
%%% END FOOTNOTES %%%

%%% Fancy dings %%%
\usepackage{pifont}

%%% DEBUG %%%
%\showoutput
%\typeoutlayout
%\typeoutstandardlayout
%%% END DEBUG %%%

%%% END OF PREAMBLE %%%

\begin{document}

%%% BLANK PAGE %%%
%\selectlanguage{english}%
%\thispagestyle{empty}
%\begingroup 
%\vfill\null 
%\endgroup
%%% END BLANK PAGE %%%

%%% BEGIN FRONT MATTER %%%
\frontmatter

% Set page numbers to lowercase roman numerals, and reset the count to 1 (no *)
\pagenumbering{roman}

%%% TITLE PAGE %%%
% We want the title to be on the right hand page.
% If we pad a page, it gives us two with openright
\iftitle
{\include{Title}}
\fi
%%% END TITLE PAGE

%%% COPYRIGHT PAGE %%%
\ifcopyright
{\include{Copyright}}
\fi
%%% END COPYRIGHT PAGE %%%


%%% TABLE OF CONTENTS ToC %%%
\maxtocdepth{section}
% clear "Contents" header
%\renewcommand*{\contentsname}{}
%\renewcommand*{\tocheadstart}{}
%
% This disables printing the chapter number next to the chapter
%\renewcommand{\chapternumberline}[1]{}
%
% Font
%\renewcommand{\cftchapterfont}{\normalfont\footnotesize}
% page number font
%\renewcommand{\cftchapterpagefont}{\normalfont\footnotesize}
%
% Dots
% space between dots
\renewcommand{\cftchapterdotsep}{15}
% dot symbol (default is period)
\renewcommand{\cftdot}{\textperiodcentered}	% centered period
%
% Set space between each entry in ToC
\setlength{\cftbeforechapterskip}{5pt}  % 5pt % 3pt
%
\tableofcontents*
%\tableofcontents
%
% Clear page number on table of contents. Must be *after* \tableofcontents*
%\thispagestyle{empty}
%%% END TABLE OF CONTENTS ToC %%%

%%% LIST OF FIGURES %%%
\clearpage
\listoffigures*
%%% END LIST OF FIGURES %%%

%%% CHAPTER STYLE %%%
\chapterstyle{jebinski} % defined in preamble
%%% END CHAPTER STYLE %%%


%%% WARNINGS %%%
\def\topblockvspace{0.11}
\ifwarnings
\chapter{\emph{WARNINGS}\protect \\
{Safety Information}}
\thispagestyle{empty}
\markboth{WARNING!}{Be Safe!}
{\include{Warnings}}
\fi
%%% END WARNINGS %%%

%%% END FRONTMATTER %%%
%%% BEGIN MAINMATTER %%%
\mainmatter*

% Set page numbering to arabic, but don't reset numbering (*)
\pagenumbering*{arabic}

%%% UNPACKING %%%
\def\topblockvspace{0.11}
\ifunpacking
\chapter{\emph{Unpacking Your Printer}}
\thispagestyle{empty}
\markboth{Unpacking Your Printer}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Unpacking}}
\fi
%%% END UNPACKING %%%

%%% SETUP %%%
\def\topblockvspace{0.11}
\ifsetup
\chapter{\emph{Setup Your Printer}}
\thispagestyle{empty}
\markboth{Setup Your Printer}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Setup}}
\fi
%%% END SETUP %%%

%%% SOFTWARE %%%
\def\topblockvspace{0.11}
\ifsoftware
\chapter{\emph{3D Printer Software}}
\thispagestyle{empty}
\markboth{3D Printer Software}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Software}}
\fi
%%% END SOFTWARE %%%

%%% FILAMENT %%%
\def\topblockvspace{0.11}
\iffilament
\chapter{\emph{Loading Filament}}
\thispagestyle{empty}
\markboth{Loading Filament}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Filament}}
\fi
%%% END FILAMENT %%%

%%% FIRSTPRINT %%%
\def\topblockvspace{0.11}
\iffirstprint
\chapter{\emph{Your First 3D Print}}
\label{firstprint}
\thispagestyle{empty}
\markboth{Your First 3D Print}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Firstprint}}
\fi
%%% END FIRSTPRINT %%%

%%% MAINTENANCE %%%
\def\topblockvspace{0.11}
\ifmaintenance
\chapter{\emph{Maintaining Your 3D Printer}}
\thispagestyle{empty}
\markboth{Maintaining Your 3D Printer}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Maintenance}}
\fi
%%% END MAINTENANCE %%%

%%% ADVANCED %%%
\def\topblockvspace{0.11}
\ifmaintenance
\chapter{\emph{Advanced Usage}}
\thispagestyle{empty}
\markboth{Advanced Usage}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Advanced}}
\fi
%%% END ADVANCED %%%

%%% FAQ %%%
\def\topblockvspace{0.11}
\iffaq
\chapter{\emph{FAQ}}
\thispagestyle{empty}
\markboth{FAQ}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{FAQ}}
\fi
%%% END FAQ %%%

%%% TROUBLESHOOTING %%%
\def\topblockvspace{0.11}
\iftroubleshooting
\chapter{\emph{Troubleshooting}}
\thispagestyle{empty}
\markboth{Troubleshooting}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Troubleshooting}}
\fi
%%% END TROUBLESHOOTING %%%

%%% SOURCE %%%
\def\topblockvspace{0.11}
\ifsource
\chapter{\emph{Hardware and Software Source Code}}
\thispagestyle{empty}
\markboth{Hardware and Software Source Code}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Source}}
\fi
%%% END SOURCE %%%

%%% SUPPORT %%%
\def\topblockvspace{0.11}
\ifsupport
\chapter{\emph{3D Printer Support}}
\thispagestyle{empty}
\markboth{3D Printer Support}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Support}}
\fi
%%% END SUPPORT %%%

%%% CONTACT %%%
\def\topblockvspace{0.11}
\ifcontact
\chapter{\emph{Contact Information}}
\thispagestyle{empty}
\markboth{Contact Information}{LulzBot\textsuperscript{\miniscule{\texttrademark}} AO-100 User Manual}
{\include{Contact}}
\fi
%%% END CONTACT %%%

%%% END MAINMATTER %%%
%%% BEGIN BACKMATTER %%%
\backmatter

%%% INDEX %%%
\clearpage
\printindex
%%% END INDEX %%%

%%% GLOSSARY %%%
% Presently disabled, until filled
% Sample:
%\glossary{glossary}{A list of terms and their descriptions.}
%\clearpage
%\printglossary
%%% END GLOSSARY %%%

%%% COLOPHON %%%
\ifcolophon
%%% skip a couple pages
\pagebreak{}
\thispagestyle{empty}
\begingroup 
\vfill\null 
\endgroup
\pagebreak{}
\thispagestyle{empty}
{\include{Colophon}}
\fi
%%% END COLOPHON %%%
%%% END BACKMATTER %%%

%%% BLANK PAGES Lulu requires minimum 68 pages %%%
\thispagestyle{empty}
\begingroup
\newpage
\mbox{}
\thispagestyle{empty}
\newpage
\mbox{}
\thispagestyle{empty}
\newpage
\mbox{}
\thispagestyle{empty}
\newpage
\endgroup
%%% END BLANK PAGE %%%

\end{document}

