% ====================[ classicthesis-lyx.sty              ]====================
%                     [ Time-stamp: "2009-04-18 19:29:36 leycec" ]
%
% --------------------( SYNOPSIS                           )--------------------
% This LyX-compatible LaTeX package loads and configures classicthesis and all
% classicthesis-required subpackages, including (in this order):
%
% * "classicthesis-lyx-conf.sty".
% * "classicthesis-lyx-ldpkg.sty".
% * "classicthesis.sty".
%
% --------------------( INSTALLATION                       )--------------------
% This package is intended to be explicitly loaded in the LaTeX preamble of each
% of your work's dependent ".lyx" files. If you reuse the default file-directory
% scheme for classicthesis as archived with the original classicthesis ".zip"
% file, then this suggests a LyX-specific file-directory scheme resembling:
%
%   classicthesis.lyx
%   front_matter.lyx
%   chapter01.lyx
%   chapter02.lyx
%   chapter03.lyx
%   chapter04.lyx
%   chapter0a.lyx
%   back_matter.lyx
%   bibliography.bib
%
% And that each of these files contains a header resembling:
%
%   % Copy the following three lines to the head of every ".lyx" file!
%   \begin_preamble
%   \RequirePackage{classicthesis-lyx}
%   \end_preamble
%
% If you reuse the sample ".lyx" files provided along with this file, then this
% has already been done for you. Sweet succulence of life, no?
%
% --------------------( CONFIGURATION                      )--------------------
% This package is quite configurable. However, as changes to this configuration
% dramatically change resulting output, please do so prior to beginning the
% writing of your LyX thesis. At the moment, this requires you manually edit
% commands in one LaTeX document, "classicthesis-lyx-conf.sty". (Happily, these
% commands are fairly straightforward and require no previous understanding of
% LaTeX.) To configure this package, please:
%
% * Open "classicthesis-lyx-conf.sty" in your favorite text editor. Because the
%   "classicthesis-lyx.sty" file implicitly loads this file when loaded, editing
%   "classicthesis-lyx-conf.sty" configures classicthesis-lyx and, thus, each
%   ".lyx" document comprising your thesis. Please edit this file manually to
%   change the default values of the macros it defines, as suites your need. For
%   example, if your specific thesis is named "A Teleological Origin of
%   Industrial Collapse," you should probably change the default value of the
%   \myTitle command from:
%
%     % Alter this...
%     \newcommand{\myTitle}{My Thesis' Title\xspace}
%     % ...to this:
%     \newcommand{\myTitle}{A Teleological Origin of Industrial Collapse\xspace}
%
% This is not an ideal solution, since your manual edits to the
% "classicthesis-lyx-conf.sty" package will be overwritten when upgrading to a
% a new version. Our sincere apologies! Please "watch out" for this, later. :(
%
% --------------------( DOCUMENT CLASSES                   )--------------------
% This package is intended to be used with KOMA-Script document classes, rather
% than Memoir or default document classes. This is in keeping with the original
% classicthesis. Since LyX handles document classes graphically, rather than in
% the LaTeX preamble, this is different from how the non-LyX version handles
% document classes. To change the document class and options in LyX:
%
% * Run LyX and open the desired ".lyx" file.
% * Set this document's document class. In the original classicthesis structure,
%   this was done by manually editing the preamble for "ClassicThesis.tex". LyX,
%   however, requires that a document's document class be graphically configured
%   through the LyX GUI at:
%
%     Document Settings --> Document Class
%
% * Note that the "scrbook" document class from the KOMA-Script bundle is a
%   perfect choice for both thesis and thesis proposals.
% * Set this document's document class options. Again, LyX requires that they be
%   graphically configured through the LyX GUI at:
%
%     Document Settings --> Document Class --> Class options
%
% * If you chose one of the several available KOMA-Script document classes
%   (i.e., any document class beginning in "scr"), consider setting these
%   classicthesis-recommended options:
%
%     paper=a4,%
%     fontsize=10pt,%
%     BCOR=5mm,%
%     captions=tableheading,%
%     cleardoublepage=empty,%
%     clear=right,%
%     numbers=noenddot,%
%     abstract=false,%
%     footinclude=true,%
%     headinclude=true,%
%     fleqn=true,%
%     titlepage=true
%
% Unfortunately, the LyX document class and document class options cannot be
% shared between the related ".lyx" files comprising classicthesis-lyx. Each
% separate ".lyx" file must repeat whichever document class and document class
% options you selected, and these should be the same for every such file. This
% is very annoying, but I'm afraid there is no way about it at the moment. Cue
% sad face here.
%
% --------------------( TEXT COLORS                        )--------------------
% This package uses the some color scheme as used throughout classicthesis and
% arsclassica, including:
%
% * "Maroon" for the thesis title and part titles. This is hexademical color
%    #AD2031 and RGB color R:173,G:32,B:49.
% * "RoyalBlue" for page numbers, hyperlinks, etc. This is hexadecimal color
%    #106DC5 and RGB color R:16,G:109,B:197.
%
% Some of these colors are classicthesis-specific, being specifically defined in 
% "classicthesis.sty"; others are xcolor-specific, a LaTeX package converting
% the standard X.org color swatch (i.e., "/usr/share/X11/rgb.txt") into LaTeX-
% accessible, cross-platform portable colors.
%
% --------------------( SEE ALSO                           )--------------------
% Please consider sending André a postcard if you appreciate his efforts. See
% his listing of all already sent postcards at:
%
%   http://postcards.miede.de
%
% This bundle of packages and LyX documents is courtesy the hard efforts of:
%
% * André Miede. "A Classic Thesis Style."
%   http://www.kom.tu-darmstadt.de/~miede/2miede/index.php?page=classicthesis
% * Nick Mariette. "Classic Thesis for LyX."
%   http://soundsorange.net/resources/classic-thesis-for-lyx/
% * Lorenzo Pantieri. "Customizing ClassicThesis with the ArsClassica Package."
%   http://www.ctan.org/tex-archive/macros/latex/contrib/arsclassica/
%
% --------------------( SYNOPSIS =fragmaster               )--------------------
% This package supports an option named "fragmaster." When enabled, this package
% loads and configures the classicthesis packages in a manner compatible with
% the external "fragmaster" Perl script. This script integrates the "psfrag"
% LaTeX package with PDFLaTeX, permitting substitution of raw text in Postscript
% graphics files (e.g., ".eps") with well-typeset LaTeX aesthetically congruent
% with the remainder of your thesis. This script is available from CTAN support:
%
%   http://www.ctan.org/tex-archive/support/fragmaster/
%
% --------------------( INSTALLATION =fragmaster           )--------------------
% When enabling the "fragmaster" package option, this package requires two
% external dependencies: the "fragmaster" Perl script and "psfrag" package.
%
% Fragmaster must be manually installed. It is usually not automatically
% installed with TeX or LaTeX package distributions, given its rather niche
% nature. Fortunately, this is a convenient process:
%
% * Download fragmaster from:
%   http://www.ctan.org/get/support/fragmaster/fragmaster.pl
% * Make the downloaded file executable and move it into your $PATH, e.g.:
%   chmod +x fragmaster.pl
%   mv fragmaster.pl /usr/local/bin
%
% Psfrag is usually automatically installed or installable via TeXLive (Linux)
% or MiXTeX (Windows). You should not have to do anything, here.
%
% --------------------( USAGE =fragmaster                  )--------------------
% The "fragmaster" package option is intended to be explicitly specified in the
% LaTeX preamble of each of your thesis' "${GRAPHIC}_fm" files, like so:
%
%   % ================[ ${GRAPHIC}_fm                      ]================
%   % This is the LaTeX preamble for the LaTeX file, "${GRAPHIC}_fm". It
%   % indicates that Fragmaster should not explicitly declare a document
%   % class, as this package assumes responsibility for doing that, and that
%   % this package should be imported via \RequirePackage rather than
%   % \usepackage. This is important, as you will see if you try calling
%   % \usepackage, instead!
%   %
%   % fmclass:false
%   % head:
%   % \RequirePackage[fragmaster]{classicthesis-lyx}
%   % end head
%   %
%   % This is the dictionary mapping input EPS text to output LaTeX. The
%   % \psfrag command accepts an input EPS string, a "psfrag"-specific
%   % positioning string (each character of which signifies a position
%   % attribute for the output LaTeX over the input EPS), and the output
%   % LaTeX. For details, see "psfrag" documentation.
%   %
%   % This particular example implies the "${GRAPHIC}_fm.eps" file
%   % corresponding to this file has two raw text strings labelled "gamma" and
%   % "zgamma", to be replaced by these LaTeX commands.
%   \psfrag{gamma}[Bc]{$\gamma(8)$}
%   \psfrag{zgamma}[Bc]{$\mathbb{Z}_{2 \times 9}(\widetilde{\gamma(8)})$}
%
% Please read the concise README at the fragmaster CTAN URL (above), for
% details. After defining a "${GRAPHIC}_fm" LaTeX file for each
% "${GRAPHIC}_fm.eps" Postscript graphics file in some thesis directory, run
% the following commands to automatically create the "${GRAPHIC}.eps" and
% "${GRAPHIC}.pdf" files corresponding to the input graphics and LaTeX files:
%
%   % Change to the directory having these files.
%   cd ${SOME_PATH}
%   % Run Fragmaster. This automatically creates output EPS and PDF files for
%   % each pair of input EPS and LaTeX files in this directory, and
%   % automatically updates the output files on each change to the input files.
%   fragmaster.pl  % that's it!
%
% --------------------( SEE ALSO =fragmaster               )--------------------
% This package recommends thumbing through the documentation for each of the
% tools depended on above, especially:
%
% * Fragmaster.
%   http://www.ctan.org/tex-archive/support/fragmaster/
% * Psfrag.
%   http://www.ctan.org/tex-archive/macros/latex/contrib/psfrag/
%
% --------------------( CHANGELOG                          )--------------------
% 2009-08-01  Cecil Curry  <http://raiazome.com>
%   * Created.
%
% --------------------( TODO                               )--------------------
% * Generate a Gentoo ebuild.
% * Generate a Gentoo ebuild for "biblatex-biber," as well.
% * Engineer a script (Python? Common Lisp?) automatically converting an input
%   "ClassicThesis.tex" into a LyX-compatible "classicthesis-tex.sty". This in
%   turns allows us to avoid including a hard "classicthesis-tex.sty" version
%   with this archive by performing this conversion in the above ebuild on a
%   per-installation basis.
% * Alternatively, push one or several patches to Andre for inclusion in the
%   next version of classicthesis, so as to improve cross compatibility with
%   LyX. This is the better long term solution, frankly. The simplest solution
%   is just to pass a new boolean option "lyx" to these packages, and have them
%   conditionally handle it as appropriate.
% * Automatically enable "nochapters" for letters and articles.
% * Discuss installation of the Enumitem LyX module. This should probably be
%   distributed with this archive, yes?
% * Most packages imported below should be optional, and imported only if
%   locally available. LaTeX must offer this functionality, I imagine.
% * The \my* family of configuration commands in "classicthesis-lyx-conf" should
%   be provided a front-facing interface as package options, much like drafting.
%   Yes! See the ".layout" discussion below.
% * Convert "classicthesis-lyx-conf.sty" into a proper LyX layout with graphical
%   configuration. This is the win, but may prove rather difficult. No, not so
%   hard actually! See the ".layout" discussion below.
% * Use the "versions.sty" package to differentiate between PDF and HTML output,
%   and to conditionally do the right thing in either case.
% * Nice! All of this should be converted into a proper ".cls" file / ".layout"
%   file pair. The ".cls" file is a LaTeX-specific file defining all LaTeX
%   commands to be used by the ".layout" file; the ".layout" file is a LyX-
%   specific file converting between LyX commands (the WYSIWYM UI interface) and
%   LaTeX commands defined in the above ".cls" file. Hopefully, it would be not
%   much work converting "classicthesis-lyx.sty" to "classicthesis-lyx.cls" and
%  "classicthesis-lyx-conf.sty" to "classicthesis-lyx.layout". For someone who
%   has already done similar work for producing a LyX layout for theses, see
%   this fantastic blog post at:
%   http://www.threewordslong.com/blog/entry/63/A_LyX_Thesis_Layout_for_UNSW_T
%   Wow! Quite simple, actually. He's done a fantastic job with commenting the
%   ".layout" file he offers.
%   ** Margin notes make an interesting example. LyX already provides a UI
%      mechanism for inserting \marginpar-style margin notes. Since
%      classicthesis implements its own margin notes with \marginpar as well, it
%      shouldn't be terribly hard to implement the \graffito command in LyX.
% * Examine "https://svn.cv.nrao.edu/view/HISimulation/Thesis/". This thesis
%   leverages classicthesis on the back end, providing additional functionality
%   in a fairly well-commented way. Fine food for LaTeX thought, in any case.
% * Implement document class-conditional switching. Code in BibLaTeX suggests
%   that this is testable via LaTeX resembling:
%     \ifcase\@tempcnta % article
% * The "small" option should be passed to the "eulervm" package, if both the
%   "eulermath" and "minion" booleans are also enabled. (See comments in
%   "latex.note" under "eulervm:".)
% * Hmm. I had to patch "fragmaster.pl" so as to remove dependency on
%   "german.sty". Submit to CTAN, yes? That script should probably be re-
%   implemented as a new "pdfrag" package, I reckon. Until then, it would at
%   least help to define a user-local configuration for it. Having to redeclare
%   "fmclass" and so on for every image is a poor idea, really.
% * Adopt the "kvoptions" package for multi-valued option handling.
% * Remove the need to manually define commands in the configuration (e.g., the
%   \myTitle family of commands) by providing a series of \setTitle commands
%   resembling: \newcommand*{\setTitle}[1]{\def\myTitle{#1}\xspace}

% ....................{ PROVIDES                           }....................
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{classicthesis-lyx}[2009/08/01 v0.0.1 Classic Thesis cum LyX]

% ....................{ DEPENDENCIES                       }....................
% Import the "amsmath" package to provide additional equation-centric commands,
% used below and widely elsewhere. Technically, LyX does import this package on
% your behalf as needed; however, since it cannot detect that need for commands
% called from this package, we manually import it here. (This is safe, since
% LyX never loads this package with options.)
%
% This does introduce slight overhead for theses, articles, and other documents
% not typesetting equations: e.g., law or humanities documents. Hopefully, this
% is not an issue. (Even my paltry iBook G3 300Mhz capably handles this...)
\RequirePackage{amsmath}
 
% Import the "ifpdf" package to provide PDF-centric conditionals. These allow
% us to test whether the current document is being output via the PDF-specific
% PDFLaTeX engine or via the plain LaTeX engine, and to customize our internal
% logic accordingly.
\RequirePackage{ifpdf}

% Import the "ifthen" package to provide boolean-centric commands. Note that
% these booleans should be prefixed with our ad-hoc namespace "clt@" to avoid
% nomenclature conflict elsewhere.
\RequirePackage{ifthen}

% ....................{ OPTIONS                            }....................
% The following sections define user-settable options as true or false booleans. 
% Please set these options in the "classicthesis-lyx-conf.sty" file
% corresponding to your particular document.
%
% Note that all options defined below default to false unless otherwise stated.
% These defaults should produce aesthetically pleasing output across a wide
% variety of software platforms and "real world" thesis dictates; as such, they
% shouldn't need much tweaking on your behalf. (This is good. Spend your
% dilegency academically, rather than hacking academic LaTeX.)

% ....................{ OPTIONS =classicthesis             }....................
% Define options specific to classicthesis-lyx.

% If true, load BibLaTeX; otherwise, load Natbib. BibLaTeX and Natbib are both
% LaTeX-centric solutions for associating bibliographic citations with 
% bibliographic entries defined by some external BibTeX-compliant database.
%
% BibLaTeX dispenses with the stack-based BibTeX language used in ".bst" files,
% preferring instead to format citation output with LaTeX itself. Additionally,
% BibLaTeX permits bibliographic entries to be encoded as Unicode text, offers
% an XML-based alternative named BibLaTeXML to the default ".bib" file format
% for defining external databases of bibliographic entries, and, in general,
% probably represents the way forward for both BibTeX and LaTeX.
%
% BibLaTeX is not, however, supplied by TeXLive 2008 (Linux) or explicitly
% supported under LyX (any OS) and must thus be installed by hand, by you, by
% whatever avenues available. As BibLaTeX is a not necessarily straightforward
% installation, you must judge the merits in walking down this gritty avenue.
%
% Natbib is supplied by TeXLive 2008 (Linux) and explicitly supported by LyX
% (any OS). Therefore, Natbib may be more appropriate for general use.
%
% Since the two packages are mutually exclusive, only one is enabled at a time.
\newboolean{ctl@biblatex}

% If true, set the default sans serif font to Iwona. This is the arsclassica
% default, but not the classicthesis default: by default, classicthesis does
% not use sans serif fonts at all. That said, this is an aesthetically pleasing
% font and you are recommended to "give her a whirl!"
\newboolean{ctl@iwona}

% If true, format the output PDF for monochrome; otherwise, for on-screen display.
% In particular, this means reducing colors to monochrome for monochrome and
% allowing colors for on-screen display.
\newboolean{ctl@monochrome}

% If true, load PGF/TikZ. PGF is a low-level vector graphics; TikZ is a high-
% level vector graphics language built on PGF. Both permit vector graphics to be
% embedded within LaTeX documents in a rather convenient fashion. Note that
% enabling this also permits embedding of Graphviz-style dot graphs in LaTeX via
% the "dot2texi" package. In other words, it's probably a good idea.
\newboolean{ctl@tikz}

% ....................{ OPTIONS =classicthesis             }....................
% The "classicthesis" and "classicthesis-ldpkg" packages accept several options
% that should be settable by the caller of this package; that is, they have no
% good default. Thus, this package accepts these options as its own and simply
% hands them on to the appropriate classicthesis package(s).
%
% Please see the classicthesis manual (e.g., the file "ClassicThesis.pdf"
% distributed on CTAN with the classicthesis ZIP archive) for option details.

% If true, enables the classicthesis-specific "drafting" option. This option
% should probably be enabled for the thesis proposal and subsequent drafts, but
% not the submission thesis.
\newboolean{ctl@drafting}

% If true, enables the classicthesis-specific "minionprospacing" option. If
% true, Adobe's non-free but clasically popular Minion Pro will be used as the
% default serif font for the text area; otherwise, a variant of Hermann Zapf's
% free and very recommended Palatino will be used. Unless you have some
% compelling reason to select Minion Pro, Palatino should be quite fine. (Yeah!)
\newboolean{ctl@minionpro}

% If true, enables the classicthesis-specific "nochapters" option. This option
% should probably be enabled for journal articles, but not the thesis proposal,
% subsequent drafts, or the submission thesis.
\newboolean{ctl@nochapters}

% If true, enables the classicthesis-specific "pdfspacing" option. This option
% will be ignored when the "ctl@minionpro" option is also enabled. This option
% should definitely be enabled for theses printed or viewed as PDFs.
\newboolean{ctl@pdf}

% ....................{ OPTIONS =i18n                      }....................
% arsclassica defines these internationalization-specific options. They strike 
% me as a top shape idea; so, I've reduplicated their use here. Thanks, 
% Lorenzo.

% Declare one boolean for every supported language. By default, English is
% enabled and all other language booleans disabled.
\newboolean{ctl@english}
\newboolean{ctl@french}
\newboolean{ctl@german}
\newboolean{ctl@spanish}
\newboolean{ctl@italian}

% ....................{ OPTIONS =user                      }....................
% Import the "classicthesis-lyx-conf" package, having this package's document-
% specific configuration, now that we've declared all available options.
\RequirePackage{classicthesis-lyx-conf}

% ....................{ OPTIONS =package                   }....................
% If true, configure classicthesis packages for "fragmaster" compatibility. See
% documentation above, for details. This option should only be specified by an
% external caller as a package option to this package.
\newboolean{ctl@fragmaster}

% Process package options passed to this package, externally.
\DeclareOption{fragmaster}{\setboolean{ctl@fragmaster}{true}}
\DeclareOption*{\PackageWarning{classicthesis-lyx}%
  {Unknown option ‘\CurrentOption’}}
\ProcessOptions\relax

% If enabling "fragmaster" compatibility, adjust our configuration accordingly.
% This manually overrides the "classicthesis-lyx-conf" configuration, above.
\ifthenelse{\boolean{ctl@fragmaster}}%
  {% Disable drafting, as permitting that prints a timestamp at the foot of each
   % page of a Postscript graphic.
   \setboolean{ctl@drafting}{false}%
   % Disable chapters, as permitting that prints excess whitespace.
   \setboolean{ctl@nochapters}{true}%
  }%
  {}

% ....................{ OPTIONS =package                   }....................
% Delegate applicable options set by the "classicthesis-lyx-conf" package,
% above, to the classicthesis packages.
\ifthenelse{\boolean{ctl@biblatex}}%
  {\PassOptionsToPackage{biblatex}{classicthesis-lyx-ldpkg}}{}
\ifthenelse{\boolean{ctl@drafting}}%
  {\PassOptionsToPackage{drafting}{classicthesis}}{}
\ifthenelse{\boolean{ctl@minionpro}}%
  {\PassOptionsToPackage{minionprospacing}{classicthesis}}{}
\ifthenelse{\boolean{ctl@pdf}}%
  {\PassOptionsToPackage{pdfspacing}{classicthesis}}{}

% If enabling "fragmaster" compatibility, set the "hyperref" package's default
% driver to "hdvips.def" rather than its customary default, "hpdftex.def".
\ifthenelse{\boolean{ctl@fragmaster}}%
  {\PassOptionsToPackage{dvips}{hyperref}}{}

\ifthenelse{\boolean{ctl@nochapters}}%
  {\PassOptionsToPackage{nochapters}{classicthesis}
   \PassOptionsToPackage{nochapters}{classicthesis-lyx-ldpkg}}%
  {% If not enabling "nochapters" (i.e., if enabling chapters), also enable
   % support for the \part command.
   \PassOptionsToPackage{parts}{classicthesis}}

% ....................{ DOCUMENT CLASS                     }....................
% Explicitly declare an appropriate document class, if running under
% "fragmaster"; otherwise leave the document class unspecified. (LyX assumes
% responsibility for declaring your document class, I'm afraid.)
\ifthenelse{\boolean{ctl@fragmaster}}%
  {\documentclass[fontsize=10pt]{scrreprt}}%
  {}

% ....................{ PACKAGES                           }....................
% Import and configure packages not otherwise imported and configured by the
% "classicthesis-ldpkg" or "classicthesis" packages prior to importing those
% "classicthesis" packages.
%
% Ideally, the order in which this package imports packages would be irrevelant.
% In the (unfortunately) real world, however, this order is quite irrelevant; in
% fact, a failure to import packages in the proper order usually causes LaTeX
% error on document parsing. Just what constitutes "proper order" is a matter of
% continual debate, but can be synopsized by the following heuristic:
%
% * Always load the "hyperref" package last.
%
% The "classicthesis-ldpkg" package loads the "hyperref" package if not already
% loaded. This implies that this package must load other packages prior to
% loading "classicthesis-ldpkg" - and this is just what we do.

% ....................{ PACKAGES =floats                   }....................
% Import the "afterpage" package. This defines the \afterpage, used to ensure a
% particular floating figure begins on an even or odd page, as needed. This is
% particularly helpful for printing multi-page wide figures in landscape mode.
\RequirePackage{afterpage}

% Import the "floatpag" package. This automatically reduces header and footer
% verbosity for all pages consisting only of floats.
\RequirePackage{floatpag}

% Reduce header and footer text for these pages to just their page number.
\floatpagestyle{plain}

% Import the "pdflscape" package if printing to PDF or the "lscape" package if
% not. Since both packages define a new "landscape" environment for formatting
% particular page content in a landscape rather than portrait orientation, this
% ensures that the actual thesis may reference this environment without concern
% for whether it's being printed to PDF or not.
\ifthenelse{\boolean{ctl@pdf}}%
  {\RequirePackage{pdflscape}}%
  {\RequirePackage{lscape}}%

%FIXME: If too extreme, consider a package option to disable this with the
%default enabling this.
% Import the "placeins" package and configure it to automatically inject a call
% to the \FloatBarrier command at the head of every \section. Not everyone may
% want this. That said, it does correct float handling enough with respect to
% floats crossing section boundaries to be of widespread help.
\RequirePackage[section,below]{placeins}

% ....................{ PACKAGES =graphics                 }....................
% Require and configure PGF/TikZ, if desired. This also implicitly requires and
% configures dot2texi when requiring PGF/TikZ. (As both are now included in
% TeXLive as of TeXLive 2009, this should not be a hardship.)
\ifthenelse{\boolean{ctl@tikz}}%
  {%\Requirepackage{dot2texi}%
   \RequirePackage{tikz}%
   \usetikzlibrary{shapes,arrows}%
  }%
  {}

%FIXME: Does this only apply to "pdflatex" generation?
% Import the "rotating" package, for rotating floats (e.g., graphics, tables)
% and font glyphs. The latter is particularly interesting: we use the package's
% "sideways" environment to invert the conventional copyright symbol into an ad-
% hoc copyleft symbol, below.
\usepackage{rotating}

% Define a new command for rotating the passed LaTeX 90 degrees counter-
% clockwise.
\newcommand{\textrotate}[1]{\begin{sideways}#1\end{sideways}}

% Define a new command for rotating the passed LaTeX 180 degrees, effectively
% "inverting" that LaTeX.
\newcommand{\textinvert}[1]{\textrotate{\textrotate{#1}}}

% Import the "cclicenses" package, for licensing a thesis into the public domain
% by embedding various Creative Commons logos into that thesis.
\RequirePackage{ccbeamer}

% Define the document-relative path under which these logos reside.
\renewcommand{\CcImagePath}{image/ccbeamer}

% ....................{ PACKAGES =references               }....................
% Import the "fncylab" package. This package permits customization of the
% format printed by the \ref command, and is quite useful.
\RequirePackage{fncylab}

% Ensure equation references are always printed non-italic and within parens.
\labelformat{equation}{\textup{(#1)}}

% Import the "prettyref" package. This package defines a context-sensitive
% analogue to the \ref command named \prettyref which, when called with a
% referenceable label in the form "${LABEL_TYPE}:${LABEL_TITLE}" where
% ${LABEL_TYPE} is one of:
%
% * eq  ~ an equation.
% * app ~ an appendix.
% * cha ~ a chapter.
% * fig ~ a figure.
% * lem ~ a lemma.
% * sec ~ a section.
% * tab ~ a table.
% * thm ~ a theorem.
%
% and where ${LABEL_TITLE} is any alphanumeric string, prints a human-readable
% reference to that label. As example:
%
%   % "prettyref" expands this:
%   \prettyref{sec:examples}
%   % ...into this:
%   Section~\ref{sec:examples}
%
% This is rather helpful, and useful enough to be included as a default here.
% See the full documentation, living at:
%
%   http://www.ctan.org/tex-archive/help/Catalogue/entries/prettyref.html
%
% Note that LyX implicitly requires this package on the first insertion of a
% "Formatted reference" in the document. However, since we'd like to configure
% it below, we necessarily require it here, also. (This is not a problem. Yeah!)
\RequirePackage{prettyref}

% Configure the "prettyref" package. Specifically, redefine its reference
% formats so as to prevent page breaks between the human-readable prefix and
% following number. Do not redefine the "eq" label type, however; the
% "prettyref" default is quite good for that.
\newrefformat{app}{Appendix~\ref{#1}}
\newrefformat{ch}{Chapter~\ref{#1}}
\newrefformat{eq}{Equation~\ref{#1}}
\newrefformat{fig}{Figure~\ref{#1}}
\newrefformat{lem}{Lemma~\ref{#1}}
\newrefformat{sec}{Section~\ref{#1}}
\newrefformat{tab}{Table~\ref{#1}}
\newrefformat{th}{Theorem~\ref{#1}}

% ....................{ CLASSIC THESIS                     }....................
% Import the "classicthesis-lyx-ldpkg" prior to importing the
% "classicthesis" package. This is necessary.
\RequirePackage{classicthesis-lyx-ldpkg}
%FIXME: Consider adding a customizable boolean for enabling "linedheaders." This
%should, ideally, be a multi-state variable accepting three options; e.g.:
%  chapterheadersrule=horizontalsingle   % This is the default.
%  chapterheadersrule=horizontaldouble   % This is the "linedheaders" option.
%  chapterheadersrule=verticalsingle     % This is as in arsclassica.
\RequirePackage%
  [beramono,eulerchapternumbers,eulermath,listings,subfig]{classicthesis}

% ....................{ PAGE LAYOUT                        }....................
% "classicthesis.sty" sets a custom text area width:height ratio of 1:2.2,
% instead of the documented default text area width:height ratio of 1:2. Since
% "ClassicThesis.pdf" suggests that this should be the default, since
% "arsclassic.sty" explicitly ensures that will be the default, and since my
% subjective analysis of the two ratios suggests that 1:2.2 almost certainly
% results in a text area too tall for its text, this alters the ratio to 1:2.
%
% Since I am lazy, however, this only alters the ratio when the paper format is
% A4, the default text font is not Minion (i.e., is probably Palatino), and the
% font size for this font is 10 point.
%
% Let's examine the math. Palatino at 10pt consumes 133.21pt for the string
% "abcdefghijklmnopqrstuvwxyz." Since we can reasonably fit 2.34 such strings
% on one horizontal line, this suggests a text area width of:
%
%    133.21pt * 2.34 = 312pt
%
% Assuming a text area width:height ratio of 1:2, this suggests a height of:
%
%    312pt * 2 = 624pt
%
% However, as classicthesis includes header and footer text in the text area,
% we must account for vertical space consumed by these texts by adding an
% additional 33pt for the header and 42pt for the footer for a final height of:
%
%    624pt + 33pt + 42pt = 699pt
%
% There! That wasn't too terrible, eh? It shouldn't be terribly hard to extend
% this by hand to other paper formats, fonts, and font sizes.

%FIXME: Shouldn't the "5mm" below delegate to the value of the "BCOR" option?
%Also, this only applies to Palatino at 10 points on A4 paper. (What would be
%the best manner of generalizing this? Is there such a manner?)
\ifthenelse{\boolean{@a5paper}}%
  {}% A5
	{\ifthenelse{\boolean{ctl@minionpro}}% A4
    {}% Minion
    {\areaset[5mm]{312pt}{699pt}}% Palatino at 10pt, hopefully.
  }

% ....................{ TYPOGRAPHY                         }....................
% Define the default serif font to be TeX Gyre Pagella, unless the user would
% rather we reuse Adobe's Minion Pro. TeX Gyre Pagella extends Hermann Zapf's
% venerate Palatino with support for non-English glyphs in a manner in keeping
% with the Palatino stroke style.
%
% This overrides the inclusion of the "mathpazo" package by the "classicthesis"
% packaged, and must therefore be performed after loading the latter.
\ifthenelse{\boolean{ctl@minionpro}}%
  {}%
  {\RequirePackage{tgpagella}}%

%FIXME: "classicthesis.sty" should be patched so as to embed \xspace commands
%as below. This ensures sanity when used throughout text. Also, use of these
%case-modifying commands prevents embedding of case-sensitive LaTeX commands
%within these arguments: we can't say, for example,
%\spacedallcaps{\color{black}My Title}, as "black" becomes "BLACK."
% If desired, define the default sans serif font to be Iwona. This comes
% courtesy Lorenzo's arsclassica style and, in this author's opinion, is
% preferable to the default. (Iwona is an aesthetically pleasing font, really.)
%
% By default, no sans serif font will be used. Instead, headers, captions, and
% other title text customarily typeset in a sans serif font will be typeset in
% the default serif font as defined above.
\ifthenelse{\boolean{ctl@iwona}}%
  {\renewcommand{\sfdefault}{iwona}%
   \ifthenelse{\boolean{ctl@minionpro}}%
     {\DeclareRobustCommand{\spacedallcaps}[1]%
        {\textsf{\textssc{\MakeTextUppercase{#1}}}\xspace}%
      \DeclareRobustCommand{\spacedlowsmallcaps}[1]%
        {\textsf{\textssc{\MakeTextLowercase{#1}}}\xspace}%
     }%
     {\ifthenelse{\boolean{ctl@pdf}}%
       {\DeclareRobustCommand{\spacedallcaps}[1]%
          {\textsf{\textls[160]{\MakeTextUppercase{#1}}}\xspace}%
        \DeclareRobustCommand{\spacedlowsmallcaps}[1]%
          {\textsf{\textls[80]{\scshape\MakeTextLowercase{#1}}}\xspace}%
       }%
       {\sodef\allcapsspacing{\sffamily\upshape}{0.15em}{0.65em}{0.6em}%
        \sodef\lowsmallcapsspacing{\sffamily\scshape}{0.075em}{0.5em}{0.6em}%   
        \DeclareRobustCommand{\spacedallcaps}[1]%
          {\MakeTextUppercase{\allcapsspacing{#1}}\xspace}%
        \DeclareRobustCommand{\spacedlowsmallcaps}[1]%
          {\MakeTextLowercase{\textsc{\lowsmallcapsspacing{#1}}}\xspace}%
  }}}%
  {}

% ....................{ WHITESPACE                         }....................
% Enable French spacing by default: that is, only print one space following the
% end of a sentence rather than two.
\frenchspacing

% Enable ragged spacing by default: that is, do not forcefully inject excess
% vertical whitespace between paragraphs so as to ensure last lines of every
% page vertically align to the bottom of every page's text area.
%
% It's antonym, flush spacing, tends to produce a vertical baseline "grid," in
% which the baselines for text in the text area are vertically aligned across
% different pages. This produces a uniform aesthetic. However, consider 
% partially empty pages; flush spacing for such pages forces excess vertical
% whitespace between paragraphs, so as to force flushing.
%
% "ClassicThesis.tex" applies ragged spacing; Bringhurst recommends applying
% flush spacing. Which is "right"? I don't know, but do concur with
% "ClassicThesis.tex": for typesetting theses, applying ragged spacing does
% seem to provide a better aesthetic. (Thus!)
\raggedbottom

% ....................{ FLOATS                             }....................
% Configure the "caption" package. Thanks, Nick and Lorenzo!
\captionsetup{format=hang,font=small,labelfont={sf,bf}}
\captionsetup[table]{skip=\medskipamount}

%FIXME: Shouldn't there by a LyX-centric way of specifying this?
\newcommand{\myfloatalign}{\centering} % how all the floats will be aligned

%FIXME: Shouldn't there by a LyX-centric way of specifying this? Also, is this
%necessarily a good idea? "\extrarowheight" is typically used to provide strut-
%style vertical whitespace in table cells to prevent row text from vertically
%colliding with horizontal lines delimiting cells. Since classicthesis doesn't
%delimit cells with horizontal lines, this shouldn't be an issue. I think.
%
%Interesting. This is exactly what LyX does when it sets fixed table cell
%dimensions, but it also requires \RequirePackage{array} and I don't see that.
%\setlength{\extrarowheight}{3pt} % increase table row height

% ....................{ MATH                               }....................
%FIXME: Also consider:
% % Restart equation numbering on each part, chapter, section, etc.
% \@addtoreset{equation}{part}
% % Format equation numbers as (chapter.section.number) or (section.number)...
% \numberwithin{equation}{part}

% Format the numbers associated with numbered equations as
% "${section}.${equation}" if a journal article or
% "${section}.${subsection}.${equation}" if a thesis or thesis proposal: e.g.,
% "3.1.4" is the fourth equation in the first subsection of the third section of
% the current chapter of the current part, and will be printed as such.
%
% By default, LaTeX formats the numbers associated with numbered equations
% "flatly": e.g., the first equation in the document will be numbered "1", the
% next equation "2", and so on. This is probably not appropriate for thesis or
% thesis proposals, but may be preferable (depending on journal) for journal
% articles.
\numberwithin{equation}{subsection}

% ....................{ MINITOC                            }....................
% Import the "minitoc" package. This appends a smaller-sized section-specific
% table of contents immediately after the head title for the section. Since LyX
% provides no explicit support for "minitoc," this must be implemented manually,
% via ERT. Fortunately, it's mostly simple to embed this ERT in thesis
% documents.
%
% "minitoc" accepts one of the following preamble-specific commands, governing
% where the miniature table of contents is to printed throughout the document.
% If this document's document class defines \part, they're printable at the
% beginning of each part; if it defines \chapter, they're printable at the
% beginning of each chapter; otherwise, they're printable only at the beginning
% of each section. The preamble must select one and only one of the above
% levels, since "minitoc" has no facilities for managing nested levels. These
% commands are:
%
% * \doparttoc ~ table of contents for parts.
% * \dopartlof ~ list of figures for parts.
% * \dopartlot ~ list of tables for parts.
% * \dominitoc ~ table of contents for chapters.
% * \dominilof ~ list of figures for chapters.
% * \dominilot ~ list of tables for chapters.
% * \dosecttoc ~ table of contents for sections.
% * \dosectlof ~ list of figures for sections.
% * \dosectlot ~ list of tables for sections.
%FIXME: Not quite yet. Note that we can do the right thing based on the value
%of the nochapters boolean. :)
%\RequirePackage{minitoc}

%FIXME: Hmm. Lorenzo's original version had no suffixing '%' characters.
% Configure the "minitoc" package. This is substantially inspired by a similar
% configuration in Lorenzo's "arsclassica" style. Thanks, Lorenzo! (It's great.)
\@ifpackageloaded{minitoc}%
  {\ifthenelse{\boolean{ctl@english}}%
    {\def\ptctitle{contents}%
     \def\mtctitle{contents}%
     \def\stctitle{contents}%
     \setlength{\mtcindent}{0pt}%
     \renewcommand{\mtifont}{\normalsize\sffamily\scshape\lsstyle}%
    }%
    {\setlength{\mtcindent}{0pt}%
     \renewcommand{\mtifont}{\normalsize\sffamily\scshape\lsstyle}%
    }%
  }%
  {}

% !!!!!!!!!!!!!!!!!!!!? IMPORTANT                          ?!!!!!!!!!!!!!!!!!!!!
% This should be the last section in this file. Generally speaking, so as to
% avoid package, command, and option conflicts, "hyperref" should usually be
% imported and configured after every other package is imported and configured.
%
% Configure the "hyperref" package. Thanks for the applicable settings, Nick and
% Lorenzo.
\hypersetup{%
  breaklinks=true,colorlinks=true,
  hyperfootnotes=false,hypertexnames=true,%
  linktocpage=true,pageanchor=true,plainpages=false,%
  bookmarksnumbered=true,%
  bookmarksopen=true,bookmarksopenlevel=1,%
  pdfhighlight=/O,%
  pdfstartpage=3,pdfstartview=FitV,pdfpagemode=UseOutlines,%
  pdfsubject={},%
  pdfkeywords={},%
  pdfcreator={pdfLaTeX},%
  pdfproducer={LaTeX with hyperref and classicthesis},%
  pdfpagelabels=true,pdftex=true%
}

% Configure the "hyperref" package's link colors according to whether we are
% producing the output PDF for physical monochrome or on-screen display: if
% monochrome, inhibit colors (i.e., enforce monochrome); otherwise, allow colors.
\ifthenelse{\boolean{ctl@monochrome}}%
  {% Print in monochrome.
   \hypersetup{%
     colorlinks=false,%
     anchorcolor=black,%
     citecolor=black,%
     filecolor=black,%
     linkcolor=black,%
     menucolor=black,%
     runcolor=black,%
     urlcolor=black,%
     linkcolor=black,%
  }}%
  {% Display in polychrome.
   \hypersetup{%
     colorlinks=true,%
     citecolor=RoyalBlue,%
     linkcolor=RoyalBlue,%citecolor=WebGreen,%
     urlcolor=webbrown
  }}

% Configure the "hyperref" package's PDF title and author according to which
% classicthesis user variables the user has set.
\ifdefined\myTitle 
   \hypersetup{pdftitle={\myTitle}}
\else 
   \relax
\fi

%FIXME: Be nice if we could incorporate this in a similar fashion.
%pdfauthor={\textcopyright\ \myName, \myUni, \myFaculty},%
\ifdefined\myName 
   \hypersetup{pdfauthor={\textcopyright\ \myName}}
\else 
   \relax
\fi

% ....................{ COMMANDS                           }....................
% Define commands intended to be used within the actual LyX documents themselves
% after importing and configuring all packages, so as to ensure we may call
% commands defined by those packages without concern. (See
% "classicthesis-lyx-ldpkg.sty" for the default collection of classicthesis-
% defined commands.)

%FIXME: Bizarre. Replacing \smallskip with \mediumskip here causes this command
%to fail with inexplicable error. Hey, anyone know why?
% Define a \graffito-specific command for printing quotations as margin notes.
\newcommand{\graffitoquote}[3]
  {\graffito{\noindent\textit{#1}\par\smallskip --- #2, \textsc{#3}}}

% Define a command for emphasizing distinguishable nouns: e.g., software,
% hardware, institutions, et al.
\newcommand{\noun}[1]{\texttt{#1}}

% Define a command for emphasizing the subject of each item in an itemization or
% enumeration: generally, the initial sentence or sentence fragment of the item.
\newcommand{\itemlead}[1]{\textsc{#1}}

% ....................{ COMMANDS =title page               }....................
% Define commands for professing (i.e., printing with emphasis) various metadata
% on the thesis title page.
\newcommand{\professTitle}%
  {\begin{center}\color{Maroon}\large\spacedallcaps{\myTitle}\end{center}}
\newcommand{\professTitleWithSubtitle}{
  \begin{center}
    \sffamily\color{Maroon}\linespread{1.5}\selectfont
    \large{\spacedallcaps{\myTitle}}\\
    \mySubtitle
  \end{center}
}
\newcommand{\professName}%
  {\begin{center}\large\spacedlowsmallcaps{\myName}\end{center}}
\newcommand{\professDegree}%
  {\begin{center}\large\spacedlowsmallcaps{\myDegree}\end{center}}
\newcommand{\professDepartment}%
  {\begin{center}\myDepartment\end{center}}
\newcommand{\professFaculty}%
  {\begin{center}\myFaculty\end{center}}
\newcommand{\professUniversity}%
  {\begin{center}\myUniversity\end{center}}
\newcommand{\professTimestamp}%
  {\begin{center}\myTimestamp\end{center}}

% ....................{ COMMANDS =title page (back)        }....................
% Define commands for itemizing thesis metadata on the "back" (i.e., next left-
% hand page) of the necessarily right-hand thesis title page.
\newcommand{\itemizeThesis}%
  {\myName: \emph{\myTitle{}}, \myDegree\ \textcopyleft{}~\myTimestamp}
\newcommand{\itemizeSupervisors}%
  {\spacedlowsmallcaps{Supervisors}: \\\myProfessor}
\newcommand{\itemizeLocation}%
  {\spacedlowsmallcaps{Location}: \\\myLocation}
\newcommand{\itemizeDuration}%
  {\spacedlowsmallcaps{Duration}: \\\myDuration}

% ....................{ COMMANDS =disclaimer               }....................
% Define commands for disclaiming a full-page copy(left|right) license.
\newcommand{\disclaimCopyright}{
  \begin{center}
    \sffamily\linespread{1.5}\selectfont
    \spacedallcaps{Copyleft \textcopyleft \myYear by \myName}\\
    Some Rights Reserved
  \end{center}
}
\newcommand{\disclaimLicense}{
  \begin{center}\CcGroupByNcSa{scale=1.0}{0.95ex}\end{center}
  \begin{center}
    \spacedallcaps{Attribution -- Noncommercial -- Share Alike}
  \end{center}
}

% --------------------( COPYRIGHT AND LICENSE              )--------------------
% The information below applies to everything in this distribution,
% except where noted.
%              
% Copyleft 2009-2010 by Cecil Curry.
%   
%   http://www.raiazome.com
% 
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
