Work around potential \chapter{Bla bla\label{x}} usage.
[drexel-thesis.git] / drexel-thesis.dtx
index d6241f854705f0c16c078e17a140f0346fe156d8..97127483aa63b2ba9ea2b0f289913aa4f9b65fde 100644 (file)
@@ -1,8 +1,8 @@
-% \def\fileversion{0.3}
-% \def\filedate{2010/01/13}
+% \def\fileversion{0.8}
+% \def\filedate{2010/05/20}
 % \iffalse meta-comment
-%<class>\def\fileversion{0.3}
-%<class>\def\filedate{2010/01/13}
+%<class>\def\fileversion{0.8}
+%<class>\def\filedate{2010/05/20}
 %
 % Copyright (C) 2010  C.Y. Ip
 %                     Christopher D. Cera
 %   Based on the University of Toronto Thesis \LaTeXe\ Class.  Also
 %   greatly improved the documentation by incorperating bits of
 %   the base/*.dtx files.}
+% \changes{0.4}{2010/02/23}{W.~Trevor King repositioned hyperref
+%   inclusion for proper hyperref overriding.  The previous
+%   implementation couldn't handle $\backslash$label for
+%   $\backslash$paragraph and some other section levels.  The page
+%   number for the reference was correct, but the link went to the
+%   label's parent chapter.}
+% \changes{0.5}{2010/03/03}{W.~Trevor King use hypcap for better
+%   caption hyperlink anchor placement.}
+% \changes{0.6}{2010/03/11}{W.~Trevor King fixed
+%   $\backslash$if\@ final handling.  Previous versions used
+%   it more like a hypothetical $\backslash$if\@ finalspace.
+%   Also adjusted theindex to use a listed\@ schapter.}
 %
 % \MakeShortVerb{\|}
 % \newcommand{\pkg}[1]{\textsf{#1}}
 % See the Manual 3.2 p9.
 %
 % \begin{command}
-%   `\cs{copyrighttextCC}'
+%   `\cs{copyrighttextCCBYSA}'
 % \end{command}
 % There are a number of predefined copyright messages for ease of use \\
 % \begin{tabular}{l l}
-%   |\copyrighttextCC| & Creative Commons copyright \\
+%   |\copyrighttextCCBYSA| &
+%     Creative Commons Attribution-ShareAlike License Version 3.0.\\
 % \end{tabular}
 %
 % \begin{command}
 % The skipped lines are always \emph{single spaced} lines, regardless
 % of the current line spacing in the environment calling this macro.
 %
+% \begin{command}
+%   `\cs{iffinal}\marg{final-mode-action}\marg{draft-mode-action}'
+% \end{command}
+% \DescribeMacro{\iffinal}
+% Include \Lopt{final}- or \Lopt{draft}-specific code.
+% \begin{example}
+%   We're in \iffinal{final}{draft} mode!
+% \end{example}
+%
 %
 % \subsection{Environments}
 %
 % \href{http://www.ctan.org/tex-archive/macros/latex/required/graphics/}{\pkg{graphicx}}
 % to define the |\includegraphics| macro,
 % \href{http://www.ctan.org/tex-archive/macros/latex/required/caption/}{\pkg{caption}}
-% for pretty caption formatting, and
+% for pretty caption formatting,
 % \href{http://www.ctan.org/tex-archive/macros/latex/required/floatrow/}{\pkg{floatrow}}
-% for placing captions.
+% for placing captions, and
+% \href{http://www.ctan.org/tex-archive/macros/latex/contrib/oberdiek/}{\pkg{hypcap}}
+% for placing caption anchors.
 %
 % Simple float definitions will look like
 % \begin{example}
 \newif\if@draftwatermark
 \newif\if@mydraftwatermark
 \newif\if@indentfirst
-\newif\if@final \@finalfalse
+\newif\if@final
 %    \end{macrocode}
 %
+% \begin{macro}{\iffinal}
+% Setup a user-friendly means for including \Lopt{final}- or
+% \Lopt{draft}-specific code.
+% \changes{0.7}{2010/03/14}{W.~Trevor King added macro.}
+%    \begin{macrocode}
+\newcommand\iffinal[2]{\if@final #1\else #2\fi}
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{option}{subfig}
 % Set \Lopt{subfig} flag
 %    \begin{macrocode}
   \def\@ssp{1} % single space
   \def\@dsp{2} % double space
   \def\@tsp{3} % triple space
-  \@finaltrue
 }
 %    \end{macrocode}
 % \end{option}
 %  Don't force chapters onto right-hand pages.
 %    \begin{macrocode}
   \PassOptionsToClass{openany}{book}
-  \@finalfalse
 }
 %    \end{macrocode}
 % \end{option}
 % \begin{option}{final}
 %    \begin{macrocode}
 \DeclareOptionX{final}{
+  \@finaltrue
   \setkeys{drexel-thesis.cls}{oneside}
   \setkeys{drexel-thesis.cls}{finalspace}
   \setkeys{drexel-thesis.cls}{dottedtoc}
 % \begin{option}{draft}
 %    \begin{macrocode}
 \DeclareOptionX{draft}{
+  \@finalfalse
   \setkeys{drexel-thesis.cls}{twoside}
   \setkeys{drexel-thesis.cls}{draftspace}
   \setkeys{drexel-thesis.cls}{dottedtoc}
 % \subsubsection{\pkg{subfig}}
 % \label{sec:subfig}
 %
-% Allow multi-partfigures with
+% Allow multi-part figures with
 % \href{http://www.ctan.org/tex-archive/macros/latex/contrib/subfig/}{\pkg{subfig}}.
 %    \begin{macrocode}
 \if@DUT@subfigopt
 %    \end{macrocode}
 % 
 % \subsubsection{\pkg{hyperref}}
+% \label{sec:hyperref}
 %
 % \href{http://www.ctan.org/tex-archive/macros/latex/contrib/hyperref/}{\pkg{hyperref}}
 % for hyperlinks.  Not strictly necessary, but I can't imagine a
-% thesis without it.
-%    \begin{macrocode}
-\RequirePackage[final]{hyperref}
-%    \end{macrocode}
-% Nobody likes the default colored boxes.  Color the text itself.
-%    \begin{macrocode}
-\hypersetup{colorlinks}
-%    \end{macrocode}
-% If we're writing a PDF, we set the |pdfauthor|, etc.\ arguments in
-% |\author|, etc.\ to avoid using |\AtBeginDocument| or some such.
+% thesis without it.  We actually include this later
+% (Section~\ref{sec:hyperref-inclusion}), because \pkg{hyperref}
+% sticks its fingers into \emph{everything} and we want it to use our
+% versions of some macros (e.g. |\@sect|) but not others
+% (e.g. |thebibliography|).
+%
+%
+% \subsubsection{\pkg{hypcap}}
+% \label{sec:hypcap}
+%
+% \href{http://www.ctan.org/tex-archive/macros/latex/contrib/oberdiek/}{\pkg{hypcap}}
+% for placing caption hyperlink anchors.  Must be included after
+% \pkg{hypercap}, so the actual inclusion is in
+% Section~\ref{sec:hypcap-inclusion}).
 %
 %
 % \subsection{\LaTeX\ overrides and extensions}
 % |\author| for use in |\maketitle|.  If not given |\maketitle| will
 % produce a warning message (\file{ltsect.dtx}, L129).
 %
-% We extend |\author| to set \pkg{hyperref}'s |pdfauthor|.
+% We extend |\author| to set \pkg{hyperref}'s |pdfauthor| if we're
+% writing a PDF to avoid using |\AtBeginDocument| or some such.
 % (\file{ltsect.dtx}, L129).
 %    \begin{macrocode}
 \let\DUT@author\author
 % \begin{macro}{\DUT@baselineskip}
 % Since we'll be messing with the spacing, save the single-spaced
 % baseline.
-%   \changes{0.3}{2010/01/13}{Use \\setlength to store the value at
-%     the default font.  The previous version used \\let, which made
-%     \\DUT\@baselineskip a synonym for \\baselineskip that changed
-%     with font size.}
+%   \changes{0.3}{2010/01/13}{Use $\backslash$setlength to store the
+%     value at the default font.  The previous version used
+%     $\backslash$let, which made $\backslash$DUT\@baselineskip a
+%     synonym for $\backslash$baselineskip that changed with font
+%     size.}
 %    \begin{macrocode}
 \newlength\DUT@baselineskip
 \setlength\DUT@baselineskip\baselineskip
 % \end{macro}
 %
 %
+% \subsection{\pkg{hyperref} inclusion}
+% \label{sec:hyperref-inclusion}
+%
+% This is the awkward \pkg{hyperref} inclusion.  See
+% Section~\ref{sec:hyperref} for an explanation of why we stash it
+% here.
+%    \begin{macrocode}
+\RequirePackage[final]{hyperref}
+%    \end{macrocode}
+% Nobody likes the default colored boxes.  Color the text itself.
+%    \begin{macrocode}
+\hypersetup{colorlinks}
+%    \end{macrocode}
+%
+% \subsubsection{\pkg{hypcap}}
+% \label{sec:hypcap-inclusion}
+%
+% \href{http://www.ctan.org/tex-archive/macros/latex/contrib/oberdiek/}{\pkg{hypcap}}
+% for placing caption hyperlink anchors.  Not strictly necessary, but
+% we're using \pkg{hyperref}, and the poor link targets are annoying.
+%    \begin{macrocode}
+\RequirePackage[all]{hypcap}
+%    \end{macrocode}
+% \Lopt{all} redefines the figure and table environments to
+% place the anchor at the start of the float.
+%
+%
 % \subsection{\cls{book} overrides and extensions}
 %
 % Here we change the behavior of a bunch of macros and environments from
 % bookmark is set at the \emph{part} level (-1) to hold all bookmarks
 % from the |preamble| environment, since those entries are all
 % chapters.
+% \changes{0.8}{2010/05/20}{W.~Trevor King replaced Titlepage with
+%   Title Page for consistency with \LaTeX's book class.}
 %    \begin{macrocode}
     \ifpdf
-      \pdfbookmark[-1]{Frontmatter}{Frontmatter}
+      \pdfbookmark[-1]{Front Matter}{Front Matter}
       \pdfbookmark[0]{Title Page}{Title Page}
     \fi
 %    \end{macrocode}
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\copyrighttextCC}
-% The Creative Commons license.
+% \begin{macro}{\copyrighttextCCBYSA}
+% The Creative Commons Attribution-ShareAlike License.
+% \changes{0.4}{2010/02/23}{W.~Trevor King renamed from
+% $\backslash$copyrighttextCC, and made specific to Creative Commons
+% Attribution-ShareAlike Version 3.0.}
 %    \begin{macrocode}
-\newcommand\copyrighttextCC{
+\newcommand\copyrighttextCCBYSA{
   \begin{quote}
     This work is licensed under the terms of the Creative Commons
-    Attribution-ShareAlike license.  The license is available at \\
+    Attribution-ShareAlike license Version 3.0.  The license is
+    available at \\
     \url{http://creativecommons.org/licenses/by-sa/3.0/}.
   \end{quote}
 }
 % \subsubsection{Front Matter, Main Matter, and Back Matter}
 %
 % A book contains these three (logical) sections. The switch
-% |\@mainmatter| is true iff we are processing Main Matter.  When this
-% switch is false, the |\chapter| command does not print chapter
-% numbers.
+% |\@mainmatter| is true if and only if we are processing main
+% matter\footnote{%
+%   \href{http://en.wikipedia.org/wiki/Book_design}{Wikipedia}
+%   suggests \emph{body matter} for the main content, but
+%   \href{http://mirror.ctan.org/macros/latex/base/classes.dtx}{\LaTeX's
+%   \cls{book}} uses \emph{Main Matter}.  We're a \LaTeX\ class, so
+%   we'll stick with ``main matter'' for consistency.
+% }.  When this switch is false, the
+% |\chapter| command does not print chapter numbers.
 %
 % \begin{macro}{\mainmatter}
 % This command clears the page (in final mode), starts arabic page
 % we display the chapter number.
 % We drop \cls{book}'s \Lopt{twocolumn} code. 
 % (\file{classes.dtx}, L2496).
-% \begin{macrocode}
+%    \begin{macrocode}
 \def\@chapter[#1]#2{
-% \end{macrocode}
+%    \end{macrocode}
 % Inform the user that a new chapter is about to be typeset by writing
 % a message to the terminal.
-% \begin{macrocode}
+% \changes{0.9}{2010/05/21}{W.~Trevor King. disabled the label macro
+% for typeout.}
+% Some users place |\label| in their chapter argument:
+% \begin{example}
+%   \chapter{Bla bla\label{x}}
+% \end{example}
+% rather than after (as recommended by
+% \href{http://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing#Sections}%
+%   {the \LaTeX\ Wikibook} and
+% \href{http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf}%
+%   {The Not So Short Introduction to \LaTeXe\ (section 2.8, p36)}):
+% \begin{example}
+%   \chapter{Bla bla}
+%   \label{x}
+% \end{example}
+% The embedded |\label| chokes |\typeout| so we temporarily redefine
+% |\label| to just gobble its contents.  |\DUT@label| stores the
+% original definition.
+%    \begin{macrocode}
+  \let\DUT@label=\label%
+  \renewcommand{\label}[1]{}%
   \typeout{\@chapapp\space\thechapter. #1}%
+%    \end{macrocode}
+% Restore |\label| to its previous glory.
+%    \begin{macrocode}
+  \let\label=\DUT@label%
+%    \end{macrocode}
+% Now we can get on with the real work.
+%    \begin{macrocode}
   \ifnum \c@secnumdepth >\m@ne
     \if@mainmatter
       \refstepcounter{chapter}%
 % Workaround is to pass the ``value of blanklines you want minus two''
 % to |\blanklines*|.  HACK!
 %    \begin{macro}
-  \blanklines*{-1}%
+  \blanklines*{-1}% HACK!
   {\parindent \z@ \raggedright \normalfont
 %    \end{macrocode}
 % Ensure single spacing.
 % \pkg{fancyhdr}.
 % (\file{classes.dtx}, L2582).
 %    \begin{macrocode}
-\def\@schapter#1{\schaptermark{#1}%
-                 \@makeschapterhead{#1}%
-                 \@afterheading}
+\def\@schapter#1{
+%    \end{macrocode}
+% Inform the user that a new chapter is about to be typeset by writing
+% a message to the terminal.
+%    \begin{macrocode}
+  \typeout{\@chapapp\space #1}%
+  \schaptermark{#1}%
+  \@makeschapterhead{#1}%
+  \@afterheading}
 %    \end{macrocode}
 % \end{macro}
 %
 }{%
   \setstretch{\@ssp}%
   \DUT@clearpage
+%    \end{macrocode}
+% \changes{0.8}{2010/05/20}{W.~Trevor King replaced Titlepage with
+%   Title Page for consistency with \LaTeX's book class.}
+%    \begin{macrocode}
   \ifpdf
     \phantomsection
-    \pdfbookmark[-1]{Backmatter}{Backmatter}
+    \pdfbookmark[-1]{Back Matter}{Back Matter}
   \fi
 }
 %    \end{macrocode}
 %    \begin{macrocode}
 \newcommand{\bib@heading}{%
   \listed@schapter{\bibname}%
-  \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
 }
 %    \end{macrocode}
 % \end{macro}
 %
+%
+% \subsubsection{Index}
+%
+% \begin{environment}{theindex}
+% The environment |theindex| can be used for indices. It makes an
+% index with two columns, with each entry a separate paragraph. At
+% the user level the commands |\item|, |\subitem| and |\subsubitem|
+% are used to produce index entries of various levels. When a new
+% letter of the alphabet is encountered an amount of |\indexspace|
+% white space can be added.
+%
+% Override \cls{book}'s version, adding a line to the table of
+% contents.  We split out the section-creation code into
+% |\bib@heading| for \pkg{natbib} compatibility.
+% (\file{classes.dtx}, L4107).
+%    \begin{macrocode}
+\renewenvironment{theindex}
+               {\if@twocolumn
+                  \@restonecolfalse
+                \else
+                  \@restonecoltrue
+                \fi
+%    \end{macrocode}
+% Here we add our TOC entry, and setup two-columness by hand
+% to avoid the |\clearpage| in \LaTeX's default |\twocolumn|.
+%    \begin{macrocode}
+  \listed@schapter{\indexname}
+  \global\columnwidth\textwidth
+  \global\advance\columnwidth-\columnsep
+  \global\divide\columnwidth\tw@
+  \global\hsize\columnwidth
+  \global\linewidth\columnwidth
+  \global\@twocolumntrue
+  \global\@firstcolumntrue
+  \col@number \tw@
+%    \end{macrocode}
+%    Parameter changes to |\columnseprule| and |\columnsep| have to be
+%    done after |\twocolumn| has acted. Otherwise they can affect the
+%    last page before the index.
+%    \begin{macrocode}
+                \parindent\z@
+                \parskip\z@ \@plus .3\p@\relax
+                \columnseprule \z@
+                \columnsep 35\p@
+                \let\item\@idxitem}
+%    \end{macrocode}
+%    When the document continues after the index and it was a one
+%    column document we have to switch back to one column after the
+%    index.
+%    \begin{macrocode}
+               {\if@restonecol\onecolumn\else\DUT@clearpage\fi}
+%    \end{macrocode}
+% \end{environment}
+%
+%
 % \subsubsection{Words}
 % \label{sec:words}
 %
 \end{preamble}
 
 \begin{thesis}
+%% If your thesis does not use \part{}s, you may want to add a
+%% part-level PDF bookmark to set the main matter of from the front
+%% matter.
+%%\pdfbookmark[-1]{Main Matter}{Main Matter}
+
 %% Use include statements to include your main thesis code
 %% from seperate files.
 %%\include{part1}
 \advisor{Collis Potter Huntington, R.R.D.}
 \advisor{Advisor 2, Ph.D.}
 \advisor{Advisor 3, Ph.D.}
-\copyrighttext{\copyrighttextCC}
+\copyrighttext{\copyrighttextCCBYSA}
 
 \usepackage[super,sort&compress]{natbib} % fancy citation extensions
 \bibliographystyle{unsrtnat}
 \begin{preamble}
 
 \begin{dedications}
-\Blindtext{10}{10}
+We're in \iffinal{final}{draft} mode!
+
+\Blindtext[3]
 \end{dedications}
 
 \begin{acknowledgments}
-\Blindtext{10}{10}
+\Blindtext[3]
 \end{acknowledgments}
 
 \tableofcontents
 \listoffigures
 
 \begin{abstract}
-\Blindtext{10}{10}
+\Blindtext[3]
 \end{abstract}
 \end{preamble}
 
 \include{example-a}
 
 \begin{vita}
-\Blindtext{10}{10}
+\Blindtext[3]
 \end{vita}
 
 \end{document}
@@ -2961,7 +3138,7 @@ Here we have a text citation \citet{rief97} followed by a
 parenthetical citation\citep{rief97}.
 
 \subsubsection{Tables and Figures}
-\Blindtext{2}{20}
+\Blindtext[2]
 \begin{table}
   \begin{center}
   \begin{tabular}{r@{.}l r@{.}l r@{.}l}
@@ -2973,7 +3150,7 @@ parenthetical citation\citep{rief97}.
     30&0 & 11&9 & 10&1 \\
     \ldots
   \end{tabular}
-  \caption{A table float.} %\blindtext{20}}  % low caption allowed with floatrow
+  \caption{A table float.} % low caption allowed with floatrow
 %% Note the strange |r@{.}l| notation in the |\tabular| column
 %% definition.  This allows for numbers aligned at the decimal point
 %% (see \href{http://www.stat.unipg.it/tex-man/ltx-68.html}{here}).
@@ -2982,14 +3159,14 @@ parenthetical citation\citep{rief97}.
 %% to span the pre- and post-decimal columns.
   \end{center}
 \end{table}
-\Blindtext{5}{20}
+\Blindtext[2]
 \begin{figure}
-  \caption{A figure float. \blindtext{20}} % high caption allowed with floatrow
+  \caption{A figure float. \blindtext} % high caption allowed with floatrow
   \begin{center}
     \includegraphics[width=0.4\textwidth]{drexel-logo}
   \end{center}
 \end{figure}
-\Blindtext{10}{20}
+\Blindtext[3]
 \begin{figure}
   \begin{center}
     \subfloat[][]{%
@@ -3005,14 +3182,14 @@ parenthetical citation\citep{rief97}.
 You can reference the subfig floats individually (\ref{fig:sub-a}) or
 together (\ref{fig:both}).
 
-\Blindtext{10}{20}
+\Blindtext[3]
 
 \part{Another Part}
 \chapter{Another Chapter}
-\Blindtext{30}{20}
+\Blindtext[5]
 \chapter{A Long Title Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla
 Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla}
-\Blindtext{30}{20}
+\Blindtext[5]
 %</example-part>
 %    \end{macrocode}
 %
@@ -3081,9 +3258,9 @@ Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla}
 %    \begin{macrocode}
 %<*example-appendix>
 \chapter{Some Appendix Heading}
-\Blindtext{10}{20}
+\Blindtext[5]
 \chapter{Another Appendix Heading}
-\Blindtext{10}{20}
+\Blindtext[5]
 %</example-appendix>
 %    \end{macrocode}
 %