%% Copyright (C) 2011-2012 by Martin Scharrer <martin@scharrer-online.de>
%% ----------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Martin Scharrer.
%%
%% This work consists of the files easyfig.dtx and easyfig.ins
%% and the derived filebase easyfig.sty.
%%
\ProvidesPackage{easyfig}[%
    2012/05/15
    v1.2
    Easy way to include figures]
\RequirePackage{adjustbox}
\RequirePackage{xkeyval}
\RequirePackage{ifetex}
\let\easyfig@caption\@gobble
\let\easyfig@captionabove\@gobble
\let\easyfig@placement\@empty
\let\easyfig@default\@empty
\let\easyfig@default@end\@empty
\let\easyfig@shortcaption\@empty
\def\easyfig@env{{figure}}
\newcommand*{\easyfigdefault}{%
    \@ifstar
        {\def\easyfig@default@end}%
        {\def\easyfig@default}%
}
\easyfigdefault*{center}
\def\easyfig@label#1{%
    \@ifundefined {easyfig@r@fig:#1}{%
        \label{fig:#1}%
        \global\@namedef{easyfig@r@fig:#1}{}%
    }{}%
}
\define@key{easyfig}{caption}{%
    \def\easyfig@caption##1{\expandafter\caption\easyfig@shortcaption{#1}\easyfig@label{##1}}%
    \let\easyfig@captionabove\@gobble
}
\define@key{easyfig}{shortcaption}{%
    \def\easyfig@shortcaption{[{#1}]}%
}
\define@key{easyfig}{captionabove}{%
    \let\easyfig@caption\@gobble
    \def\easyfig@captionabove##1{{%
        \@tempdima=\abovecaptionskip
        \abovecaptionskip=\belowcaptionskip
        \belowcaptionskip=\@tempdima
        \expandafter\caption\easyfig@shortcaption{#1}%
        \easyfig@label{##1}%
    }}%
}
\define@key{easyfig}{label}{%
    \def\easyfig@label##1{\label{#1}}%
}
\define@key{easyfig}{placement}{%
    \def\easyfig@placement{[#1]}%
}
\define@key{easyfig}{here}[]{%
    \def\easyfig@env{{easyfighere}}%
}
\newenvironment{easyfighere}{%
    \trivlist
    \def\@captype{figure}%
    \item\relax
}{%
    \endtrivlist
}
\define@key{easyfig}{twocolumn}[true]{%
    \begingroup
    \def\@tempa{#1}%
    \def\@tempb{true}%
    \ifx\@tempa\@tempb
        \endgroup
        \def\easyfig@env{{figure*}}%
    \else
        \endgroup
        \def\easyfig@env{{figure}}%
    \fi
}
\newcommand{\Figure}{%
    \begingroup
    \@ifstar
        {\def\easyfig@env{{figure*}}\@Figure}%
        {\@Figure}%
}
\ifetex
\def\easyfig@expandonce#1{%
    \expandafter\unexpanded\expandafter{#1}%
}
\newcommand{\@Figure}[2][]{%
    \edef\@tempa{%
        \noexpand\setkeys*{easyfig}{%
            \easyfig@expandonce\easyfig@default,%
            \unexpanded{#1},%
            \easyfig@expandonce\easyfig@default@end
        }%
    }%
    \@tempa
    \edef\@tempa{%
        \noexpand\begin\easyfig@env%
        \easyfig@placement
    }%
    \@tempa
    \easyfig@captionabove{#2}%
    \edef\@tempa{\noexpand\begin{adjustbox}{\easyfig@expandonce\XKV@rm}}%
    \@tempa
        \includegraphics{#2}%
    \end{adjustbox}%
    \easyfig@caption{#2}%
    \expandafter\end\easyfig@env%
    \endgroup
}
\else
\newcommand{\@Figure}[2][]{%
    \def\@tempa{\setkeys*{easyfig}}%
    \expandafter\toks@\expandafter{\easyfig@default,#1}%
    \expandafter\expandafter\expandafter\toks@
    \expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks@\expandafter,\easyfig@default@end}%
    \expandafter\@tempa\expandafter{\the\toks@}
    \edef\@tempa{\noexpand\begin\easyfig@env}%
    \expandafter\@tempa\easyfig@placement
    \easyfig@captionabove{#2}%
    \def\@tempa{\begin{adjustbox}}%
    \expandafter\def\expandafter\@tempb\expandafter{\expandafter{\XKV@rm}}%
    \expandafter\@tempa\@tempb
        \includegraphics{#2}%
    \end{adjustbox}%
    \easyfig@caption{#2}%
    \expandafter\end\easyfig@env%
    \endgroup
}
\fi
\endinput
%%
%% End of file `easyfig.sty'.
