% \iffalse meta-comment
%
% Copyright (C) 2011 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.3c
% 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.3c or later is part of all distributions of LaTeX
% version 2008/05/04 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 adjustbox.dtx, adjustbox.ins
% and the derived file adjustbox.sty.
%
% $Id$
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{adjustbox.dtx}[2011/08/21 v0.5a DTX File]
\expandafter\ifx\csname ifenglish\endcsname\relax
    \expandafter\newif\csname ifenglish\endcsname
    \englishtrue
\fi
\ifenglish
    \RequirePackage[english]{babel}
\else
    \RequirePackage[ngerman]{babel}
\fi

%\PassOptionsToPackage{ngerman}{hyperref}
%\RequirePackage[ngerman]{babel}
\documentclass{ydoc}[2011/08/11]
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\GetFileInfo{adjustbox.dtx}
\usepackage{newverbs}
\MakeSpecialShortVerb\qverb\"
%\AtBeginDocument{\MakeShortMacroArgs\`\relax}
%\AtEndDocument{\DeleteShortVerb\`}
\usepackage{adjustbox}[2011/08/21]
\usepackage{tikz}
\normalmarginpar

\renewenvironment{example}[1][Example:]{%
    \subsubsection*{#1}%
}{%
    \par
}
\newenvironment{examples}[1][Examples:]{%
    \subsubsection*{#1}%
}{%
    \par
}

\newcommand\babelfiledate{%
    \expandafter\babelfileDate\filedate\relax
}
\def\babelfileDate#1/#2/#3\relax{%
    \begingroup
    \year#1
    \month#2
    \day#3
    \today
    \endgroup
}
\optionaloff

\lstdefinelanguage{none}{}%
\lstdefinelanguage{adjustbox}{%
  moretexcs={%
      begin,end,adjustbox
  },
  emph={%
      frame,fbox,cframe,cfbox,minipage,raise
  },
}%

\lstdefinestyle{examplecode}{%
    basicstyle=\ttfamily\small,
    numbers=none,language=none,
    classoffset=1,
    morekeywords={begin,end},
    keywordstyle=\bfseries,
    classoffset=0,
    morekeywords={adjustbox,minsizebox,maxsizebox,lapbox,marginbox,phantombox},
    keywordstyle=\macrodescstyle,
    emph={viewport, trim, Trim, Viewport, Clip, Clip*, frame, fbox, cframe, cfbox, reflect, lap, margin, margin*, dpi,
    pxdim, execute, raise, valign, bgcolor, set, height, depth, width, totalheight, center, left, right, outer, inner, min, max,
    size, totalsize,
    minipage, innerenv, innercode, env, Addcode, addcode, precode, Precode, appcode, angle, scale, height, width, totalheight, resolution,
    },
    emphstyle=\keydescstyle,
}

\makeatletter
\def\PrintExample{%
  \begingroup
  \par\smallskip\noindent
  \leavevmode
  \BoxExample
  \@tempdima=\textwidth
  \advance\@tempdima by -\wd\examplecodebox\relax
  \advance\@tempdima by -\wd\exampleresultbox\relax
  \advance\@tempdima by -15pt\relax
  \ifdim\@tempdima>\bigskipamount
    \hbox to \textwidth{%
     \null\hss
     \minipage[c]{\wd\examplecodebox}\usebox\examplecodebox\endminipage
     \hfill\hskip\bigskipamount\hfill
     \minipage[c]{\wd\exampleresultbox}%
        \EXAMPLERESULT
     \endminipage
     \hss\null
     }%
  \else
    \vbox{%
        \leftline{\usebox\examplecodebox}%
        \vspace{\bigskipamount}%
        \rightline{\EXAMPLERESULT}%
    }%
  \fi
  \par\smallskip
  \endgroup
}
\def\EXAMPLERESULT{%
    \leavevmode\hbox{%
    \textcolor{exampleborder}{%
        \boxframe
            {\dimexpr\wd\exampleresultbox+2\fboxrule\relax}%
            {\dimexpr\ht\exampleresultbox+\fboxrule\relax}%
            {\dimexpr\dp\exampleresultbox+\fboxrule\relax}%
        \hskip-\wd\exampleresultbox
        \hskip-2\fboxrule
    }%
    \usebox\exampleresultbox
    }%
}%
\makeatother
\colorlet{exampleborder}{black!33}

%\EnableCrossrefs
%\CodelineIndex
%\RecordChanges
\OnlyDescription
\renewcommand{\bottomfraction}{0.5}
\begin{document}
 \DocInput{adjustbox.dtx}
  \PrintChanges
  %\newpage\PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{1842}
%
% \CharacterTable
%  {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 \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v0.1}{2011/01/24}{First internal version}
% \changes{v0.2}{2011/01/27}{First released version}
% \changes{v0.3}{2011/03/20}{Bug fix for wrong baseline placed on the bottom}
% \changes{v0.4}{2011/07/xx}{Added pdftex driver}
% \changes{v0.5}{2011/08/13}{Added more macros and keys}
% \changes{v0.5a}{2011/08/21}{Fixed \Key{left} and \Key{right} keys. Fixed \Key{valign}'='t}
%
% \GetFileInfo{adjustbox.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment,\def,\edef,\xdef,\gdef,\let}
%
% \ifenglish\else
%   \title{Das \pkgtitle{adjustbox} Paket}
% \fi
% \author{Martin Scharrer}
% \email{martin@scharrer-online.de}
% \ydocpdfsettings
% \maketitle
%
% \makeatletter
% \def\LATeX{\texorpdfstring{(L\kern -.36em{\sbox \z@ T\vbox to\ht \z@ {\hbox {\check@mathfonts
%  \fontsize \sf@size \z@ \math@fontsfalse \selectfont A}\vss }}\kern -.15em)\TeX}{(La)TeX}}
% \makeatother
%
% \ifenglish
% \begin{abstract}
%  This package provides macros missing in \pkg{graphics} to trim, clip and generally adjust boxed \LaTeX{} material
%  as well as further box modification macros and option keys usable for \Macro\adjustbox and \Macro\includegraphics.
%  The macros use the \pkg{collectbox} package to allow for verbatim content. Equivalent environments are also provided.
%  The trim operation is now implemented in \TeX\ and the clip operation uses |pdftex| primitives if available.
%  Otherwise the \pkg{pgf} package is used for clipping, which supports both DVI/PS and PDF output.
%  \\
%  \textcolor{yellow}{This package is still a little new and its implementation might not be fully stable yet.}
% \end{abstract}
% \else
% \begin{abstract}
%  Dieses Paket stellt einige Makros zur Verfügung die im \pkg{graphics} Paket vermisst werden
%  und \LaTeX{} Material zu beschneiden (\emph{trim}, \emph{clip}) oder allgemein zu modifizieren.
%  Die Makros erlauben Inhalt das im \emph{verbatim} Modus gesetzt ist.
%  Ebenfalls werden passende Umgebungen für die Makros bereitgestellt.
%  Das Beschneiden wird durch eine \env{pgfpicture} Umgebung des Pakets \pkg{pgf} verwirklicht,
%  dass sowohl das PS und PDF Ausgabeformat unterstützt.\\
%  \textcolor{red}{Dieses Paket ist noch neu und seine Implementieren kann sich in zukünftigen Versionen noch ändern!}
% \end{abstract}
% \fi
%
% \ifenglish
% \section{Introduction}
% The standard \LaTeX{} package \pkg{graphicx} (the extended version of \pkg{graphics}) provides the macro \Macro\includegraphics[<options>]{<file name>} which can
% be used to include graphic files. Several options can be used to scale, resize, rotate, trim and/or clip the graphic.
% The macros \Macro\scalebox, \Macro\resizebox and \Macro\rotatebox are also provided to apply the corresponding 
% operation on \LATeX{} material, which is subsequently placed inside a \Macro\hbox.
% However no macros are provided to trim or clip \LATeX{} material, most likely because this operations
% are not done by \TeX{} but by the output format, i.e. using PostScript (PS) or PDF operations.
%
% This package provides the missing macros \Macro\clipbox and \Macro\trimbox
% as well as the general \Macro\adjustbox macro. The trim operation is implemented as \TeX\ code
% and the clip operation either using a |pdftex| or a \env{pgfpicture} environment from the \pkg{pgf} package
% which supports both PS and PDF output. All \LaTeX\ compilers should be supported, but |pdflatex| is the main target of the
% author.
% \else
% \section{Einleitung}
% Das \LaTeX{} Paket \pkg{graphicx} (die erweiterte Version von \pkg{graphics}) stellt das Macro \Macro\includegraphics[<Optionen>]{<Dateiname>} zur Verfügung
% mit dem Bilddateien eingebunden werden können. Zahlreiche Optionen können benutzt werden um das Bild zu skalieren, an eine vorgegebene Größe anzupassen, es zu rotieren 
% oder den Rand zu beschneiden.
% Ebenfalls stellt das Paket die Makros \Macro\scalebox\relax (skalieren), \Macro\resizebox\relax (Größe ändern) und \Macro\rotatebox\relax (rotieren) zur Verfügung um \LATeX{} Material,
% z.B.\ normalen Text, entsprechend anzupassen. Dies wird dazu in eine horizontale Box (\Macro\hbox) gesetzt.
% Allerdings fehlen Makros um \LATeX{} Material zu beschneiden, wobei der abgeschnittenen Rand entweder sichtbar bleibt (engl.: \emph{trim}) oder ausgeblendet wird (engl. \emph{clip}).
% Dies ist wahrscheinlich der Fall, weil diese Operationen nicht von \TeX{} selbst vorgenommen werden, sondern von dem verwendeten Ausgabeformat, z.B.\ durch PostScript (PS)
% oder PDF Operationen.
%
% Das \textsf{adjustbox} Paket definiert die Makros \Macro\clipbox und \Macro\trimbox, sowie das allgemeine \Macro\adjustbox Macro (engl.: \emph{adjust} = anpassen).
% Das Beschneiden wird durch eine \env{pgfpicture} Umgebung des Pakets \pkg{pgf} verwirklicht, dass sowohl das PS und PDF Ausgabeformat unterstützt.
% \fi
%
% \section{Package Option}\label{sec:options}
% Following v0.5 from 2011/08/13 this package accepts the following package options. Some of them can also be used as
% optional keys for macros.
%
% \begin{description}\def\oitem#1{\item[{\normalfont\opt{#1}}]}
%   \oitem{minimal} Only define the minimal set of macros, i.e.\ \Macro\trimbox, \Macro\clipbox and \Macro\adjustbox as
%       with previous versions before v0.5.
%   \oitem{export} Export the now keys of \Macro\adjustbox also to \Macro\includegraphics so that they can be used for
%       images as well. This option is meaningless if \opt{minimal} was used.
%   \oitem{patch} Patch the internal \pkg{graphicx} code to allow the usage of size macros.
%                 This simply loads the small \pkg{adjgrfx} package which can also be used independently.
%                 (Not fully implemented and tested yet!)
%   \oitem{pgf} Uses the \pkg{pgf} package for all clip operations. This overrides all automatically detected drivers.
%               At the moment only a |pdftex| driver is provided, all other compilers and output formats use this option already.
%   \oitem{PGF} Uses the \pkg{pgf} package for clip operations and configures the macros to parse lengths using
%   \pkg{pgfmath} (compare with the \opt{pgf} option below).
%  \end{description}
%
% The following options define the way length values are processed by the provided macros.
% They can be used either as package options and as keys for \Macro\adjustbox\relax (but not for \Macro\includegraphics
% even if the \opt{export} option was used) to change the settings locally.
% The only difference between these two usages is that they also load required packages when used as package options.
% Therefore all keys used in the document should be loaded as package options first or the required packages must be loaded
% manually. (It is also possible to disable the advanced parsing of lengths using the \opt{none} option, but this is not recommended.)
%
% \begin{description}\def\oitem#1{\item[{\normalfont\opt{#1}}]}
%   \oitem{etex} Uses the $\epsilon$-\TeX\ primitive \Macro\glueexpr to parse length values. This allows for additions,
%      subtractions as well as multiplications and devision by a numeric factor. See the official \pkg{etex\_man} document
%      for more details. This setting is the default if $\epsilon$-\TeX\ is detected (which should be the case with all
%      modern \LaTeX\ distributions).
%   \oitem{calc} Uses the \pkg{calc} package to parse length values. It supports all operations mentioned for \opt{etex} and
%      also some other operation like \Macro\widthof{<text>}.
%      See the \pkg{calc} package manual for more details.
%      This is the default setting if $\epsilon$-TeX is not detected.
%   \oitem{pgfmath} Uses the \pkg{pgfmath} package of the \pkg{pgf} bundle to parse length values. It supports all basic
%      numeric operations and also advanced mathematical functions.
%      See the \pkg{pgf} manual for more details.
%      Because the \pkg{pgfmath} package can't be loaded
%      independently in the current version (v2.10) the whole \pkg{pgf} package will be loaded.
% \end{description}
%
% One further option exists which can also be used as optional key for \Macro\adjustbox\relax (but not for
% \Macro\includegraphics):
% \begin{description}\def\oitem#1{\item[{\normalfont\opt{#1}}]}
%   \oitem{defaultunit}\MacroArgs'='<unit>\relax
%      This sets the default unit used for the values of \Macro\trimbox, \Macro\clipbox and \Macro\marginbox
%      including there starred versions
%      as well as all related keys like \Key{trim}, \Key{viewport}, \Key{margin}, \Key{trim}, \Key{viewport}, \Key{Clip} and \Key{Clip*}.
%      The standard default unit is the same as for \Macro\includegraphics: "bp" (big points, PostScript points).
%      However, for \LaTeX\ material \TeX\ normal unit "pt" (\TeX\ points) are better suited and will avoid rounding
%      errors which otherwise get introduced by the internal conversion.
%      The default unit is only used if the particular value is only a single number without unit,
%      but not if any mathematical operations are used.
%      If the special value |none| is used no default unit is applied and the internal check if the value is a single number
%      is by-passed. This gives a small speed bonus and can be used to avoid potential issues with complex values.
%      At this moment this setting will disable the default unit feature for the rest of the current group (i.e.\ all
%      further \Macro\adjustbox keys or globally if used as a package option) and further usages of this option will
%      have no affect. This might change in future versions of this package.
% \end{description}
%
% \ifenglish
% \def\llx{llx}
% \def\lly{lly}
% \def\urx{urx}
% \def\ury{ury}
% \def\TEXT{content}
% \def\height{height}
% \def\width{width}
% \def\totalheight{totalheight}
% \def\depth{depth}
% \def\factor{factor}
% \def\xfactor{x-factor}
% \def\yfactor{y-factor}
% \def\Angle{angle}
% \def\options{options}
% \else
% \def\llx{lux}
% \def\lly{luy}
% \def\urx{orx}
% \def\ury{ory}
% \def\TEXT{Inhalt}
% \def\height{Höhe}
% \def\width{Weite}
% \def\totalheight{Totale Höhe}
% \def\depth{Tiefe}
% \def\factor{Faktor}
% \def\xfactor{X-Faktor}
% \def\yfactor{Y-Faktor}
% \def\Angle{Winkel}
% \def\options{Optionen}
% \fi
%
% \ifenglish
% \section{Usage}
% This section describes the usage of the provided macros, which are outlined in \autoref{sec:basicmacros}.
% Possible advanced values for the macro arguments are mentioned in \autoref{sec:argval}. The existing verbatim support
% is explained in \autoref{sec:verbatim}. Finally \autoref{sec:alternatives} compares the existing macros with the 
% corresponding options of \Macro\adjustbox.
% Further box modification macros and keys are described in \autoref{sec:moremacros} and \autoref{sec:newkeys}, respectively.
%
% It is recommended to also read the \emph{Graphics Guide} (\pkg{grfguide}, i.e.~the manual of the \pkg{graphics}/|x| packages),
% to understand the existing options for \Macro\includegraphics. 
% \else
% \newpage
% \section{Anleitung}
% Dieser Abschnitt beschreibt die Verwendung der Makros dieses Pakets. Diese werden zuerst im \autoref{sec:basicmacros} beschrieben.
% \autoref{sec:argval} erklärt welche Werte in den Makroargumenten verwendet werden können. Die Makros unterstützen sogenannten
% \emph{verbatim} (engl.: wortgetreu) Inhalt was im \autoref{sec:verbatim} erleutert wird.
% Schlussendlich wird im \autoref{sec:alternatives} die exisitierenden Makros mit den entsprechendem Optionen von \Macro\adjustbox
% verglichen. Beispiele für die beschriebenen Makros befinden sich im folgendem \autoref{sec:example}.
%
% Dem Leser wird darüberhinaus die Lektüre der Anleitung der \pkg{graphic}/|x| Pakete, der \emph{Graphics Guide}, empfohlen wo
% die möglichen Optionen für das Makro \Macro\includegraphics gelistet sind, die auch für \Macro\adjustbox verwendet werden.
% \fi
%
% \ifenglish
% \Needspace*{7\baselineskip}
% \subsection{Basic Box Modification Macros}\label{sec:basicmacros}
% This section lists the provided macros \Macro\clipbox and \Macro\trimbox missing in the \pkg{graphicx} package
% as well as the general \Macro\adjustbox macro.  If the package is loaded with the \opt{minimal} option no further macros or keys are defined.
% \else
% \subsection{Makros zur Modifikation von {\LaTeX} Material}\label{sec:basicmacros}
% \fi
%
% \ifenglish
% \subsubsection*{Trim Box Content}
% \else
% \subsubsection*{Rand beschneiden ohne Überhang auszublenden}
% \fi
% \vskip-\lastskip
% \DescribeMacro\trimbox{<all sites>}{<\TEXT>}
% \DescribeMacro\trimbox{<left/right>~<top/bottom>}{<\TEXT>}
% \DescribeMacro\trimbox{<\llx>~<\lly>~<\urx>~<\ury>}{<\TEXT>}
% \DescribeMacro\trimbox*{<\llx>~<\lly>~<\urx>~<\ury>}{<\TEXT>}
% \ifenglish
% The macro \Macro\trimbox trims the given amount from the lower left (ll) and the upper right (ur) corner of
% the box. This means that the amount \meta{llx} is trimmed from the left side, \meta{lly} from the bottom and
% \meta{urx} and \meta{ury} from the right and top of the box, respectively.
% If only one value is given it will be used for all four sites.
% If only two values are given the first one will be used for the left and right side (llx, urx) and the second for the bottom and top side (lly, ury).
% Trimming means that the official size of the box is reduced, but no material
% is actual removed. The material in the trimmed areas simply swaps over the official border.
%
% If the starred version is used the four coordinates are taken as the \Key{viewport} instead, i.e. the box
% is trimmed to the rectangle described by the coordinates. In this case using all four values must be specified.
% \else
% Das Makro \Macro\trimbox setzt den \meta{Text} in eine \TeX{} Box und reduziert dessen offizielle Größe
% (\emph{bounding box}, engl.: begrenzende Box), so dass \TeX{} annimmt es wäre entsprechend kleiner. Überstehendes Material
% ragt deswegen in den umgebenden Text hinein.
% Die angegebenen Werte im ersten Argument stehen für die Beträge die von der unteren linken (lu) und der oberen rechten (or)
% Ecke entfernt werden. Das heisst, dass der Wert \meta{lux} vom linken Rand, \meta{lly} vom unterem Rand und \meta{orx} und \meta{ory}
% von rechten bzw. oberen Rand abgezogen werden.
% Wird das Makro allerdings in der Sternvariante aufgerufen, stehen die vier Werte für den Darstellungsbereich (\emph{viewport}) und 
% alles ausserhalb wird von der offiziellen Größe abgeschnitten.
% \fi
%
%
% \DescribeEnv[<\TEXT>]{trimbox}{<1, 2 or 4 trim values>}
% \vspace{-\baselineskip}
% \DescribeEnv[<\TEXT>]{trimbox*}{<\llx>~<\lly>~<\urx>~<\ury>}
% \ifenglish
% The \env{trimbox} and \env{trimbox*} environments do the same as the corresponding macros.
% Special care is taken so that the macros and the environments can have the same name.
% Because of this the star can be either part of the name or an optional argument.
% Also the plain\TeX{} syntax for environments (|\trimbox ... \endtrimbox|) can not be used
% because it will trigger \Macro\trimbox as a macro. 
% \else
% Die Umgebungen \env{trimbox} und \env{trimbox*} erzeugen den selben Effekt wie die gleichnamigen Makros.
% Ein spezieller Trick wird verwendet, damit der selbe Name für ein Makro und für eine Umgebung verwendet werden kann,
% was normallerweise nicht der Fall ist. Aufgrund dessen akzeptier die \env{trimbox} Umgebung auch einen optionallen Stern.
% Die plain\TeX{} Schreibweise für Umgebungen (|\trimbox ... \endtrimbox|) kann allerdings nicht verwendet werden,
% da es \Macro\trimbox als Makro aufrufen würde.
% \fi
%
%
% \ifenglish
% \subsubsection*{Clip Box Content}
% \else
% \subsubsection*{Rand beschneiden und Überhang ausblenden}
% \fi
% \vskip-\lastskip
% \DescribeMacro\clipbox{<all sites>}{<\TEXT>}
% \DescribeMacro\clipbox{<left/right>~<top/bottom>}{<\TEXT>}
% \DescribeMacro\clipbox{<\llx>~<\lly>~<\urx>~<\ury>}{<\TEXT>}
% \DescribeMacro\clipbox*{<\llx>~<\lly>~<\urx>~<\ury>}{<\TEXT>}
% \ifenglish
% The \Macro\clipbox macro works like the \Macro\trimbox and trims the given amounts from the \meta{text}.
% However, in addition the trimmed material is also clipped, i.e. it is not shown in the final document.
% Note that the material will still be part of the output file but is simply not shown.
% It might be exported using special tools, so using \Macro\clipbox\relax (or \Macro\includegraphics[clip,trim=...])
% to censor classified information would be a bad idea.
% The starred version will again use the given coordinates as \Key{viewport}. 
% \else
% Das \Macro\clipbox Makro arbeiten ähnlich wie \Macro\trimbox nur, dass der entfernte Rand auch wirklich
% ausgeblendet wird. Allerdings bleibt dieses Material Teil der Ausgabedatei und könnte durch spezielle Software exportiert werden.
% Von der Verwendung von \Macro\clipbox\relax (oder \Macro\includegraphics'[clip,trim=...]') um vertrauliche Informationen zu zensieren
% kann deswegen nur abgeraten werden.
% Die Sternvariante verwendet die angegebenen Werte als den zu darstellenden Bereich wie bei \Macro\trimbox'*'.
% \fi
%
% \DescribeEnv[<\TEXT>]{clipbox}{<1, 2 or 4 trim values>}
% \vspace{-\baselineskip}
% \DescribeEnv[<\TEXT>]{clipbox*}{<\llx>~<\lly>~<\urx>~<\ury>}
% \iffalse
% The environment versions of \Macro\clipbox and \Macro\clipbox*. The same rules as for the trimming environments apply.
% \else
% Die obigen Makros als Umgebungen. Es gelten die gleichen Regeln wie bei den \env{trimbox} Umgebungen.
% \fi
%
%
% \ifenglish
% \subsubsection*{Adjust Box Content}
% \else
% \subsubsection*{Allgemeine Manipulationen von \LaTeX{} Material}
% \fi
% \vskip-\lastskip
% \DescribeMacro\adjustbox{<includegraphics \options>}{<\TEXT>}
% \ifenglish
% The \Macro\adjustbox macro is the general form of all box modifying macros mentioned in the introduction.
% It can be thought as an \Macro\includegraphics for \LATeX{} material.
% It supports the same set of \meta{options}, however they are provided as a mandatory not as an optional argument.
% An \Macro\adjustbox without options would not make sense and can be replaced by a simple \Macro\mbox.
% There is no starred version of this macro. See also \autoref{tab:alternatives} for a comparison of \Macro\adjustbox
% with the other macros.
% \else
% Mit Hilfe des \Macro\adjustbox Makros (engl.\ \emph{adjust} = anpassen, justieren) ist es möglich die selben Optionen
% die \Macro\inludegraphics für Bilder zur Verfügung stellt auch auf beliebiges \LATeX{} Material anzuwenden.
% Die \meta{Optionen} sind dabei allerdings nicht optional, da \Macro\adjustbox ohne jegliche Optionen einem \Macro\mbox
% gleich käme. Eine Sternvariante existiert für dieses Makro nicht.
% Es kann dazu verwendet werden Kombinationen von anderen ähnlichen Makros zu ersetzen, was in \autoref{tab:alternatives} dargestellt wird.
% \fi
%
% \DescribeEnv[<\TEXT>]{adjustbox}{<includegraphics \options>}
% \ifenglish
% The environment version of \Macro\adjustbox.
% \else
% Wie für die anderen Makros gibt es auch für \Macro\adjustbox eine passende Umgebung.
% \fi
%
% \ifenglish
% \section*{Examples}
% The following examples show the application of the aforementioned macros on an example text.
% The result is placed in a tight, colored frame box to show the resulting dimensions.
% \else
% \section*{Beispiele}
% Die folgenden Beispiele zeigen die Anwendung der Makros dieses Packets auf einen Beispieltext (\Macro\example).
% Das Ergebnis wird mit einer engen, farbigen Umrandung dargestellt um die entgültigen Dimensionen sichtbar zu machen.
% \fi
% \begingroup
% \def\examplecontent{\begin{tabular}{@{}|c|c|@{}}
%       \hline
%       A & B \\
%       \hline
%       C & D \\
%       \hline
%   \end{tabular}^^A
% }
% \fboxsep=0pt%
% \def\Fbox{\fcolorbox{red}{white}}%
% \def\X{\vspace*{20pt}}%
% \par\bigskip\noindent
% \begin{tabular}{@{}lc}
%   \X\Macro\example      & \Fbox{\examplecontent} \\
%   \X\Macro\trimbox{10 5 10 5}{\AlsoMacro\example} & \Fbox{\trimbox{10 5 10 5}{\examplecontent}} \\
%   \X\Macro\clipbox{10 5 10 5}{\AlsoMacro\example} & \Fbox{\clipbox{10 5 10 5}{\examplecontent}} \\
%   \X\Macro\trimbox*{15 5 25 30}{\AlsoMacro\example} & \Fbox{\trimbox*{15 5 25 30}{\examplecontent}} \\
%   \X\Macro\clipbox*{15 5 25 30}{\AlsoMacro\example} & \Fbox{\clipbox*{15 5 25 30}{\examplecontent}} \\
%   \X\Macro\adjustbox{trim=10 5 10 5,angle=45}{\AlsoMacro\example} & \Fbox{\adjustbox{trim=10 5 10 5,angle=45}{\examplecontent}} \\
%   \X\Macro\adjustbox{scale=1.5}{\AlsoMacro\example} & \Fbox{\adjustbox{scale=1.5}{\examplecontent}} \\
%   \X\Macro\adjustbox{width=180pt,height=20pt}{\AlsoMacro\example} & \Fbox{\adjustbox{width=40pt,height=10pt}{\examplecontent}} \\
%   \X\Macro\adjustbox{width=180pt,height=20pt,keepaspectratio}{\AlsoMacro\example} & \Fbox{\adjustbox{width=40pt,height=10pt,keepaspectratio}{\examplecontent}} \\
% \end{tabular}
% \endgroup
%
% \clearpage
% \ifenglish
% \subsection{Argument Values}\label{sec:argval}
% All\marginpar{Parsing} length values given in the arguments of all macros and keys provided by this package are parsed by and advanced version of
% \Macro\setlength (called \Macro\adjsetlength) which uses either $\epsilon$-\TeX\ expressions (default), the \pkg{calc} package (default fall-back)
% or the \Macro\pgfmathparse of the \pkg{pgf} package.
% This allows for arithmetic expressions in these arguments. See the package options in \autoref{sec:options} to learn how to change the used length parser.
% Note that early versions of this package used \Macro\pgfmathparse by default. Older documents therefore might need now use the \opt{pgfmath} option to compile correctly.
%
% Note\marginpar{Space=Separator} that the four values for \Macro\trimbox and \Macro\clipbox as well as for the \Key{trim} and \Key{viewport} option of \Macro\adjustbox
% are separated by spaces. If the expression of any of this values holds a space or ends with a macro (eats trailing spaces!) it must be wrapped into braces "{ }".
% \else
% \newpage
% \subsection{Erlaubte Werte für Makroargumente}\label{sec:argval}
% Die numerischen Werte für die Makros werden durch das vielseitige \Macro\pgfmathparse Makro des sowieso schon verwendeten \pkg{pgf} Paketes
% eingelesen. Dies erlaubt die Verwendung von einfachen oder komplizierten Formeln.
% Eine genaue Beschreibung der unterstützten mathematischen Operationen befindet sich im Handbuch des \pkg{pgf} Paketes.
% Dabei muss beachtet werden das die vier Werte für die \Macro\trimbox und \Macro\clipbox Makros sowie für die \Key{trim} und \Key{viewport} Optionen von \Macro\adjustbox
% durch Leerzeichen getrennt werden müssen. Komplizierte Angaben die ein Leerzeichen enthalten oder auf ein Makro enden (entfernt nachfolgende Leerzeichen) müssen
% deswegen in geschweifte Klammern "{ }" gesetzt werden.
% \fi
%
%
% \DescribeMacros
%    \hbox{\Macro\width~~~\Macro\height~~~\Macro\depth~~~\Macro\totalheight}%
% \endDescribeMacros
% \ifenglish
% These \LaTeX{} lengths hold the original dimension of \meta{text} and can be used as part of the arguments to \Macro\adjustbox, \Macro\trimbox and \Macro\clipbox.
% The totalheight is the height plus depth. With the \pkg{patch} option these lengths can also be used for \Macro\includegraphics.
% \else
% Diese \LaTeX{} Längen enthalten die Weite, Höhe, Tiefe bzw.\ die totale Höhe (Höhe + Tiefe) des \meta{\TEXT} Arguments bzw.\ des Inhalts der Umgebung.
% Diese Längen können in den ersten Argument von \Macro\adjustbox, \Macro\trimbox und \Macro\clipbox verwendet werden um relative Änderungen vorzunehmen.
% \fi
%
% If\marginpar{Default unit} no unit is provided for of the bounding box coordinates (\llx, \lly, \urx, \ury) then PostScript points
% (\emph{big points}, bp, $72\,\text{bp}=1\,\text{inch}$) are used, as it is the default behaviour
% of the \Key{trim} and \Key{viewport} options of \pkg{graphicx}'s \Macro\includegraphics. Note that \pkg{graphicx} converts all values, independent if a unit is provided or not,
% internally to bp, because graphics where traditionally stored in Encapsulated PostScript (EPS) files. The more modern PDF files also use bp instead of pt.
% Because the \pkg{adjustbox} package macros target \LATeX{} material and users will mostly use pt values this internal conversion to bp got disabled for them to 
% avoid unnecessary rounding errors. Since v0.5 the default unit can be changed using the |defaultunit|\MacroArgs'='<unit>\relax
% key (which is also usable as global package option).
%
%
% \subsection{Verbatim Support}\label{sec:verbatim}
% The macros read the \meta{text} as \TeX{} \Macro\hbox and not as an macro argument in order to support verbatim content.
% This functionality is now provided as dedicated package \pkg{collectbox} which can also be used independently.
% This means that the braces around the content can also be written as \Macro\bgroup and \Macro\egroup:
% \begin{macroquote}
%   \trimbox{1 2 3 4}\AlsoMacro\bgroup~<\TEXT>\AlsoMacro\egroup
% \end{macroquote}
% Special care is taken to allow the \meta{text} to be a single macro (except \Macro\bgroup) without any braces:
% \begin{macroquote}
%   \clipbox{1 2 3 4}\AlsoMacro\somemacro
% \end{macroquote}
% This is to support the questionable habit of some \LaTeX{} users to drop the braces for single token arguments.
% All environments support verbatim content.
%
% \clearpage
% \ifenglish
% \subsection{Alternatives for existing Macros}\label{sec:alternatives}
% The flexible \Macro\adjustbox can also be used as an alternative to existing macros from the \pkg{graphics} package as shown by Table~\ref{tab:alternatives}.
% Because it is longer then the originals this is only of benefit if combinations are to be replaced or verbatim text must be supported.
% \else
% \subsection{Alternativen für existierende Makros}\label{sec:alternatives}
% Das flexible \Macro\adjustbox Makro kann auch als Alternative für die vorhandenen Makros des \pkg{graphics} Paketes verwenden werden.
% Dies ist in Tabelle~\ref{tab:alternatives} dargestellt.
% Die dies allerdings mehr Schreibarbeit darstellt ist es nur dann von Vorteil, falls mehrere Operationen verknüpft werden sollen
% oder wenn der entsprechende Text im \emph{verbatim} Modus eingelesen werden soll.
% \fi
%
% \ifenglish
% \begin{table}[!hb]
% \else
% \begin{table}[!hb]
% \fi
% \belowcaptionskip\abovecaptionskip
% \colorlet{optional}{black}
% \ifenglish
% \caption{Alternatives for existing Macros}
% \else
% \caption{Alternativen für existierende Makros}
% \fi
% \label{tab:alternatives}
% \hbox to \linewidth{\hss
% \begin{tabular}{ll}
%   \toprule
%   \ifenglish
%   Original Macro (w/o content argument)  &  Alternative \Macro\adjustbox keys \\
%   \else
%   Originales Makro (ohne Textargument)  &  Alternative \Macro\adjustbox Schlüssel \\
%   \fi
%   \midrule
%   \Macro\rotatebox{<\Angle>}                   & \MacroArgs'angle='<\Angle>  \\
%                                                & \MacroArgs'rotate='<\Angle>  \\
%   \Macro\scalebox{<\factor>}                   & \MacroArgs'scale='<\factor>  \\
%   \Macro\scalebox{<\xfactor>}[<\yfactor>]      & \MacroArgs'width='<\xfactor>\AlsoMacro\width',height='<\yfactor>\AlsoMacro\height  \\
%   \Macro\reflectbox                            & \MacroArgs'reflect'  \\
%                                                & \MacroArgs'width=-'\AlsoMacro\width',height='\AlsoMacro\height  \\
%   \Macro\resizebox{<\width>}{<\height>}        & \MacroArgs'width='<\width>',height='<\height>  \\
%   \Macro\resizebox*{<\width>}{<\totalheight>}  & \MacroArgs'width='<\width>',totalheight='<\totalheight>  \\
%   \Macro\trimbox{<\llx>~<\lly>~<\urx>~<\ury>}  & \MacroArgs'trim='<\llx>~<\lly>~<\urx>~<\ury>  \\
%                                                & \MacroArgs'Trim='<\llx>~<\lly>~<\urx>~<\ury>  \\
%   \Macro\trimbox*{<\llx>~<\lly>~<\urx>~<\ury>} & \MacroArgs'viewport='<\llx>~<\lly>~<\urx>~<\ury>  \\
%                                                & \MacroArgs'Viewport='<\llx>~<\lly>~<\urx>~<\ury>  \\
%   \Macro\clipbox{<\llx>~<\lly>~<\urx>~<\ury>}  & \MacroArgs'trim='<\llx>~<\lly>~<\urx>~<\ury>,clip  \\
%                                                & \MacroArgs'Clip='<\llx>~<\lly>~<\urx>~<\ury>  \\
%   \Macro\clipbox*{<\llx>~<\lly>~<\urx>~<\ury>} & \MacroArgs'viewport='<\llx>~<\lly>~<\urx>~<\ury>,clip  \\
%                                                & \MacroArgs'Clip*='<\llx>~<\lly>~<\urx>~<\ury>  \\
%   \bottomrule
% \end{tabular}%
% \hss}%
% \end{table}
%
%
%
% \subsection{Further Box Modification Macros}\label{sec:moremacros}
% This section lists further macros which are also defined unless the package is loaded with the \opt{minimal} option.
% Note that the authors other package \pkg{realboxes} provides variants of existing box macros
% defined by the \LaTeX\ core or common packages like \pkg{graphicx}. Like the box macros here this variants allow for verbatim content
% because they read it as real box and not as macro arguments.
%
% \DescribeMacro\marginbox{<all sites>}{<\TEXT>}
% \DescribeMacro\marginbox{<left/right>~<top/bottom>}{<\TEXT>}
% \DescribeMacro\marginbox{<\llx>~<\lly>~<\urx>~<\ury>}{<\TEXT>}
% This macro can be used to add a margin (white space) around the content. It can be seen as the opposite of \Macro\trim.
% The original baseline of the content is preserved because \meta{\lly} is added to the depth.
% It is also available as \env{marginbox} environment and also usable as \Key{margin} option (see below).
%
% \begin{example}
%   \begin{examplecode}
%   Before \fbox{\marginbox{1ex 2ex 3ex 4ex}{Text}} After
%   \end{examplecode}
% \end{example}
%
%
% \DescribeMacro\marginbox'*'{<all sites>}{<\TEXT>}
% \DescribeMacro\marginbox'*'{<left/right>~<top/bottom>}{<\TEXT>}
% \DescribeMacro\marginbox'*'{<\llx>~<\lly>~<\urx>~<\ury>}{<\TEXT>}
% This starred version is almost identical to the normal \Macro\marginbox, but also raises the content by the \MacroArgs<\lly>
% amount, so that the original depth instead of the original baseline is preserved.
% Note that while \Macro\marginbox is basically the opposite of \Macro\trim, \Macro\marginbox* is not the opposite of \Macro\trim*.
% Instead it also takes the same values as the normal value and not view port values like \Macro\trim*.
%
% \begin{example}
%   \begin{examplecode}
%   Before \fbox{\marginbox*{1ex 2ex 3ex 4ex}{Text}} After
%   \end{examplecode}
% \end{example}
%
%
% \DescribeMacro\minsizebox{<width>}{<height>}{<\TEXT>}
% \DescribeMacro\minsizebox'*'{<width>}{<totalheight>}{<\TEXT>}
% This macro is like \Macro\resizebox of the \pkg{graphics/x} package, but only resizes the content if its natural size is smaller
% than the given \meta{width} or \meta{height}.
% If only one value should be set the other one can be replaced by "!".
% If required the content is scaled up so that the width and height is equal or larger than the given values, but does not change 
% the aspect ratio. 
% The star variant uses the total height instead of only the height.
% This macro is used internally for the \Key{min width}, \Key{min height}, \Key{min totalheight} and \Key{min totalsize} options.
%
% \begin{examples}
%   \begin{examplecode}
%   \minsizebox{3cm}{2ex}{Some Text} which will be enlarged
%   \end{examplecode}
%   \begin{examplecode}
%   \minsizebox{!}{4ex}{\fbox{Some Text}} which will be enlarged
%   \end{examplecode}
%   \begin{examplecode}
%   \minsizebox*{!}{4ex}{\fbox{Some Text}} which will be enlarged
%   \end{examplecode}
%   \begin{examplecode}
%   \minsizebox{3cm}{!}{Some Text} which will be enlarged
%   \end{examplecode}
%   \begin{examplecode}
%   \minsizebox{1cm}{1ex}{Some Text}, already large enough
%   \end{examplecode}
% \end{examples}
%
%
%
% \DescribeMacro\maxsizebox{<width>}{<height>}{<\TEXT>}
% \DescribeMacro\maxsizebox'*'{<width>}{<totalheight>}{<\TEXT>}
% This macro is like \Macro\resizebox of the \pkg{graphics/x} package, but only resizes the content if its natural size is larger
% than the given \meta{width} or \meta{height}.
% If only one value should be set the other one can be replaced by "!".
% If required the content is scaled down so that the width and height is equal or smaller than the given values, but does not change 
% the aspect ratio.
% The star variant uses the total height instead of only the height.
% This macro is used internally for the \Key{max width}, \Key{max height}, \Key{max totalheight} and \Key{max totalsize} options.
%
% \begin{examples}
%   \begin{examplecode}
%   \maxsizebox{1cm}{1ex}{Some Text} which will be reduced
%   \end{examplecode}
%   \begin{examplecode}
%   \maxsizebox{!}{1ex}{\fbox{Some Text}} which will be reduced
%   \end{examplecode}
%   \begin{examplecode}
%   \maxsizebox*{!}{1ex}{\fbox{Some Text}} which will be reduced
%   \end{examplecode}
%   \begin{examplecode}
%   \maxsizebox{1cm}{!}{Some Text} which will be reduced
%   \end{examplecode}
%   \begin{examplecode}
%   \maxsizebox{3cm}{1cm}{Some Text}, already small enough
%   \end{examplecode}
% \end{examples}
%
% \DescribeMacro\lapbox[<width>]{<lap amount>}{<\TEXT>}
% This macro is a generalisation of the \LaTeX\ core macros \Macro\rlap{<\TEXT>} and \Macro\llap{<\TEXT>} which lap the
% text to the right or left without taking any official space. The \Macro\lapbox macro can be used to only partially lap
% the content to the right (positive amount) or left (negative amount). As with all macros of this package the original width
% can be references using \Macro\width. The resulting official width of the box is normally the original width minus the absolute
% lap amount. However, it can also be set explicitly using the option argument.
% It is also possible to use lap amount which absolute values are larger than the original width. In this case the resulting
% official width will be zero by default and the content will padded with the required white space.
% Note that the lap amount always states the distance between the right side of the official box and the right side of the actual
% content for positive amounts or the distance between the left side of the official box and the left side of the actual content 
% for negative values.
%
% \begin{examples}
%   General lapping:
%   \begin{examplecode}
%   \lapbox{1cm}{Some Text}
%   \end{examplecode}
%   \vspace{-2\smallskipamount}%
%   \begin{examplecode}
%   \lapbox{-1cm}{Some Text}
%   \end{examplecode}
%   \vspace{-2\smallskipamount}%
%   \begin{examplecode}
%   \lapbox[4cm]{1cm}{Some Text}
%   \end{examplecode}
%   \vspace{-2\smallskipamount}%
%   \begin{examplecode}
%   \lapbox[3cm]{2cm}{Some Text}
%   \end{examplecode}
%   \vspace{\smallskipamount}%
%   Like \Macro\rlap:
%   \vspace{-\smallskipamount}%
%   \begin{examplecode}
%   \lapbox[0pt]{\width}{Some Text}
%   \end{examplecode}
%   \vspace{\smallskipamount}%
%   Like \Macro\llap:
%   \vspace{-\smallskipamount}%
%   \begin{examplecode}
%   \lapbox[0pt]{-\width}{Some Text}
%   \end{examplecode}
%   \vspace{\smallskipamount}%
%   A centering \Macro\clap macro can be achieved using:
%   \vspace{-\smallskipamount}%
%   \begin{examplecode}
%   \lapbox[0pt]{-.5\width}{Some Text}
%   \end{examplecode}
%   \vspace{-2\smallskipamount}%
%   \begin{examplecode}
%   \lapbox[0pt]{.5\width}{Some Text}
%   \end{examplecode}
%
% \end{examples}
%
%
% \DescribeMacro\phantombox{<width>}{<height>}{<depth>}
% This macro produces an empty box with the given width, height and depth.
% It is equivalent to \Macro\phantom{\AlsoMacro\rule['-'<depth>]{<width>}{<height>'+'<depth>}} but more efficient and more user friendly.
%
% \begin{example}
%   \begin{examplecode}
%   Before \fbox{\phantombox{1cm}{2ex}{1ex}} After
%   \end{examplecode}
% \end{example}
%
%
% \subsection{New keys for \cs{adjustbox} and \cs{includegraphics}}\label{sec:newkeys}
% This section lists provided keys usable as \Macro\adjustbox options and, if the \opt{export} package option was used, also as \Macro\includegraphics options.
% If the package is loaded with the \opt{minimal} option this code is skipped.
%
% \subsubsection{Trimming and Clipping}
%
% \DescribeKey{Trim}'='<all sites>
% \DescribeKey{Trim}'='<left/right>~<top/bottom>
% \DescribeKey{Trim}'='<llx>~<lly>~<urx>~<ury>
% \DescribeKey{Viewport}'='<llx>~<lly>~<urx>~<ury>
% The normal \Key{trim} and \Key{viewport} keys
% as described earlier are applied on the original content before any resizing
% or other effects. This is because for \Macro\includegraphics the trimming is done by the internal graphic driver,
% while the effects can be applied later (but can also be driver dependent).
% If the \Key{trim} and \Key{viewport} keys are used multiple times the last values will be used for the trimming, i.e. the content is only 
% trimmed once. The upper case variants \Key{trim} and \Key{viewport} will wrap the content internally in a \Macro\trimbox or \Macro\trimbox*\relax
% macro which can be applied multiple times, e.g.\ before and after the content is rotated.
% These two keys awaits the same format as the original keys. However, the \Key{clip} key has no effect on them.
%
% \DescribeKey{Clip}'='<all sites>
% \DescribeKey{Clip}'='<left/right>~<top/bottom>
% \DescribeKey{Clip}'='<llx>~<lly>~<urx>~<ury>
% \DescribeKey{Clip*}'='<llx>~<lly>~<urx>~<ury>
% As stated above the \Key{clip} boolean key
% which will make the default \Key{trim} and \Key{viewport} keys clip the trimmed content, has no effect
% on the \Key{trim} and \Key{viewport} keys. Instead \Key{Clip} and \Key{Clip*} are provided which wrap the content internally in a \Macro\clipbox or 
% \Macro\clipbox*\relax macro. They can be used several times.
%
%
% \subsubsection{Frame and Margin}
%
% \DescribeKey{frame}
% \DescribeKey{frame}'='<width>
% \DescribeKey{frame}'='<width>~<sep>
% This key will draw a black frame around the content.
% By default the frame lines will have a thickness of \Macro\fboxrule\relax
% (i.e.\ the same thickness like \Macro\fbox) and will be placed tightly around the content with zero separation.
% The line width and also the separation can be defined as the optional value.
%
%
% \DescribeKey{margin}'='<all sites>
% \DescribeKey{margin}'='<left/right>~<top/bottom>
% \DescribeKey{margin}'='<llx>~<lly>~<urx>~<ury>
% This key can be used to add a margin (white space) around the content (using \Macro\marginbox).
% It can be seen as the opposite of \Key{trim} (and in fact is implemented
% almost identical to it with negated signs). The four values are added to the left, bottom, right and top side of the content, respectively.
% The original baseline of the content is preserved by adding \meta{\lly} to the depth.
% If negative values are given the content is actually trimmed, but this will lead to wrong results if the absolute values are bigger
% than the available amount. This is particularly a problem with the depth. The \Key{trim} and \Key{trim} code will handle this case correctly, however.
%
% \DescribeKey{margin*}'='<all sites>
% \DescribeKey{margin*}'='<left/right>~<top/bottom>
% \DescribeKey{margin*}'='<llx>~<lly>~<urx>~<ury>
% Like \Key{margin} but also raises the content by \meta{\lly} and therefore preserves the original depth and not the original baseline.
%
% \subsubsection{Size/Scaling}
%
% \DescribeKey{min width}'='<width>
% \DescribeKey{max width}'='<width>
% \DescribeKey{min height}'='<height>
% \DescribeKey{max height}'='<height>
% \DescribeKey{min totalheight}'='<total height>
% \DescribeKey{max totalheight}'='<total height>
% These keys allow to set the minimum and maximum width, height or totalheight of the content.
% The current size of the content is measured and the content is resized if the constraint is not already met,
% otherwise the content is unchanged. Multiple usages of these keys are checked one after each other, and therefore
% it is possible that a later one is undoing the size changes of an earlier one.
% A good example is \Key{max width}'='\AlsoMacro\textwidth which will limit large content to the text width but will not affect smaller
% content.
%
% \DescribeKey{min size}'='{<width>}{<height>}
% \DescribeKey{max size}'='{<width>}{<height>}
% \DescribeKey{min totalsize}'='{<width>}{<total height>}
% \DescribeKey{max totalsize}'='{<width>}{<total height>}
% These keys allow to specify the minimum or maximum width and (total)height of the content together,
% which is more efficient than using the width and (total)height keys described earlier.
%
% \DescribeKey{scale}'='<factor>
% \DescribeKey{scale}'='{<h-factor>}{<v-factor>}
% The normal \Key{scale} key of \pkg{graphicx} only allows for one scale factor which is used for both the horizontal and vertical scaling.
% With \pkg{adjustbox} it is also possible to provide the horizontal and vertical scale factors separately.
%
% \DescribeKey{reflect}
% This reflects the content by using \Macro\reflectbox internally, which is identical to \Macro\scalebox{-1}[1],
% i.e.\ this key is identical to \Key{scale}'='{-1}{1}.
%
%
% \begin{examples}
%   \begin{examplecode}
%   \adjustbox{reflect}{\sffamily OTTO}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{reflect}{\sffamily ANNA}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{reflect}{Some text!}
%   \end{examplecode}
% \end{examples}
%
% \subsubsection{Positioning and Alignment}
%
% \DescribeKey{raise}'='<amount>
% \DescribeKey{raise}'='{<amount>}{<height>}
% \DescribeKey{raise}'='{<amount>}{<height>}{<depth>}
% This key uses 
% \Macro\raisebox{<amount>}{\ldots} to raise the content upwards for the given \meta{amount} (length).
% A negative length moves the content down.
% The two optional arguments of \Macro\raisebox{<amount>}[<height>][<depth>]{\ldots}\relax are also available
% as optional brace arguments. They can be used to set the official height and depth of the content.
% This is also possible using the \Key{set height} and \Key{set depth} keys.
%
% \begin{examples}
%   \begin{examplecode}
%   Is \adjustbox{raise=1ex}{higher}
%   than the normal text
%   \end{examplecode}
%   \begin{examplecode}
%   Is \adjustbox{raise={1ex}{\height}}{higher}
%   than the normal text but sill has 
%   its original official height
%   \end{examplecode}
%   \begin{examplecode}
%   Is \adjustbox{raise={1ex}{1ex}{0pt}}{higher and 
%   \rotatebox{-90}{depth}} but with limited official
%   height and no depth.
%   \end{examplecode}
% \end{examples}
%
% \DescribeKey{valign}'='<letter>
% This key allows to vertically align the content to the top, middle and bottom.  The uppercase letters |T|, |M| and |B|
% align to the content top (i.e. all depth, no height), the geometric, vertical center (equal height and depth) and to
% the bottom (all height, no depth), respectively.  This allows the alignment of content of different size, but will not
% result in good alignment with text.  The lowercase letters |t|, |m| and |b| are aligning the content again to the top,
% center and bottom but take the current text size in account.
% The |t| letter leaves a certain height given by the macro\footnote{A macro and not a length is used to allow for
% font size relative values like \texttt{1ex}.} \Macro\adjboxvtop\relax
% (by default set to the height of \Macro\strut\relax, i.e.\ |\ht\strutbox|, which is |.7\baselineskip|),
% while |b| sets a certain depth given (as negative length) by the macro \Macro\adjboxvbottom\relax
% (by default equal to the (negated) \Macro\strut depth, i.e.\ |-\dp\strutbox|, which is |.3\baselineskip|).
% The |m| letter will center towards the vertical center of the text line which is determined by the macro
% \Macro\adjboxvcenter\relax (by default \texttt{1ex}).
%
% The following table shows the different alignments for three different sized blocks:
% 
% \bigskip
% \begingroup
% \def\vr{%
%     \unskip
%     \tikz [gray] {\useasboundingbox (0,0);
%       \draw (-13.5em,0) -- (2.25em,0);
%       \draw (-13.5em,\adjboxvcenter) -- (2.25em,\adjboxvcenter);
%     }%
%     \unskip\ignorespaces
% }%
% \centerline{%
% \begin{tabular}{cccm{2em}}
%  \toprule
%   \texttt{T} & \texttt{M} & \texttt{B} & Text \\
%   \adjustbox{valign=T}{\textcolor{red}{\rule{1em}{2em}\unskip}}\unskip
%   \adjustbox{valign=T}{\textcolor{green}{\rule{1em}{3em}\unskip}}\unskip
%   \adjustbox{valign=T}{\textcolor{blue}{\rule{1em}{1ex}\unskip}} &
%   \adjustbox{valign=M}{\textcolor{red}{\rule{1em}{2em}\unskip}}\unskip
%   \adjustbox{valign=M}{\textcolor{green}{\rule{1em}{3em}\unskip}}\unskip
%   \adjustbox{valign=M}{\textcolor{blue}{\rule{1em}{1ex}\unskip}} &
%   \adjustbox{valign=B}{\textcolor{red}{\rule{1em}{2em}\unskip}}\unskip
%   \adjustbox{valign=B}{\textcolor{green}{\rule{1em}{3em}\unskip}}\unskip
%   \adjustbox{valign=B}{\textcolor{blue}{\rule{1em}{1ex}\unskip}} &
%   Mxy \newline \mbox{\vr Mxy}\newline Mxy \\
%  \midrule
%   \texttt{t} & \texttt{m} & \texttt{b} & Text \\
%   \adjustbox{valign=t}{\textcolor{red}{\rule{1em}{2em}\unskip}}\unskip
%   \adjustbox{valign=t}{\textcolor{green}{\rule{1em}{3em}\unskip}}\unskip
%   \adjustbox{valign=t}{\textcolor{blue}{\rule{1em}{1ex}\unskip}} &
%   \adjustbox{valign=m}{\textcolor{red}{\rule{1em}{2em}\unskip}}\unskip
%   \adjustbox{valign=m}{\textcolor{green}{\rule{1em}{3em}\unskip}}\unskip
%   \adjustbox{valign=m}{\textcolor{blue}{\rule{1em}{1ex}\unskip}} &
%   \adjustbox{valign=b}{\textcolor{red}{\rule{1em}{2em}\unskip}}\unskip
%   \adjustbox{valign=b}{\textcolor{green}{\rule{1em}{3em}\unskip}}\unskip
%   \adjustbox{valign=b}{\textcolor{blue}{\rule{1em}{1ex}\unskip}} &
%   Mxy \newline \mbox{\vr Mxy}\newline Mxy \\
%  \bottomrule
% \end{tabular}}
% \endgroup
%
%
% \DescribeKey{set height}'='<height>
% This sets the official height of the content without actual changing it. This can be seen as a form of trimming.
% It uses the same internal code as\\
% \Macro\raisebox{'0pt'}[<height>]{<content>}.
%
% \begin{examples}
%   \begin{examplecode}
%   \adjustbox{set height=.5\height}
%       {\shortstack{some stacked\\content}}
%   \end{examplecode}
% \end{examples}
%
% \DescribeKey{set depth}'='<depth>
% This sets the official depth of the content without actual changing it. This can be seen as a form of trimming.
% It uses the same internal code as\\
% \Macro\raisebox{'0pt'}['\height'][<depth>]{<content>}.
%
% \begin{examples}
%   \begin{examplecode}
%   \adjustbox{set depth=0pt}
%       {\shortstack{some stacked\\content
%       with \raisebox{-1ex}{depth}}}
%   \end{examplecode}
% \end{examples}
%
% \DescribeKey{lap}'='<lap amount>
% \DescribeKey{lap}'='{<length>}{<lap amount>}
% This wraps the content into a
% \Macro\lapbox{<lap amount>}{\ldots} and
% \Macro\lapbox[<length>]{<lap amount>}{\ldots}, respectively. Positive \meta{amounts} lap the content to the right
% and negative to the left. The optional \meta{length} argument allows to set the final width.
%
% \begin{examples}
%   \begin{examplecode}
%   \adjustbox{lap=.5\width}{Some content}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{lap=-.5\width}{Some content}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{lap=\width}{Some content}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{lap=-\width}{Some content}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{lap={\width}{\width}}{Some content}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{lap={\width}{-\width}}{Some content}
%   \end{examplecode}
% \end{examples}
%
%
% \DescribeKey{center}
% \DescribeKey{center}'='<width>
% This key places 
% the content in a horizontal box which is by default \Macro\linewidth wide (i.e.\ as wide as a normal text paragraph)
% and centers it in it. The effect is very similar to \Macro\centerline. The original content is unchanged, but simply identical
% white space is added as a left and right margin. This is useful if the content is a figure or table and can be used as a replacement
% for \Macro\centering. One important difference is that the content will then have the given width which might influence (sub-)caption
% placement.
% If the content is wider than the available width it will stick out on both sides equally without causing an overfull hbox warning.
% Note that when \Macro\adjustbox paragraph is used at the beginning of a paragraph the normal paragraph indention is added, which
% will push the while box to the right and might cause an overfull line. In such cases a \Macro\noindent must be added beforehand.
% The \env{adjustbox} environment already uses this macro.
%
% \begin{examples}
%   \begin{examplecode}
%   \adjustbox{center}{Some content}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{center=5cm}{Some content}
%   \end{examplecode}
% \end{examples}
%
% \DescribeKey{right}
% \DescribeKey{right}'='<width>
% Like \Key{center} this key
% places the content in a box with the given width (by default \Macro\linewidth) but right aligns it.
% If the content is wider than the available width it will stick out into the left side without causing an overfull hbox warning.
%
% \begin{examples}
%   \begin{examplecode}
%   \adjustbox{right}{Some content}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{right=5cm}{Some content}
%   \end{examplecode}
% \end{examples}
%
%
% \DescribeKey{left}
% \DescribeKey{left}'='<width>
% Like \Key{center} this key
% places the content in a box with the given width (by default \Macro\linewidth) but left aligns it.
% If the content is wider than the available width it will stick out into the right side without causing an overfull hbox warning.
%
% \begin{examples}
%   \begin{examplecode}
%   \adjustbox{left}{Some content}
%   \end{examplecode}
%   \begin{examplecode}
%   \adjustbox{left=5cm}{Some content}
%   \end{examplecode}
% \end{examples}
%
%
%
% \DescribeKey{inner}
% \DescribeKey{inner}'='<width>
% Like \Key{center}, \Key{left} and \Key{right} this key 
% places the content in a box with the given width (by default \Macro\linewidth) but aligns it towards the inner margin.
% If the content is wider than the available width it will stick into the outer margin without causing an overfull hbox warning.
% In |twoside| mode this key is equal to \Key{left} for odd pages and equal to \Key{right} for even pages.
% For |oneside| mode it is always equal to \Key{center}, because there is no inner or outer margin.
% Note that the page-is-odd test might not always lead to correct results for some material close to a page boundary, because \TeX\
% might not have decided on which page it will be placed. This can be improved by loading the \pkg{changepage} package with the 
% \opt{strict} option, which uses a reference to determine the correct page number (and requires the usual additional compiler run).
%
% \DescribeKey{outer}
% \DescribeKey{outer}'='<width>
% Identical to \Key{inner} but aligns the content towards the outer margin.
% If the content is wider than the available width it will stick into the outer inner without causing an overfull hbox warning.
%
%
% \subsubsection{Pixel size}
%
% \DescribeKey{dpi}'='<number (dots per inch)>
% The \Key{dpi} key provides a simple interface to set the pixel size to the given DPI (dots per inch) value.
% For |pdflatex| the length unit |px| can be used to specify pixels. However, the equivalent dimension (length) of one pixel must be
% set using the \Macro\pdfpxdimen length register. To set a specific DPI value this length must be set using
% \Macro\setlength\AlsoMacro\pdfpxdimen{'1in/'<dots>}, which is done by the \Key{dpi}'='<dots> key.
%
% \begin{example}
%   \begin{examplecode}
%   \adjustbox{dpi=72,trim=10px,frame}
%       {\textcolor{green}{\rule{50px}{50px}}}
%   \end{examplecode}
% \end{example}
%
% \DescribeKey{pxdim}'='<length>
% Alternatively
% to the \Key{dpi} key the \Macro\pdfpxdimen length can be set directly to the given value. Afterwards |1px| will stand
% for the given \meta{length}.
%
% \begin{example}
%   \begin{examplecode}
%   \adjustbox{pxdim=2pt,trim=2px,frame}
%       {\textcolor{green}{\rule{10px}{10px}}}
%   \end{examplecode}
% \end{example}
%
% \subsection{Minipage or other inner Environment}
% The following keys will overwrite each other and only defined for \env{adjustbox} but do not apply for \Macro\includegraphics.
% Because they are therefore only used inside a mandatory argument and never in an optional these keys allow for optional bracket arguments.
%
% \DescribeKey{minipage}'='<width>
% \DescribeKey{minipage}'='[<position>][<height>][<inner position>]{<width>}
% This key wraps the inner content in a \env{minipage} with the given \meta{width} before it is stored as horizontal box.
% Its order relative to other keys is not meaningful (except that future keys of this sub-section will overwrite it).
% This allows for line breaks and footnotes in the \env{adjustbox}.
% All optional arguments of \env{minipage} are supported. I only the width is given it does not have to be enclosed in braces.
% The \meta{position} argument must be "t" for top baseline, "b" for bottom baseline and "c" for center alignment relative to other
% text, i.e.\ defines the resulting baseline. If a \meta{height} is defined the \meta{inner position} defaults to \meta{position} but
% can also be "s" to stretch the content over the whole height. This requires the content to include some vertical stretchable material.
%
% \begin{examples}
%   \begin{examplecode}
%   \adjustbox{minipage=5cm,angle=-10}{%
%      Some example code which will 
%      be automatically broken or can include \\
%      line breaks\footnote{AND footnotes!!}\\
%      or verbatim \verb+@%^&}_+!%
%   }
%   \end{examplecode}
%   \begin{examplecode}
%   Before \begin{adjustbox}{minipage=[b][3cm][s]{5cm}}
%      Some example code
%
%      \vfill
%      with line breaks\footnote{AND footnotes!!}
%
%      \vfill
%      or verbatim \verb+@%^&}_+!%
%   \end{adjustbox} After
%   \end{examplecode}
% \end{examples}
%
% \DescribeKey{innerenv}'='<environment name>
% \DescribeKey{innerenv}'='{<environment name>}<environment options>
% Wraps the inner content in the given \meta{environment} before it is stored as horizontal box. Only one inner environment can be used 
% and further uses of this key will overwrite previous ones as well as any \Key{minipage} and \Key{innercode} key.
% It should be kept in mind that there is some internal code between the begin of the environment and the content. For this reason
% a \env{tabular}, \env{innerenv} or similar environment will not work here, because that code will be taken as part of the first cell.
%
% \begin{example}
%   \begin{examplecode}
%   \newenvironment{myenv}[2][]{Before [#1](#2)}{After}
%   \adjustbox{innerenv={myenv}[ex]{amble}}{Content}
%   \end{examplecode}
% \end{example}
%
%
% \DescribeKey{innercode}'='{<begin code>}{<end code>}
% Places the given code before and after the inner content before it is stored as horizontal box. Only one set of inner code can be used 
% and further uses of this key will overwrite previous ones as well as any \Key{minipage} and \Key{innerenv} key.
%
% \begin{example}
%   \begin{examplecode}
%   \adjustbox{innercode={\color{green}}{!}}{Content}
%   \end{examplecode}
% \end{example}
%
% \subsection{Adding own Code or Environments}
%
% \DescribeKey{env}'='<environment name>
% \DescribeKey{env}'='{<environment name>}<environment options>
% Adds an \meta{environment} around the content and the already existing code around it which was added by other keys beforehand.
% Potential \meta{environment options} (or any other code) can follow the environment name if it was set inside braces.
% At this stage the content is already boxed and format macros won't have any effect on any included text. For this the \Key{innerenv} key needs to be used instead.
%
% \DescribeKey{addcode}'='{<code before>}{<code afters>}
% Adds some \meta{code before} and some \meta{code after} the content and the 
% already existing code around it which was added by other keys beforehand.
% At this stage the content is already boxed and format macros won't have any effect on any included text.
%
% \DescribeKey{appcode}'='<code afterwards>
% Appends come \meta{code after} the content and the already existing code around it which was added by other keys beforehand.
% More complex code should be enclosed in braces.
%
% \DescribeKey{precode}'='<code before>
% Prepends come \meta{code afterwards} the content and the already existing code around it which was added by other keys beforehand.
% More complex code should be enclosed in braces.
%
%
% \StopEventually{}
% \clearpage
% \section{Implementation}
% \setcounter{lstnumber}{1}
% \ifenglish\else
% Die Dokumentation des Quellcodes ist nur auf Englisch verfügbar.
% \fi
%
% \iffalse
%<*de>
%% Wrapper to set language to German and jobname to 'adjustbox-de'.
%% Does not have to be included in distributions or placed on CTAN.
\expandafter\newif\csname ifenglish\endcsname
\englishfalse
\input{adjustbox.dtx}
%</de>
% \fi
%
% \iffalse
%<*adjustbox>
% \fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Package header, options and dependencies}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \begin{macrocode}
\ProvidesPackage{adjustbox}[2011/08/21 v0.5a Adjusting TeX boxes (trim, clip, ...)]
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{xkeyval}

\def\adjbox@defaultunit{bp}
\DeclareOptionX<adjbox>{defaultunit}{%
    \def\adjbox@defaultunit{#1}%
    \begingroup
    \def\@tempa{none}%
    \expandafter\endgroup
    \ifx\@tempa\adjbox@defaultunit
        \def\adjbox@default{\adjsetlength}%
    \fi
}

\def\adjbox@fam{adjbox}
\DeclareOptionX<adjbox>{export}{\def\adjbox@fam{Gin}}
\DeclareOptionX<adjbox>{patch}{\AtEndOfPackage{\RequirePackage{adjgrfx}}}
\DeclareOptionX<adjbox>{minimal}{\let\adjbox@maybeend\endinput}

\def\adjbox@driver{adj\Gin@driver}
\DeclareOptionX<adjbox>{pgf}{\def\adjbox@driver{adjpgf.def}}
\DeclareOptionX<adjbox>{PGF}{\def\adjbox@driver{adjpgf.def}\adjcalc@pgfmath}
\DeclareOptionX<adjbox>*{\PassOptionsToPackage\CurrentOption{graphicx}}

\let\adjbox@maybeend\relax
\input{adjcalc.sty}
\disable@keys{adjbox}{patch,export,PGF,minimal}
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{graphicx}[1999/02/16]
\RequirePackage{collectbox}[2011/08/11]
%    \end{macrocode}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Basic commands}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{macro}{\adjbox@viewport}
%    \begin{macrocode}
\define@key{adjbox}{viewport}{%
    \let\Gin@viewport@code\adjbox@@viewport
    \let\adjustbox@@@\adjustbox@@@trimclip
    \adjbox@parse@v{#1}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@trim}
%    \begin{macrocode}
\define@key{adjbox}{trim}{%
    \let\Gin@viewport@code\adjbox@@trim
    \let\adjustbox@@@\adjustbox@@@trimclip
    \adjbox@parse@v{#1}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjustbox@@@trimclip}
%    \begin{macrocode}
\def\adjustbox@@@trimclip{%
    \Gin@viewport@code
    \ifGin@clip
        \expandafter\@clipbox
    \else
        \expandafter\@trimbox
    \fi
        \adjbox@tllx
        \adjbox@tlly
        \adjbox@turx
        \adjbox@tury
        \collectedbox
    \usebox\collectedbox
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\adjbox@parse@v}
%    \begin{macrocode}
\def\adjbox@parse@v#1{%
    \adjbox@parse@@v#1 {} {} {} \\%
}
\def\adjbox@parse@@v#1 #2 #3 #4 #5\\{%
  \adjbox@default\adjbox@tllx{#1}%
  \ifx\@nnil#2\@nnil
    \adjbox@tlly\adjbox@tllx
    \adjbox@turx\adjbox@tllx
    \adjbox@tury\adjbox@tlly
  \else
    \adjbox@default\adjbox@tlly{#2}%
    \ifx\@nnil#3\@nnil
      \adjbox@turx\adjbox@tllx
      \adjbox@tury\adjbox@tlly
    \else
      \adjbox@default\adjbox@turx{#3}%
      \adjbox@default\adjbox@tury{#4}%
    \fi
  \fi
}%
%%\newdimen\adjbox@llx
%%\newdimen\adjbox@lly
%%\newdimen\adjbox@urx
%%\newdimen\adjbox@ury
\newdimen\adjbox@tllx
\newdimen\adjbox@tlly
\newdimen\adjbox@turx
\newdimen\adjbox@tury
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\adjbox@@trim}
%    \begin{macrocode}
\let\adjbox@@trim\relax
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@@viewport}
%    \begin{macrocode}
\def\adjbox@@viewport{%
    %\advance\adjbox@tllx by -\z@
    \advance\adjbox@tlly by  \dp\collectedbox
    \advance\adjbox@turx by -\wd\collectedbox
    \advance\adjbox@tury by -\ht\collectedbox
    \adjbox@turx=-\adjbox@turx
    \adjbox@tury=-\adjbox@tury
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\trimbox}
%    \begin{macrocode}
\newcommand\trimbox{%
    \collectboxcheckenv{trimbox}%
    \@ifstar
        \trimbox@s
        \trimbox@
}
\def\trimbox@#1{%
    \collectbox{\trimbox@@\@trimbox{#1}}%
}
\def\trimbox@s#1{%
    \collectbox{\trimbox@@{\adjbox@@viewport\@trimbox}{#1}}%
}
\def\trimbox@@#1#2{%
    \adjbox@parse@v{#2}%
    #1%
        \adjbox@tllx
        \adjbox@tlly
        \adjbox@turx
        \adjbox@tury
        \collectedbox
    \usebox\collectedbox
}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{trimbox*}
%    \begin{macrocode}
\expandafter\newcommand\expandafter*\csname trimbox*\endcsname{%
    \@collectboxisenv{trimbox*}%
    \trimbox@s
}
%    \end{macrocode}
% \end{environment}
%
%
% \begin{macro}{\clipbox}
%    \begin{macrocode}
\newcommand\clipbox{%
    \collectboxcheckenv{clipbox}%
    \@ifstar
        \clipbox@s
        \clipbox@
}
\def\clipbox@#1{%
    \collectbox{\trimbox@@\@clipbox{#1}}%
}
\def\clipbox@s#1{%
    \collectbox{\trimbox@@{\adjbox@@viewport\@clipbox}{#1}}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{environment}{clipbox*}
%    \begin{macrocode}
\expandafter\newcommand\expandafter*\csname clipbox*\endcsname{%
    \@collectboxisenv{clipbox*}%
    \clipbox@s
}
%    \end{macrocode}
% \end{environment}
%
%
% \begin{macro}{\adjustbox}
% Now processes the keys before the box is read to allow for parbox or similar modes.
%
% This code was originally adapted from the \Macro\Gin@ii macro from the |graphicx| package.
% The \emph{temp switch a} is set to |true| to indicate to |graphicx| that the
% scaling should be done internal, so this package doesn't have to do it.
% The content including macro \Macro\adjustbox@@@ is but into place,
% the saved options are activated and the final size is set.
% The typesetting of the content is finally done by executing the token register.
%    \begin{macrocode}
\newcommand\adjustbox[1]{%
    \collectboxcheckenv{adjustbox}%
    \begingroup
    \adjustbox@dimcmds
    \let\Gin@esetsize\adjbox@esetsize
    \@tempswatrue
    \toks@{{\adjustbox@@@@}}%
    \def\setlength{\adjsetlength}%
    \setkeys{adjbox,Gin}{#1}%
    \adjbox@esetsize
    \adjbox@collectbox{\the\toks@\endgroup}%
}
\let\adjbox@collectbox\@collectbox
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\adjustbox@@@@}
% Content wrapper which might be redefined when the size is specified.
%    \begin{macrocode}
\def\adjustbox@@@@{\adjustbox@@@}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@esetsize}
% Replacement of \Macro\Gin@esetsize.
% Now always called in external mode. Checks if any size is set and, as an optimation, does nothing otherwise.
% 
% OLD:
% When called in \emph{external} mode (switch is true) then the content is wrapped in
% the internal form of \Macro\resizebox. In \emph{internal} mode, i.e.\ resizing is done by the graphic driver,
% the same code is added around the inner macro. This ensures the same behaviour as \Macro\includegraphics.
%    \begin{macrocode}
\def\adjbox@esetsize{%
  \ifcase0%
    \ifx\Gin@ewidth\Gin@exclamation\else 1\fi
    \ifx\Gin@eheight\Gin@exclamation\else 1\fi
  \relax
  \else
    \edef\@tempa{\toks@{\noexpand
                \Gscale@@box\noexpand\Gin@eresize
                {\Gin@ewidth}{\Gin@eheight}{\the\toks@}}}%
    \@tempa
    \let\Gin@ewidth\Gin@exclamation
    \let\Gin@eheight\Gin@exclamation
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjustbox@dimcmds}
% Inits the dimension macro in an unexpandedable way. They will be redefined to the correct
% values by \Macro\collectbox.
%    \begin{macrocode}
\def\adjustbox@dimcmds{%
    \let\width\relax
    \let\height\relax
    \let\depth\relax
    \let\totalheight\relax
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjustbox@@@}
%    \begin{macrocode}
\def\adjustbox@@@{%
    \usebox\collectedbox
}
%    \end{macrocode}
% \end{macro}
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsubsection{Low-level trim and clip boxes}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{macro}{\@trimbox}
%    \begin{macrocode}
\def\@trimbox#1#2#3#4#5{%
    \setbox#5=\hbox{%
        \adjsetlength\@tempdima{#1}%
        \hskip-\@tempdima
        \adjsetlength\@tempdima{\dp#5 - (#2)}%
        \adjsetlength\@tempdimb{\wd#5 - (#3)}%
        \adjsetlength\@tempdimc{\ht#5 - (#4)}%
        \dp#5=\@tempdima
        \wd#5=\@tempdimb
        \ht#5=\@tempdimc
        \ifdim\dp#5<\z@
            \raise\dp#5%
        \else
        \ifdim\ht#5<\z@
            \lower\ht#5%
        \fi\fi
        \box#5%
    }%
    \ifdim\dp#5<\z@ \dp#5=\z@ \fi
    \ifdim\wd#5<\z@ \wd#5=\z@ \fi
    \ifdim\ht#5<\z@ \ht#5=\z@ \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@clipbox}
%    \begin{macrocode}
\def\@clipbox#1#2#3#4#5{%
    \@trimbox{#1}{#2}{#3}{#4}{#5}%
    \pdfxform#5%
    \setbox#5=\hbox{%
        \pdfrefxform\pdflastxform
    }%
}
%    \end{macrocode}
% \end{macro}
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Driver}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The clipping support is output driver dependent. The driver selected by \pkg{graphics} is used and a definition file
% is used if its exists. Otherwise either the default \texttt{pdftex} implementation or the \pkg{pgf} fall-back driver
% is used.
%    \begin{macrocode}
\RequirePackage{ifpdf}
\InputIfFileExists{\adjbox@driver}{%
    \PackageInfo{adjustbox}{Using driver '\adjbox@driver'.}%
}{%
    \ifpdf
        \PackageInfo{adjustbox}{Using default pdftex driver.}
    \else
        \input{adjpgf.def}%
        \PackageInfo{adjustbox}{Using fall-back PGF driver.}
    \fi
}
%    \end{macrocode}
%
%
% Stop here if 'minimal' option was used.
%    \begin{macrocode}
\adjbox@maybeend
%    \end{macrocode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{More box commands}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{macro}{\phantombox}[3]{width}{height}{depth}
% Produces an empty box with the given width, height and depth.
%    \begin{macrocode}
\newcommand*\phantombox[3]{%
    \begingroup
    \adjsetlength\@tempdima{#1}%
    \adjsetlength\@tempdimb{#2}%
    \adjsetlength\@tempdimc{#3}%
    \setbox\collectedbox\hbox{}%
    \wd\collectedbox\@tempdima
    \ht\collectedbox\@tempdimb
    \dp\collectedbox\@tempdimc
    \leavevmode
    \box\collectedbox
    \endgroup
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\minsizebox}
%    \begin{macrocode}
\newcommand*\minsizebox{%
    \collectboxcheckenv{minsizebox}%
    \@ifstar{\@minsizebox\totalheight}{\@minsizebox\height}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{minsizebox*}
%    \begin{macrocode}
\expandafter\newcommand\expandafter*\csname minsizebox*\endcsname{%
    \@collectboxisenv{minsizebox*}%
    \@minsizebox\totalheight
}
%    \end{macrocode}
% \end{environment}
%
%
% \begin{macro}{\@minsizebox}
%    \begin{macrocode}
\newcommand*\@minsizebox[3]{%
    \@collectbox{\@minmaxsizebox>#1{#2}{#3}}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\maxsizebox}
%    \begin{macrocode}
\newcommand*\maxsizebox{%
    \collectboxcheckenv{maxsizebox}%
    \@ifstar{\@maxsizebox\totalheight}{\@maxsizebox\height}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{maxsizebox*}
%    \begin{macrocode}
\expandafter\newcommand\expandafter*\csname maxsizebox*\endcsname{%
    \@collectboxisenv{maxsizebox*}%
    \@maxsizebox\totalheight
}
%    \end{macrocode}
% \end{environment}
%
%
% \begin{macro}{\@maxsizebox}
%    \begin{macrocode}
\newcommand*\@maxsizebox[3]{%
    \@collectbox{\@minmaxsizebox<#1{#2}{#3}}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@minmaxsizebox}[4]{Compare sign \texttt{<} or \texttt{>}}{\cs{height} or \cs{totalheight}}{width}{height}
% Used for all min/max-size boxes including the starred version. The first two arguments determine the style.
%
% The width and height values are expanded to allow for \Macro\ifdim or similar conditionals.
%    \begin{macrocode}
\newcommand*\@minmaxsizebox[4]{%
    \edef\@tempa{#3}%
    \edef\@tempb{#4}%
    \ifcase0%
%    \end{macrocode}
% Do nothing if both values are `|!|', otherwise use case 1 if the height is to large/small (|#1|)
% than the \Macro\height or \Macro\totalheight (|#2|).
%    \begin{macrocode}
    \ifx\@tempa\Gin@exclamation
        \ifx\@tempb\Gin@exclamation
        \else
            \ifdim\@tempb#1#2%
                1%
            \fi
        \fi
    \else
%    \end{macrocode}
% If the width is given, but not the height, use case 2 if the width is to large/small (|#1|) than the native \Macro\width.
%    \begin{macrocode}
        \ifx\@tempb\Gin@exclamation
            \ifdim\@tempa#1\width
                2%
            \fi
        \else
%    \end{macrocode}
% If both values are given.
% Use case 0-3 depending if the width and/or height is to large/small.
%    \begin{macrocode}
            \ifdim\@tempa#1\width
                \ifdim\@tempb#1#2%
                    3%
                \else
                    2%
                \fi
            \else
                \ifdim\@tempb#1#2%
                    1%
                \fi
            \fi
        \fi
    \fi
%    \end{macrocode}
%  Case 0: no scaling is needed. Insert content unchanged.
%    \begin{macrocode}
    \relax% 0
        \BOXCONTENT
%    \end{macrocode}
%  Case 1: height needs scaling. Calculate factor and scale the content with it.
%    \begin{macrocode}
    \or
        \adjsetlength\@tempdima\@tempb
        \Gscale@div\@tempa\@tempdima#2%
        \Gscale@box\@tempa[\@tempa]\BOXCONTENT
%    \end{macrocode}
%  Case 2: width needs scaling. Calculate factor and scale the content with it.
%    \begin{macrocode}
    \or
        \adjsetlength\@tempdima\@tempa
        \Gscale@div\@tempa\@tempdima\width
        \Gscale@box\@tempa[\@tempa]\BOXCONTENT
%    \end{macrocode}
%  Case 3: both width and height need scaling.
%  Both scale factors are calculated and the more extreme value is used.
%    \begin{macrocode}
    \or
        \adjsetlength\@tempdima\@tempa
        \Gscale@div\@tempa\@tempdima\width
        \adjsetlength\@tempdima\@tempb
        \Gscale@div\@tempb\@tempdima#2%
        \ifdim\@tempa\p@#1\@tempb\p@
            \let\@tempb\@tempa
        \else
            \let\@tempa\@tempb
        \fi
        \Gscale@box\@tempa[\@tempb]\BOXCONTENT
    \fi
}
%    \end{macrocode}
% \end{macro}
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{New \cs{includegraphics} and \cs{adjustbox} options}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{key}{adjbox}{Trim}
%    \begin{macrocode}
\define@key\adjbox@fam{Trim}{%
    \adjbox@Gin@Add{\trimbox@{#1}}%
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{Viewport}
%    \begin{macrocode}
\define@key\adjbox@fam{Viewport}{%
    \adjbox@Gin@Add{\trimbox@s{#1}}%
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{Clip}
%    \begin{macrocode}
\define@key\adjbox@fam{Clip}{%
    \adjbox@Gin@Add{\clipbox@{#1}}%
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{Clip*}
%    \begin{macrocode}
\define@key\adjbox@fam{Clip*}{%
    \adjbox@Gin@Add{\clipbox@s{#1}}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{frame}
%    \begin{macrocode}
\define@key\adjbox@fam{frame}[{{\fboxrule}}]{%
    \adjbox@frame{\fboxsep\z@}#1 {} {} \relax\relax\@nnil
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{fbox}
%    \begin{macrocode}
\define@key\adjbox@fam{fbox}[{{\fboxrule}}]{%
    \adjbox@frame{}#1 {} {} {} \relax\relax\@nnil
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{macro}{\adjbox@frame}
%    \begin{macrocode}
\def\adjbox@frame#1#2 #3 #4 #5\relax{%
    \adjbox@Gin@Add{%
        \@collectbox{#1\adjbox@@frame{}{#2}{#3}{#4}}%
    }%
    \remove@to@nnil
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{key}{adjbox}{cframe}
%    \begin{macrocode}
\define@key\adjbox@fam{cframe}{%
    \adjbox@cframe{\fboxsep\z@}#1 {} {} {} \relax\relax\@nnil
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{cfbox}
%    \begin{macrocode}
\define@key\adjbox@fam{cfbox}{%
    \adjbox@cframe{}#1 {} {} {} \relax\relax\@nnil
}
%    \end{macrocode}
% \end{key}
%
% \begin{macro}{\adjbox@cframe}
%    \begin{macrocode}
\def\adjbox@cframe#1#2 #3 #4 #5 #6\relax{%
    \adjbox@Gin@Add{%
        \@collectbox{#1\adjbox@@frame{\color{#2}}{#3}{#4}{#5}}%
    }%
    \remove@to@nnil
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@@frame}
%    \begin{macrocode}
\def\adjbox@@frame#1#2#3#4{%
    \ifx\@nnil#2\@nnil\else
        \adjsetlength\fboxrule{#2}%
    \fi
    \ifx\@nnil#3\@nnil\else
        \adjsetlength\fboxsep{#3}%
    \fi
    \adjsetlength\adjbox@tllx{\fboxrule + \fboxsep}%
    \@marginbox
        \adjbox@tllx
        \adjbox@tllx
        \adjbox@tllx
        \adjbox@tllx
        \collectedbox
    \ifx\@nnil#4\@nnil\else
      \setbox\collectedbox
    \fi
      \hbox\bgroup\color@setgroup
        \BOXCONTENT
        \hskip-\width
        #1%
        \adjbox@boxframe\width\height\depth
      \color@endgroup\egroup
    \ifx\@nnil#4\@nnil\else
      \adjsetlength\adjbox@tllx{#4}%
      \@marginbox
        \adjbox@tllx
        \adjbox@tllx
        \adjbox@tllx
        \adjbox@tllx
        \collectedbox
      \BOXCONTENT
    \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\adjbox@boxframe}
% Tries to reuse the definition of the \pkg{xcolor} package.
% If it isn't loaded its definition is defined here.
%
% This code was taken from the \pkg{xcolor} package under the free LPPL license.
%    \begin{macrocode}
\let\adjbox@boxframe\boxframe
\providecommand\adjbox@boxframe[3]{%
    \hbox{%
        \dimen@ #2%
        \advance \dimen@ #3\relax
        \lower #3\vbox {%
            \hrule \@height \fboxrule
            \@tempdima -0.5\fboxrule
            \ifodd\fboxrule
                \advance \@tempdima \m@ne sp
            \fi
            \kern \@tempdima
            \hbox {%
                \advance \dimen@ -\fboxrule
                \vrule \@width \fboxrule \@height \dimen@ \@depth \z@
                \@tempdima #1%
                \advance \@tempdima -\tw@ \fboxrule
                \kern \@tempdima
                \vrule \@width \fboxrule \@height \dimen@ \@depth \z@
            }%
            \kern -0.5\fboxrule
            \hrule \@height \fboxrule
        }%
    }%
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{key}{adjbox}{scale}
%    \begin{macrocode}
\define@key\adjbox@fam{scale}{%
    \@ifnextchar\bgroup{%
        \adjbox@scale@xy
    }{%
        \adjbox@scale@x
    }#1\@nnil
}
%    \end{macrocode}
% \end{key}
%
% \begin{macro}{\adjbox@scale@x}
%    \begin{macrocode}
\def\adjbox@scale@x#1\@nnil{%
    \adjbox@scale@xy{#1}{#1}\@nnil%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\adjbox@scale@xy}
%    \begin{macrocode}
\def\adjbox@scale@xy#1#2\@nnil{%
  \if@tempswa
    \adjbox@Gin@add{\Gscale@box{#1}[{#2}]}%
  \else
    \def\Gin@req@sizes{%
      \def\Gin@scalex{#1}\def\Gin@scaley{#2}%
      \Gin@req@height\Gin@scaley\Gin@nat@height
      \Gin@req@width\Gin@scalex\Gin@nat@width}%
  \fi
  \@tempswatrue
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{key}{adjbox}{reflect}
% Taken from the \Key{scale} key of the \pkg{graphicx} package.
% Open question: why is \Macro\Gin@esetsize not called?
%    \begin{macrocode}
\define@key\adjbox@fam{reflect}[]{%
    \adjbox@scale@xy{-1}{1}\@nnil
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{rotate}
% New alias of existing |angle| key.
%    \begin{macrocode}
\expandafter\let\csname KV@\adjbox@fam @rotate\endcsname\KV@Gin@angle
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{lap}
%    \begin{macrocode}
\define@key\adjbox@fam{lap}{%
    \@ifnextchar\bgroup{%
        \adjbox@lapbox
    }{%
        \adjbox@lapbox{#1}{}%
    }#1{}{}\@nnil
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{macro}{\adjbox@lapbox}
%    \begin{macrocode}
\def\adjbox@lapbox#1#2#3\@nnil{%
    \ifx\@nnil#2\@nnil
        \adjbox@Gin@Add{\lapbox{#1}}%
    \else
        \adjbox@Gin@Add{\lapbox[{#1}]{#2}}%
    \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{key}{adjbox}{margin}
%    \begin{macrocode}
\define@key\adjbox@fam{margin}{%
    \adjbox@Gin@Add{\marginbox@{#1}}%
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{margin*}
%    \begin{macrocode}
\define@key\adjbox@fam{margin*}{%
    \adjbox@Gin@Add{\marginbox@s{#1}}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{dpi}
%    \begin{macrocode}
\define@key\adjbox@fam{dpi}{%
    \adjsetlength\pdfpxdimen{1in/(#1)}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{pxdim}
%    \begin{macrocode}
\define@key\adjbox@fam{pxdim}{%
    \adjsetlength\pdfpxdimen{#1}%
}
%    \end{macrocode}
% \end{key}
%
%
%    \begin{macrocode}
\define@key\adjbox@fam{execute}{%
    #1%
}
%    \end{macrocode}
%
%
% \begin{key}{adjbox}{raise}
%    \begin{macrocode}
\define@key\adjbox@fam{raise}{%
    \@ifnextchar\bgroup{%
        \adjbox@raisebox
    }{%
        \adjbox@raisebox{#1}{}{}%
    }#1{}{}{}\@nnil
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{macro}{\adjbox@raisebox}
%    \begin{macrocode}
\def\adjbox@raisebox#1#2#3#4\@nnil{%
    \ifx\@nnil#3\@nnil
        \adjbox@Gin@Add{\@irsbox{#1}[{#2}]}%
    \else
        \adjbox@Gin@Add{\@iirsbox{#1}[{#2}][{#3}]}%
    \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{key}{adjbox}{valign}
%    \begin{macrocode}
\define@key\adjbox@fam{valign}{%
    \csname adjbox@valign@#1\endcsname
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{macro}{\adjboxvtop}
%    \begin{macrocode}
\def\adjboxvtop{\ht\strutbox}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\adjboxvcenter}
%    \begin{macrocode}
\def\adjboxvcenter{1ex}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\adjboxvbottom}
%    \begin{macrocode}
\def\adjboxvbottom{-\dp\strutbox}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@valign@t}
%    \begin{macrocode}
\def\adjbox@valign@t{%
    \adjbox@Gin@Add{\@irsbox{-\height+\adjboxvtop}[]}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@valign@T}
%    \begin{macrocode}
\def\adjbox@valign@T{%
    \adjbox@Gin@Add{\@irsbox{-\height}[]}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@valign@M}
%    \begin{macrocode}
\def\adjbox@valign@M{%
    \adjbox@Gin@Add{\@irsbox{.5\depth-.5\height}[]}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@valign@m}
%    \begin{macrocode}
\def\adjbox@valign@m{%
    \adjbox@Gin@Add{\@irsbox{.5\depth-.5\height+\adjboxvcenter}[]}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@valign@b}
%    \begin{macrocode}
\def\adjbox@valign@b{%
    \adjbox@Gin@Add{\@irsbox{\depth+\adjboxvbottom}[]}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@valign@B}
%    \begin{macrocode}
\def\adjbox@valign@B{%
    \adjbox@Gin@Add{\@irsbox{\depth}[]}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{key}{adjbox}{bgcolor}
%    \begin{macrocode}
\define@key\adjbox@fam{bgcolor}{%
    \@ifnextchar\bgroup{%
        \adjbox@bgcolor
    }{%
        \adjbox@bgcolor{}{#1}%
    }#1\@nnil
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{macro}{\adjbox@bgcolor}
%    \begin{macrocode}
\def\adjbox@bgcolor#1#2#3\@nnil{%
    \adjbox@Gin@add{\@collectbox{\adjbox@@bgcolor{#1}{#2}}}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@@bgcolor}
%    \begin{macrocode}
\def\adjbox@@bgcolor#1#2{%
    \mbox{%
        \hbox{%
            \ifx\@nnil#1\@nnil
                \color{#2}%
            \else
                \color[#1]{#2}%
            \fi
            \vrule\@width\width\@height\height\@depth\depth
        }%
        \hskip-\width
        \BOXCONTENT
    }%
}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{key}{adjbox}{set height}
%    \begin{macrocode}
\define@key\adjbox@fam{set height}{%
    \adjbox@Gin@Add{\@irsbox\z@[{#1}]}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{set depth}
%    \begin{macrocode}
\define@key\adjbox@fam{set depth}{%
    \adjbox@Gin@Add{\@iirsbox\z@[\height][{#1}]}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{macro}{\adjbox@Gin@add}
%    \begin{macrocode}
\def\adjbox@Gin@add#1{%
    \def\@tempa{#1}%
    \toks@\expandafter\expandafter\expandafter{\expandafter\@tempa\expandafter{\the\toks@}}%
}
\def\adjbox@Gin@Add{%
    \Gin@esetsize
    \@tempswatrue
    \adjbox@Gin@add
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@Gin@sizeadd}
% Checks if key-value is actually two arguments. If not it is doubled.
% E.g.: \verb+min size=\A+ is the same as  \verb+min size={\A}{\A}+
%    \begin{macrocode}
\def\adjbox@Gin@sizeadd#1#2#3\relax{%
    \ifx\@nnil#3\@nnil
        \adjbox@Gin@add{#1{#2}{#2}}%
    \else
        \adjbox@Gin@add{#1{#2}{#3}}%
    \fi
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\adjbox@halign}
%    \begin{macrocode}
\def\adjbox@halign#1#2#3{%
    \Gin@esetsize
    \@tempswatrue
    \adjsetlength\@tempdima{#1}%
    \edef\@tempa{\hb@xt@\the\@tempdima}%
    \toks@\expandafter\expandafter\expandafter{\expandafter\@tempa\expandafter{\expandafter#2\the\toks@#3}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{key}{adjbox}{center}
%    \begin{macrocode}
\define@key\adjbox@fam{center}[\linewidth]{%
    \adjbox@halign{#1}\hss\hss
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{left}
%    \begin{macrocode}
\define@key\adjbox@fam{left}[\linewidth]{%
    \adjbox@halign{#1}\relax\hss
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{right}
%    \begin{macrocode}
\define@key\adjbox@fam{right}[\linewidth]{%
    \adjbox@halign{#1}\hss\relax
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{outer}
%    \begin{macrocode}
\define@key\adjbox@fam{outer}[\linewidth]{%
    \def\@tempa{\adjbox@halign{#1}}%
    \if@twoside
      \adjbox@ifoddpage
        {\@tempa\hss\relax}%
        {\@tempa\relax\hss}%
    \else
        \@tempa\hss\hss
    \fi
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{inner}
%    \begin{macrocode}
\define@key\adjbox@fam{inner}[\linewidth]{%
    \def\@tempa{\adjbox@halign{#1}}%
    \if@twoside
      \adjbox@ifoddpage
        {\@tempa\relax\hss}%
        {\@tempa\hss\relax}%
    \else
        \@tempa\hss\hss
    \fi
}
%    \end{macrocode}
% \end{key}
%
% \begin{macro}{\adjbox@ifoddpage}
%    \begin{macrocode}
\def\adjbox@ifoddpage{%
    \begingroup
    \adjbox@checkoddpage
    \expandafter\endgroup
    \ifoddpage
        \expandafter\@firstoftwo
    \else
        \expandafter\@secondoftwo
    \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjbox@checkoddpage}
%    \begin{macrocode}
\def\adjbox@checkoddpage{%
    \ifodd\c@page
        \oddpagetrue
    \else
        \oddpagefalse
    \fi
}%
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\newif\ifoddpage
\AtBeginDocument{%
    \@ifpackageloaded{changepage}{\let\adjbox@checkoddpage\checkoddpage}%
     {\@ifpackageloaded{chngpage}{\let\adjbox@checkoddpage\checkoddpage}{}}%
}%
%    \end{macrocode}
%
% \begin{key}{adjbox}{min width}
%    \begin{macrocode}
\define@key\adjbox@fam{min width}{%
    \adjbox@Gin@Add{\@minsizebox\height{#1}!}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{max width}
%    \begin{macrocode}
\define@key\adjbox@fam{max width}{%
    \adjbox@Gin@Add{\@maxsizebox\height{#1}!}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{min height}
%    \begin{macrocode}
\define@key\adjbox@fam{min height}{%
    \adjbox@Gin@Add{\@minsizebox\height!{#1}}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{max height}
%    \begin{macrocode}
\define@key\adjbox@fam{max height}{%
    \adjbox@Gin@Add{\@maxsizebox\height!{#1}}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{min totalheight}
%    \begin{macrocode}
\define@key\adjbox@fam{min totalheight}{%
    \adjbox@Gin@Add{\@minsizebox\totalheight!{#1}}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{max totalheight}
%    \begin{macrocode}
\define@key\adjbox@fam{max totalheight}{%
    \adjbox@Gin@Add{\@maxsizebox\totalheight!{#1}}%
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{min size}
%    \begin{macrocode}
\define@key\adjbox@fam{min size}{%
    \adjbox@Gin@sizeadd{\@minsizebox\height}#1\relax
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{max size}
%    \begin{macrocode}
\define@key\adjbox@fam{max size}{%
    \adjbox@Gin@sizeadd{\@maxsizebox\height}#1\relax
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{min totalsize}
%    \begin{macrocode}
\define@key\adjbox@fam{min totalsize}{%
    \adjbox@Gin@sizeadd{\@minsizebox\totalheight}#1\relax
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{max totalsize}
%    \begin{macrocode}
\define@key\adjbox@fam{max totalsize}{%
    \adjbox@Gin@sizeadd{\@maxsizebox\totalheight}#1\relax
}
%    \end{macrocode}
% \end{key}
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsubsection{Lap box}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{macro}{\lapbox}
%    \begin{macrocode}
\newcommand*\lapbox[2][\width-\@tempdimb]{%
    \collectboxcheckenv{lapbox}%
    \@collectbox{\@lapbox{#1}{#2}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@lapbox}
%    \begin{macrocode}
\def\@lapbox#1#2{%
    \adjsetlength\@tempdima{#2}%
    \ifdim\@tempdima<\z@
        \@tempdimb=-\@tempdima
    \else
        \@tempdimb=\@tempdima
    \fi
    \adjsetlength\@tempdimc{#1}%
    \ifdim\@tempdimc<\z@
        \@tempdimc=\z@
    \fi
    \leavevmode
    \ifdim\@tempdima<\z@
        \hb@xt@\@tempdimc{\hss\hb@xt@\@tempdimb{\usebox\collectedbox\hss}\hskip\@tempdimc}%
    \else
        \hb@xt@\@tempdimc{\hskip\@tempdimc\hb@xt@\@tempdimb{\hss\usebox\collectedbox}\hss}%
    \fi
}
%    \end{macrocode}
% \end{macro}
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsubsection{Margin box}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{macro}{\marginbox}[1]{Margins as space separated values (like for 'trim')}
% Collect box first.
%    \begin{macrocode}
\newcommand\marginbox{%
    \collectboxcheckenv{marginbox}%
    \@ifstar
        \marginbox@s
        \marginbox@
}
\def\marginbox@#1{%
    \@collectbox{\marginbox@@{#1}}%
}
\def\marginbox@s#1{%
    \@collectbox{\marginbox@@s{#1}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{marginbox*}[1]{Margins as space separated values (like for 'trim')}
%    \begin{macrocode}
\expandafter\newcommand\expandafter*\csname marginbox*\endcsname{%
    \@collectboxisenv{marginbox*}%
    \marginbox@s
}
%    \end{macrocode}
% \end{environment}
%
%
% \begin{macro}{\marginbox@@}
% (1) Parse margins (must be done here to allow the user to use the original box dimensions).
% (2) Change box margins and (3) place the box.
%    \begin{macrocode}
\def\marginbox@@#1{%
    \adjbox@parse@v{#1}%
    \@marginbox
        \adjbox@tllx
        \adjbox@tlly
        \adjbox@turx
        \adjbox@tury
        \collectedbox
    \usebox\collectedbox
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\marginbox@@s}
% (1) Parse margins (must be done here to allow the user to use the original box dimensions).
% (2) Change box margins and (3) raise the box by the bottom margin to preserve original depth.
%    \begin{macrocode}
\def\marginbox@@s#1{%
    \adjbox@parse@v{#1}%
    \@marginbox
        \adjbox@tllx
        \adjbox@tlly
        \adjbox@turx
        \adjbox@tury
        \collectedbox
    \raise\adjbox@tlly\copy\collectedbox
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@marginbox}
% Adds the given margins to the depth, width and height.
% The left margin is created by an horizontal skip.
% This implementation assumes that the margins are positive and no special checks are added.
% While negative margins will trim some margin off, this will not lead to correct results if this amounts
% are larger than the existing dimensions. For this the \Macro\trimbox macro should be used.
%    \begin{macrocode}
\def\@marginbox#1#2#3#4#5{%
    \setbox#5=\hbox{%
        \adjsetlength\@tempdima{#1}%
        \hskip\@tempdima
        \adjsetlength\@tempdima{\dp#5 + #2}%
        \adjsetlength\@tempdimb{\wd#5 + #3}%
        \adjsetlength\@tempdimc{\ht#5 + #4}%
        \dp#5=\@tempdima
        \wd#5=\@tempdimb
        \ht#5=\@tempdimc
        \box#5%
    }%
}
%    \end{macrocode}
% \end{macro}
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsubsection{Minibox and other Environments Keys}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \begin{key}{adjbox}{minipage}
%    \begin{macrocode}
\define@key{adjbox}{minipage}{%
    \@ifnextchar[{%
        \adjbox@innerenv{minipage}%
    }{%
        \adjbox@innerenv{minipage}{{#1}}\@nnil%
        \remove@to@nnil
    }#1\@nnil
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{key}{adjbox}{innerenv}
%    \begin{macrocode}
\define@key{adjbox}{innerenv}{%
    \@ifnextchar\bgroup{%
        \adjbox@innerenv
    }{%
        \adjbox@innerenv{#1}\@nnil%
        \remove@to@nnil
    }#1\@nnil
}
%    \end{macrocode}
% \end{key}
%
% \begin{macro}{\adjbox@innerenv}
%    \begin{macrocode}
\def\adjbox@innerenv#1#2\@nnil{%
    \def\adjbox@collectbox##1{\collectbox@{\begin{#1}#2}{##1}{\end{#1}}}%
}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{key}{adjbox}{innercode}
%    \begin{macrocode}
\define@key{adjbox}{innercode}{%
    \adjbox@innercode#1{}{}%
}
%    \end{macrocode}
% \end{key}
%
% \begin{macro}{\adjbox@innerenv}
%    \begin{macrocode}
\def\adjbox@innerenv#1#2\@nnil{%
    \def\adjbox@collectbox##1{\collectbox@{\begin{#1}#2}{##1}{\end{#1}}}%
}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\adjbox@innercode}
%    \begin{macrocode}
\def\adjbox@innercode#1#2{%
    \def\adjbox@collectbox##1{\collectbox@{#1}{##1}{#2}}%
}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{key}{adjbox}{env}
%    \begin{macrocode}
\define@key{adjbox}{env}{%
    \@ifnextchar\bgroup{%
        \adjbox@addenv
    }{%
        \adjbox@addenv{#1}\@nnil%
        \remove@to@nnil
    }#1\@nnil
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{macro}{\adjust@addenv}
%    \begin{macrocode}
\def\adjbox@addenv#1#2\@nnil{%
    \def\@tempa{\begin{#1}#2}%
    \toks@\expandafter\expandafter\expandafter{\expandafter\@tempa\the\toks@\end{#1}}%
}%
%    \end{macrocode}
% \end{macro}
%
% \begin{key}{adjbox}{addcode}
%    \begin{macrocode}
\define@key{adjbox}{Addcode}{%
    \adjust@@addcode#1{}\@nnil%
}
\define@key{adjbox}{addcode}{%
    \Gin@esetsize
    \@tempswatrue
    \adjust@@addcode#1{}\@nnil%
}
\def\adjust@@addcode#1#2#3\@nnil{%
    \ifx\@nnil#3\@nnil
        \adjust@addcode{#1}{#2}%
    \else
        \PackageError{adjustbox}{Incorrect input for key 'addcode={<code before>}{<code afterwards>}'!}%
    \fi
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{precode}
%    \begin{macrocode}
\define@key{adjbox}{precode}{%
    \Gin@esetsize
    \@tempswatrue
    \adjust@addcode{#1}{}%
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{Precode}
%    \begin{macrocode}
\define@key{adjbox}{Precode}{%
    \adjust@addcode{#1}{}%
}
%    \end{macrocode}
% \end{key}
%
% \begin{key}{adjbox}{appcode}
%    \begin{macrocode}
\define@key{adjbox}{appcode}{%
    \toks@\expandafter{\the\toks@#1}%
}
%    \end{macrocode}
% \end{key}
%
% \begin{macro}{\adjust@addcode}
%    \begin{macrocode}
\def\adjust@addcode#1#2{%
    \def\@tempa{#1}%
    \toks@\expandafter\expandafter\expandafter{\expandafter\@tempa\expandafter{\the\toks@}#2}%
}%
%    \end{macrocode}
% \end{macro}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \subsection{New, experimental macros and keys}
%
% \begin{macro}{\bgimagebox}
%    \begin{macrocode}
\newcommand*\bgimagebox[2][]{%
    \collectboxcheckenv{bgimagebox}%
    \@collectbox{\@bgimagebox{#1}{#2}}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@bgimagebox}
%    \begin{macrocode}
\def\@bgimagebox#1#2{%
    \mbox{%
        \lower\depth\hbox{%
            \edef\@tempa{\noexpand\includegraphics%
                [#1,width=\the\width,totalheight=\the\totalheight]%
                {#2}%
            }%
            \@tempa
        }%
        \hskip-\width%
        \BOXCONTENT
    }%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{key}{adjbox}{bgimage}
%    \begin{macrocode}
\define@key{adjbox}{bgimage}{%
    \@ifnextchar\bgroup{%
        \adjbox@bgimage
    }{%
        \adjbox@bgimage{}{#1}%
    }#1\@nnil
}
%    \end{macrocode}
% \end{key}
%
%
% \begin{macro}{\adjbox@bgimage}
%    \begin{macrocode}
\def\adjbox@bgimage#1#2#3\@nnil{%
    \adjbox@Gin@add{\@collectbox{\@bgimagebox{#1}{#2}}}%
}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</adjustbox>
% \fi
%
%
% \iffalse
%<*adjgrfx>
% \fi
%    \begin{macrocode}
\ProvidesPackage{adjgrfx}[2011/07/28 v0.1 Patches to graphicx used by adjustbox]
\RequirePackage{graphicx}
%    \end{macrocode}
%
%
%%^^A  \width, \height, \totalheight, \depth  =  size current at option execution (changes after every option) (initial: natural size)
%%^^A  \Width, \Height, \Totalheight, \Depth  =  requested size of image (height/totalheight and width) (initial: natural size)
%%^^A  \WIDTH, \HEIGHT, \TOTALHEIGHT, \DEPTH  =  natural size of image
%%  
%%
%
% \begin{macro}{\Gin@adj@adddim}
%    \begin{macrocode}
\newcommand*\Gin@adj@adddim{%
    \let\height\Gin@nat@height
    \let\width\Gin@nat@width
    \let\totalheight\height
    \let\depth\z@
    \let\adjbox@HEIGHT\HEIGHT
    \let\adjbox@WIDTH\WIDTH
    \let\adjbox@TOTALHEIGHT\TOTALHEIGHT
    \let\adjbox@DEPTH\DEPTH
    \global\let\HEIGHT\Gin@nat@height
    \global\let\WIDTH\Gin@nat@width
    \global\let\TOTALHEIGHT\HEIGHT
    \global\let\DEPTH\z@
    \let\adjbox@Height\Height
    \let\adjbox@Width\Width
    \let\adjbox@Totalheight\Totalheight
    \let\adjbox@Depth\Depth
    \global\let\Height\Gin@nat@height
    \global\let\Width\Gin@nat@width
    \global\let\Totalheight\Height
    \global\let\Depth\z@
    \edef\adjbox@restore@dims{%
        \global\adjbox@nat@height\the\adjbox@nat@height\relax
        \global\adjbox@nat@width \the\adjbox@nat@width\relax
        \global\adjbox@req@height\the\adjbox@req@height\relax
        \global\adjbox@req@width \the\adjbox@req@width\relax
    }%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\Gin@adj@remdim}
%    \begin{macrocode}
\newcommand*\Gin@adj@remdim{%
    \global\let\HEIGHT\adjbox@HEIGHT
    \global\let\WIDTH\adjbox@WIDTH
    \global\let\TOTALHEIGHT\adjbox@TOTALHEIGHT
    \global\let\DEPTH\adjbox@DEPTH
    \global\let\Height\adjbox@Height
    \global\let\Width\adjbox@Width
    \global\let\Totalheight\adjbox@Totalheight
    \global\let\Depth\adjbox@Depth
    \adjbox@restore@dims
}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\newdimen\adjbox@nat@width
\newdimen\adjbox@nat@height
\newdimen\adjbox@req@width
\newdimen\adjbox@req@height
%    \end{macrocode}
%
% \begin{macro}{\Gin@adj@keepdim}
%    \begin{macrocode}
\newcommand*\Gin@adj@keepdim{%
    \global\adjbox@nat@height\Gin@nat@height
    \global\adjbox@nat@width \Gin@nat@width
    \global\adjbox@req@height\Gin@req@height
    \global\adjbox@req@width \Gin@req@width
    \global\let\HEIGHT\adjbox@nat@height
    \global\let\WIDTH\adjbox@nat@width
    \global\let\TOTALHEIGHT\adjbox@nat@height
    \global\let\DEPTH\z@
    \global\let\Height\adjbox@req@height
    \global\let\Width\adjbox@req@width
    \global\let\Totalheight\adjbox@req@height
    \global\let\Depth\z@
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\Gin@ii}
%    \begin{macrocode}
\def\Gin@ii[#1]#2{%
    \def\@tempa{[}\def\@tempb{#2}%
    \ifx\@tempa\@tempb
      \def\@tempa{\Gin@iii[#1][}%
      \expandafter\@tempa
    \else
     \begingroup
       \Gin@adj@adddim
       \@tempswafalse
       \toks@{\Ginclude@graphics{#2}}%
       \setkeys{Gin}{#1}%
       \Gin@esetsize
       \the\toks@
       \Gin@adj@remdim
     \endgroup
     \fi}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\Gin@iii}
%    \begin{macrocode}
\def\Gin@iii[#1,#2][#3,#4]#5{%
  \begingroup
  \Gin@adj@adddim
  \Gin@bboxtrue
  \Gin@defaultbp\Gin@llx{#1}%
  \Gin@defaultbp\Gin@lly{#2}%
  \Gin@defaultbp\Gin@urx{#3}%
  \Gin@defaultbp\Gin@ury{#4}%
  \Ginclude@graphics{#5}%
  \Gin@adj@remdim
  \endgroup}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\Gin@setfile}
%    \begin{macrocode}
\def\Gin@setfile#1#2#3{%
  \ifx\\#2\\\Gread@false\fi
  \ifGin@bbox\else
    \ifGread@
      \csname Gread@%
         \expandafter\ifx\csname Gread@#1\endcsname\relax
           eps%
         \else
           #1%
         \fi
      \endcsname{\Gin@base#2}%
    \else
      \Gin@nosize{#3}%
    \fi
  \fi
  \Gin@viewport@code
  \Gin@nat@height\Gin@ury bp%
  \advance\Gin@nat@height-\Gin@lly bp%
  \Gin@nat@width\Gin@urx bp%
  \advance\Gin@nat@width-\Gin@llx bp%
  \Gin@req@sizes
  \Gin@adj@keepdim
  \expandafter\ifx\csname Ginclude@#1\endcsname\relax
    \Gin@drafttrue
    \expandafter\ifx\csname Gread@#1\endcsname\relax
      \@latex@error{Can not include graphics of type: #1}\@ehc
      \global\expandafter\let\csname Gread@#1\endcsname\@empty
    \fi
  \fi
  \leavevmode
  \ifGin@draft
      \hb@xt@\Gin@req@width{%
        \vrule\hss
        \vbox to \Gin@req@height{%
           \hrule \@width \Gin@req@width
           \vss
           \edef\@tempa{#3}%
           \rlap{ \ttfamily\expandafter\strip@prefix\meaning\@tempa}%
           \vss
           \hrule}%
        \hss\vrule}%
  \else
    \@addtofilelist{#3}%
    \ProvidesFile{#3}[Graphic file (type #1)]%
    \setbox\z@\hbox{\csname Ginclude@#1\endcsname{#3}}%
    \dp\z@\z@
    \ht\z@\Gin@req@height
    \wd\z@\Gin@req@width
  \box\z@
  \fi}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</adjgrfx>
% \fi
%
%
% \iffalse
%<*adjcalc>
% \fi
% Test if this package was loaded as package or as file (as part of 'adjustbox'):
%    \begin{macrocode}
\begingroup
\def\@tempa{adjcalc}
\expandafter
\endgroup
\ifx\@tempa\@currname
    \ProvidesPackage{adjcalc}[2011/08/07 v1.0 Provides advanced setlength with multiple back-ends (calc, etex, pgfmath)]
    \RequirePackage{xkeyval}
\fi
%    \end{macrocode}
%
%
%
% Use e-TeX by default if available, otherwise LaTeX (maybe with \pkg{calc})
%    \begin{macrocode}
\AtEndOfPackage{\adjcalc@atend}
\def\adjcalc@atend{%
\begingroup
\expandafter\ifx\csname eTeXversion\endcsname\relax
    \endgroup
    \RequirePackage{calc}%
    \adjcalc@calc
    \def\adjcalc@etex{\PackageError{adjcalc}{e-TeX not available for current compiler!}}%
\else
    \endgroup
    \adjcalc@etex
\fi
}
%    \end{macrocode}
%
% Initial definitions for the package options. This macros are later redefined because the same keys
% can be used as macro options.
%    \begin{macrocode}
\def\adjcalc@pgfmath{\AtEndOfPackage{\RequirePackage{pgf}}\def\adjcalc@atend{\adjcalc@pgfmath}}
\def\adjcalc@etex{\def\adjcalc@atend{\adjcalc@etex}}
\def\adjcalc@calc{\AtEndOfPackage{\RequirePackage{calc}}\def\adjcalc@atend{\adjcalc@calc}}
\def\adjcalc@overwrite{\AtEndOfPackage{\adjcalc@overwrite}}
%    \end{macrocode}
%
% Options:
%    \begin{macrocode}
\DeclareOptionX<adjbox>{pgfmath}{\adjcalc@pgfmath}
\DeclareOptionX<adjbox>{etex}{\adjcalc@etex}
\DeclareOptionX<adjbox>{calc}{\adjcalc@calc}
\DeclareOptionX<adjbox>{none}{\let\adjcalc@atend\relax\def\adjsetlength{\setlength}\let\adjcalc@overwrite\relax}
\DeclareOptionX<adjbox>{overwrite}{\adjcalc@overwrite}
\ProcessOptionsX*<adjbox>
\disable@keys{adjbox}{none}
%    \end{macrocode}
%
% \begin{macro}{\adjcalc@etex}
%    \begin{macrocode}
\def\adjcalc@etex{%
    \protected\def\adjsetlength##1##2{%
        ##1=\glueexpr(##2)\relax
    }%
    \protected\def\adjaddtolength##1##2{%
        \advance##1 by \glueexpr(##2)\relax
    }%
    \protected\def\adjsetcounter##1##2{%
        \@ifundefined{c@##1}%
            {\@nocounterr{##1}}%
            {\global\csname c@##1\endcsname\numexpr(##2)\relax}%
    }%
    \protected\def\adjaddtocounter##1##2{%
        \@ifundefined{c@##1}%
            {\@nocounterr{##1}}%
            {\global\advance\csname c@##1\endcsname\numexpr(##2)\relax}%
    }%
    \def\adjbox@default##1##2{%
        \@defaultunits##1=\glueexpr##2 \adjbox@defaultunit\relax\@nnil
    }%
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\adjcalc@calc}
% This uses the underlying (re-)definitions of the normal macros (\Macro\setlength, ...) done by the \pkg{calc} package.
% This allows to locally redefine \Macro\setlength to call \Macro\adjsetlength, etc., without causing an infinite loop.
%    \begin{macrocode}
\def\adjcalc@calc{%
    \DeclareRobustCommand\adjsetlength{\calc@assign@skip}%
    \DeclareRobustCommand\adjaddtolength[1]{\calc@assign@skip{\advance ##1}}%
    \DeclareRobustCommand\adjsetcounter[2]{\@ifundefined{c@##1}{\@nocounterr{##1}}{\calc@assign@count{\global\csname c@##1\endcsname}{##2}}}%
    \DeclareRobustCommand\adjaddtocounter[2]{\@ifundefined{c@##1}{\@nocounterr{##1}}{\calc@assign@count{\global\advance\csname c@##1\endcsname}{##2}}}%
    \def\adjbox@checkdefault##1\@nnil##2##3{%
        \ifx\relax##1\relax\else
            \calc@assign@skip{##2}{##3}%
        \fi
    }%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjcalc@pgfmath}
%    \begin{macrocode}
\def\adjcalc@pgfmath{%
    \DeclareRobustCommand\adjsetlength{\pgfmathsetlength}%
    \DeclareRobustCommand\adjaddtolength{\pgfmathaddtolength}%
    \DeclareRobustCommand\adjsetcounter{\pgfmathsetcounter}%
    \DeclareRobustCommand\adjaddtocounter{\pgfmathaddtocounter}%
    \def\adjbox@default##1##2{%
        \edef\pgfmathresultunitscale{1\adjbox@defaultunit}%
        \let\pgfmathpostparse\pgfmathscaleresult
        \pgfmathparse{##2}%
        ##1=\pgfmathresult pt\relax
    }%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\adjcalc@overwrite}
%    \begin{macrocode}
\def\adjcalc@overwrite{%
    \let\setlength\adjsetlength
    \let\addtolength\adjaddtolength
    \let\setcounter\adjsetcounter
    \let\addtocounter\adjaddtocounter
}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</adjcalc>
% \fi
%
%
% \iffalse
%<*adjpgf.def>
% \fi
%    \begin{macrocode}
\RequirePackage{pgf}
%    \end{macrocode}
%
% \begin{macro}{\@trimbox}
%    \begin{macrocode}
\def\@clipbox#1#2#3#4#5{%
    \@trimbox{#1}{#2}{#3}{#4}{#5}%
    \setbox#5\hbox{\begin{pgfpicture}%
        \pgfpathmoveto{\pgfqpoint\z@{-\dp#5}}%
        \pgfpathlineto{\pgfqpoint\z@{\ht#5}}%
        \pgfpathlineto{\pgfqpoint{\wd#5}{\ht#5}}%
        \pgfpathlineto{\pgfqpoint{\wd#5}{-\dp#5}}%
        \pgfpathclose
        \pgfusepathqclip
        \pgfset{inner sep=\z@,outer sep=\z@,minimum size=\z@}%
        \pgfnode{rectangle}{base west}{\usebox#5}{}{}%
        \pgfsetbaselinepointnow{\pgfpoint\z@\z@}%
    \end{pgfpicture}}%
}
%    \end{macrocode}
% \end{macro}
%<VIM> vim: ft=tex
%
% \iffalse
%</adjpgf.def>
% \fi
%
%
% \Finale
% \endinput
