%%%%%%%%%%%%%%%%%%
% layoutv3.tex
% Copyright @ 2018 Robert Petry
% This file contains a list of commands for determining the formatting
% of the textbook.
%%%%%%%%%%%%%%%%%%
% Set a font encoding
\usepackage[T1]{fontenc}
\usepackage{lmodern}
% The following make micro-typographical improvements
\usepackage{microtype}
%The following is useful to allow boxing of formulas, etc.
\usepackage{boxedminipage}
%Create environments boxedequation and boxedeqnarray which can be used
%exactly like the equation and eqnarray environments.  Note that I needed
%to put a \par\vspace{-\parskip} in the definition to make it so that the
%equations starts on a new line without inserting paragraph space (like it
%would for a regular equation.)  If you want to box an unnumbered equation
%such as would be produced by \[ ... \], you can use
% \[\boxed{...}\]
%which is provided by the amsmath package below.
% The * versions of the boxedequation and boxedeqnarray* also don't number the
% equations but the box extends the whole page width.
%Note the empheq package exists which could be used for more sophisticated things.
\newenvironment{boxedequation}{\par\vspace{-\parskip}\begin{boxedminipage}{\textwidth}\begin{equation}}{\end{equation}\end{boxedminipage}}
\newenvironment{boxedequation*}{\par\vspace{-\parskip}\begin{boxedminipage}{\textwidth}\begin{equation*}}{\end{equation*}\end{boxedminipage}}
\newenvironment{boxedeqnarray}{\par\vspace{-\parskip}\begin{boxedminipage}{\textwidth}\begin{eqnarray}}{\end{eqnarray}\end{boxedminipage}}
\newenvironment{boxedeqnarray*}{\par\vspace{-\parskip}\begin{boxedminipage}{\textwidth}\begin{eqnarray*}}{\end{eqnarray*}\end{boxedminipage}}
% The following is a second version of boxedeqnarray which inserts some negative
% space at the top to prevent having too much space at the top.
\newenvironment{boxedeqnarray2}{\par\vspace{-\parskip}\begin{boxedminipage}{\textwidth}\vspace{-1em}\begin{eqnarray}}{\end{eqnarray}\end{boxedminipage}}
%The following allows one to box a piece of text.
\newcommand{\boxedtext}[1]{{\centering\fbox{\parbox{.9\textwidth}{{#1}}}}}
%%The following allows the \vref command which acts like \ref but adds
%text which refers to the page the table is on.
\usepackage{varioref}
%This package allows us to define a new float (like a table or figure).
%This allows me below to create the \textassignment command which puts
%a box around an assignment and floats it to the bottom of the current page.
\usepackage{float}
\floatstyle{plain}
\newfloat{assignmentfloat}{b}{.assign}
%The following command takes two arguments, the first is the reading assigned
%while the second is the list of problems.  We use the problem list to
%define the box width.  If it isn't a longer line than the reading list
%one will have to pad it accordingly.
\makeatletter
\newlength{\@assignmentboxlength}
\newcommand{\textassignment}[2]{
\settowidth{\@assignmentboxlength}{{#2}}
\addtolength{\@assignmentboxlength}{2ex}
\begin{assignmentfloat}
\begin{boxedminipage}{\@assignmentboxlength}
\textbf{Reading:}

{#1}

\textbf{Problems:}

{#2}
\end{boxedminipage}
\end{assignmentfloat}
\clearpage}
\makeatother
% The next assignment is for actual problems in the text of the document.
% The lone argument is the text.
% The command uses the framed package.  There are several options, framed
% (which puts a frame around the text), leftbar (which puts a bar down the
% left side), and shaded (which shades the background a given color).  I've
% gone with a frame to save ink.
\usepackage{framed}
% A frame:
\newcommand{\assignment}[1]{\begin{framed}\raggedright\textbf{Assignment: }{#1}\end{framed}}
% A left bar:
%\newcommand{\assignment}[1]{\begin{leftbar}\raggedright\textbf{Assignment: }{#1}\end{leftbar}}
% A grey backing: (requires the color package etc.)
%\usepackage{color}
%\definecolor{shadecolor}{gray}{0.9}
%\newcommand{\assignment}[1]{\begin{shaded}\raggedright\textbf{Assignment: }{#1}\end{shaded}}

%\newcommand{\assignment}[1]{\begin{framed}\textbf{Assignment: }\newline{#1}}\end{framed}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following is for a text reference/page assignment.  It will appear in
% the margin.  Currently the references are set as an empty command.
% The mparhack package helps ensure that margins are in the correct place.
\usepackage{mparhack}
%\newcommand{\reading}[1]{\marginpar{\hrule\vspace{.3em}\small\raggedright\textbf{Text:\linebreak}{#1}\vspace{.3em}\hrule}}
\newcommand{\reading}[1]{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%We need the xparse command to allow for more sophisticated argument parsing.
%(See texdoc xparse).  xparse is used elsewhere as well in this file.
% Note http://www.texdev.net/tag/xparse/ has some good examples with xparse.
\usepackage{xparse}
%%%%%%%%%%%%%%%%%%%%
% The \definition command highlights text as a definition.
\newcommand{\definition}[1]{\begin{description}\item[Definition:]{#1}\end{description}}
% The \theorem command highlights text as a theorem.  See the wikibooks latex
% entry on the theorem package.
\usepackage{amsthm}
% Define my own theoremstyle which is essentially the same as definition
% (so no italics in the text) with the exception that the period is
% at the end of the theorem number is replaced with a colon.
\newtheoremstyle{mytheoremstyle}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\normalfont}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\bfseries} % HEADFONT
  {:}         % HEADPUNCT (Removed the default period here.)
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {}          % CUSTOM-HEAD-SPEC
\theoremstyle{mytheoremstyle}
% In general theorems will be numbered with chapters, however when making
% handouts the documentclass is article which has no chapters.  The
% following code checks we aren't an article before defining the chapter
% numbering.
\makeatletter
\@ifclassloaded{article}
  {\newtheorem{mytheorem}{Theorem}}
  {\newtheorem{mytheorem}{Theorem}[chapter]}%
\makeatother
% My current convention for numbering examples is to use a dash rather
% than a period between the sectioning number (here the chapter) and
% the theorem counter within the section.  (The default is to write 3.1, etc.
% which is confusing with subsectioning names.)  I modify it so it writes
% 3-1.
\renewcommand{\themytheorem}{\thechapter-\arabic{mytheorem}}%
% Up to this point we have the mytheorem environment and so one can write
% \begin{mytheorem} ... \end{mytheorem} or one can write {\mytheorem ...}
% Since I want to be able to write \theorem{...} I now define the following.
% Unfortunately we cannot use the same word for mytheorem as theorem as the
% mytheorem command is automatically defined with the environment.
\newcommand{\theorem}[1]{{\mytheorem{#1}}}
% This was my original attempt:
%\newcommand{\theorem}[1]{\begin{description}\item[Theorem:]{#1}\end{description}}
% Variables for the title page.  Define these in your preamble.
% Note the logo will be placed to the left of the name.  If the logo already
% has a name, then for the institution just put an empty rule, eg.
% \institution{\rule{0em}{1em}}
\makeatletter
\def\institution#1{\gdef\@institution{#1}}
\def\institutiontwo#1{\gdef\@institutiontwo{#1}}%Name of a second (optional) institution
\def\logofile#1{\gdef\@logofile{#1}}%The file containing institution's logo.
\def\logofiletwo#1{\gdef\@logofiletwo{#1}}%The file containing an (optional) second institution's logo.
\def\department#1{\gdef\@department{#1}}
\def\coursenumber#1{\gdef\@coursenumber{#1}}
\def\coursetitle#1{\gdef\@coursetitle{#1}}
\def\unittitle#1{\gdef\@unittitle{#1}}
\def\unitnumber#1{\gdef\@unitnumber{#1}}
\def\date#1{\gdef\@date{#1}}
\def\author#1{\gdef\@author{#1}}
\def\coverpic#1{\gdef\@coverpic{#1}}
%Note the publisher, when using the GNU Free Documentation License is just
%the entity which is distributing copies.  It conveys no ownership rights.
\def\publisher#1{\gdef\@publisher{#1}}
\makeatother
% Command for creating the title page for a unit.  Put it after the \begin{document}
\makeatletter
\def\makecoursetitle{\begin{titlepage}
% The following is unnecessary assuming the \frontmatter command is used
%\pagenumbering{roman}
%\setcounter{page}{1}
 \null
 \begin{center}
   \Huge
   \bfseries
   %Note this page has useful discussion on centering images:
   %http://tex.stackexchange.com/questions/7219/how-to-vertically-center-two-images
   \@ifundefined{logofiletwo}{%Only one logo
   \resizebox{.7\textwidth}{!}{%
     \raisebox{-0.5\height}{\includegraphics[height=1em]{\@logofile}}~%
     \raisebox{-0.5\height}{\resizebox{!}{.8em}{\@institution}}%
     }%
     }{%Two logos
   \resizebox{.8\textwidth}{!}{%
     \raisebox{-0.5\height}{\includegraphics[height=1em]{\@logofile}}~%
     \raisebox{-0.5\height}{\resizebox{!}{.8em}{\@institution}}\hfill%
     \raisebox{-0.5\height}{\includegraphics[height=1em]{\@logofiletwo}}~%
     \raisebox{-0.5\height}{\resizebox{!}{.8em}{\@institutiontwo}}%
   }%
   }
   \vfill
   \vfill
   \@coursenumber \par
   {\@coursetitle}
   \vfill
\begin{center}
%\fbox{\includegraphics[height=3.8in]{\@coverpic}}
\includegraphics[height=3in]{\@coverpic}
\end{center}
   \vfill
       {\large by \@author \par}
   \vfill
   {\normalsize published by \@publisher \par}
   \vfill
 \end{center} \par
 \null
\end{titlepage}
\let\thanks\relax
\gdef\@thanks{}\gdef\@author{}\gdef\@title{}\let\maketitle\relax}
\makeatother
% Command for creating the title page for a unit.  Put it after the \begin{document}
\def\makeunittitle{\begin{titlepage}
\pagenumbering{roman}
\setcounter{page}{1}
 \null
 \begin{center}
   \Huge
   \bfseries
   {\@institution \par}
   \vfill
   \vfill
   {\@department \par}
   {\@course \par}
   \vfill
   {Lecture Notes and Examples \par}
   \vfill
   Unit {\@unitnumber} \par
   {\@unittitle}
   \vfill
   \vfill
   {\large by \@author \par}
   \vfill
   {\normalsize published by \@publisher \par}
   \vfill
   \vfill
   \vfill
 \end{center} \par
 \null
\end{titlepage}
\let\thanks\relax
\gdef\@thanks{}\gdef\@author{}\gdef\@title{}\let\maketitle\relax}
%This command is just for typesetting the unit header on the first actual
%page of text.  It uses the \unittitle and \unitnumber above.
\newcommand{\unitheader}{
\begin{center}
\begin{Large}
\textbf{Unit {\@unitnumber}}

\textbf{{\@unittitle}}
\end{Large}
\end{center}
\vspace{-2em}
}
% The following defines our margins.  This may break compatibility
% with how units 1-3 were originally formatted.
%\usepackage[outer=3cm,top=2.75cm,inner=3cm,bottom=2.75cm]{geometry}
\usepackage[outer=3.5cm,top=2.75cm,inner=2.5cm,bottom=2.75cm]{geometry}
%%%%%%%%%%%%%%
% I want to call my chapter's Unit rather than Chapter.  Use \chaptername
% in the text when making the reference to make changes easier later.
% We use the xparse command creator because in the article class the command
% doesn't exist already while in book it does.  \Declare... works regardless.
%\DeclareDocumentCommand\chaptername{}{Unit}
%%%%%%%%%%%%%%
%The following package ensures the footnote is at the bottom of the page
%even when there is space left on the page.  Note I could add the ragged
%option here if I wanted footnotes typeset raggedright.
\usepackage[bottom]{footmisc}
%%%%%%%%%%%%%%
\usepackage{dcolumn}%Useful for formatting tables with decimals
%%%%%%%%%%%%%%
%The following defines how we want our headers and footers
%We won't have footers since there are footnotes.  Some of the footer
%commands have been left in commented out.
\usepackage{fancyhdr}
\pagestyle{fancy}
%This renews the \chaptermark and \sectionmark commands to format
%with fewer capitals.  See the fancyhdr texdoc pages.  For chaptermark
%use DeclareDocumentCommand since \chaptermark may or may not already exist
%based on the document class.
%\renewcommand{\chaptermark}[1]{% 
%\markboth{#1}{}}
\DeclareDocumentCommand\chaptermark{ m }{% 
\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\renewcommand\headrulewidth{.4pt}
%\renewcommand\footrulewidth{.4pt}
\makeatletter
\if@twoside
%The following work for two-sided printing
\fancyhead{}%clear header fields
\fancyhead[LO]{\footnotesize{\emph{\leftmark}}}
\fancyhead[RO]{\textbf{\thepage}}
\fancyhead[RE]{\footnotesize{\emph{\rightmark}}}
\fancyhead[LE]{\textbf{\thepage}}
\fancyfoot{}%clear footer fields
\else
%The following are suitable for single-side
\lhead{\footnotesize{\emph{\leftmark}}}
\chead{\footnotesize{\emph{\rightmark}}}
\rhead{\textbf{\thepage}}
\cfoot{}
\fi
\makeatother
%%%%%%%%%%%%%%%
% The following formats the (last) page of a chapter to have formulae
% in it.  In particular it changes the header so that rather than the
% last section title appearing the word Formulae will appear.  This formatting
% is separate from the actual formulae which may be kept in their separate
% files and thereby included in other documents like formula sheets.
\newcommand{\formulapage}{\clearpage\markright{Formulae}}
%Set the paragraph indent to zero.
\setlength{\parindent}{0ex}
%Set the paragraph spacing to the height of G in the current font.
\settoheight{\parskip}{G}
%It is useful to define a length equal to the document \parskip value which 
%can be used in minipages to redefine \parskip to the value of the rest of
%the document.  (In the minipage environment \parskip is set to 0 by default
%regardless of its value in the rest of the document.)
\newlength{\docparskip}
\setlength{\docparskip}{\parskip}
%Load graphics package
\usepackage{graphicx}
%Add paths to directories containing images
%Note that latexmk is unaware of this command and so you need to use
%the full path (i.e. graphics/myimage, etc.) in includegraphics for latexmk
%to work.  For ungenerated images (such as in graphics_uncompiled or logos) this
% does not matter.
\graphicspath{{graphics}{graphics_uncompiled}{logo}}
%Loads package for putting pictures within paragraphs
\usepackage{picinpar}
\usepackage{pict2e}% Required to remove limitations on circle size in picture environment.
\usepackage{rotating}% Allows easy rotation of figs and tables
\usepackage{threeparttable}%Used to create a table in stats notes
\usepackage[inline]{asymptote}%Allows use of asymptote graphics in the code.
%Put all asymptote files in a subdirectory
\def\asydir{graphics}
%%%%%%%%%%%%%%%%%%%%%%%%
% Multicolumn package for answer table of contents, answer lists, etc.
\usepackage{multicol}
%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{verbatim}% provides comment environment for block comments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following snippet makes a footnote with a symbol. Usage is
% \symfootnote[<number>]{my footnote} where <number> is 0 for an
% unnumbered footnote, 1 is *, 2 is dagger, 3 is doubledagger, 4 is ...
% I use unnumbered foonote below to put a comment at the bottom of my
% custom table of contents.
\long\def\symfootnote[#1]#2{\begingroup%
\def\thefootnote{\fnsymbol{footnote}}\footnote[#1]{#2}\endgroup} 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Command for generating our customized table of contents
%Place the line below as required to ensure a table of contents column
%starts at a good spot.
%\addtocontents{toc}{\protect\columnbreak}
%Note the \cleardoublepage appears to be required to get the first chapter
%(page number 1) on the right side of the page.  While openright is a default
%option for book it doesn't seem to be doing the job for some reason.
\newcommand{\customtableofcontents}{%
\setlength{\columnseprule}{.4pt}
\begin{multicols}{2}
%\symfootnote[0]{*\,Sections denoted with an asterisk are optional and may be omitted in the course.}
\tableofcontents
\end{multicols}
\setlength{\columnseprule}{0pt}
\cleardoublepage}
%%%%%%%%%%%%%%%%
%paralist package allows enumerate to take an optional argument to
%make changing list format easy as well as providing compact and inparagraph
%list environments.  Note the enumitem is a more advanced (newer) package
%which gives more list control but does not provide the special list
%environments of paralist.  It can be included after paralist but it does alter
%spacing a bit from what paralist does.
\usepackage{paralist}
%\usepackage[shortlabels]{enumitem}
%%%%%%%%%%%%%%%%
%titlesec allows us to change how section headers are formatted.  In
% particular it allows the math formulas which appear there to properly
% appear in bold.  I might want to look at the titlespacing command contained
% in it to set the spacing differently.  Note that the minitoc package
% would be useful if we want a toc at the beginning of each chapter.
\usepackage{titlesec}
\titleformat*{\section}{\bf\boldmath\Large}
\titleformat*{\subsection}{\bf\boldmath\large}
\titleformat*{\subsubsection}{\bf\boldmath\large}
% Make sections start a new page.  This is also provided by titlesec package.
\newcommand{\sectionbreak}{\clearpage}
% The following formats our chapter front page.
\titleformat{\chapter}[hang]{\normalfont\huge\bfseries}{\Huge \chaptername~\thechapter:}{1ex}{\Huge}
%%%%%%%%%%%%%%%%%%%%%%
% The following creates an "optional" environment.  Any sectioning command
% included in the environment will have an asterisk placed in front of it.
% It was inspired by the discussion here:
% http://tex.stackexchange.com/questions/16336/add-an-asterisk-in-front-of-section-label-in-toc
\usepackage{tocloft}
\newenvironment{optional}
{\renewcommand{\thesection}{*\thechapter.\arabic{section}}}
{}
% set section numbers in TOC flush right (from the tocloft documentation)
\newlength{\extralen}
\setlength{\extralen}{0.5em}    % need some extra space at end of number
\renewcommand{\cftsecpresnum}{\hfill} % note the double ‘l’ 
\renewcommand{\cftsecaftersnum}{\hspace*{\extralen}}
\addtolength{\cftsecnumwidth}{\extralen}
\renewcommand{\cftsubsecpresnum}{\hfill}
\renewcommand{\cftsubsecaftersnum}{\hspace*{\extralen}}
\addtolength{\cftsubsecnumwidth}{\extralen}
% The following makes the toc entries raggedright, no hyphenation
% See texdoc tocloft
\makeatletter
\renewcommand{\@tocrmarg}{2.55em plus1fil}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%
% Provides support for color table highlighting and multirow stubs
\usepackage[table]{xcolor}
\usepackage{multirow}
%%%%%%%%%%%%%%%%%%%%%%%%
% Allows the usage of bold math symbols, especially Greek letters
\usepackage{bm}
% The following command is to make the subscript font size smaller.
% Now one can write \s instead of \scriptscriptstyle and also change it
% back if so desired.
\newcommand{\s}{\scriptscriptstyle}
%%%%%%%%%%%%%%%%%%%%%%%%
% This package implements \ifthenelse, booleans, among other things
\usepackage{ifthen}
% This package allows the creation of switches in LaTeX
\usepackage{boolexpr}
%%%%%%%%%%%%%%%%%%%%%%%%
% These packages provide some math symbols and fonts.  amsmath provides
% the useful \boxed command for boxing things.
\usepackage{amsmath,amssymb,amsfonts}
%%%%%%%%%%%%%%%%%%%%%%%%
% A useful package for doing derivatives.
\usepackage[italic]{esdiff}
%%%%%%%%%%%%%%%%%%%%%%%%
% The following allows for finer control of lines within the tabular
% environment.
\usepackage{hhline}
%%%%%%%%%%%%%%%%%%%%%%%%
% The following allows for a more modern tabular lines, etc.
\usepackage{booktabs}
%%%%%%%%%%%%%%%%%%%%%%%%
% The following allows for the inclusion of other pdf's in this one.
% It is used for inclusion of the license.  See texdoc pdfpages
\usepackage{pdfpages}
%%%%%%%%%%%%%%%%%%%
% The following snippet removes headers on empty pages before new chapters.
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
    \hbox{}
    \thispagestyle{plain}
    \newpage
    \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother \clearpage{\pagestyle{plain}\cleardoublepage}
%%%%%%%%%%%%%%%%%%%%%%%%
% The following includes a copy of the GNU free documentation
% license.  Note the the relevant gfdl included files must be found in the
% gfdl directory. The
% \gfdlsingle places it as a single page
% \gfdldouble places it on two pages (more legible)
% Both of these commands place the pages potentially starting on the back
% of a document page.  If in twosided mode this can be avoided by using
% \gfdlsinglenewpage and \gfdldoublenewpage which will insert a page if
% necessary to start on a new physical page.
% The default is to add a toc entry for the license at the section level.
% An optional argument (for example [chapter] ) will put this at the chapter or
% other chosen level.  The starred version of the commands put no entry in
% the toc.  (The section level is default so this will work in article class.)
% The phantomsection commands makes the links work when hyperref is used.
%
% These commands have been designed to work both with pdflatex and the
% older latex->dvips->ps2pdf method for which the \includepdf does not work.
% If the \includepdf command is desired remember to include the pdfpages
% package.  Note that it is reported that \includepdf will work on single
% pages with dvips but it did not on my system so the more rudimentary
% \includegraphics command from the graphicx package was used.  The geometry
% package in this case was needed to remove the margins on the pages.
% 
\NewDocumentCommand\gfdlsingle{sO{section}}{\clearpage\phantomsection%
  \IfBooleanTF{#1}{}{\addcontentsline{toc}{#2}{GNU Free Documentation License}}
%  \includepdf[lastpage=1]{gfdl/gfdlsingle}
  \newgeometry{margin=0cm}
  \includegraphics{gfdl/gfdlsingle}
  \restoregeometry
}
\NewDocumentCommand\gfdlsinglenewpage{sO{section}}{\cleardoublepage\phantomsection%
  \IfBooleanTF{#1}{}{\addcontentsline{toc}{#2}{GNU Free Documentation License}}
%  \includepdf[lastpage=1]{gfdl/gfdlsingle}
  \newgeometry{margin=0cm}
  \includegraphics{gfdl/gfdlsingle}
  \restoregeometry
}
\NewDocumentCommand\gfdldouble{sO{section}}{\clearpage\phantomsection%
  \IfBooleanTF{#1}{}{\addcontentsline{toc}{#2}{GNU Free Documentation License}}
%  \includepdf[lastpage=1]{gfdl/gfdldouble1}
%  \includepdf[lastpage=1]{gfdl/gfdldouble2}
  \newgeometry{margin=0cm}
  \includegraphics{gfdl/gfdldouble1}\newpage
  \includegraphics{gfdl/gfdldouble2}
  \restoregeometry
}
\NewDocumentCommand\gfdldoublenewpage{sO{section}}{\cleardoublepage\phantomsection%
  \IfBooleanTF{#1}{}{\addcontentsline{toc}{#2}{GNU Free Documentation License}}
%  \includepdf[lastpage=1]{gfdl/gfdldouble1}
%  \includepdf[lastpage=1]{gfdl/gfdldouble2}
  \newgeometry{margin=0cm}
  \includegraphics{gfdl/gfdldouble1}\newpage
  \includegraphics{gfdl/gfdldouble2}
  \restoregeometry
}
% Provides a copyright notice. Arguments are year then author(s).
% \gfdlcopyright{2011}{I. M. Authorone, I. M. Authortwo}
\newcommand{\gfdlcopyright}[2]{Copyright \copyright{} #1 #2.}
% Use xparse (see texdoc xparse) to create commands with defaults, etc.
% Note this license notice is for no invariant texts (see the license)
% Something more sophisticated will be needed if they are required.
\newcommand{\gfdllicensenoticenoinvar}{Permission is granted to
  copy, distribute and/or modify this document under the terms of the
  GNU Free Documentation License, Version 1.3 or any later version
  published by the Free Software Foundation; with no Invariant
  Sections, no Front-Cover Texts, and no Back-Cover Texts.  A copy of
  the license is included in the section entitled ``GNU Free
  Documentation License''.}
% The following statement grants later document modifiers permission to
% retain the title of the document.  This is not necessary in a gfdl
% doc but may be useful.  Note that it is the publisher (i.e. the distributor)
% not the author according to the license that makes this call.
\newcommand{\gfdltitlepermission}{Permission is granted to retain (if
  desired) the original title of this document on modified copies.}
% The following is a content disclaimer which is not part of the gfdl license,
% but is convenient for my documents.
\newcommand{\contentdisclaimer}{All numerical data in this document
  should be considered fabricated unless a source is cited directly.
  Comments in the transparent copy of the document may contain
  references indicating inspiration behind some of the data.}
% The following needs to be added otherwise the document is stretched out to
% the bottom of the page.
\raggedbottom
%%%%%%%%%%%%%%%%%%
% The following typesetting rules are invisible (widthless) but are convenient
% for adding extra space in tables, especially formula sheets.
\newcommand{\rowrule}{\raisebox{-1.5em}{\rule{0em}{3.5em}}}
\newcommand{\rowrulelarge}{\raisebox{-1.5em}{\rule{0em}{4.5em}}}
\newcommand{\rowrulesmall}{\raisebox{-1em}{\rule{0em}{2.5em}}}
%%%%%%%%%%%%%%%%%%%
% The following inputs a formula file, formula_file.tex, into the notes.
% We put it in one place so we can customize how it is included.
\newcommand{\inputformulafile}[1]{%
  \clearpage
  \addcontentsline{toc}{section}{Formulae}
  \input{#1}
}
% The following boolean can be set within a formula sheet document to
% allow special formatting within its inputted formulafile documents.
\newboolean{informulasheet}
\setboolean{informulasheet}{false}
% This creates a formula sheet at the end of the notes for students to
% use. Its mandatory argument is the name of the pdf file of the formula
% sheet which must exist.
% The default is to add a toc entry for the formula sheets at the section level.
% An optional argument (for example [chapter] ) will put this at the chapter or
% other chosen level.  The starred version of the commands put no entry in
% the toc.  (The section level is default so this will work in article class.)
% The "reduced" version will put two formula sheets per page. Both versions
% start on a new piece of paper and purge the last page so that the formula
% sheet is guaranteed to be removable from the document.
\NewDocumentCommand\formulasheetreduced{sO{section}m}{\cleardoublepage%
  \IfBooleanTF{#1}{}{\addcontentsline{toc}{#2}{Formula Sheet}}
  \includepdf[angle=270,pages=1-,nup=1x2,delta=0 -1in]{#3}
  \cleardoublepage
}
\NewDocumentCommand\formulasheet{sO{section}m}{\cleardoublepage%
  \IfBooleanTF{#1}{}{\addcontentsline{toc}{#2}{Formula Sheet}}
  \includepdf[pages=1-,noautoscale,scale=.9]{#3}
  \cleardoublepage
}
%%%%%%%%%%%%%%%%%%%%%%%
% Provides tally symbols, dice symbols, circles and squares
%\usepackage[misc,geometry]{ifsym}
% I undefine the \Letter command as it prevents marvosym package loading.
\makeatletter
\@ifundefined{Letter}{}{%
\let\Letter\@undefined
\let\endLetter\@undefined}
\makeatother
% I undefine the \Cross command as it prevents another package loading.
\makeatletter
\@ifundefined{Cross}{}{%
\let\Cross\@undefined
\let\endCross\@undefined}
\makeatother
% Provides a variant dice
\usepackage{epsdice}
%The following imports symbols needed for chess figures.  It requires
%installation of texlive-games package on ubuntu.
\usepackage[skaknew]{chessboard,skak}
% Provides \smiley and \frownie emoticons
\usepackage{wasysym}
% I undefine the \Square command as it prevents another package loading.
\makeatletter
\@ifundefined{Square}{}{%
\let\Square\@undefined
\let\endSquare\@undefined}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%
% Commands for temporarily setting the table column separation to zero and
% then restoring it later.  This is convenient for getting spacing right
% on formula sheets where any additional column separation messes with
% overall spacing.
\newlength{\tmptabcolsep}
\newcommand{\cleartabcolsep}{\setlength{\tmptabcolsep}{\tabcolsep}%
\setlength{\tabcolsep}{0cm}}
\newcommand{\restoretabcolsep}{\setlength{\tabcolsep}{\tmptabcolsep}}
%%%%%%%%%%%%%%%%%%%
% TODO
% It would be good to have hyperlinks in the pdf (see the hyperref package).
% Make a "HINT" function for consistency.
% Make example have numbering and allow labelling.
% Make it so formulas can be autodumped to a formula sheet?
% Perhaps I can use the xparse commands to create an \answer command
% which doesn't require all the \protect stuff since this worked for \example.
% Answers should be coupled with questions as a single command.
% Make a \caution{} command which would allow for highlights of what students
% should watch for - it could put a slippery highway symbol in the margin.
% Make a command to indicate how far you should get in a typical lecture. - It
% could put a line in the margin.
% Make my documents pdf'able using hyperlatex or latex2html or one of the
% options listed here: http://enc.com.au/docs/latexhtml/
% Put parentheses around stat commands so they can be used as subsecripts.
% Figure out how to remove the trailing \ when used in text.
% Remove stat commands from the documentclass file.
% Problems and examples need to have numbers and be labelable.
% Make \example friendly to asymptote code.  See my alignvert.sty package
% which, among other things, allows asymptote code in an argument so that
% it will work in a list environment.
% Change verbalassignment to new, meaningful name.
% Fix word hyphenation in section headings - should be raggedright.
% Remove extra space occuring after "Solution" in \example.
% Fix the toc to put the bold symbols as bold.
% Make a switch for colour and b&w so one could have options to add
% colours either for reading pdf's or colour printing.
% Fix \example command so that page breaks don't occur after Solution:
% Fix my answerlist command so that it doesn't break when using
% \includeonly for partial documents.
%
% Create a definition command to allow definitions of important words to be
% made.  It should have a version that stands out (eg. boxed) and a version
% that is inline (perhaps a *'d version) which allows the definition to be
% inline.  Both versions should automatically put the term in a glossary.
% The definition command should take an optional argument that is the
% glossary entry so, especially for the starred version, it can be less
% casual or slightly differently worded.  The word being defined should also
% likely be an optional argument.
%
% Fix page breaking which sometimes occurs between page number and answers
% in answerlist.
%
% Fix Answers header which appears as uppercase compared to the rest of the
% headers.

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master"
%%% End:
