Packages Packages Introduction
New Commands
Page 1 Page 2
Fancyhdr
Quotchap
Page 1 Page 2
Todonotes
Geometry
Page 1 Page 2
Hyperref Babel Xcolor
Beamer
Page 1 Page 2 Page 3
"Top 5" useful packages "Top 3" styling packages
Quotchap

Implementation
Option parsing
The first part is about parsing the options. We may not \RequirePackages in here and thus define a flag: @usecolor is true whenever the grey option is specified
CODE
\newif\if@usecolor\@usecolortrue
\DeclareOption{grey}{\@usecolortrue}
\DeclareOption{nogrey}{\@usecolorfalse}

For the fonts, there follows a bunch of options that are all meant to be specified exclusively. It would have been possible to use \newcommand to ensure this, but it gives cryptic errors. Rather check this first.
CODE
\newcommand*{\@newfontcmd}{\@ifundefined{@defaultcnfont}{\newcommand*}{%
\PackageWarning{quotchap}{%
You have tried to specify more than one font to be\MessageBreak
used for the chapter numbers. I ignore the font\MessageBreak
‘\CurrentOption’}
\providecommand*}}

Next is defining the font options. We set \@defaultcnfont according to Karl Berry’s font name scheme. Providing more than one font gives an error (due to defining an already defined command); the options exclude each other.
CODE
\DeclareOption{avantgarde}{\@newfontcmd{\@defaultcnfont}{pag}}
\DeclareOption{beramono}{\@newfontcmd{\@defaultcnfont}{fvm}}
\DeclareOption{berasans}{\@newfontcmd{\@defaultcnfont}{fvs}}
\DeclareOption{beraserif}{\@newfontcmd{\@defaultcnfont}{fve}}
\DeclareOption{biolinum}{\@newfontcmd{\@defaultcnfont}{LinuxBiolinumO-LF}}
\DeclareOption{bookman}{\@newfontcmd{\@defaultcnfont}{pbk}}
\DeclareOption{charter}{\@newfontcmd{\@defaultcnfont}{bch}}
\DeclareOption{courier}{\@newfontcmd{\@defaultcnfont}{pcr}}
\DeclareOption{helvetica}{\@newfontcmd{\@defaultcnfont}{phv}}
\DeclareOption{kpfonts}{\@newfontcmd{\@defaultcnfont}{jkp}}
\DeclareOption{libertine}{\@newfontcmd{\@defaultcnfont}{LinuxLibertineO-LF}}
\DeclareOption{lmodern}{\@newfontcmd{\@defaultcnfont}{lmr}}
\DeclareOption{newcentury}{\@newfontcmd{\@defaultcnfont}{pnc}}
\DeclareOption{palatino}{\@newfontcmd{\@defaultcnfont}{ppl}}
\DeclareOption{times}{\@newfontcmd{\@defaultcnfont}{ptm}}
\DeclareOption{utopia}{\@newfontcmd{\@defaultcnfont}{put}}

We can now let the options be processed. If no postscript font has been specified, the default is Adobe’s Bookman.
CODE
\ProcessOptions\relax
\providecommand*{\@defaultcnfont}{pbk}

If nobody said nogrey, we fetch the color package and define our colour. If the color package is not included until now, we define \color to do nothing but gobble up its argument. An error is issued when grey is turned on and the color package is nonexistent. When you read the documentation because of this: color.sty is included in the graphics bundle to be found at ctan.
CODE
\if@usecolor
\IfFileExists{color.sty}{%
\RequirePackage{color}
\definecolor{chaptergrey}{rgb}{0.6,0.6,0.6}}{%
\PackageError{quotchap}{%
The color package is apparently unavailable.\MessageBreak
Turn off the ‘grey’ option and come back again}{%
Since you did not say ‘nogrey’, quotchap defined chapter
numbers to appear\MessageBreak grey. You do not need a color
printer, since most printing devices can cope\MessageBreak with
grey scales
\else
\providecommand*{\color}[1]{}
\fi

Now we are ready to give the final font declarations. The commands \sectfont and \chapterhead{start|end}vskip are defined in the KOMA-Script classes the chapter is based on, they are provided in case quotchap is used with other, e.g. the default classes. If we are building a report, there is no \frontmatter, \mainmatter and \backmatter resp. everything is \mainmatter, thus we have to provide the corresponding switch used in the \chapter command.
CODE
\AtEndOfPackage{%
\newcommand*{\chapnumfont}{%
\usefont{T1}{\@defaultcnfont}{b}{n}\fontsize{100}{130}\selectfont%
\color{chaptergrey}}
\let\size@chapter\huge
\providecommand*{\chapterheadstartvskip}{\vspace*{2.3\baselineskip}}
\providecommand*{\chapterheadendvskip}{\vspace{1.7\baselineskip}}
\providecommand*{\sectfont}{\relax}
\@ifundefined{@mainmattertrue}{\newif\if@mainmatter\@mainmattertrue}{}}


User Level Commands

Savequote

Here go the top level command declarations (and definitions, too). We use the lrbox environment to save the contents of the whole environment in a horizontal box. The quotes are effectively a paragraph box typeset in footnote size and oblique style, to the width given as a parameter, while any spacing at the beginning and the end of the environment is ignored. Since \newenvironment implies a group, we have to make the box \@quotebox global explicitly. Finally, we enable the box insertion command that is disabled initially and after each chapter heading. (Possibly it is faster to delete the save box contents and insert a nearly-empty vertical box at each chapter—profilers to the front.)
CODE
\newenvironment{savequote}[1][10cm]{%
\begin{lrbox}{\@quotebox}
\begin{minipage}[t]{#1}\footnotesize\slshape
\ignorespaces}{%
\unskip\end{minipage}\end{lrbox}
\global\setbox\@quotebox\copy\@quotebox
\global\let\@printcites\@iprintcites
\ignorespacesafterend}

\qauthor

The \qauthor command simply selects some font and skip—lets the name be set in roman letters and flush right at two ems distance from the margin.
CODE
\newcommand{\qauthor}[1]{%
\par\smallskip
{\raggedleft\upshape #1\qquad\hbox{}\par}\bigskip}

\qsetcnfont

The user can set any font for the chapter number by providing its family name to this command.
CODE
\newcommand{\qsetcnfont}[1]{%
\renewcommand*{\@defaultcnfont}{#1}}


Making up the chapter heading
Here are the modification to the chapter command definitions of the KOMA-Script document classes. This package was originally designed to co-operate only with them; therefore we have to provide some measurement defined only there. We insert the citations (if available) by calling the insert box or do nothing wrapper. The second modification is the formatting of the heading. If there is a chapter number to be printed, our really huge font is selected and the number is typeset to the right margin, followed by the title, as usual.
CODE
\newsavebox{\@quotebox}
\let\@printcites\relax
\renewcommand\chapter{%
\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@
\@printcites
\@afterindentfalse
\secdef\@chapter\@schapter}
\renewcommand{\@makechapterhead}[1]{\chapterheadstartvskip%
{\size@chapter{\sectfont\raggedleft
{\chapnumfont
\ifnum \c@secnumdepth >\m@ne%
\if@mainmatter\thechapter%
\fi\fi
\par\nobreak}%
{\raggedleft\advance\leftmargin10em\interlinepenalty\@M #1\par}}
\nobreak\chapterheadendvskip}}
\renewcommand{\@makeschapterhead}[1]{%
{\let\c@secnumdepth\m@ne\@makechapterhead{#1}}}
\newcommand*{\@iprintcites}{%
\vbox to\z@{\copy\@quotebox\vss}
\global\let\@printcites\relax}