%%
%% This is file `longfigure.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% longfigure.dtx  (with options: `longfigure')
%% ----------------------------------------------------------------
%% longfigure --- A LaTeX package providing a table-like environment
%%                that can display a stream of subfigures as a single
%%                figure that can be broken by T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emX\spacefactor \@m 's
%%                standard page-breaking algorithm.
%% 
%% E-mail: tim.arnold@sas.com
%% ----------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{longfigure}[2014/1/06 v1.0]
\ProvidesPackage{longfigure}[2014/01/06 longfigure]
\RequirePackage{xkeyval}
\newcommand*{\LFcounter}{figure}
\newcommand*{\LFreset}{\@empty}
\DeclareOptionX{figname}[figure]{\renewcommand*{\LFcounter}{#1}}
\DeclareOptionX{resetby}{\renewcommand*{\LFreset}{#1}}
\DeclareOptionX{set}{}
\DeclareOptionX{final}{}
\DeclareOptionX{errorshow}{\def\LF@warn{\PackageInfo{longfigure}}}
\DeclareOptionX{pausing}{\def\LF@warn#1{\LF@err{#1}{This is not really an error}}}
\ProcessOptionsX
\def\LFProcessOptions#1{
  \@ifundefined{c@#1}{%
      \RequirePackage{tocloft}
      \def\LFuc##1##2{\MakeUppercase{##1}{##2}}
      \expandafter\def\csname list#1name\endcsname{List of \LFuc#1s}
      \ifx\@empty\LFreset%
        \newlistof{#1}{lft}{\csname list#1name\endcsname}
      \else
        \newlistof[\LFreset]{#1}{lft}{\csname list#1name\endcsname}
      \fi
  }{}%
}
\expandafter\LFProcessOptions\expandafter{\LFcounter}
\newif\ifLF@same
\newcommand{\strcfstr}[2]{%
  \LF@samefalse
  \begingroup\def\2{#2}
    \ifx\2#1\endgroup\LF@sametrue
    \else\endgroup
    \fi
}
\def\LFupcase#1{%
  \def\x##1##2{%
    \MakeUppercase{##1}{##2}}\x#1%
}
\def\LF@name{\expandafter\LFupcase%
             \expandafter{\LFcounter}~%
             \expandafter\csname the\LFcounter\endcsname}%
\def\LF@err{\PackageError{longfigure}}
\def\LF@warn{\PackageWarning{longfigure}}
\def\LF@final@warn{%
  \AtEndDocument{%
    \LF@warn{\LFcounter \@width s have changed. Rerun \LaTeX\.\@gobbletwo}}%
  \global\let\LF@final@warn\relax}
\newskip\LFleft       \LFleft=\fill
\newskip\LFright      \LFright=\fill
\newskip\LFpre        \LFpre=\bigskipamount
\newskip\LFpost       \LFpost=\bigskipamount
\newcount\LFchunksize \LFchunksize=20
\let\c@LFchunksize\LFchunksize
\newdimen\LFcapwidth  \LFcapwidth=4in
\newbox\LF@head
\newbox\LF@firsthead
\newbox\LF@foot
\newbox\LF@lastfoot
\newcount\LF@cols
\newcount\LF@rows
\newcounter{LF@tables}
\newcounter{LF@chunks}[LF@tables]
\newtoks\LF@p@ftn
\mathchardef\LF@end@pen=30000
\def\longfigure{%
  \par
  \ifx\multicols\@undefined
  \else
     \ifnum\col@number>\@ne
       \@twocolumntrue
     \fi
  \fi
  \if@twocolumn
    \LF@err{longfigure not in 1-column mode}\@ehc
  \fi
  \begingroup
  \@ifnextchar[\LF@array{\LF@array[x]}}
\def\LF@array[#1]#2{%
  \refstepcounter{\LFcounter}\stepcounter{LF@tables}%
  \if l#1%
    \LFleft\z@ \LFright\fill
  \else\if r#1%
    \LFleft\fill \LFright\z@
  \else\if c#1%
    \LFleft\fill \LFright\fill
  \fi\fi\fi
  \let\LF@mcol\multicolumn
  \let\LF@@tabarray\@tabarray
  \let\LF@@hl\hline
  \def\@tabarray{%
    \let\hline\LF@@hl
    \LF@@tabarray}%
  \let\\\LF@tabularcr\let\tabularnewline\\%
  \def\newpage{\noalign{\break}}%
  \def\pagebreak{\noalign{\ifnum`}=0\fi\@testopt{\LF@no@pgbk-}4}%
  \def\nopagebreak{\noalign{\ifnum`}=0\fi\@testopt\LF@no@pgbk4}%
  \let\hline\LF@hline \let\kill\LF@kill\let\caption\LF@caption
  \@tempdima\ht\strutbox
  \let\@endpbox\LF@endpbox
  \ifx\extrarowheight\@undefined
    \let\@acol\@tabacol
    \let\@classz\@tabclassz \let\@classiv\@tabclassiv
    \def\@startpbox{\vtop\LF@startpbox}%
    \let\@@startpbox\@startpbox
    \let\@@endpbox\@endpbox
    \let\LF@LL@FM@cr\@tabularcr
  \else
    \advance\@tempdima\extrarowheight
    \col@sep\tabcolsep
    \let\@startpbox\LF@startpbox\let\LF@LL@FM@cr\@arraycr
  \fi
  \setbox\@arstrutbox\hbox{\vrule
    \@height \arraystretch \@tempdima
    \@depth \arraystretch \dp \strutbox
    \@width \z@}%
  \let\@sharp##\let\protect\relax
   \begingroup
    \@mkpream{#2}%
    \xdef\LF@bchunk{%
       \global\advance\c@LF@chunks\@ne
       \global\LF@rows\z@\setbox\z@\vbox\bgroup
       \LF@setprevdepth
       \tabskip\LFleft \noexpand\halign to\hsize\bgroup
      \tabskip\z@ \@arstrut \@preamble \tabskip\LFright \cr}%
  \endgroup
  \expandafter\LF@nofcols\LF@bchunk&\LF@nofcols
  \LF@make@row
  \m@th\let\par\@empty
  \everycr{}\lineskip\z@\baselineskip\z@
  \LF@bchunk}
\def\LF@no@pgbk#1[#2]{\penalty #1\@getpen{#2}\ifnum`{=0\fi}}
\def\LF@start{%
  \let\LF@start\endgraf
  \endgraf\penalty\z@\vskip\LFpre
  \dimen@\pagetotal
  \advance\dimen@ \ht\ifvoid\LF@firsthead\LF@head\else\LF@firsthead\fi
  \advance\dimen@ \dp\ifvoid\LF@firsthead\LF@head\else\LF@firsthead\fi
  \advance\dimen@ \ht\LF@foot
  \dimen@ii\vfuzz
  \vfuzz\maxdimen
    \setbox\tw@\copy\z@
    \setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
    \setbox\tw@\vbox{\unvbox\tw@}%
  \vfuzz\dimen@ii
  \advance\dimen@ \ht
        \ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
  \advance\dimen@\dp
        \ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
  \advance\dimen@ -\pagegoal
  \ifdim \dimen@>\z@\vfil\break\fi
      \global\@colroom\@colht
  \ifvoid\LF@foot\else
    \advance\vsize-\ht\LF@foot
    \global\advance\@colroom-\ht\LF@foot
    \dimen@\pagegoal\advance\dimen@-\ht\LF@foot\pagegoal\dimen@
    \maxdepth\z@
  \fi
  \ifvoid\LF@firsthead\copy\LF@head\else\box\LF@firsthead\fi\nobreak
  \output{\LF@output}}
\def\endlongfigure{%
  \crcr
  \noalign{%
    \let\LF@entry\LF@entry@chop
    \xdef\LF@save@row{\LF@save@row}}%
  \LF@echunk
  \LF@start
  \unvbox\z@
  \LF@get@widths
  \if@filesw
    {\let\LF@entry\LF@entry@write\immediate\write\@auxout{%
      \gdef\expandafter\noexpand
        \csname LF@\romannumeral\c@LF@tables\endcsname
          {\LF@save@row}}}%
  \fi
  \ifx\LF@save@row\LF@@save@row
  \else
    \LF@warn{Column \@width s have changed\MessageBreak
             in table \thetable}%
    \LF@final@warn
  \fi
  \endgraf\penalty -\LF@end@pen
  \endgroup
  \global\@mparbottom\z@
  \pagegoal\vsize
  \endgraf\penalty\z@\addvspace\LFpost
  \ifvoid\footins\else\insert\footins{}\fi}
\def\LF@nofcols#1&{%
  \futurelet\@let@token\LF@n@fcols}
\def\LF@n@fcols{%
  \advance\LF@cols\@ne
  \ifx\@let@token\LF@nofcols
    \expandafter\@gobble
  \else
    \expandafter\LF@nofcols
  \fi}
\def\LF@tabularcr{%
  \relax\iffalse{\fi\ifnum0=`}\fi
  \@ifstar
    {\def\crcr{\LF@crcr\noalign{\nobreak}}\let\cr\crcr
     \LF@t@bularcr}%
    {\LF@t@bularcr}}
\let\LF@crcr\crcr
\let\LF@setprevdepth\relax
\def\LF@t@bularcr{%
  \global\advance\LF@rows\@ne
  \ifnum\LF@rows=\LFchunksize
    \gdef\LF@setprevdepth{%
      \prevdepth\z@\global
      \global\let\LF@setprevdepth\relax}%
    \expandafter\LF@xtabularcr
  \else
    \ifnum0=`{}\fi
    \expandafter\LF@LL@FM@cr
  \fi}
\def\LF@xtabularcr{%
  \@ifnextchar[\LF@argtabularcr\LF@ntabularcr}
\def\LF@ntabularcr{%
  \ifnum0=`{}\fi
  \LF@echunk
  \LF@start
  \unvbox\z@
  \LF@get@widths
  \LF@bchunk}
\def\LF@argtabularcr[#1]{%
  \ifnum0=`{}\fi
  \ifdim #1>\z@
    \unskip\@xargarraycr{#1}%
  \else
    \@yargarraycr{#1}%
  \fi
  \LF@echunk
  \LF@start
  \unvbox\z@
  \LF@get@widths
  \LF@bchunk}
\def\LF@echunk{%
  \crcr\LF@save@row\cr\egroup
  \global\setbox\@ne\lastbox
    \unskip
  \egroup}
\def\LF@entry#1#2{%
  \ifhmode\@firstofone{&}\fi\omit
  \ifnum#1=\c@LF@chunks
  \else
    \kern#2\relax
  \fi}
\def\LF@entry@chop#1#2{%
  \noexpand\LF@entry
    {\ifnum#1>\c@LF@chunks
       1}{0pt%
     \else
       #1}{#2%
     \fi}}
\def\LF@entry@write{%
  \noexpand\LF@entry^^J%
  \@spaces}
\def\LF@kill{%
  \LF@echunk
  \LF@get@widths
  \expandafter\LF@rebox\LF@bchunk}
\def\LF@rebox#1\bgroup{%
  #1\bgroup
  \unvbox\z@
  \unskip
  \setbox\z@\lastbox}
\def\LF@blank@row{%
  \xdef\LF@save@row{\expandafter\LF@build@blank
    \romannumeral\number\LF@cols 001 }}
\def\LF@build@blank#1{%
  \if#1m%
    \noexpand\LF@entry{1}{0pt}%
    \expandafter\LF@build@blank
  \fi}
\def\LF@make@row{%
  \global\expandafter\let\expandafter\LF@save@row
    \csname LF@\romannumeral\c@LF@tables\endcsname
  \ifx\LF@save@row\relax
    \LF@blank@row
  \else
    {\let\LF@entry\or
     \if!%
         \ifcase\expandafter\expandafter\expandafter\LF@cols
         \expandafter\@gobble\LF@save@row
         \or
         \else
           \relax
         \fi
        !%
     \else
       \aftergroup\LF@blank@row
     \fi}%
  \fi}
\let\setlongfigures\relax
\def\LF@get@widths{%
  \setbox\tw@\hbox{%
    \unhbox\@ne
    \let\LF@old@row\LF@save@row
    \global\let\LF@save@row\@empty
    \count@\LF@cols
    \loop
      \unskip
      \setbox\tw@\lastbox
    \ifhbox\tw@
      \LF@def@row
      \advance\count@\m@ne
    \repeat}%
  \ifx\LF@@save@row\@undefined
    \let\LF@@save@row\LF@save@row
  \fi}
\def\LF@def@row{%
  \let\LF@entry\or
  \edef\@tempa{%
    \ifcase\expandafter\count@\LF@old@row
    \else
      {1}{0pt}%
    \fi}%
  \let\LF@entry\relax
  \xdef\LF@save@row{%
    \LF@entry
    \expandafter\LF@max@sel\@tempa
    \LF@save@row}}
\def\LF@max@sel#1#2{%
  {\ifdim#2=\wd\tw@
     #1%
   \else
     \number\c@LF@chunks
   \fi}%
  {\the\wd\tw@}}
\def\LF@hline{%
  \noalign{\ifnum0=`}\fi
    \penalty\@M
    \futurelet\@let@token\LF@@hline}
\def\LF@@hline{%
  \ifx\@let@token\hline
    \global\let\@gtempa\@gobble
    \gdef\LF@sep{\penalty-\@medpenalty\vskip\doublerulesep}%
  \else
    \global\let\@gtempa\@empty
    \gdef\LF@sep{\penalty-\@lowpenalty\vskip-\arrayrulewidth}%
  \fi
  \ifnum0=`{\fi}%
  \multispan\LF@cols
     \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
  \noalign{\LF@sep}%
  \multispan\LF@cols
     \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
  \noalign{\penalty\@M}%
  \@gtempa}
\def\LF@caption{%
  \noalign\bgroup
    \@ifnextchar[{\egroup\LF@c@ption\@firstofone}\LF@capti@n}
\def\LF@c@ption#1[#2]#3{%
  \LF@makecaption#1\LF@name{#3}%
  \def\@tempa{#2}%
  \ifx\@tempa\@empty\else
     {\let\\\space
     \strcfstr{\LFcounter}{figure}
       \ifLF@same\def\LFoutfile{lof}\else
         \strcfstr{\LFcounter}{table}
           \ifLF@same\def\LFoutfile{lot}\else
             \def\LFoutfile{lft}\fi\fi
     \addcontentsline{\LFoutfile}{\LFcounter}
     {\expandafter\protect\expandafter\numberline\expandafter%
  {\expandafter\csname the\LFcounter\endcsname}{#2}}}%
  \fi
}
\def\LF@capti@n{%
  \@ifstar
    {\egroup\LF@c@ption\@gobble[]}%
    {\egroup\@xdblarg{\LF@c@ption\@firstofone}}}
\def\LF@makecaption#1#2#3{%
  \LF@mcol\LF@cols c{\hbox to\z@{\hss\parbox[t]\LFcapwidth{%
    \sbox\@tempboxa{#1{#2: }#3}%
    \ifdim\wd\@tempboxa>\hsize
      #1{#2: }#3%
    \else
      \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
    \fi
    \endgraf\vskip\baselineskip}%
  \hss}}}
\def\LF@output{%
  \ifnum\outputpenalty <-\@Mi
    \ifnum\outputpenalty > -\LF@end@pen
      \LF@err{floats and marginpars not allowed in a longfigure}\@ehc
    \else
      \setbox\z@\vbox{\unvbox\@cclv}%
      \ifdim \ht\LF@lastfoot>\ht\LF@foot
        \dimen@\pagegoal
        \advance\dimen@-\ht\LF@lastfoot
        \ifdim\dimen@<\ht\z@
          \setbox\@cclv\vbox{\unvbox\z@\copy\LF@foot\vss}%
          \@makecol
          \@outputpage
          \setbox\z@\vbox{\box\LF@head}%
        \fi
      \fi
      \global\@colroom\@colht
      \global\vsize\@colht
      \vbox
        {\unvbox\z@\box\ifvoid\LF@lastfoot\LF@foot\else
         \LF@lastfoot\fi}%
    \fi
  \else
    \setbox\@cclv\vbox{\unvbox\@cclv\copy\LF@foot\vss}%
    \@makecol
    \@outputpage
      \global\vsize\@colroom
    \copy\LF@head\nobreak
  \fi}
\def\LF@end@hd@ft#1{%
  \LF@echunk
  \ifx\LF@start\endgraf
    \LF@err
     {Longfigure head or foot not at start of table}%
     {Increase LFchunksize}%
  \fi
  \setbox#1\box\z@
  \LF@get@widths
  \LF@bchunk}
\def\endLFfirsthead{\LF@end@hd@ft\LF@firsthead}
\def\endLFhead{\LF@end@hd@ft\LF@head}
\def\endLFfoot{\LF@end@hd@ft\LF@foot}
\def\endLFlastfoot{\LF@end@hd@ft\LF@lastfoot}
 %
\def\LF@startpbox#1{%
  \bgroup
    \let\@footnotetext\LF@p@ftntext
    \setlength\hsize{#1}%
    \@arrayparboxrestore
    \vrule \@height \ht\@arstrutbox \@width \z@}
\def\LF@endpbox{%
  \@finalstrut\@arstrutbox
  \egroup
  \the\LF@p@ftn
  \global\LF@p@ftn{}%
  \hfil}
\def\LF@p@ftntext#1{%
  \edef\@tempa{\the\LF@p@ftn\noexpand\footnotetext[\the\c@footnote]}%
  \global\LF@p@ftn\expandafter{\@tempa{#1}}}%
%% Copyright (C) 2014 by SAS Institute Inc. <tim.arnold@sas.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
%% version 1.3c of this license or any later version.
%% The latest version of this license is in the file:
%% http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%% Tim Arnold.
%% 
%% This work consists of the file longfigure.dtx
%% and the derived files:
%%    README (this file)
%%    longfigure.ins
%%    longfigure.pdf
%%    longfigure.sty
%%
%% End of file `longfigure.sty'.
