\newif\ifbeamermode\beamermodefalse % I still need to automate this using something like 
\newif\ifpapermode\papermodetrue % I still need to automate this using something like  \ifx\beamer\@empty

% 2012Nov! Commented out following. Something has become obselete!
%\usepackage{subfig}

%\usepackage{underscore} % This is to allow filenames in input graphics. NO! DO NOT USE THIS. SEE DOCUMENTAITON. IT BREAKS INCLUDEGRAPHICS, ETC, ETC.
%\usepackage{color}
% Huh? The table option for xcolor allows for rowcolor in beamer, and rowwise unveiling of tables???
%\usepackage[table]{xcolor} % can't remember what all this is for, but it dfines some colors that I use below, like olive.
% Agh but it's classhing. Jan 2011. don't konw what's wrong. 2013: Fixed. Use google! 
%\usepackage[table]{xcolor} % can't remember what all this is for, but it dfines some colors that I use below, like olive.

% Useful reference shorthand for including figures and for
% cross-referencing to figures, sections, and tables.
% 
% CPBL, 1997-2008

\newcommand{\posterfig}[3]{
{%  \begin{center}
       \centering\includegraphics{figures/#1.eps}
%       \centering\includegraphics{figures/pdfCopies/#1.pdf}
%\end{center}
} %%%      \caption{\label{fig:#1} #2. #3 
 %%% %{\bfseries \sc \small [#2]}
 %%% }% End of caption
#2. #3
}


%%             \figw{width=\textwidth}{location}{epsFileName}
%                   {Figure title}{This is the figure caption.}
                    
\newcommand{\fig}[4]{
\figw{#1}{tbh}{#2}{#3}{#4}
}
\newcommand{\figw}[5]{
%\afterpage{\clearpage
\begin{figure}[#2] % This could be [H] with afterpage\clearpage method...
      \centering
       \includegraphics[#1]{figures/#3.eps}
%       \includegraphics[#1]{figures/pdfCopies/#3.pdf}
%       \includegraphics[width=5 cm]{figures/#3.eps}
       \caption[#4]{{\bfseries #4.} #5 
%{\bfseries \sc \small [#3]}
} 
       \label{fig:#3}
 \end{figure}
%}
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define shorthand for referencing a figure or section number
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sample usage:
% \figref{epsFileName}
% Used in conjunction with the naming convention above, in \fig.
%
% 2000 May: cPbL of alum.mit.edu
%\newcommand{\figref}[1]{Figure~\ref{fig:#1}}
%\newcommand{\Figref}[1]{Figure~\ref{fig:#1}}
%\newcommand{\figrefp}[1]{Figure~\ref{fig:#1} on page~\pageref{fig:#1}}
%\newcommand{\Figrefp}[1]{Figure~\ref{fig:#1} on page~\pageref{fig:#1}}
% Why have I not converted above to \autoref yet?  Autoref sucks. It doesn't know about upper case and says subsection for subsections! So redo them all by hand using the hyperref model, below.
% Okay, here they are April 2011:
%\renewcommand{\figref}[1]{\autoref{fig:#1}}
%\renewcommand{\Figref}[1]{\autoref{fig:#1}}
% Note that I have redefined all these to use a \linkback function in my Quebec paper.

% And some for multiple refs / ranges:
\newcommand{\twofigs}[2]{Figures \ref{fig:#1} and \ref{fig:#2}}
\newcommand{\figrange}[2]{Figures \ref{fig:#1} to \ref{fig:#2}}
\newcommand{\twotabs}[2]{Tables \ref{tab:#1} and \ref{tab:#2}}

% Also (apr2011) All of above should be redefined so that the onpage and Figure or etc part is all part of one link.

%\newcommand{\secref}[1]{Section~\ref{sec:#1}}
%\newcommand{\Secref}[1]{Section~\ref{sec:#1}}
% June 2011: Not good enough. Make my own from scratch.
\newcommand{\secref}[1]{\hyperref[sec:#1]{section \ref{sec:#1}}\xspace} 
\newcommand{\Secref}[1]{\hyperref[sec:#1]{Section \ref{sec:#1}}\xspace} 
\newcommand{\secrefp}[1]{Section~\ref{sec:#1} on page~\pageref{sec:#1}}
\newcommand{\Secrefp}[1]{Section~\ref{sec:#1} on page~\pageref{sec:#1}}

\newcommand{\figref}[1]{\hyperref[fig:#1]{figure \ref{fig:#1}}\xspace} 
\newcommand{\Figref}[1]{\hyperref[fig:#1]{Figure \ref{fig:#1}}\xspace} 
\newcommand{\figrefp}[1]{Figure~\ref{fig:#1} on page~\pageref{fig:#1}}
\newcommand{\Figrefp}[1]{Figure~\ref{fig:#1} on page~\pageref{fig:#1}}
% Umran doesn't want the ``on page'' thing:
%\newcommand{\secrefp}[1]{\secref{#1}}
%\newcommand{\Secrefp}[1]{\Secref{#1}}

% eqref requires amsmath package!
\newcommand{\equref}[1]{equation~\eqref{eq:#1}} % NOTE! builtin \eqref
                                              % is usually better.
\newcommand{\Equref}[1]{Equation~\eqref{eq:#1}} % NOTE! builtin \eqref
                                              % is usually better.
\newcommand{\equrefp}[1]{Equation~\eqref{eq:#1}  on page~\pageref{eq:#1}} 
\newcommand{\Equrefp}[1]{Equation~\eqref{eq:#1}  on  page~\pageref{eq:#1}} 
% Umran doesn't want the ``on page'' thing:
%\newcommand{\equrefp}[1]{\equref{#1}}
%\newcommand{\Equrefp}[1]{\Equref{#1}}

\newcommand{\prefsec}[1]{page~\pageref{sec:#1} (Section~\ref{sec:#1})}

% Tables

\ifdefined\hyperref
\newcommand{\tabref}[1]{\hyperref[tab:#1]{table \ref{tab:#1}}\xspace} 
\newcommand{\Tabref}[1]{\hyperref[tab:#1]{Table \ref{tab:#1}}\xspace} 
\newcommand{\tabrefp}[1]{\hyperref[tab:#1]{Table~\ref{tab:#1} on page~\pageref{tab:#1}}}
\newcommand{\Tabrefp}[1]{\hyperref[tab:#1]{Table~\ref{tab:#1} on page~\pageref{tab:#1}}}
\else
\newcommand{\tabref}[1]{Table~\ref{tab:#1}}
\newcommand{\Tabref}[1]{Table~\ref{tab:#1}}
\newcommand{\tabrefp}[1]{Table~\ref{tab:#1} on page~\pageref{tab:#1}}
\newcommand{\Tabrefp}[1]{Table~\ref{tab:#1} on page~\pageref{tab:#1}}
\fi

% BIG CHANGE!!! APRIL 2011. If using hyperref, I want the links to include all the words in the phrases above. For the ones without page refs, I can do that using \autoref, except that there can be more space between "Figure" and "5" than I'd like, e.g. But too bad; for now this is probably better. Could put this inside a hyperref if:

% June 2011: should implement capitalisation of autoref commands, eg.: \def\sectionautorefname{Section}

% Or, to do them all by myself, can I just use: 
%\hyperref[sec:intro]{Appendix~\ref*{sec:intro}}.


\renewcommand{\tabref}[1]{\autoref{tab:#1}}%\label{linkback:#1}}
\renewcommand{\Tabref}[1]{\autoref{tab:#1}}%label{linkback:#1}}
\renewcommand{\figref}[1]{\autoref{fig:#1}}%\label{linkback:#1}}
\renewcommand{\Figref}[1]{\autoref{fig:#1}}%\label{linkback:#1}}
%\renewcommand{\secref}[1]{\autoref{sec:#1}}
%\renewcommand{\Secref}[1]{\autoref{sec:#1}}
% Does it know about eq, too?
\renewcommand{\equref}[1]{\autoref{eq:#1}} % NOTE! builtin \eqref
                                              % is usually better.
\renewcommand{\Equref}[1]{\autoref{eq:#1}} % NOTE! builtin \eqref
                                              % is usually better.



% Chapters.   All levels of sections simply have the "sec:" prefix.
\newcommand{\Chapref}[1]{Chapter~\ref{sec:#1}}

\newcommand{\Lemrefp}[1]{Lemma~\ref{lem:#1} on page~\pageref{lem:#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define Section labelling command which also displays the name in
% draft versions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sample usage:
% \seclabel{sectionName}
% Used in conjunction with the naming convention above, in \secref.
%
% 2000 July: cPbL of alum.mit.edu
\newcommand{\seclabel}[1]{
%{\bfseries \sc [sec:#1]} % This should of course be removed for non-draft
\label{sec:#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% If using the report style, use - instead of . in the figure number.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\@ifundefined{thechapter}{}{\def\thefigure{\thechapter-\arabic{figure}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Some more indexing, referencing, and commenting tools
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\cpblcomment}[1]{}
\newcommand{\draftComment}[1]{{ \footnotesize\em\color{olive} #1}\xspace}


% DEFINITIONS NEEDED THROUGHOUT THE DOCUMENT:

% Oh dear.. in 2008 I'm removing the following line. This seems like a
% bad name for a macro! And LyX doesn't like it. I assume this is
% needed in my Stanford thesis, but it already has a copy of the
% definition... Not sure where the oroginal \newcommand is?
%%\renewcommand{\text}[1]{{{\rm #1}}}

\newcommand{\todo}[1]{{\par\ensuremath{\Longrightarrow}\color{red} #1 }}

% BELOW ARE INDEXING SHORTCUTS AND TEXT SHORTHAND
\newcommand{\Sections}{Sections\xspace}
\newcommand{\sections}{Sections\xspace}
\newcommand{\figures}{Figures\xspace}
\newcommand{\Index}[1]{#1\index{#1}} % Shorthand. See Companion, p352
\newcommand{\Sindex}[2]{#1\index{#1#2}} % Shorthand. See Companion, p352
\newcommand{\nn}[1]{#1n} % Used to denote that a index ref is in a footnote.
\newcommand{\ULF}{\index{ultra low frequency (ULF)}ULF}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Family of figure calls (is this duplicating something elsewhere? Surely!! However, I've made a new landscape one, so make similar family.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Could use simplefigurecap in some of below.

% ADDED 2010 JUNE for landscape figures which do not break a page. Uses afterpage feature to clearpage, switch PDF to landscape mode, do figure, switch back to portrait... Also makes use of draftComment 

\newcommand{\cpblLandscapeFigure}[5]{
% Arguments: 1=filepath, 2=height or width declaration, 3=caption for TOC and fig, 4=caption details, 5=figlabel
\cpblLandscapeFigureTC{#1}{#2}{#3}{#3}{#4}{#5}
}

% The "TC" in this command means there are two caption titles: one for TOC, one for figure. 
\newcommand{\cpblLandscapeFigureTC}[6]{%{\begin{figure}\centerline{\includegraphics{#1.eps}}
% Arguments: 1=filepath, 2=height or width declaration, 3=caption for TOC, 4=caption title, 5=caption details, 6=figlabel
\afterpage{
\clearpage\newpage\begin{landscape}
\begin{figure}  
\centering%\begin{center}
\includegraphics[#2]{#1}\caption[#3]{{\bfseries #4.} #5\label{fig:#6}\draftComment{\\{\bfseries label:} #6 {\bfseries file:} #1}}
%\end{center}
\end{figure}
%\clearpage
\newpage\end{landscape}
}%afterpage
\clearpage
}

% The "TC" in this command means there are two caption titles: one for TOC, one for figure. 
\ifpapermode
\newcommand{\cpblFigureTC}[6]{%{\begin{figure}\centerline{\includegraphics{#1.eps}}
% Arguments: 1=filepath, 2=height or width declaration, 3=caption for TOC, 4=caption title, 5=caption details, 6=figlabel
\begin{figure}  
\centering %  \begin{center}
    \includegraphics[#2]{#1}\caption[#3]{{\bfseries #4.} #5\label{fig:#6}\draftComment{\\{\bfseries label:} #6 {\bfseries file:} #1}}
%  \end{center}
\end{figure}
}
\fi
\ifbeamermode
\newcommand{\cpblFigureTC}[6]{%{\begin{figure}\centerline{\includegraphics{#1.eps}}
% Arguments: 1=filepath, 2=height or width declaration, 3=caption for TOC, 4=caption title, 5=caption details, 6=figlabel
\titledImageFrame{#1}{#4}
}
\fi
% I need to redefine these for use in Beamer, so that I can include common code for articles and beamer.... what's the ifbeamer loaded switch?
\newcommand{\cpblFigure}[5]{
% Arguments: 1=filepath, 2=height or width declaration, 3=caption for TOC and fig, 4=caption details, 5=figlabel
\cpblFigureTC{#1}{#2}{#3}{#3}{#4}{#5}
}

% And now a version with two graphics stacked on top of each other, but only one caption
% 2011 Dec: I renamed this by  inserting "Stack" in the name. ie was \newcommand{\cpblTwinFigureTC}
\newcommand{\cpblTwinFigureStackTC}[7]{%{\begin{figure}\centerline{\includegraphics{#1.eps}}
% Arguments: 1=filepath one, 2=filepath 2, 3=height or width declaration, 4=caption for TOC, 5=caption title, 6=caption details, 7=figlabel
\begin{figure}
  \centering
    \includegraphics[#3]{#1}
    \includegraphics[#3]{#2}
\caption[#4]{{\bfseries #5.} #6\label{fig:#6}\draftComment{\\{\bfseries label:} #6 {\bfseries file:} #1}}
\end{figure}
}
\newcommand{\cpblTwinFigureSideTC}[7]{%
% This doesn't allow detailed captions for the (a), (b), ie by filling the [][] below
% Arguments: 1=filepath one, 2=filepath 2, 3=height or width declaration, 4=caption for TOC, 5=caption title, 6=caption details, 7=figlabel
\begin{figure}
  \centering
\subfloat[][]{\includegraphics[width=.45\textwidth]{#1}}
\qquad
\subfloat[][]{\includegraphics[width=.45\textwidth]{#2}}
%\subfloat[][]{\includegraphics[#3]{#2}}
\caption[#4]{{\bfseries #5.} #6\label{fig:#7}\draftComment{\\{\bfseries label:} #7 {\bfseries file:} #1; #2}}
\end{figure}
}

%%%%%%%%%%%%%%%%%%% Added 2008 for UBC thesis!
\newcommand{\centrefigureeps}[3]{\begin{figure}\centerline{\includegraphics{#1.eps}}
\caption{
%{\scriptsize  \em [#1.eps]:}
 {#2}\label{fig:#3}}\end{figure}}
% Should replace the above:

\newcommand{\cpblcentrefigure}[3]{\begin{figure}\centerline{\includegraphics{#1.\epspdf}}
\caption{
%{\scriptsize  \em [#1.eps]:}
 {#2}\label{fig:#3}}\end{figure}}

% Replace above with this. It fixes caption to be same in TOF and fig, though.
\newcommand{\cpblcentrefig}[4]{\begin{figure}\centerline{\includegraphics{#1.\epspdf}}
\simplefigcap{#2}{#3}{fig:#4}
\end{figure}}
% {#2}\label{fig:#3}}
%{\scriptsize  \em [#1.eps]:}

\newcommand{\cpblwfig}[5]{\begin{figure}\centerline{\includegraphics[width=#5]{#1.\epspdf}}
\simplefigcap{#2}{#3}{fig:#4}
\end{figure}}


\newcommand{\cpblOldComment}[1]{}
\newcommand{\cpblSwallow}[1]{}

\newcommand{\eg}{{e.g.}}% Usage: <\eg\ > or <\eg,>
\newcommand{\ie}{{i.e.}\xspace}


\newcommand{\rdctex}{/home/cpbl/rdc/texdocs/}

\usepackage{xspace}


\newcommand{\simplefigcap}[3]{\caption[#1]{{\bfseries #1.} #2\label{#3}}}

\newcommand{\LELpath}{/home/cpbl/models/veblenNeighbourhoods/figuresLEL/}




\@ifclassloaded{beamer}{
\usepackage{beamerImageScalingTwentyThirteen}
}% End of ifclassloaded

%\ifx \@cbbf \@empty
\newcommand{\cbbf}{\bfseries \color{blue}}
%\fi


% In order to refer to a footnote by number, need these:
\newcommand{\footnoteremember}[2]{\footnote{#2\label{foot:#1}}\newcounter{#1}\setcounter{#1}{\value{footnote}}\xspace}
% Hyperref version:
\newcommand{\footnoterefp}[1]{\hyperref[foot:#1]{footnote \arabic{#1} on page \pageref{foot:#1}}\xspace} % Still need to make this whole string into a hyperref. :(
\newcommand{\footnotereuse}[1]{
  \footnotemark[\value{#1}] 

}











