% Upper-case    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
% Lower-case    a b c d e f g h i j k l m n o p q r s t u v w x y z
% Digits        0 1 2 3 4 5 6 7 8 9
% Exclamation   !           Double quote "          Hash (number) #
% Dollar        $           Percent      %          Ampersand     &
% Acute accent  '           Left paren   (          Right paren   )
% Asterisk      *           Plus         +          Comma         ,
% Minus         -           Point        .          Solidus       /
% Colon         :           Semicolon    ;          Less than     <
% Equals        =           Greater than >          Question mark ?
% At            @           Left bracket [          Backslash     \
% Right bracket ]           Circumflex   ^          Underscore    _
% Grave accent  `           Left brace   {          Vertical bar  |
% Right brace   }           Tilde        ~

% ---------------------------------------------------------------------|
% Index management (including acronyms and symbols)
% ---------------------------------------------------------------------|
%
% (c) Copyright 2007 by Theodore P. Pavlic
%

% ---------------------------------------------------------------------|
% --------------------------- 72 characters ---------------------------|
% ---------------------------------------------------------------------|

% Use multiple indices, and repeat main entries at the top of a new page
% if subentries go over a page break
%
% The multicol package is for formatting the index environment
%
% NOTE: The \index from this package does *NOT* expand its argument!
%       This is VERY annoying for macro programming.
%
% NOTE: If you want to load repeatindex AFTER index, then makeidx must
%       be loaded BEFORE index. Loading repeatindex before index
%       implicitly loads makeidx (which gets overridden by index).
%
% *) REPEATINDEX is not compatible with MULTICOL
%
% *) FOOTNOTES cannot be used in \twocolumn mode
%
% *) SO, repeatindex has to be excluded so we can have footnotes
%\usepackage{repeatindex,index,multicol}
\usepackage{index,multicol}

% In the future, consider trying the GLOSSARIES package. It is very
% similar to the index package, but more advanced macros are built in
% for acronym and glossary entries.

%%fakechapter{Main Index Setup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Generate the main index
%\makeindex
\newindex{default}{idx}{ind}{\MakeUppercase{Index}}

% How to show a page with definition on it
\newcommand{\indexdeffmt}[1]{\textbf{#1}}
\newcommand{\indexdef}[1]{\indexdeffmt{\hyperpage{#1}}}

% How to show a page in the glossary
\newcommand{\indexglofmt}[1]{\textit{#1}}
\newcommand{\indexglo}[1]{\indexglofmt{\hyperpage{#1}}}

\newcommand{\indexfoottext}{Notation: \indexdeffmt{\pageref{ch:index}}
is a definition page, and \indexglofmt{\pageref{ch:index}} is a glossary
page.}

% What the headers look like
\newcommand{\indexheading}[1]{\dotfill\textbf{#1}}

%%fakeparagraph{theindexindex environment definition}
%-----------------------------------------------------------------------
%
% We use this theindexindex environment so that we can have a footnote
% giving the page notation.
%
% The standard environment uses twocolumn mode, which does not support
% footnotes. 
%
\makeatletter
\newenvironment{theindexindex}{%
        \begin{multicols}{2}%
        [\chapter*{Index\footnote{\indexfoottext}}][10\baselineskip]%
        \markboth{\MakeUppercase\indexname}{\MakeUppercase\indexname}%
        \phantomsection\label{ch:index}%
        \addcontentsline{toc}{chapter}{Index}%
        \setlength\parindent{0pt}\pagestyle{plain}%
        %\begin{NoHyper}%
        \let\item\@idxitem}
       {%\end{NoHyper}%
        \end{multicols}}
\makeatother
%-----------------------------------------------------------------------

%%fakechapter{Author Index Setup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% This tells authorindex to use hyperrefs (and sort pages by lowercase
% Roman, uppercase Roman, then Arabic numerals; this is necessary to
% prevent authorindex from sorting alphabetically by all of the
% ``hyperpage'' commands added)
\aipagetypeorder{rRn}
\def\theaipage{\string\hyperpage{\thepage}}

% How to show a first author
\renewcommand{\aifirstpage}[1]{\textbf{#1}}

% How to show a bibliography page reference
\renewcommand{\aibibpage}[1]{\textit{#1}}

% Some text that will be displayed as a footnote to author index title
\newcommand{\aifoottext}{Notation: \aifirstpage{\pageref{ch:people}} is
a first-author citation, and \aibibpage{\pageref{ch:people}} is a
bibliography page.}

% The environment used for the author index; should produce entries with
% a 40pt hanging indent (TLC2 says that's what LaTeX uses in @idxitem)
\renewenvironment{theauthorindex}{%
        \setcounter{footnote}{0}%
        \begin{multicols}{2}%
        [\chapter*{People\footnote{\aifoottext}}][10\baselineskip]%
        \phantomsection\label{ch:people}%
        \addcontentsline{toc}{chapter}{People}%
        \pagestyle{plain}%
        %\begin{NoHyper}%
        \raggedright%
        \setlength{\leftskip}{40pt}%
        \setlength{\parindent}{-40pt}%
        \def\item[##1]{\par\hspace{0mm}\ainame{##1},}
        \aisize}
       {\par%\end{NoHyper}%
        \end{multicols}}

%%fakechapter{Generic Index Helpers}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Bracket references look like this
\newcommand{\bracketref}[1]{$<$#1$>$}
\newcommand{\nohyperbracketref}[1]{$<$\begin{NoHyper}#1\end{NoHyper}$>$}

% A bold hyperpage
\newcommand{\ibold}[1]{\textbf{\hyperpage{#1}}}

% An italicized hyperpage
\newcommand{\iemph}[1]{\textit{\hyperpage{#1}}}

% A teletype hyperpage
\newcommand{\itt}[1]{\texttt{\hyperpage{#1}}}

% Gets rid of the page number
\newcommand{\nopage}[1]{}

% Our symbol for default argument
\newcommand{\defarg}{!*!,!}

% This generates an labeled anchor called def:#2 (for creating index
% entries); the anchor will be linked to text #1 if it is provided
\newcommand{\anchordef}[2][]{\hypertarget{def:#2}{#1}\label{def:#2}}

% This is similar to hyperpage, but it puts angle brackets around the
% page
\newcommand{\bhyperpage}[1]{\bracketref{\hyperpage{#1}}}

% An example bracketed page reference
\newcommand{\examplebracketref}[1]%
           {\bracketref{\hyperlink{#1}{\pageref*{#1}}}}
\newcommand{\examplenohyperbracketref}[1]{\nohyperbracketref{#1}}

% This is similar to bhyperpage, but it links to the SYMBOL ANCHOR
% itself, rather than the top of the page
\newcommand{\bhypersym}[1]{\examplebracketref{def:#1}}

% Whether to link acronym and symbol entries to the PAGE (like the
% index) or to the ANCHOR
\newboolean{anchorlinkdefs}        % Defaults to page link defs
\setboolean{anchorlinkdefs}{true}  % Set to true for anchor link defs

%%fakechapter{Terms Support}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Generate the List of Terms
\newindex{terms}{ter}{tem}{List of Terms}

%%%%% Create a term with an anchor and a label and link its term
%%%%% entry based on \boolean{anchorlinkdefs} above

%%%%% Create an unlinked term (no anchor).
%
% anchor_text=#1, sort_text=#2, symbol=#3, definition=#4
%
% \term{sort_text}{term}{definition} 
%
%       defines ``symbol'' as ``definition''
%
%       sorts by ``sort_text''
%
% \term[display_text]{sort_text}{term}{definition} 
%
%       defines ``symbol'' as ``definition''
%
%       displays ``display_text''
%
%       sorts by ``sort_text''
%
\newcommand{\term}[4][]{#1\index[terms]{#2@[#3] #4|nopage}}

%%%%% Create a linked term (i.e., with an anchor). 
%
% anchor_text=#1, sort_text=#2, label=#3, term=#4, definition=#5
%
% All uses define term b as c.
%
% \termdef{sort_text}{label}{term}{definition} 
%
%       defines ``term'' as ``definition''
%
%       displays ``term'' and links to target ``def:label''
%
%       sorts by ``sort_text''
%
% \termdef[anchor_text]{sort_text}{label}{term}{definition} 
%
%       defines ``term'' as ``definition''
%
%       displays ``anchor_text'' and links to target ``def:label''
%
%       sorts by ``sort_text''
%
%%fakeparagraph{termdef command definition}
%-----------------------------------------------------------------------
\newcommand{\termdef}[5][\defarg]{%
        \ifthenelse{\boolean{anchorlinkdefs}}%
                   {\index[terms]%
                        {#2@[#4] #5~\bhypersym{term:#3}|nopage}}%
                   {\index[terms]{#2@[#4] #5~|bhyperpage}}%
        \anchordef[\ifthenelse{\equal{#1}{\defarg}}{#4}{#1}]{term:#3}}
%-----------------------------------------------------------------------

%%fakeparagraph{terms environment definition}
%-----------------------------------------------------------------------
\newenvironment{theterms}{%
\setcounter{footnote}{0}%
\phantomsection\chapter*{List of Terms\footnote{\termsfootnote{}}}
\addcontentsline{toc}{chapter}{List of Terms}
\label{ch:terms}
\begin{list}{}{%
        \setlength{\itemsep}{0pt}%
        \setlength{\parskip}{0pt}%
        \setlength{\parsep}{0pt}%
        \addtolength{\labelsep}{4pt}%    % Spacing between columns %
        \settowidth{\labelwidth}
                   {\hfil$\E(G)/\E(T)$}%
        \setlength{\leftmargin}{\labelwidth+\labelsep}%
        }}{\end{list}}
%-----------------------------------------------------------------------

%%fakeparagraph{termheader command definition}
%-----------------------------------------------------------------------
% The following is a hack. It would be much nicer to use xindy. However,
% how can we install quality indexing software on such an aweful
% operating system as Windows? 
%
% I wonder how much of my career has been degraded by the existence of
% Microsoft Windows. I feel physical effects of depression after
% thinking about this.
%
\newcommand{\termheader}[1]{\emph{%
        %\ifthenelse{\equal{#1}{*}}{}{}%
        %\ifthenelse{\equal{#1}{0}}{}{}%
        \ifthenelse{\equal{#1}{A}}{General Environment and Task-Type
        Terms}{}%
        \ifthenelse{\equal{#1}{B}}{Classical OFT Terms}{}%
        \ifthenelse{\equal{#1}{C}}{Processing-Only Terms}{}%
        %\ifthenelse{\equal{#1}{D}}{}{}%
        %\ifthenelse{\equal{#1}{E}}{}{}%
        %\ifthenelse{\equal{#1}{F}}{}{}%
        %\ifthenelse{\equal{#1}{G}}{}{}%
        %\ifthenelse{\equal{#1}{H}}{}{}%
        %\ifthenelse{\equal{#1}{I}}{}{}%
        %\ifthenelse{\equal{#1}{J}}{}{}%
        %\ifthenelse{\equal{#1}{K}}{}{}%
        %\ifthenelse{\equal{#1}{L}}{}{}%
        %\ifthenelse{\equal{#1}{M}}{}{}%
        %\ifthenelse{\equal{#1}{N}}{}{}%
        %\ifthenelse{\equal{#1}{O}}{}{}%
        %\ifthenelse{\equal{#1}{P}}{}{}%
        %\ifthenelse{\equal{#1}{Q}}{}{}%
        %\ifthenelse{\equal{#1}{R}}{}{}%
        %\ifthenelse{\equal{#1}{S}}{}{}%
        %\ifthenelse{\equal{#1}{T}}{}{}%
        %\ifthenelse{\equal{#1}{U}}{}{}%
        %\ifthenelse{\equal{#1}{V}}{}{}%
        %\ifthenelse{\equal{#1}{W}}{}{}%
        %\ifthenelse{\equal{#1}{X}}{}{}%
        %\ifthenelse{\equal{#1}{Y}}{}{}%
        %\ifthenelse{\equal{#1}{Z}}{}{}%
        }}
%-----------------------------------------------------------------------

%%fakechapter{Acronym Support}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Generate the List of Acronyms
\newindex{acronyms}{acr}{acn}{List of Acronyms}

%%%%% Create an acronym with an anchor and a label and link its acronym
%%%%% entry based on \boolean{anchorlinkdefs} above
%
% anchor_text=#1, sort_text=#2, acronym=#3, definition=#4
% d=#1, e=#2, a=#3, b=#4
%
% If used as \acro{a}{b}, links def:a anchor to b~(a)
% If used as \acro[]{a}{b}, links def:a anchor to a
% If used as \acro[d]{a}{b}, links def:a anchor to d
% If used as \acro[d][e]{a}{b}, links def:a anchor to d and sorts by e
% If used as \acro[\defarg][e]{a}{b}, links def:a anchor to b~(a) and 
%                                     sorts by e
%
% Later, use \ac{acronym} to refer to the acronym.
%

%%fakeparagraph{acro command definition}
%-----------------------------------------------------------------------
\newcommandtwoopt{\acro}[4][\defarg][\defarg]{%
        \ifthenelse{\boolean{anchorlinkdefs}}%
                   {\ifthenelse{\equal{#2}{\defarg}}%
                               {\index[acronyms]{#3@[#3] #4~%
                                                 \bhypersym%
                                                  {acro:#3}|nopage}}
                               {\index[acronyms]{#2@[#3] #4~%
                                                 \bhypersym{acro:#3}%
                                                 |nopage}}}%
                   {\ifthenelse{\equal{#2}{\defarg}}%
                               {\index[acronyms]{#3@[#3] #4~%
                                                 |bhyperpage}}
                               {\index[acronyms]{#2@[#3] #4~%
                                                 |bhyperpage}}}%
        \ifthenelse{\equal{#1}{\defarg}}%
                   {\anchordef[#4~(#3)]{acro:#3}}%
                   {\anchordef[\ifthenelse{\equal{#1}{}}{#3}{#1}]%
                        {acro:#3}}}
%-----------------------------------------------------------------------

%%fakeparagraph{ac command definition}
%-----------------------------------------------------------------------
% A text-only reference to the acronym
\newcommand{\ac}[1]{#1}

% % A reference to the acronym linked to its anchor 
% \newcommand{\ac}[1]{\hyperlink{def:#1}{#1}}

% % A reference to the acronym linked to its page 
% \newcommand{\ac}[1]{\hyperlink{page.\pageref*{def:#1}}{#1}}
%-----------------------------------------------------------------------

%%fakeparagraph{theacronyms environment definition}
%-----------------------------------------------------------------------
\newenvironment{theacronyms}{%
\setcounter{footnote}{0}%
\phantomsection\chapter*{List of Acronyms\footnote{\acronymsfootnote{}}}
\addcontentsline{toc}{chapter}{List of Acronyms}
\label{ch:acronyms}
\begin{list}{}{%
        \setlength{\itemsep}{0pt}%
        \setlength{\parskip}{0pt}%
        \setlength{\parsep}{0pt}%
        \addtolength{\labelsep}{4pt}%    % Spacing between columns %
        %\settowidth{\labelwidth}{\hfil\ac{CRBRR}}%
        \settowidth{\labelwidth}{\hfil\ac{MLPM}}%
        \setlength{\leftmargin}{\labelwidth+\labelsep}%
        }}{\end{list}}
%-----------------------------------------------------------------------

%%fakechapter{Symbols Support}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Generate the List of Symbols
\newindex{symbols}{glo}{gls}{List of Symbols}

%%%%% Create a symbol with an anchor and a label and link its symbol
%%%%% entry based on \boolean{anchorlinkdefs} above

%%%%% Create an unlinked symbol (no anchor).
%
% anchor_text=#1, sort_text=#2, symbol=#3, definition=#4
%
% \sym{sort_text}{symbol}{definition} 
%
%       defines ``symbol'' as ``definition''
%
%       sorts by ``sort_text''
%
% \sym[display_text]{sort_text}{symbol}{definition} 
%
%       defines ``symbol'' as ``definition''
%
%       displays ``display_text''
%
%       sorts by ``sort_text''
%
\newcommand{\sym}[4][]{#1\index[symbols]{#2@[#3] #4|nopage}}

%%%%% Create a linked symbol (i.e., with an anchor). 
%
% anchor_text=#1, sort_text=#2, label=#3, symbol=#4, definition=#5
%
% All uses define symbol b as c.
%
% \symdef{sort_text}{label}{symbol}{definition} 
%
%       defines ``symbol'' as ``definition''
%
%       displays ``symbol'' and links to target ``def:label''
%
%       sorts by ``sort_text''
%
% \symdef[anchor_text]{sort_text}{label}{symbol}{definition} 
%
%       defines ``symbol'' as ``definition''
%
%       displays ``anchor_text'' and links to target ``def:label''
%
%       sorts by ``sort_text''
% 
%%fakeparagraph{symdef command definition}
%-----------------------------------------------------------------------
\newcommand{\symdef}[5][\defarg]{%
        \ifthenelse{\boolean{anchorlinkdefs}}%
                   {\index[symbols]%
                        {#2@[#4] #5~\bhypersym{sym:#3}|nopage}}%
                   {\index[symbols]{#2@[#4] #5~|bhyperpage}}%
        \anchordef[\ifthenelse{\equal{#1}{\defarg}}{#4}{#1}]{sym:#3}}
%-----------------------------------------------------------------------

%%fakeparagraph{theglossary environment definition}
%-----------------------------------------------------------------------
\newenvironment{theglossary}{%
\setcounter{footnote}{0}%
%\phantomsection\chapter*{List of Symbols\footnote{\symbolsfootnote{}}}
\phantomsection\chapter*{List of Symbols}
\addcontentsline{toc}{chapter}{List of Symbols}
\label{ch:symbols}
\begin{list}{}{%
        \setlength{\itemsep}{0pt}%
        \setlength{\parskip}{0pt}%
        \setlength{\parsep}{0pt}%
        \addtolength{\labelsep}{4pt}%    % Spacing between columns %
        \settowidth{\labelwidth}
                   {\hfil$\total^2 f(x)/{\total x}^2|_{x=x_0}$}%
        \setlength{\leftmargin}{\labelwidth+\labelsep}%
        }}{\end{list}}
%-----------------------------------------------------------------------

%%fakeparagraph{symheader command definition}
%-----------------------------------------------------------------------
% The following is a hack. It would be much nicer to use xindy. However,
% how can we install quality indexing software on such an aweful
% operating system as Windows? 
%
% I wonder how much of my career has been degraded by the existence of
% Microsoft Windows. I feel physical effects of depression after
% thinking about this.
%
\newcommand{\symheader}[1]{\emph{%
        \ifthenelse{\equal{#1}{*}}{Document Conventions}{}%
        %\ifthenelse{\equal{#1}{0}}{}{}%
        \ifthenelse{\equal{#1}{A}}{\index{mathematics|(indexglo}General Mathematics}{}%
        \ifthenelse{\equal{#1}{B}}{\index{mathematics!numbers|(indexglo}Numbers}{}%
        \ifthenelse{\equal{#1}{C}}{\index{mathematics!numbers|)indexglo}\index{mathematics!sets|(indexglo}Sets}{}%
        \ifthenelse{\equal{#1}{D}}{\index{mathematics!sets|)indexglo}Families and Sequences}{}%
        \ifthenelse{\equal{#1}{E}}{\index{mathematics!logic|(indexglo}Logic}{}%
        \ifthenelse{\equal{#1}{F}}{\index{mathematics!logic|)indexglo}\index{mathematics!order|(indexglo}Order}{}%
        \ifthenelse{\equal{#1}{G}}{\index{mathematics!order|)indexglo}\index{mathematics!functions(|indexglo}Functions and Real Analysis}{}%
        \ifthenelse{\equal{#1}{H}}{\index{mathematics!functions|)indexglo}\index{mathematics!vector spaces|(indexglo}Vectors and Linear Algebra}{}%
        \ifthenelse{\equal{#1}{I}}{\index{mathematics!vector spaces|)indexglo}\index{stochasticity|(indexglo}Probability and Measure Theory}{}%
        %\ifthenelse{\equal{#1}{J}}{}{}%
        %\ifthenelse{\equal{#1}{K}}{}{}%
        %\ifthenelse{\equal{#1}{L}}{}{}%
        %\ifthenelse{\equal{#1}{M}}{}{}%
        %\ifthenelse{\equal{#1}{N}}{}{}%
        %\ifthenelse{\equal{#1}{O}}{}{}%
        %\ifthenelse{\equal{#1}{P}}{}{}%
        %\ifthenelse{\equal{#1}{Q}}{}{}%
        %\ifthenelse{\equal{#1}{R}}{}{}%
        %\ifthenelse{\equal{#1}{S}}{}{}%
        %\ifthenelse{\equal{#1}{T}}{}{}%
        %\ifthenelse{\equal{#1}{U}}{}{}%
        %\ifthenelse{\equal{#1}{V}}{}{}%
        %\ifthenelse{\equal{#1}{W}}{}{}%
        %\ifthenelse{\equal{#1}{X}}{}{}%
        %\ifthenelse{\equal{#1}{Y}}{}{}%
        %\ifthenelse{\equal{#1}{Z}}{}{}%
        }}
%-----------------------------------------------------------------------
