%%% 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{float}
\usepackage{comment}
\usepackage{graphicx}
\usepackage{epstopdf}
% For full size print graphics
%\graphicspath{{./images-original/}}
% For web quality output
\graphicspath{{./images-1600x1200/}}

\makeindex
%%% GLOSSARY
\makeglossary
%%% END GLOSSARY

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

%%% PAGE, STOCK, AND MARGIN SIZE %%%
% 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}

% \setulmargins{ upper }{ lower }{ ratio }
\setulmargins{2.0cm}{*}{*}

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

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

%%% INCLUDED FILES %%%
% select which chapters to render:
\newif\iftitle\titletrue
\newif\ifcopyright\copyrighttrue
\newif\ifwarnings\warningstrue %true
\newif\ifsetup\setupfalse %false
\newif\ifslicer\slicertrue %true
\newif\ifsoftware\softwaretrue %true
\newif\iffilament\filamentfalse %false
\newif\iffirstprint\firstprintfalse %false
\newif\ifglcd\glcdtrue %true
\newif\ifmaintenance\maintenancetrue %true
\newif\ifadvanced\advancedtrue %true
\newif\iffaq\faqfalse %false - Not yet written
\newif\iftroubleshooting\troubleshootingfalse %false - Not yet written
\newif\ifsource\sourcetrue %true
\newif\ifsupport\supporttrue %true
\newif\ifcontact\contacttrue %true
\newif\ifcolophon\colophontrue %true
%% or just render everything:
\newif\ifrendereverything\rendereverythingfalse
\ifrendereverything \titletrue \copyrighttrue \warningstrue \setuptrue \slicertrue \softwaretrue \filamenttrue \firstprinttrue \maintenancetrue \advancedtrue \faqtrue \troubleshootingtrue \colophontrue \fi
%%% END INCLUDED FILES %%%

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

\usepackage[english]{babel}
\usepackage{ucs}

%%% PDFLATEX %%%
\usepackage{etex}

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

\usepackage{ledmac}

%%% PAGE STYLE %%%
\makepagestyle{jebstyle}
\pagestyle{jebstyle}
\makeevenhead{jebstyle}{}{\hspace{2em}\itshape\small\leftmark}{} % KLUDGE
\makeoddhead{jebstyle}{}{\scshape\small\rightmark}{}
\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}
% \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}

%%% 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}
% 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*
%%% END TABLE OF CONTENTS ToC %%%

%%% LIST OF FIGURES %%%
%\addtodef{\listoffigures}{\clearpage\pagestyle{lof}}{}
% Fit all of List of Figures on one page
\renewcommand*{\lofheadstart}{\vspace{1cm}}
\clearpage
\listoffigures*
%%% END LIST OF FIGURES %%%

%%% CHAPTER STYLE %%%
\chapterstyle{jebinski} % defined in preamble
\def\topblockvspace{0.11}


%%% WARNINGS %%%
\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}

%%% SETUP %%%
\ifsetup
\chapter{\emph{Setup Your Printer}}
\thispagestyle{empty}
\markboth{Setup Your Printer}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Setup}}
\fi
%%% END SETUP %%%

%%% FILAMENT %%%
\iffilament
\chapter{\emph{Loading Filament}}
\thispagestyle{empty}
\markboth{Loading Filament}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Filament}}
\fi
%%% END FILAMENT %%%

%%% SOFTWARE %%%
\ifsoftware
\chapter{\emph{3D Printer Software}}
\thispagestyle{empty}
\markboth{3D Printer Software}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Software}}
\fi
%%% END SOFTWARE %%%

\begin{comment}
%%% Moving Slic3r to allow for more linear reading/setup. Slic3r will not be needed until after first test print %%%%
%%% SLIC3R %%%
\ifsoftware
\chapter{\emph{Slic3r}}
\thispagestyle{empty}
\markboth{Slic3r}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Slicer}}
\fi
%%% END SLIC3R %%%
\end{comment}


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

%%% SLIC3R %%%
\ifsoftware
\chapter{\emph{Slic3r}}
\thispagestyle{empty}
\markboth{Slic3r}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Slicer}}
\fi
%%% END SLIC3R %%%

%%% GLCD %%%
\ifglcd
\chapter{\emph{Printing with the Graphic LCD}}
\label{glcd}
\thispagestyle{empty}
\markboth{Printing with the Graphic LCD}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{glcd}
\fi
%%% END GLCD %%%

%%% MAINTENANCE %%%
\ifmaintenance
\chapter{\emph{Maintaining Your 3D Printer}}
\thispagestyle{empty}
\markboth{Maintaining Your 3D Printer}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Maintenance}}
\fi
%%% END MAINTENANCE %%%

%%% ADVANCED %%%
\ifmaintenance
\chapter{\emph{Advanced Usage}}
\thispagestyle{empty}
\markboth{Advanced Usage}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Advanced}}
\fi
%%% END ADVANCED %%%

%%% FAQ %%%
\iffaq
\chapter{\emph{FAQ}}
\thispagestyle{empty}
\markboth{FAQ}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{FAQ}}
\fi
%%% END FAQ %%%

%%% TROUBLESHOOTING %%%
\iftroubleshooting
\chapter{\emph{Troubleshooting}}
\thispagestyle{empty}
\markboth{Troubleshooting}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Troubleshooting}}
\fi
%%% END TROUBLESHOOTING %%%

%%% SOURCE %%%
\ifsource
\chapter{\emph{Hardware and Software Source Code}}
\thispagestyle{empty}
\markboth{Hardware and Software Source Code}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Source}}
\fi
%%% END SOURCE %%%

%%% SUPPORT %%%
\ifsupport
\chapter{\emph{3D Printer Support}}
\thispagestyle{empty}
\markboth{3D Printer Support}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Support}}
\fi
%%% END SUPPORT %%%

%%% CONTACT %%%
\ifcontact
\chapter{\emph{Contact Information}}
\thispagestyle{empty}
\markboth{Contact Information}{LulzBot\textsuperscript{\miniscule{\texttrademark}} TAZ User Manual}
{\include{Contact}}
\fi
%%% END CONTACT %%%

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

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

%%% GLOSSARY %%%
\renewcommand{\memgloterm}[1]{\textbf{#1}}
\renewcommand{\memglodesc}[1]{\textit{#1}}
\renewcommand{\memglonum}[1]{}

\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 %%%
\begin{comment}
\thispagestyle{empty}
\begingroup
\newpage
\mbox{}
\thispagestyle{empty}
\newpage
\mbox{}
\thispagestyle{empty}
\newpage
\mbox{}
\thispagestyle{empty}
\newpage
\mbox{}
\thispagestyle{empty}
\newpage
\mbox{}
\thispagestyle{empty}
\newpage
\endgroup
\end{comment}
%%% END BLANK PAGE %%%

\end{document}

