%%
%% This is file `boxhandler.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% boxhandler.dtx  (with options: `package')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from boxhandler.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file boxhandler.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%%
%% boxhandler.sty
%% Copyright Steven B. Segletes.
%%
%% This file may be redistributed and/or modified with attribution.
%%
%% This is boxhandler.sty, derived from earlier incarnations of savcap.sty &
%% arlcaptions.sty.
%%
\ProvidesPackage{boxhandler}
[2012/10/18 v1.30
 Tools for Optimizing Captions, Presentation, and
 Placement of Tables and Figures]
\NeedsTeXFormat{LaTeX2e}
%% Examples of a number of calls provided in this style are given below,
%% in no particular order:
%%
%%|                                                                 |\\
%%|\bxtable[t]                                                      |\\
%%|  {This is a test of nonwrapping caption\label{tb:mytable}}      |\\
%%|  {                                                              |\\
%%|  \begin{tabular}{|c|c|c|}                                       |\\
%%|    \hline                                                       |\\
%%|    column 1 data & 2nd column data & and the third column data\\|\\
%%|    \hline                                                       |\\
%%|  \end{tabular}                                                  |\\
%%|  }                                                              |\\
%%|                                                                 |\\
%%|\usepackage{graphicx}                                            |\\
%%|\bxfigure[ht]                                                    |\\
%%|  {Here is an example of a particularly long caption that will   |\\
%%|          test wrapping}                                         |\\
%%|  {\includegraphics[width=3.64in,height=4.30in]{Atest1.eps}}     |\\
%%|                                                                 |\\
%%|\relaxCaptionWidth[2in]                                          |\\
%%|                                                                 |\\
%%|\captionStyle{}{c}                                               |\\
%%|                                                                 |\\
%%|\setlength\captionGap{3ex}                                       |\\
%%|                                                                 |\\
%%|\setcounter{abovecaptionskipterm}{10}                            |\\
%%|\setcounter{belowcaptionskipterm}{0}                             |\\
%%|                                                                 |\\
%%|\TableFontSize\normalsize                                        |\\
%%|                                                                 |\\
%%|\LRFigurePlacement{flushleft}                                    |\\
%%|                                                                 |\\
%%|\killtableofcontents                                             |\\
%%|                                                                 |\\
%%|\holdFigures                                                     |\\
%%|                                                                 |\\
%%|\clearFigures                                                    |\\
%%|                                                                 |\\
%%|\newsavebox{\mybox}                                              |\\
%%|\SaveCBox{\mybox}{\framebox(200,100){Ack!}}                      |\\
%%|                                                                 |\\
%%|\ReciteFigure[ht]{\figcapii}{\figii}{\figcapwdthii}%             |\\
%%|                {\figwrapii}{\figwrapstatusii}                   |\\
%%
%% \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         \~}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{ifthen}
\usepackage{pbox}
\newcounter{TableIndex}          \setcounter{TableIndex}{0}
\newcounter{FigureIndex}         \setcounter{FigureIndex}{0}
\newcounter{TableClearedIndex}   \setcounter{TableClearedIndex}{0}
\newcounter{FigureClearedIndex}  \setcounter{FigureClearedIndex}{0}
\let\old@makecaption \@makecaption% SAVE PREVAILING \@makecaption STYLE
\newlength\oldabovecaptionskip
\setlength\oldabovecaptionskip \abovecaptionskip
\newlength\oldbelowcaptionskip
\setlength\oldbelowcaptionskip \belowcaptionskip
%% \captionGap CAN BE INCREASED TO PLACE MORE SPACE BETWEEN THE CAPTION
%% LABEL AND THE ACTUAL CAPTION TEXT.
\newlength\captionGap          \setlength\captionGap{1ex}
%% \TableDeadMargin AND \FigureDeadMargin REFER TO THE TABLE & FIGURE
%% MARGIN OF A BOX THAT COUNTS TOWARDS ITS SIZE, BUT IN WHICH NO
%% ACTIVE DATA FALLS; DEADMARGIN ASSUMED ON BOTH LEFT & RIGHT SIDE.
\newlength\TableDeadMargin     \setlength\TableDeadMargin{0.375em}
\newlength\FigureDeadMargin    \setlength\FigureDeadMargin{0em}
%% INITIALIZE \above- AND \belowcaptionskip VALUES; CAN BE RESET
%% USED TO SET GAPS ABOVE & BELOW CAPTIONS
\newcounter{abovecaptionskipterm}  \setcounter{abovecaptionskipterm}{10}
\newcounter{belowcaptionskipterm}  \setcounter{belowcaptionskipterm}{7}
%% RESET \@minCaptionBoxWidth TO Default VALUE WITH \relaxCaptionWidth
%% SET \@minCaptionBoxWidth TO USER VALUE WITH \relaxCaptionWidth[<len>]
\newlength\@minCaptionBoxWidth
\newlength\@minCaptionBoxWidthDefault
\setlength\@minCaptionBoxWidthDefault{1in}
%% RESET \@maxCaptionBoxWidth TO Default WITH \limitCaptionWidth
%% SET \@maxCaptionBoxWidth WITH \limitCaptionWidth[<len>]
\newlength\@maxCaptionBoxWidth
\newlength\@maxCaptionBoxWidthDefault
\setlength\@maxCaptionBoxWidthDefault{\textwidth}
%% DEFINE promptTablesFlag & PROVIDE ROUTINE TO CHANGE IT FROM
%% "PROMPT"(1) TO "ON HOLD"(0)
\newcounter{promptTablesFlag}    \setcounter{promptTablesFlag}{1}
\newcommand\holdTables{\setcounter{promptTablesFlag}{0}}
%% SAME FOR promptFiguresFlag
\newcounter{promptFiguresFlag}   \setcounter{promptFiguresFlag}{1}
\newcommand\holdFigures{\setcounter{promptFiguresFlag}{0}}
%% DEFAULT CaptionFontSize & TableFontSize AS \small; CAN BE RESET
\let \CaptionFontSize \small
\let \TableFontSize \small
%% DEFAULT TABLE & FIGURE LR ALIGNMENT TO center;
%% CAN RESET TO flushleft/-right
\def \LRTablePlacement {center}
\def \LRFigurePlacement {center}
%% WITHIN-CAPTION JUSTIFICATION CAN BE SET
%% OPTIONS: {}, {\raggedleft}, {\raggedright}, or {\centering}
\def\CaptionJustification{} % <---DEFAULT IS FULL JUSTIFICATION

%% WORKING VARIABLES
\newlength\DeadMargin
\newlength\@DataBoxWidth
\newlength\CaptionBoxWidth
\newlength\@DataBoxOffset
\newlength\@CaptionBoxOffset
\newlength\@captionIDwidth
\newlength\@captionWidth
\newlength\@DataBoxSurplus

%% FIGURE & TABLE WRAPPER INITIALIZATIONS
\def\wrapper{F}
\def\WrapperTextStyle{\bf\small}
\def\WrapperTextDefault{DEFAULT WRAPPER}
\global\def\WrapperText{\noexpand\WrapperTextStyle\WrapperTextDefault}
\newcommand\WrapperOn[1][]{%
  \def\wrapper{T}%
  \ifthenelse{\equal{#1}{}}%
  {}{\def\WrapperTextDefault{\noexpand#1}}%
  \global\def%
     \WrapperText{\noexpand\WrapperTextStyle\WrapperTextDefault}%
}
\newcommand\WrapperOff{\def\wrapper{F}}
\newcommand\Wrapper[1]{\global\def%
  \WrapperText{\noexpand\WrapperTextStyle\noexpand#1}}

\newcommand\bxtable[3][t]{%
  \StoreTable[#1]{#2}{#3}{\WrapperText}{\wrapper}%
  \ifnum\arabic{promptTablesFlag}=1%
    \addtocounter{TableClearedIndex}{1}%
    \def\TableBoxLabel{tbl\roman{TableIndex}}%
    \def\TableCaptionLabel{tblcap\roman{TableIndex}}%
    \def\TblCaptionWidthLabel{tblcapwdth\roman{TableIndex}}%
    \def\TableWrapper{tblwrap\roman{TableIndex}}%
    \def\WrapperStatus{tblwrapstatus\roman{TableIndex}}%
    \ReciteTable[#1]{\csname\TableCaptionLabel\endcsname}%
                    {\csname\TableBoxLabel\endcsname}%
                    {\csname\TblCaptionWidthLabel\endcsname}%
                    {\csname\TableWrapper\endcsname}%
                    {\csname\WrapperStatus\endcsname}%
  \fi
}

\newcommand\StoreTable[5][]{%
  \addtocounter{TableIndex}{1}%
  \setlength\DeadMargin\TableDeadMargin%
  \def\TableBoxLabel{tbl\roman{TableIndex}}%
  \def\TableCaptionLabel{tblcap\roman{TableIndex}}%
  \def\TblCaptionWidthLabel{tblcapwdth\roman{TableIndex}}%
  \def\TableWrapper{tblwrap\roman{TableIndex}}%
  \def\WrapperStatus{tblwrapstatus\roman{TableIndex}}%
  \expandafter\SaveCBox\csname\TableBoxLabel\endcsname{\TableFontSize#3}%
  \expandafter\def\csname\TableCaptionLabel\endcsname{#2}%
  \expandafter\newlength\csname\TblCaptionWidthLabel\endcsname%
  \expandafter\setlength\csname\TblCaptionWidthLabel\endcsname%
                                              \CaptionBoxWidth%
  \expandafter\edef\csname\TableWrapper\endcsname{#4}%
  \expandafter\edef\csname\WrapperStatus\endcsname{#5}%
%% After storing table, reset wrapper to default value
  \global\def%
   \WrapperText{\noexpand\WrapperTextStyle\WrapperTextDefault}%
}

\newcommand\ReciteTable[6][ht]{%
  \begin{table}[#1]%
    \begin{\LRTablePlacement}%
      \let\@makecaption\new@makecaption%
      \setlength\abovecaptionskip{\arabic{abovecaptionskipterm}\p@}%
      \setlength\belowcaptionskip{\arabic{belowcaptionskipterm}\p@}%
        \set@DataBoxWidth{#3}%
        \setlength\CaptionBoxWidth{#4}%
        \set@BoxOffsets%
        \if T#6%
          \rule{\@DataBoxOffset}{0in}%
          \makebox[\@DataBoxWidth][l]{#5}%
          \rule{\@DataBoxOffset}{0in}\\%
        \fi
        \rule{\@CaptionBoxOffset}{0em}%
        \parbox{\CaptionBoxWidth}{\bx@caption{#2}}%
        \rule{\@CaptionBoxOffset}{0em}%
        \par%
        \rule{\@DataBoxOffset}{0in}%
        \usebox{#3}%
        \rule{\@DataBoxOffset}{0in}\\%
        \if T#6%
          \rule{\@DataBoxOffset}{0in}\\%
          \makebox[\@DataBoxWidth][r]{#5}%
        \rule{\@DataBoxOffset}{0in}%
        \fi
      \let\@makecaption\old@makecaption%
      \setlength\abovecaptionskip \oldabovecaptionskip%
      \setlength\belowcaptionskip \oldbelowcaptionskip%
    \end{\LRTablePlacement}%
  \end{table}%
}

\newcommand\nextTable[1][ht]{%
  \ifnum\arabic{TableClearedIndex}<\arabic{TableIndex}{%
    \addtocounter{TableClearedIndex}{1}%
%%  \TableBoxLabel       : tbli,    tblii,    tbliii,    tbliv,    etc.
%%  \TableCaptionLabel   : tblcapi, tblcapii, tblcapiii, tblcapiv, etc.
%%  \TblCaptionWidthLabel: tblcapwdthi, tblcapwdthii, tblcapwdthiii,etc.
    \def\TableBoxLabel{tbl\roman{TableClearedIndex}}%
    \def\TableCaptionLabel{tblcap\roman{TableClearedIndex}}%
    \def\TblCaptionWidthLabel{tblcapwdth\roman{TableClearedIndex}}%
    \def\TableWrapper{tblwrap\roman{TableClearedIndex}}%
    \def\WrapperStatus{tblwrapstatus\roman{TableClearedIndex}}%
    \ReciteTable[#1]{\csname\TableCaptionLabel\endcsname}%
                    {\csname\TableBoxLabel\endcsname}%
                    {\csname\TblCaptionWidthLabel\endcsname}%
                    {\csname\TableWrapper\endcsname}%
                    {\csname\WrapperStatus\endcsname}%
  }\fi
}

\newcommand\clearTables{%
  \clearpage%
  \clearlistoftables%
  \clearpage%
%%DO UNTIL ALL HELD TABLES ARE CLEARED
  \whiledo{\arabic{TableClearedIndex}<\arabic{TableIndex}}{%
    \addtocounter{TableClearedIndex}{1}%
%%  \TableBoxLabel       : tbli,    tblii,    tbliii,    tbliv,    etc.
%%  \TableCaptionLabel   : tblcapi, tblcapii, tblcapiii, tblcapiv, etc.
%%  \TblCaptionWidthLabel: tblcapwdthi, tblcapwdthii, tblcapwdthiii,etc.
    \def\TableBoxLabel{tbl\roman{TableClearedIndex}}%
    \def\TableCaptionLabel{tblcap\roman{TableClearedIndex}}%
    \def\TblCaptionWidthLabel{tblcapwdth\roman{TableClearedIndex}}%
    \def\TableWrapper{tblwrap\roman{TableClearedIndex}}%
    \def\WrapperStatus{tblwrapstatus\roman{TableClearedIndex}}%
    \theClearedTable{\csname\TableCaptionLabel\endcsname}%
                    {\csname\TableBoxLabel\endcsname}%
                    {\csname\TblCaptionWidthLabel\endcsname}%
                    {\csname\TableWrapper\endcsname}%
                    {\csname\WrapperStatus\endcsname}%
  }%
}

%% \theClearedTable CAN BE RENEWED IF DIFFERENT OUTPUT FORMAT IS DESIRED
\newcommand\theClearedTable[6][ht]{%
%%  CLEAR THIS TABLE ON A PAGE BY ITSELF, CENTERED VERTICALLY
  \vspace*{\fill}%
  \ReciteTable[#1]{#2}{#3}{#4}{#5}{#6}%
  \vspace*{\fill}%
  \clearpage%
}

\newcommand\bxfigure[3][t]{%
  \StoreFigure[#1]{#2}{#3}{\WrapperText}{\wrapper}%
  \ifnum\arabic{promptFiguresFlag}=1%
    \addtocounter{FigureClearedIndex}{1}%
    \def\FigureBoxLabel{fig\roman{FigureIndex}}%
    \def\FigureCaptionLabel{figcap\roman{FigureIndex}}%
    \def\FigCaptionWidthLabel{figcapwdth\roman{FigureIndex}}%
    \def\FigureWrapper{figwrap\roman{FigureIndex}}%
    \def\WrapperStatus{figwrapstatus\roman{FigureIndex}}%
    \ReciteFigure[#1]{\csname\FigureCaptionLabel\endcsname}%
                        {\csname\FigureBoxLabel\endcsname}%
                        {\csname\FigCaptionWidthLabel\endcsname}%
                        {\csname\FigureWrapper\endcsname}%
                        {\csname\WrapperStatus\endcsname}%
  \fi
}

\newcommand\StoreFigure[5][]{%
  \addtocounter{FigureIndex}{1}%
  \setlength\DeadMargin\FigureDeadMargin%
  \def\FigureBoxLabel{fig\roman{FigureIndex}}%
  \def\FigureCaptionLabel{figcap\roman{FigureIndex}}%
  \def\FigCaptionWidthLabel{figcapwdth\roman{FigureIndex}}%
  \def\FigureWrapper{figwrap\roman{FigureIndex}}%
  \def\WrapperStatus{figwrapstatus\roman{FigureIndex}}%
  \expandafter\SaveCBox\csname\FigureBoxLabel\endcsname{#3}%
  \expandafter\def\csname\FigureCaptionLabel\endcsname{#2}%
  \expandafter\newlength\csname\FigCaptionWidthLabel\endcsname%
  \expandafter\setlength\csname\FigCaptionWidthLabel\endcsname%
                                              \CaptionBoxWidth%
  \expandafter\edef\csname\FigureWrapper\endcsname{#4}%
  \expandafter\edef\csname\WrapperStatus\endcsname{#5}%
%% After storing figure, reset wrapper to default value
  \global\def%
   \WrapperText{\noexpand\WrapperTextStyle\WrapperTextDefault}%
}

\newcommand\ReciteFigure[6][ht]{%
  \begin{figure}[#1]%
    \begin{\LRFigurePlacement}%
      \let\@makecaption\new@makecaption%
      \setlength\abovecaptionskip{\arabic{abovecaptionskipterm}\p@}%
      \setlength\belowcaptionskip{\arabic{belowcaptionskipterm}\p@}%
        \set@DataBoxWidth{#3}%
        \setlength\CaptionBoxWidth{#4}%
        \set@BoxOffsets%
        \if T#6%
          \rule{\@DataBoxOffset}{0in}%
          \makebox[\@DataBoxWidth][l]{#5}%
          \rule{\@DataBoxOffset}{0in}\\%
        \fi
        \rule{\@DataBoxOffset}{0in}%
        \usebox{#3}%
        \rule{\@DataBoxOffset}{0in}%
        \par%
        \rule{\@CaptionBoxOffset}{0em}%
        \parbox{\CaptionBoxWidth}{\bx@caption{#2}}%
        \rule{\@CaptionBoxOffset}{0em}%
        \if T#6%
          \rule{\@DataBoxOffset}{0in}\\%
          \makebox[\@DataBoxWidth][r]{#5}%
          \rule{\@DataBoxOffset}{0in}%
        \fi
      \let\@makecaption\old@makecaption%
      \setlength\abovecaptionskip\oldabovecaptionskip%
      \setlength\belowcaptionskip\oldbelowcaptionskip%
    \end{\LRFigurePlacement}%
  \end{figure}%
}

\newcommand\nextFigure[1][ht]{%
  \ifnum\arabic{FigureClearedIndex}<\arabic{FigureIndex}{%
    \addtocounter{FigureClearedIndex}{1}%
%%  \FigureBoxLabel:     : figi,    figii,    figiii,    figiv,    etc.
%%  \FigureCaptionLabel  : figcapi, figcapii, figcapiii, figcapiv, etc.
%%  \FigCaptionWidthLabel: figcapwdthi, figcapwdthii, figcapwdthiii,etc.
    \def\FigureBoxLabel{fig\roman{FigureClearedIndex}}%
    \def\FigureCaptionLabel{figcap\roman{FigureClearedIndex}}%
    \def\FigCaptionWidthLabel{figcapwdth\roman{FigureClearedIndex}}%
    \def\FigureWrapper{figwrap\roman{FigureClearedIndex}}%
    \def\WrapperStatus{figwrapstatus\roman{FigureClearedIndex}}%
    \ReciteFigure[#1]{\csname\FigureCaptionLabel\endcsname}%
                     {\csname\FigureBoxLabel\endcsname}%
                     {\csname\FigCaptionWidthLabel\endcsname}%
                     {\csname\FigureWrapper\endcsname}%
                     {\csname\WrapperStatus\endcsname}%
  }\fi
}

\newcommand\clearFigures{%
  \clearpage%
  \clearlistoffigures%
  \clearpage%
%%DO UNTIL ALL HELD FIGURES ARE CLEARED
  \whiledo{\arabic{FigureClearedIndex}<\arabic{FigureIndex}}{%
    \addtocounter{FigureClearedIndex}{1}%
%%  \FigureBoxLabel      : figi,    figii,    figiii,    figiv,    etc.
%%  \FigureCaptionLabel  : figcapi, figcapii, figcapiii, figcapiv, etc.
%%  \FigCaptionWidthLabel: figcapwdthi, figcapwdthii, figcapwdthiii,etc.
    \def\FigureBoxLabel{fig\roman{FigureClearedIndex}}%
    \def\FigureCaptionLabel{figcap\roman{FigureClearedIndex}}%
    \def\FigCaptionWidthLabel{figcapwdth\roman{FigureClearedIndex}}%
    \def\FigureWrapper{figwrap\roman{FigureClearedIndex}}%
    \def\WrapperStatus{figwrapstatus\roman{FigureClearedIndex}}%
    \theClearedFigure{\csname\FigureCaptionLabel\endcsname}%
                     {\csname\FigureBoxLabel\endcsname}%
                     {\csname\FigCaptionWidthLabel\endcsname}%
                     {\csname\FigureWrapper\endcsname}%
                     {\csname\WrapperStatus\endcsname}%
  }%
}

%% \theClearedFigure CAN BE RENEWED IF DIFFERENT OUTPUT FORMAT DESIRED
\newcommand\theClearedFigure[6][ht]{%
%%  CLEAR THIS FIGURE ON A PAGE BY ITSELF, CENTERED VERTICALLY
  \vspace*{\fill}%
  \ReciteFigure[#1]{#2}{#3}{#4}{#5}{#6}%
  \vspace*{\fill}%
  \clearpage%
}

\newcommand\relaxCaptionWidth[1][\@minCaptionBoxWidthDefault]{%
  \setlength\@minCaptionBoxWidth{#1}%
  \ifdim \@minCaptionBoxWidth > \@maxCaptionBoxWidth%
    \setlength\@maxCaptionBoxWidth\@minCaptionBoxWidth%
  \fi
}
\relaxCaptionWidth% SET INITIAL \@minCaptionBoxWidth TO DEFAULT VALUE

\newcommand\limitCaptionWidth[1][\@maxCaptionBoxWidthDefault]{%
  \setlength\@maxCaptionBoxWidth{#1}%
  \ifdim \@maxCaptionBoxWidth < \@minCaptionBoxWidth%
    \setlength\@minCaptionBoxWidth\@maxCaptionBoxWidth%
  \fi
}
\limitCaptionWidth% SET INITIAL \@maxCaptionBoxWidth TO DEFAULT VALUE

\newcommand\constrainCaptionWidth[2][-1in]{%
  \ifdim #1 < 0in%
    \setlength\@minCaptionBoxWidth{#2}%
    \setlength\@maxCaptionBoxWidth{#2}%
  \else
    \ifdim #1 < #2%
      \setlength\@minCaptionBoxWidth{#1}%
      \setlength\@maxCaptionBoxWidth{#2}%
    \else
      \setlength\@minCaptionBoxWidth{#2}%
      \setlength\@maxCaptionBoxWidth{#1}%
    \fi
  \fi
}

\newcommand\SaveCBox[2]{%
  \newsavebox{#1}%
  \sbox{#1}{#2}%
  \set@BoxWidths{#1}%
}

\newcommand\set@BoxWidths[1]{% of DataBox & CaptionBox (-2\DeadMargin)%
  \set@DataBoxWidth{#1}%
  \set@CaptionBoxWidth%
}

\newcommand\set@DataBoxWidth[1]{%
  \setlength {\@DataBoxWidth}{\widthof{\usebox{#1}}}%
}

\newcommand\set@CaptionBoxWidth{%
  \setlength\CaptionBoxWidth\@DataBoxWidth%
  \addtolength{\CaptionBoxWidth}{-2\DeadMargin}%
  \ifdim \CaptionBoxWidth < \@minCaptionBoxWidth%
    \setlength\CaptionBoxWidth\@minCaptionBoxWidth%
  \fi
  \ifdim \CaptionBoxWidth > \@maxCaptionBoxWidth%
    \setlength\CaptionBoxWidth\@maxCaptionBoxWidth%
  \fi
}

\newcommand\set@BoxOffsets{%
  \setlength\@DataBoxSurplus{\@DataBoxWidth}%
  \addtolength\@DataBoxSurplus{-\CaptionBoxWidth}%
  \ifdim \@DataBoxSurplus > 0in%
    \setlength\@CaptionBoxOffset{0.5\@DataBoxSurplus}%
    \setlength\@DataBoxOffset{0in}%
  \else
    \setlength\@CaptionBoxOffset{0in}%
    \setlength\@DataBoxOffset{-0.5\@DataBoxSurplus}%
  \fi
}

\long\def\offset@caption#1#2{%
  \setlength\@captionIDwidth{\widthofpbox{\CaptionFontSize{#1.}}}%
  \addtolength\@captionIDwidth\captionGap%
  \setlength\@captionWidth\CaptionBoxWidth%
  \addtolength\@captionWidth{-\@captionIDwidth}%
  \CaptionFontSize{#1.}\hfill\parbox[t]{\@captionWidth}%
                  {\CaptionJustification\CaptionFontSize{#2.}}%
}

\long\def\nooffset@caption#1#2{%
  \CaptionJustification\CaptionFontSize #1.\rule{\captionGap}{0in}#2.%
}

\long\def\shortleft@caption#1#2{%
  \raggedright\CaptionFontSize #1.\rule{\captionGap}{0in}#2.%
}

\long\def\shortcenter@caption#1#2{%
  \centering\CaptionFontSize #1.\rule{\captionGap}{0in}#2.%
}

\long\def\shortright@caption#1#2{%
  \raggedleft\CaptionFontSize #1.\rule{\captionGap}{0in}#2.%
}

\long\def\new@makecaption#1#2{%
  \vskip\abovecaptionskip%
  \sbox\@tempboxa{\CaptionFontSize #1.\rule{\captionGap}{0in}#2.}%
  \ifdim \wd\@tempboxa >\hsize%
    \long@caption{#1}{#2}%
  \else
    \short@caption{#1}{#2}%
  \fi
  \vskip\belowcaptionskip%
}

\newcommand\captionStyle[2]{%
  \if o#1\let\long@caption\offset@caption\fi
  \if n#1\let\long@caption\nooffset@caption\fi
  \if l#2\let\short@caption\shortleft@caption\fi
  \if c#2\let\short@caption\shortcenter@caption\fi
  \if r#2\let\short@caption\shortright@caption\fi
}

%% SET DEFAULT CAPTION STYLE: CAPTION ID OFFSET FOR LONG CAPTIONS,
%%                            SHORT CAPTIONS LEFT ALIGNED
\captionStyle{o}{l}

\newcommand\killtableofcontents{%
  \renewcommand\tableofcontents{}%
}

%%LIST OF FIGURES HANDLING:
\newcounter{lofInvocations}   \setcounter{lofInvocations}{0}
\newcounter{lofPrints}        \setcounter{lofPrints}{0}
\let\oldlistoffigures\listoffigures

\newcommand\killlistoffigures{%
  \def\oldlistoffigures {}%
  \renewcommand\listoffigures{}%
}

\newcommand\holdlistoffigures{%
  \renewcommand\listoffigures{\addtocounter{lofInvocations}{1}}%
}

\newcommand\clearlistoffigures{%
  \whiledo{\arabic{lofPrints} < \arabic{lofInvocations}}{%
    \addtocounter{lofPrints}{1}%
    \oldlistoffigures%
  }%
}

%%LIST OF TABLES HANDLING:
\newcounter{lotInvocations}   \setcounter{lotInvocations}{0}
\newcounter{lotPrints}        \setcounter{lotPrints}{0}
\let\oldlistoftables\listoftables

\newcommand\killlistoftables{%
  \def\oldlistoftables {}%
  \renewcommand\listoftables{}%
}

\newcommand\holdlistoftables{%
  \renewcommand\listoftables{\addtocounter{lotInvocations}{1}}%
}

\newcommand\clearlistoftables{%
  \whiledo{\arabic{lotPrints} < \arabic{lotInvocations}}{%
    \addtocounter{lotPrints}{1}%
    \oldlistoftables%
  }%
}

%% \hyperactive PROVIDES A CORRECTIVE CAPTION SHIFT WHEN USING THE
%% hyperref PACKAGE; OPTIONAL ARGUMENT IS SHIFT LENGTH
\let\bx@caption\caption
\newlength\hyper@shift
\newcommand\hyper@cap[1]{\caption{\vspace*{\hyper@shift}#1}}%
\newcommand\hyperactive[1][-1.55ex]{%
  \setlength\hyper@shift{#1}\let\bx@caption\hyper@cap}

%% TO RETAIN BACKWARD COMPATIBILITY WITH THE PREDECESSOR TO boxhandler,
%% THE FOLLOWING ASSIGNMENTS ARE MADE.
\let\arltable\bxtable
\let\arlfigure\bxfigure

\endinput
%%
%% End of file `boxhandler.sty'.
