
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Some macros and declarations for side-by-side figures.
% Can handle eps/jpg/png and pstex.
% Can scale automatially, and has manual control for scaling.
% Works with latex and pdflatex (despite the name of the macros ;-) ).
%
% Requires packages graphicx, color, ifpdf.
%
% Package options:
%   draft - don't really include a picture, but draw a box instead
%           (similar to graphics.sty's 'draft' option)
%   all options are passed along to graphicx.sty
%
% Author: Gabriel Zachmann (zach@cs.uni-bonn.de)
% Version: 0.93, May 2004
%
% Todo :
%   Use keyval package, and \@ifstart.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%                                The Macros
%                                ----------
%
% One/two/three eps/jpeg pictures in a row:
% -----------------------------------------
%
%
% \epspic{file}{caption}            % for one picture, with label fg:file
%
% \epspicb{file}{caption}           % [b]-option at \begin{figure}[b]
%
% \epspicy{file}{caption}           % across both columns (figure*)
% \epspicz{frac}{file}{caption}
% \epspiczy{scale}{file}{caption}   % across both columns with scaling
% \epspiczx{nominator}{denominator}{file}
% \epspicx{file}
%
% \epswrappic{scale}{file}			% puts a figure within a paragraph
%                                   % text flowing around it. This cmd
%                                   % should go at the beginning of a paragr.
%                                   % scale = multiple of \textwidth
%
% \twoepspic{file}{caption}         % for two pic's in a row, each with
%            {file}{caption}		% its own caption and label fg:file
%
% \twoepspicu{file}{caption}        % for two pic's in a row, where
%          {file}{caption}          % the 1st picture occupies frac1, the 2nd
%          {frac1}{frac2}           % occupies frac2 \textwidth.
%
% \twoepspicz{file}{caption}        % two pic's in a row, where
%          {file}{caption}          % each picture occupies
%          {frac}                   % frac * textwidth
%
% \twoepspicx{file1}{file2}			% No caption, no label
%
% \threepspic{file}{caption}        % for three pic's in a row,
%             {file}{caption}       % each with label "fg:file"
%             {file}{caption}		% and each with its own caption
%
% \threepspicz{frac}{file1}{file2}{file3}{caption}{lbl}
%
% \twoepspicone{file1}{file2}       % for two pic's inside one figure
%               {caption}{lbl}      % with one caption and label fg:lbl
%
% \threepspicone{file}{file}{file}  % for three pic's
%                {caption}{lbl}     % with 1 caption and label fg:lbl
%
% \fourepspicone{file}{file}{file}{file}  % for 4 pic's
%                {caption}{lbl}     % with 1 caption and label fg:lbl
%
%
% All one/two/three pictures are enclosed in a figure.
% All pictures are scaled to fit their alloted width.
%
% The *z versions get two additional arg's a,b , which scale the
% the picture; 1,1 gives the same size as the *picx-macros
% The *zx versions are like the *z versions, except they don't
% create a figure environment.
% The *x versions create no figure environment, just the scaling.
%
% The captions of the three..pic macros are set with a slight ragged right.
%
% \tabcaption and \figcaption are two helper macros to place figure & table
% side-by-side.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                             INIT & HELPER MACROS                            %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypicture}
	[2004/09/22 v0.93 wrapper macros for pictures (side-by-side etc.)]

\PackageInfo{mypicture}{  graphicx convenience macros}

\DeclareOption{draft}{%
	\PackageInfo{mypicture}{  draw boxes instead of actually including pictures}
	\@picincludefalse
	\PassOptionsToPackage{draft}{graphicx}
}
\newif\if@picinclude\@picincludetrue

\DeclareOption*{%
	\PassOptionsToPackage{\CurrentOption}{graphicx}%
}

\ProcessOptions\relax

\ifx\ifpdf\undefined
  \RequirePackage{ifpdf}
\fi
\ifpdf
 \RequirePackage[pdftex]{graphicx}
 \RequirePackage[pdftex]{color}
 \pdfcompresslevel=9
\else
 \RequirePackage[dvips,draft]{graphicx}
 \RequirePackage[dvips]{color}
\fi

%\RequirePackage{picins}					% needed for \epswrappic

% Set path where to look for images
\graphicspath{{Snapshots/}{images/}{Snapshots_misc/}{Pdf_fig}{Pdf_plt}{Pdf_misc}}

% Use \captionfont if defined (mylayout.sty defines it through caption.sty)
\ifx\captionfont\undefined
  \newcommand{\captionfont}{}
\fi

% Define href for embedding hyperlinks for images, so we can start
% an external viewer / program for images/drawings/plots.
% ~/.mime.types and ~/.mailcap must contain
% application/xdvi_dispatch  qqq
% application/xdvi_dispatch; xdvi_dispatch %s
% Must use xdvi(k) 22.74.
\edef\mypic@hyper@quote{\string"}		% stolen from hyperref.sty
\ifx\sourcespecials\undefined			% set/unset by ~/bin/ltx
\def\mypic@href@start#1{}
\def\mypic@href@end{}
\else
\def\mypic@href@start#1{\special{html:<a href=\mypic@hyper@quote file:#1.qqq\mypic@hyper@quote>}}
% use bogus suffix, to avoid conflicts with other mime-types
\def\mypic@href@end{\special{html:</a>}}
\fi



%   For figures & tables side-by-side 
\newcommand{\tabcaption}{\def\@captype{table}\caption}
\newcommand{\figcaption}{\def\@captype{figure}\caption}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                             THE MEAT                                        %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newlength{\picwid}
\newlength{\picwidscaled}

\newcommand{\picwidhalf}{%
\picwid=\textwidth
\advance \picwid - \columnsep
\divide \picwid \tw@
}

\newcommand{\picwidthird}{%
\picwid=\textwidth
\advance \picwid - \columnsep
\divide \picwid \thr@@
}


\newcommand{\drawpicbox}[1]{%
	\fbox{\parbox{0.95\linewidth}{\center%
			\raisebox{0pt}[\baselineskip][\baselineskip]{}%
			\ttfamily #1}}%
}

\newcommand{\@includegrfiles}[1]{%
\IfFileExists{#1.tex}{%
% then: we seem to include pstex
\resizebox{\hsize}{!}{%
\begin{picture}(0,0)%
\includegraphics{#1}%
\end{picture}%
\input #1.tex %
}%
}{%
% else: regular eps file
\includegraphics[width=\hsize]{#1}%
}%
}

\newcommand{\@includegr}[1]{%
\mypic@href@start{#1}
\captionfont \centering
\if@picinclude
\@includegrfiles{#1}%
\else
\drawpicbox{#1}%
\fi
\mypic@href@end
}



\newcommand{\pictraggedright}{
\@rightskip\z@ plus 2ex
% reduce the "plus" component to get less raggedness and more hyphenation
\rightskip\@rightskip
\pretolerance=1
\hyphenpenalty=1 \exhyphenpenalty=1
}

% negative length added between side-by-side figures and captions
% Can anyone explain to me why this is needed?
\newlength{\piccapspace}
\piccapspace=-1.5ex


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                            EPS MACROS                                       %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





\newcommand{\twoepspic}[4]{%
\picwidhalf
\begin{figure*}%
\begin{minipage}[b]{\picwid}\@includegr{#1}\end{minipage}%
\hfill%
\begin{minipage}[b]{\picwid}\@includegr{#3}\end{minipage}%
\\[\piccapspace]
\begin{minipage}[t]{\picwid}\caption{#2}\label{fg:#1}\end{minipage}%
\hfill\mbox{}%
\begin{minipage}[t]{\picwid}\caption{#4}\label{fg:#3}\end{minipage}
\end{figure*}
}


\newcommand{\twoepspicu}[6]{%
\picwidhalf
\begin{figure*}%
\hfill%
\begin{minipage}[b]{#5\textwidth}\centering\@includegr{#1}\end{minipage}%
\hfill%
\begin{minipage}[b]{#6\textwidth}\centering\@includegr{#3}\end{minipage}%
\hfill\mbox{}%
\\[\piccapspace]
\picwid=#5\textwidth
\advance \picwid - 0.3\columnsep
\begin{minipage}[t]{\picwid}\caption{#2}\label{fg:#1}\end{minipage}%
\hfill%
\picwid=#6\textwidth
\advance \picwid - 0.3\columnsep
\begin{minipage}[t]{\picwid}\caption{#4}\label{fg:#3}\end{minipage}
\end{figure*}
}


\newcommand{\twoepspicz}[5]{%
\picwidhalf
\begin{figure*}%
\hfill%
\begin{minipage}[b]{#5\textwidth}\@includegr{#1}\end{minipage}%
\hfill%
\begin{minipage}[b]{#5\textwidth}\@includegr{#3}\end{minipage}%
\hfill%
\\[\piccapspace]
\begin{minipage}[t]{\picwid}\caption{#2}\label{fg:#1}\end{minipage}%
\hfill\mbox{}%
\begin{minipage}[t]{\picwid}\caption{#4}\label{fg:#3}\end{minipage}
\end{figure*}
}


\newcommand{\twoepspicone}[4]{%
\picwidhalf
\begin{figure*}%
\begin{minipage}[b]{\picwid}\@includegr{#1}\end{minipage}%
\hfill%
\begin{minipage}[b]{\picwid}\@includegr{#2}\end{minipage}
\caption{#3}
\label{fg:#4}
\end{figure*}
}

\newcommand{\threepspic}[6]{%
\picwidthird
\begin{figure*}
\begin{minipage}[b]{\picwid}\@includegr{#1}\end{minipage}%
\hfill%
\begin{minipage}[b]{\picwid}\@includegr{#3}\end{minipage}%
\hfill%
\begin{minipage}[b]{\picwid}\@includegr{#5}\end{minipage}%
\\[\piccapspace]
\begin{minipage}[t]{\picwid}\caption{\pictraggedright #2}\label{fg:#1}\end{minipage}%
\hfill%
\begin{minipage}[t]{\picwid}\caption{\pictraggedright #4}\label{fg:#3}\end{minipage}%
\hfill%
\begin{minipage}[t]{\picwid}\caption{\pictraggedright #6}\label{fg:#5}\end{minipage}
\end{figure*}
}

\newcommand{\threepspicone}[5]{%
\picwidthird
\begin{figure*}
\begin{minipage}[b]{\picwid}\@includegr{#1}\end{minipage}%
\hfill%
\begin{minipage}[b]{\picwid}\@includegr{#2}\end{minipage}%
\hfill%
\begin{minipage}[b]{\picwid}\@includegr{#3}\end{minipage}
\caption{#4}
\label{fg:#5}
\end{figure*}
}



\newcommand{\threepspicz}[7]{%
\picwidthird
\begin{figure*}
\begin{minipage}[b]{#1\picwid}\@includegr{#2}\end{minipage}%
\hfill%
\begin{minipage}[b]{#1\picwid}\@includegr{#3}\end{minipage}%
\hfill
\begin{minipage}[b]{#1\picwid}\@includegr{#4}\end{minipage}%
\caption{#5}
\label{fg:#6}
\end{figure*}
}


\newcommand{\fourepspicone}[6]{%
\picwid=\textwidth
\advance \picwid - \columnsep	% sic
\divide \picwid 4
\begin{figure*}
\begin{minipage}[b]{\picwid}\@includegr{#1}\end{minipage}%
\hfill%
\begin{minipage}[b]{\picwid}\@includegr{#2}\end{minipage}%
\hfill%
\begin{minipage}[b]{\picwid}\@includegr{#3}\end{minipage}%
\hfill%
\begin{minipage}[b]{\picwid}\@includegr{#4}\end{minipage}
\caption{#5}
\label{fg:#6}
\end{figure*}
}


\newcommand{\epspic}[2]{%
\begin{figure}%
\@includegr{#1}%
\caption{#2}%
\label{fg:#1}%
\end{figure}}


\newcommand{\epspicy}[2]{%
\begin{figure*}%
\@includegr{#1}%
\caption{#2}%
\label{fg:#1}%
\end{figure*}}


\newcommand{\epspiczy}[3]{%
\begin{figure*}%
\hsize #1\linewidth
\@includegr{#2}%
\hsize\linewidth
\caption{#3}%
\label{fg:#2}%
\end{figure*}}


\newcommand{\epspicb}[2]{%
\begin{figure}[b]%
\@includegr{#1}%
\caption{#2}%
\label{fg:#1}%
\end{figure}}


\newcommand{\epspich}[2]{%
\begin{figure}[h]%
\@includegr{#1}%
\caption{#2}%
\label{fg:#1}%
\end{figure}}



%\newcommand{\epswrappic}[2]{%
%\parpic[r]{%
%\hsize #1\textwidth%
%\@includegr{#2}%
%}%
%}



\newcommand{\epspicz}[3]{%
\begin{figure}
\hfill%
\begin{minipage}[b]{#1\linewidth}\@includegr{#2}\end{minipage}%
\hfill\mbox{}%
\caption{#3}
\label{fg:#2}
\end{figure}
}



\newcommand{\epspiczx}[3]{%
\picwid=\linewidth
\multiply \picwid by #1
\divide \picwid by #2
{\hsize\picwid \@includegr{#3}}%
}



\newcommand{\twoepspicx}[2]{%
\picwidhalf
{\hsize\picwid\@includegr{#1}}%
\hfill
{\hsize\picwid\@includegr{#2}}%
}


\newcommand{\epspicx}[1]{%
\picwid=\linewidth
{\hsize\picwid\@includegr{#1}}%
}


