\catcode`\@=11
\long\def\islandpairdata#1#2{{\data@true
 \place@true
 #1%
 \global\setbox\islandboxi\box\islandbox@
 \global\setbox\captionboxi\box\Captionbox@
 #2%
 \global\setbox\islandboxii\box\islandbox@
 \global\setbox\captionboxii\box\Captionbox@
 }}
\long\def\islandpairbox#1#2{\islandpairdata{#1}{#2}%
 \dimen@\ht\captionboxi
 \ifdim\ht\captionboxii>\dimen@\dimen@\ht\captionboxii\fi
 \ifdim\dimen@>\z@
  \ifdim\ht\captionboxi<\dimen@
   \global\setbox\captionboxi\vbox to\dimen@{\unvbox\captionboxi\vfil}\fi
  \ifdim\ht\captionboxii<\dimen@
   \global\setbox\captionboxii\vbox to\dimen@{\unvbox\captionboxii\vfil}\fi
 \fi
 \global\setbox\islandbox@\vbox
 {\hbox to\hsize{\hfil\box\islandboxi\hfil\box\islandboxii\hfil}%
 \ifdim\dimen@>\z@\nointerlineskip
 {\rm\global\skipi@\dp\strutbox}\global\advance\skipi@\medskipamount
  \vskip\skipi@
  \hbox to\hsize{\hfil\box\captionboxi\hfil\box\captionboxii\hfil}\fi}}	
\long\def\islandpairboxa#1#2{\islandpairdata{#1}{#2}%
 \dimen@\ht\captionboxi
 \ifdim\ht\captionboxii>\dimen@\dimen@\ht\captionboxii\fi
 \ifdim\dimen@>\z@
  \ifdim\ht\captionboxi<\dimen@
   \global\setbox\captionboxi\vbox to\dimen@{\vfil\unvbox\captionboxi}\fi
  \ifdim\ht\captionboxii<\dimen@
   \global\setbox\captionboxii\vbox to\dimen@{\vfil\unvbox\captionboxii}\fi
 \fi
 \dimen@ii\ht\islandboxi
 \ifdim\ht\islandboxii>\dimen@ii \dimen@ii\ht\islandboxii\fi
 \ifdim\dimen@ii>\z@
  \ifdim\ht\islandboxi<\dimen@ii
   \global\setbox\islandboxi\vbox to\dimen@ii{\box\islandboxi\vfil}\fi
  \ifdim\ht\islandboxii<\dimen@ii
   \global\setbox\islandboxii\vbox to\dimen@ii{\box\islandboxii\vfil}\fi
 \fi
 \global\setbox\islandbox@\vbox{\ifdim\dimen@>\z@
  \hbox to\hsize{\hfil\box\captionboxi\hfil\box\captionboxii\hfil}%
  \nointerlineskip{\rm\global\skipi@-\dp\strutbox}%
  \global\advance\skipi@\bigskipamount\vskip\skipi@\fi
  \hbox to\hsize{\hfil\box\islandboxi\hfil\box\islandboxii\hfil}}}
\long\def\islandtripledata#1#2#3{{\data@true\place@true
 #1%
 \global\setbox\islandboxi\box\islandbox@
 \global\setbox\captionboxi\box\Captionbox@
 #2%
 \global\setbox\islandboxii\box\islandbox@
 \global\setbox\captionboxii\box\Captionbox@
 #3%
 \global\setbox\islandboxiii\box\islandbox@
 \global\setbox\captionboxiii\box\Captionbox@
 }}
\long\def\islandtriplebox#1#2#3{\islandtripledata{#1}{#2}{#3}%
 \dimen@\ht\captionboxi
 \ifdim\ht\captionboxii>\dimen@ \dimen@\ht\captionboxii\fi
 \ifdim\ht\captionboxiii>\dimen@ \dimen@\ht\captionboxiii\fi
 \ifdim\dimen@>\z@
  \ifdim\ht\captionboxi<\dimen@
   \global\setbox\captionboxi\vbox to\dimen@{\unvbox\captionboxi\vfil}\fi
  \ifdim\ht\captionboxii<\dimen@
   \global\setbox\captionboxii\vbox to\dimen@{\unvbox\captionboxii\vfil}\fi
  \ifdim\ht\captionboxiii<\dimen@
   \global\setbox\captionboxiii\vbox to\dimen@{\unvbox\captionboxiii\vfil}\fi
 \fi
 \global\setbox\islandbox@\vbox
  {\hbox to\hsize{\hfil\box\islandboxi\hfil\box\islandboxii\hfil
   \box\islandboxiii\hfil}%
 \ifdim\dimen@>\z@\nointerlineskip
  {\rm\global\skipi@\dp\strutbox}\global\advance\skipi@\medskipamount
  \vskip\skipi@
  \hbox to\hsize{\hfil\box\captionboxi\hfil\box\captionboxii\hfil
   \box\captionboxiii\hfil}\fi}}
\def\islandtripleboxa#1#2#3{\islandtripledata{#1}{#2}{#3}%
 \dimen@\ht\captionboxi
 \ifdim\ht\captionboxii>\dimen@ \dimen@\ht\captionboxii\fi
 \ifdim\ht\captionboxiii>\dimen@ \dimen@\ht\captionboxiii\fi
 \ifdim\dimen@>\z@
  \ifdim\ht\captionboxi<\dimen@
   \global\setbox\captionboxi\vbox to\dimen@{\vfil\unvbox\captionboxi}\fi
  \ifdim\ht\captionboxii<\dimen@
   \global\setbox\captionboxii\vbox to\dimen@{\vfil\unvbox\captionboxii}\fi
  \ifdim\ht\captionboxiii<\dimen@
   \global\setbox\captionboxiii\vbox to\dimen@{\vfil\unvbox\captionboxiii}\fi
 \fi
 \dimen@ii\ht\islandboxi
 \ifdim\ht\islandboxii>\dimen@ii \dimen@ii\ht\islandboxii\fi
 \ifdim\ht\islandboxiii>\dimen@ii \dimen@ii\ht\islandboxiii\fi
 \ifdim\dimen@ii>\z@
  \ifdim\ht\islandboxi<\dimen@ii
   \global\setbox\islandboxi\vbox to\dimen@ii{\box\islandboxi\vfil}\fi
  \ifdim\ht\islandboxii<\dimen@ii
   \global\setbox\islandboxii\vbox to\dimen@ii{\box\islandboxii\vfil}\fi
  \ifdim\ht\islandboxiii<\dimen@ii
   \global\setbox\islandboxiii\vbox to\dimen@ii{\box\islandboxiii\vfil}\fi
 \fi
 \global\setbox\islandbox@\vbox
  {\ifdim\dimen@>\z@
  \hbox to\hsize{\hfil\box\captionboxi\hfil\box\captionboxii\hfil
   \box\captionboxiii\hfil}%
  \nointerlineskip{\rm\global\skipi@-\dp\strutbox}%
  \global\advance\skipi@\bigskipamount\vskip\skipi@\fi
  \hbox to\hsize{\hfil\box\islandboxi\hfil\box\islandboxii\hfil
   \box\islandboxiii\hfil}}}
\def\Figurepair#1\and#2\endFigurepair{\island@true
 \islandpairbox{\Figure#1\endFigure}{\Figure#2\endFigure}}
\def\Figuretriple#1\and#2\and#3\endFiguretriple{\island@true
 \islandtriplebox{\Figure#1\endFigure}{\Figure#2\endFigure}%
  {\Figure#3\endFigure}}
\def\Tablepair#1\and#2\endTablepair{\island@true
 \islandpairboxa{\Table#1\endTable}{\Table#2\endTable}}
\def\Tabletriple#1\and#2\and#3\endTabletriple{\island@true
 \islandtripleboxa{\Table#1\endTable}{\Table#2\endTable}%
 {\Table#3\endTable}}
\def\Par{\par\global\csname Parprev1\endcsname\prevdepth
 \global\Parcount@\@ne
 \global\Par@true\global\let\Parlist@\empty
 \global\setbox\Parbox@\vbox\bgroup\break}
\long\def\AAplace#1{\prevanish@\place@true\island@false
 #1%
 \place@ A\AAplace@
 \postvanish@}
\def\AAplace@{\AA@true\Aplace@\AA@false}
\long\def\Bplace#1{\prevanish@\place@true\island@false
 #1%
 \place@ b\Bplace@
 \postvanish@}
\def\Bplace@{\allowbreak
 \ifnum\topinscount@=\z@
  \setbox\z@\vbox{\vbox to-\belowtopfigskip{}}%
  \dimen@-\skip\topins
  \ht\z@\dimen@
  \storedim@
  \advancedimtopins@
  \insert\topins{\boxz@}%
  \global\advance\topinscount@\@ne
  \xdef\AAlist@{\AAlist@0}%
 \fi
 \dimen@\ht\islandbox@
 \advance\dimen@\abovebotfigskip
 \ht\islandbox@\dimen@
 \advance\dimen@\dp\islandbox@
 \storedim@
 \xdef\AAlist@{\AAlist@0}%
 \ifnum\topinscount@>\@ne\else\advancedimtopins@\fi
 \insert\topins{\penalty\z@\splittopskip\z@
  \floatingpenalty\z@
  \box\islandbox@}%
 \global\advance\topinscount@\@ne}
\def\Place@#1#2{%
 \ifisland@
  \ifhmode
   \ifPar@
    \ifnum\Parcount@>5
     \Err@{Only 5 \string\place's allowed per
       \string\Par...\noexpand\endPar paragraph}%
    \else
     \expandafter\expandafter\expandafter\global\expandafter\setbox
      \csname Parfigbox\number\Parcount@\endcsname\box\islandbox@
     \global\advance\Parcount@\@ne
     \xdef\Parlist@{\Parlist@#1}%
     \vadjust{\break}%
    \fi
   \else
    \Err@{\noexpand#2allowed only in a \string\Par...\noexpand\endPar
     paragraph}%
   \fi
  \else
   #2%
  \fi
 \else
  \Err@{Who ... there's no \string\Figure, \string\Table,
   etc., here}%
 \fi
 \place@false}
\long\def\Cplace#1{\prevanish@\place@true\island@false
 #1%
 \Place@ c\Cplace@
 \postvanish@}
\def\Cplace@{\allowbreak
 \ifnum\topinscount@>\z@\else
  \global\C@true\global\Cdim@\pagetotal\fi
 \Aplace@}
\long\def\Mplace#1{\prevanish@\place@true\island@false
 #1%
 \Place@ m\Mplace@
 \postvanish@}
\long\def\MXplace#1{\prevanish@\place@true\island@false
 #1%
 \Place@ M\MXplace@
 \postvanish@}
\def\MXplace@{\MX@true\Mplace@\MX@false}
\def\Mplace@{\allowbreak
 \dimen@\ht\islandbox@\advance\dimen@\dp\islandbox@
 \ifdim\pagetotal=\z@\else
  \ifdim\lastskip<\abovebotfigskip\advance\dimen@\abovebotfigskip
  \advance\dimen@-\lastskip\fi
 \fi
 \advance\dimen@\pagetotal
 \ifdim\dimen@>\pagegoal
  \Aplace@
 \else
  \nointerlineskip
  \ifdim\lastskip<\abovebotfigskip\removelastskip\vskip\abovebotfigskip\fi
  \setbox\z@\vbox{\unvbox\islandbox@
   \breakisland@}%
  \printisland@
  \ifnum\topinscount@=\z@
   \setbox\z@\vbox{\vbox to-\belowtopfigskip{}}%
   \dimen@-\skip\topins
   \ht\z@\dimen@
   \storedim@
   \advancedimtopins@
   \insert\topins{\boxz@}%
   \global\advance\topinscount@\@ne
   \xdef\AAlist@{\AAlist@0}%
  \fi
  \ifMX@
   \ifnum\topinscount@=\@ne
    \setbox\z@\vbox{\vbox to-\abovebotfigskip{}}%
    \ht\z@\z@
    \dimen@\z@
    \storedim@
    \advancedimtopins@
    \insert\topins{\boxz@}%
    \global\advance\topinscount@\@ne
    \xdef\AAlist@{\AAlist@0}%
   \fi
  \fi
  \nointerlineskip
  \vskip\belowtopfigskip
 \fi}
\def\endPar{\egroup
 \count@\@ne
 {\vbadness\@M\vfuzz\maxdimen\splitmaxdepth\maxdimen\splittopskip\ht\strutbox
 \setbox\z@\vsplit\Parbox@ to\ht\Parbox@
 \loop
  \ifnum\count@<\Parcount@
  \expandafter\expandafter\expandafter\global\expandafter\setbox
   \csname Parbox\number\count@\endcsname\vsplit\Parbox@ to\ht\Parbox@
  \count@@\count@\advance\count@@\@ne
  \global\csname Parprev\number\count@@\endcsname
   \dp\csname Parbox\number\count@\endcsname
  \advance\count@\@ne
  \repeat}%
 \vskip\parskip
 \count@\@ne
 \def\nextv@##1##2\nextv@{\DN@{##1}\gdef\Parlist@{##2}}%
 \loop
  \ifnum\count@<\Parcount@
   \dimen@\csname Parprev\number\count@\endcsname
   \advance\dimen@\ht\strutbox
   \ifdim\dimen@<\baselineskip
    \advance\dimen@-\baselineskip\vskip-\dimen@
   \else
    \vskip\lineskip
   \fi
   \unvbox\csname Parbox\number\count@\endcsname
   \global\setbox\islandbox@\box\csname Parfigbox\number\count@\endcsname
   \expandafter\nextv@\Parlist@\nextv@
   \if a\next@\Aplace@\else
   \if A\next@\AAplace@\else
   \if b\next@\Bplace@\else
   \if c\next@\Cplace@\else
   \if m\next@\Mplace@\else
   \if M\next@\MXplace@\fi\fi\fi\fi\fi\fi
  \advance\count@\@ne
  \repeat
 \global\Par@false
 \ifvoid\Parbox@
  \prevdepth\csname Parprev\number\count@\endcsname
 \else
  \dimen@\csname Parprev\number\count@\endcsname\advance\dimen@\ht\strutbox
  \ifdim\dimen@<\baselineskip
    \advance\dimen@-\baselineskip\vskip-\dimen@
  \else
    \vskip\lineskip
  \fi
  \dimen@\dp\Parbox@
  \unvbox\Parbox@
  \prevdepth\dimen@
 \fi}
\catcode`\@=\active
