%% SOME HELPERS %%

% derivatives from Andrew
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}} % partial derivative
\newcommand{\pdd}[2]{\frac{\partial^2 #1}{\partial #2^2}} % partial double derivative
\newcommand{\diffd}{\mathrm{d}} % differential d
\newcommand{\dd}[2]{\frac{\diffd #1}{\diffd #2}} % derivative
\newcommand{\ddd}[2]{\frac{\diffd^2 #1}{\diffd #2^2}} % double derivative

% general scaled single figure
\newcommand{\scalefig}[4]{\begin{figure}
	\begin{center}
		\includegraphics*[width=#4\textwidth]{#1}
  	\caption{#2}
  	\label{fig:#3}
  \end{center}
\end{figure}}
% use this for wide pictures
\newcommand{\largefig}[3]{\scalefig{#1}{#2}{#3}{0.99}}
% use this for normal pictures (gets rather large -> use scalefig or twofig for smaller ones)
\newcommand{\onefig}[3]{\scalefig{#1}{#2}{#3}{0.85}}
% use this for small pictures (gets just as small as the ones in twofig)
\newcommand{\smallfig}[3]{\scalefig{#1}{#2}{#3}{0.45}}

% figure with no captions
\newcommand{\titfig}[2]{\begin{figure}
	\begin{center}
		\includegraphics*[width=0.75\textwidth]{#1}
  \end{center}
\end{figure}}

% nice way to put two pictures next to each other
\newcommand{\twofig}[6]{\begin{figure}
  \hfill
  \begin{minipage}[t]{.45\textwidth}
    \begin{center}  
      \includegraphics*[width=1.0\textwidth]{#1}
      \caption{#2}
      \label{fig:#3}
    \end{center}  \end{minipage}
  \hfill
  \begin{minipage}[t]{.45\textwidth}
    \begin{center}  
      \includegraphics*[width=1.0\textwidth]{#4}
      \caption{#5}
      \label{fig:#6}
    \end{center}
  \end{minipage}
  \hfill
\end{figure}}

% same as twofig but with only one caption and label
\newcommand{\twofigonecap}[4]{\begin{figure}
  \hfill
  \includegraphics*[width=0.45\textwidth]{#1}
  \hfill
  \includegraphics*[width=0.45\textwidth]{#2}
  \hfill
  \caption{#3}
  \label{fig:#4}
\end{figure}}

\newcommand{\refig}[1]{Fig.~\ref{fig:#1}}

%%%%%%%%%%%
% listings setup
%%%%%%%%%%%

% Some font settings
\DeclareFontShape{OT1}{cmtt}{bx}{n}{<5><6><7><8><9><10><10.95><12><14.4><17.28><20.74><24.88>cmttb10}{}
\usepackage[T1]{fontenc} 
\newcommand{\changefont}[3]{ 
\fontfamily{#1} \fontseries{#2} \fontshape{#3} \selectfont} 

% based on tex from IFM course and google
% see ftp://ftp.tex.ac.uk/tex-archive/macros/latex/contrib/listings/listings.pdf
\usepackage{fancyvrb,listings,color}
\VerbatimFootnotes % allow verbatim in footnotes (fancyvrb)
\lstloadlanguages{C++}
% basic setup
\lstset{
  tabsize=4,		% CHANGE THIS IS TAB = bigger/smaller
  basicstyle=\changefont{pcr}{m}{n}\footnotesize,
  %basicstyle=\ttfamily\footnotesize,
  %basicstyle=\footnotesize,
  fancyvrb=on,                % use fancyvrb for formattingg
  escapechar=@,               % this escapes to LaTeX
  frame=lines,                % horizontal lines above and below
  captionpos=b,               % caption below
  numbers=none
}
% make it prettier
\lstset{
  showstringspaces=false,     % don't mark spaces in strings
  %numbers=left,               % put line numbers left
  %numberstyle=\tiny,		% small line numbers
  xleftmargin=7mm             % no line numbers in left margin
}
% deal with long lines
\lstset{
  breaklines=true,
  breakautoindent=true,
  postbreak=\space
}
% C++ setup
\definecolor{XcodeComments}{RGB}{00,116,00}
\definecolor{XcodeKeywords}{RGB}{170,13,145}
\definecolor{XcodeStringstyle}{RGB}{196,26,21}
\lstdefinestyle{cppCode}{
  language=C++, 
  commentstyle=\color{XcodeComments}\fontseries{b}\fontshape{sl}\selectfont,
  keywordstyle=\color{XcodeKeywords}\fontseries{b}\selectfont,
  %commentstyle=\color{XcodeComments}\bfseries,
  %keywordstyle=\color{XcodeKeywords}\bfseries,
  stringstyle=\color{XcodeStringstyle}
}

\newcommand{\showskeleton}[1]{
  \lstinputlisting[style=cppCode,caption={Skeleton code \texttt{\detokenize{#1}}}]{../skeleton_codes/#1}
} 

\newcommand{\showsolution}[1]{
  \lstinputlisting[style=cppCode,caption={Solution code \texttt{\detokenize{#1}}}]{../solution_codes/#1}
} 


