%RCS: $Id: //TEI/web/Software/passivetex/fotex.sty#29 $, $Date: 2002/06/26 $
%
% Copyright 2002 Sebastian Rahtz/Oxford University  
%      <sebastian.rahtz@oucs.ox.ac.uk>
%
% Permission is hereby granted, free of charge, to any person obtaining
% a copy of this software and any associated documentation files (the
% ``Software''), to deal in the Software without restriction, including
% without limitation the rights to use, copy, modify, merge, publish,
% distribute, sublicense, and/or sell copies of the Software, and to
% permit persons to whom the Software is furnished to do so, subject to
% the following conditions:
% 
% The above copyright notice and this permission notice shall be included
% in all copies or substantial portions of the Software.
%
% Includes fixes from Tomas Bures <ghort@pauline.vellum.cz>
%
\ProvidesPackage{fotex}[2002/06/25: version 1.17. support for XSL formatting, S Rahtz]
\RequirePackage{graphicx}
\IfFileExists{multicol.sty}
  {\RequirePackage{multicol}[1997/12/16]}
  {\newenvironment{multicols}[1]%
  {\typeout{Warning,  at line \the\inputlineno, multicol package not available}}{}%
}
\RequirePackage{rotating}
\RequirePackage{array}
\gdef\arraybackslash{\let\\=\@arraycr}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{P}[1]{>{\arraybackslash}p{#1}}
\RequirePackage{amsmath}
\let\Vec\undefined
\RequirePackage{longtable}
\RequirePackage{url}
\RequirePackage[normalem]{ulem}
\RequirePackage{color}
\RequirePackage{times}
\RequirePackage{mlnames}
\RequirePackage{unicode}
\RequirePackage{marvosym}
\RequirePackage{ucharacters}
%\usepackage{ucs}\usepackage[utf8]{inputenc}
\RequirePackage{nameref}
\RequirePackage[colorlinks=false,plainpages=true,hypertexnames=false,pdfborder={1 0 0}]{hyperref}[1999/08/1]
%-------------------------------------------
\newcount\FOListBlocks
\newcount\FOTableNesting
\newcount\FOinList
\newcount\FOinTable
\newcount\NCols
\newcount\RowCount
\newdimen\CurrentCellWidth
\newdimen\FObalancespace
\newdimen\FOspaceleft
\newdimen\MasterBottomMargin
\newdimen\MasterLeftMargin
\newdimen\MasterRightMargin
\newdimen\MasterTopMargin
\newdimen\NoTableCellHeight
\newdimen\TableWidth
\newdimen\XFOendindent
\newdimen\XFOstartindent
\newdimen\bottommargin
\newdimen\FOtempdim
\newif\ifFOBlockGrab
\newif\ifFODebug
\newif\ifFODefiningPage
\newif\ifFOFirstCell
\newif\ifFOListBody
\newif\ifFOListInnerPar
\newif\ifFOSub
\newif\ifFOSuper
\newif\ifFOinLayout
\newif\ifFOinOutput
\newif\ifMulticolPending
\newif\ifNoTableCheckHeight
\newif\ifStartWithOmit
\newsavebox\BlockBox
\newsavebox\CellBox
\newsavebox\FOBOX
\newsavebox\ItemBox
\newtoks\ColSpecs
%
\FODebugfalse
\FOBlockGrabfalse
\FODefiningPagefalse
\FOListBodyfalse
\FOListInnerParfalse
\FOinLayoutfalse
\FOinList0
\FOinOutputfalse
\FOTableNesting0
\FOinTable0
\MasterBottomMargin\z@
\MasterLeftMargin\z@
\MasterRightMargin\z@
\MasterTopMargin\z@
\MulticolPendingfalse
\StartWithOmitfalse
\def\DEBUG#1{%
 \ifFODebug
   \typeout{#1, at \the\inputlineno}%
 \fi
}
\def\expandFont#1 #2 #3\\{%
 \typeout{FONT expanding to #1 / #2 / #3}%
}
\def\expandBorder#1 #2 #3\\{%
    \def\FOborderstartcolor{#3}%
    \def\FOborderendcolor{#3}%
    \def\FOborderbeforecolor{#3}%
    \def\FOborderaftercolor{#3}%
    \def\FOborderstartwidth{#1}%
    \def\FOborderendwidth{#1}%
    \def\FOborderbeforewidth{#1}%
    \def\FOborderafterwidth{#1}%
    \def\FOborderstartstyle{#2}%
    \def\FOborderendstyle{#2}%
    \def\FOborderbeforestyle{#2}%
    \def\FOborderafterstyle{#2}%
}
\def\FOexpandattributes{%
%
% links
\ifx\FObordertopstyle\LINK\else\let\FOborderbeforestyle\FObordertopstyle\fi
\ifx\FOborderbottomstyle\LINK\else\let\FOborderafterstyle\FOborderbottomstyle\fi
\ifx\FOborderrightstyle\LINK\else\let\FOborderendstyle\FOborderrightstyle\fi
\ifx\FOborderleftstyle\LINK\else\let\FOborderstartstyle\FOborderleftstyle\fi
\ifx\FObordertopwidth\LINK\else\let\FOborderbeforewidth\FObordertopwidth\fi
\ifx\FOborderbottomwidth\LINK\else\let\FOborderafterwidth\FOborderbottomwidth\fi
\ifx\FOborderrightwidth\LINK\else\let\FOborderendwidth\FOborderrightwidth\fi
\ifx\FOborderleftwidth\LINK\else\let\FOborderstartwidth\FOborderleftwidth\fi
\ifx\FObordertopcolor\LINK\else\let\FOborderbeforecolor\FObordertopcolor\fi
\ifx\FOborderbottomcolor\LINK\else\let\FOborderaftercolor\FOborderbottomcolor\fi
\ifx\FOborderrightcolor\LINK\else\let\FOborderendcolor\FOborderrightcolor\fi
\ifx\FOborderleftcolor\LINK\else\let\FOborderstartcolor\FOborderleftcolor\fi
% shortcuts
  \ifx\FObordercolor\att@black
  \else
    \let\FOborderstartcolor\FObordercolor
    \let\FOborderendcolor\FObordercolor
    \let\FOborderbeforecolor\FObordercolor
    \let\FOborderaftercolor\FObordercolor
  \fi  
  \ifx\FOborderwidth\@empty
  \else
    \let\FOborderstartwidth\FOborderwidth
    \let\FOborderendwidth\FOborderwidth
    \let\FOborderbeforewidth\FOborderwidth
    \let\FOborderafterwidth\FOborderwidth
  \fi  
  \ifx\FOborderstyle\@empty
  \else
    \let\FOborderstartstyle\FOborderstyle
    \let\FOborderendstyle\FOborderstyle
    \let\FOborderbeforestyle\FOborderstyle
    \let\FOborderafterstyle\FOborderstyle
  \fi  
  \ifx\FOborder\@empty
  \else
    \expandafter\expandBorder\FOborder\\{}%
  \fi
%  \ifx\FOfont\@empty
%  \else
%    \expandafter\expandFont\FOfont\relax  \\{}%
%  \fi
  \ifdim\FOpadding>\z@
    \let\FOpaddingstart\FOpadding
    \let\FOpaddingend\FOpadding
    \let\FOpaddingbefore\FOpadding
    \let\FOpaddingafter\FOpadding
  \fi  
  \ifx\FOmargin\@empty
  \else
    \let\tmpmargin\FOmargin
    \let\FOmarginleft\tmpmargin
    \let\FOmarginright\tmpmargin
    \let\FOmargintop\tmpmargin
    \let\FOmarginbottom\tmpmargin
  \fi  
% end of shortcuts
  \ifx\FOborderendstyle\att@solid
   \ifx\FOborderendwidth\att@thin\def\FOborderendwidth{0.4pt}\fi
   \ifx\FOborderendwidth\att@medium\def\FOborderendwidth{0.8pt}\fi
   \ifx\FOborderendwidth\att@thick\def\FOborderendwidth{1.2pt}\fi
   \FOBlockGrabtrue
  \else
   \def\FOborderendwidth{\z@}%
  \fi
  \ifx\FOborderstartstyle\att@solid
   \ifx\FOborderstartwidth\att@thin\def\FOborderstartwidth{0.4pt}\fi
   \ifx\FOborderstartwidth\att@medium\def\FOborderstartwidth{0.8pt}\fi
   \ifx\FOborderstartwidth\att@thick\def\FOborderstartwidth{1.2pt}\fi
   \FOBlockGrabtrue
  \else
   \def\FOborderstartwidth{\z@}%
  \fi
  \ifx\FOborderafterstyle\att@solid
   \ifx\FOborderafterwidth\att@thin\def\FOborderafterwidth{0.4pt}\fi
   \ifx\FOborderafterwidth\att@medium\def\FOborderafterwidth{0.8pt}\fi
   \ifx\FOborderafterwidth\att@thick\def\FOborderafterwidth{1.2pt}\fi
  \else
   \def\FOborderafterwidth{\z@}%
  \fi
  \ifx\FOborderbeforestyle\att@solid
   \ifx\FOborderbeforewidth\att@thin\def\FOborderbeforewidth{0.4pt}\fi
   \ifx\FOborderbeforewidth\att@medium\def\FOborderbeforewidth{0.8pt}\fi
   \ifx\FOborderbeforewidth\att@thick\def\FOborderbeforewidth{1.2pt}\fi
   \FOBlockGrabtrue
  \else
   \def\FOborderbeforewidth{\z@}%
  \fi
}
%-------------------------------------------
%
% NoTable. Making tables using fixed width cells.
% From ideas and code by C V Radhakrishnan.
%
\newcount\AbsoluteTableCount
\newcount\CellCount
\newcount\arraylength
\newcounter{ArrayIndex}%
\newcounter{zeroCtr}%
\def\DeclareArray#1{%
   \Array{#1}[0]{}%
   \expandafter\gdef\csname #1\endcsname[##1]{\csname #1##1\endcsname}%
}
\def\Array#1[#2]#3{%
  \expandafter\xdef\csname #1#2\endcsname{#3}%
}

%
\def\getArraylength#1{%
   \arraylength0
   \loop\expandafter\ifx\csname #1\the\arraylength\endcsname\relax%
   \else\advance\arraylength by1\repeat}%
%
\def\addToArray#1#2{\arraylength0%
        \loop\expandafter\ifx\csname #1\the\arraylength\endcsname\relax%
        \else\advance\arraylength by 1\repeat%
        \Array{#1}[\the\arraylength]{#2}}%
%
\def\clearArray#1{\getArraylength{#1}%
        \loop\ifnum\arraylength >0%
        \global\expandafter\let\csname #1\the\arraylength\endcsname\relax%
        \advance\arraylength by-1\repeat}%
%
\long\def\ArrayIterator#1#2{%
        \setcounter{ArrayIndex}{1}\getArraylength{#1}%
        \setcounter{zeroCtr}{\c@arraylength}%
        \loop\ifnum\c@ArrayIndex<\c@zeroCtr{#2}%
        \stepcounter{ArrayIndex}\repeat%
}%

\def\NoTableSetup{%
  \global\advance\AbsoluteTableCount by 1
  \DeclareArray{fotable\the\AbsoluteTableCount:}%
  \global\CellCount0
}

\def\NoTableStart#1{#1}

\def\NoTableEnd{\clearArray{fotable\the\AbsoluteTableCount:}}

\def\NoTableColumn{%
   \ifx\@empty\FOcolumnnumber
    \global\advance\NCols by 1
   \else
    \global\NCols\FOcolumnnumber
   \fi
   \ifx\prop@width\FOcolumnwidth\def\FOcolumnwidth{1in}\fi
   \ifx\@empty\FOcolumnwidth\def\FOcolumnwidth{1in}\fi
   \TablePercentToDimen{\FOcolumnwidth}%
   \addToArray{fotable\the\AbsoluteTableCount:}{\the\@tempdima}%
   \DEBUG{Table Column \the\NCols, in Table \the\AbsoluteTableCount, 
     \FOcolumnwidth, = \the\@tempdima}%
}
\def\NoTableRow#1{%
 \setbox0=\vbox{\strut They}%
 \NoTableCellHeight=\ht0
 \advance\NoTableCellHeight by \dp0
 \global\CellCount0
 \NoTableCheckHeightfalse
 \setbox0=\hbox{#1}%
 \@tempdima=\ht0
 \advance\@tempdima by \dp0
 \FOspaceleft=\pagegoal
 \advance\FOspaceleft by -\pagetotal
%   \DEBUG{Space check for \the\@tempdima, [\the\FOspaceleft] PageTotal [\the\pagetotal/\the\pagegoal] l.\the\inputlineno}%
 \ifdim\FOspaceleft<\@tempdima
   \DEBUG{ .. page in table break fires, l. \the\inputlineno... }%
   \clearpage
 \fi
 \ifdim\@tempdima>\NoTableCellHeight
%\typeout{row pass 2 at \the\inputlineno, as [\the\@tempdima] > [\the\NoTableCellHeight]}%
   \global\CellCount0
   \NoTableCellHeight=\@tempdima
   \NoTableCheckHeighttrue
   \vbox{\hbox{#1}}%
 \else
   \box0\relax
 \fi
 \vskip-\lineskip
}

\def\NoTableCell#1{%
 \ifx\FOstartsrow\att@true
    \vskip-\lineskip
    \global\CellCount1
 \else
    \global\advance\CellCount by 1
 \fi
 \ifnum\NCols<1
  \CurrentCellWidth\z@
  \setbox0=\hbox{#1}%
  \CurrentCellWidth=\wd0
\DEBUG{report \the\CurrentCellWidth}%
 \else
  \CurrentCellWidth=\csname fotable\the\AbsoluteTableCount:\the\CellCount\endcsname
 \fi
 \advance\CurrentCellWidth by -\FOpaddingstart
 \advance\CurrentCellWidth by -\FOpaddingend
 \ifx\FOborderstartstyle\att@solid\advance\CurrentCellWidth by -\FOborderstartwidth\fi
 \ifx\FOborderendstyle\att@solid\advance\CurrentCellWidth by -\FOborderendwidth\fi
 \advance\CurrentCellWidth by -\FOmarginright
 \advance\CurrentCellWidth by -\FOmarginleft
 \ifnum\FOnumbercolumnsspanned>1
    \@tempcnta1
    \loop\ifnum\@tempcnta<\FOnumbercolumnsspanned
        \advance\@tempcnta by 1
        \global\advance\CellCount by 1
        \advance\CurrentCellWidth\csname fotable\the\AbsoluteTableCount:\the\CellCount\endcsname
%        \typeout{add extra column \the\@tempcnta, to reach \FOnumbercolumnsspanned: \the\CurrentCellWidth}%
    \repeat
 \fi
 \ifx\XML@parent\FOTableRow
   \FOTableCellBlock#1\FOEndTableCellBlock
 \else
   \leavevmode\hbox{\FOTableCellBlock#1\FOEndTableCellBlock}%
 \fi
 \ifx\FOendsrow\att@true
    \vskip-\lineskip
    \global\CellCount0
 \fi
}

\def\FOTableCellBlock{%
 \begin{lrbox}{\CellBox}%
 \vbox\bgroup
 \hsize\the\CurrentCellWidth
 \color@begingroup
 \FOSetFont{tablecellblock}%
 \ifx\FOwhitespace\att@pre\obeyspaces\obeylines\fi
 \ifx\FOwhitespacecollapse\att@false\obeyspaces\fi
 \ifx\FOwrapoption\att@nowrap\obeylines\fi
 \ifx\TOverticalalign\att@bottom\vfill\fi
 }

\def\FOEndTableCellBlock{%
 \ifx\TOverticalalign\att@top\vfill\fi
 \color@endgroup
 \egroup
 \end{lrbox}%
 \@tempdima\FOmargintop
 \advance\@tempdima\FOpaddingbefore
 \ifx\FOborderbeforestyle\att@solid\advance\@tempdima\FOborderbeforewidth\fi
% \advance\@tempdima\dp\CellBox
%\typeout{CELL to height \the\NoTableCellHeight. Padding \FOpaddingbefore,\FOpaddingafter,\FOpaddingstart,\FOpaddingend; Border \FOborderbeforewidth,\FOborderafterwidth,\FOborderstartwidth,\FOborderendwidth; lower by \the\@tempdima; Margin \FOmargintop,\FOmarginbottom,\FOmarginleft,\FOmarginright}%
\@tempdimb\wd\CellBox
\advance\@tempdimb by \FOpaddingstart
\advance\@tempdimb by \FOpaddingend
\hbox{%
    \lower\@tempdima
     \hbox{%
      \hskip\FOmarginleft
      \vbox{%
        \vskip\FOmargintop
        \vbox{%
        \ifx\FOborderbeforestyle\att@solid
           {\color{\FOborderbeforecolor}\hrule\@height\FOborderbeforewidth}%
        \fi
        \hbox{%
          \ifx\FOborderstartstyle\att@solid
            {\color{\FOborderstartcolor}\vrule\@width\FOborderstartwidth}%
          \fi
          \ifx\FObackgroundcolor\att@transparent
          \else
           {\color{\FObackgroundcolor}\vrule\@width\@tempdimb\kern-\@tempdimb}%
          \fi
           \ifNoTableCheckHeight
% According to FOdisplayalign property, we put glue 
% before and/or after the cell contents
             \vtop to \NoTableCellHeight{%
               \vskip\FOpaddingbefore
               \ifx\FOdisplayalign\att@auto
                 \else\ifx\FOdisplayalign\att@after
                   \else\ifx\FOdisplayalign\att@before\vfil
                     \else\ifx\FOdisplayalign\att@centered\vfil\fi
                   \fi
                 \fi
               \fi
               \hbox{\kern\FOpaddingstart\box\CellBox\kern\FOpaddingend}%
               \ifx\FOdisplayalign\att@auto\vfil
                 \else\ifx\FOdisplayalign\att@after\vfil
                   \else\ifx\FOdisplayalign\att@before
                     \else\ifx\FOdisplayalign\att@centered\vfil\fi
                   \fi
                 \fi
               \fi
               \vskip\FOpaddingafter
             }%
           \else
            \vbox{%
              \vskip\FOpaddingbefore
                \hbox{\kern\FOpaddingstart\box\CellBox\kern\FOpaddingend}%
              \vskip\FOpaddingafter
              }%
           \fi
          \ifx\FOborderendstyle\att@solid
           {\color{\FOborderendcolor}\vrule\@width\FOborderendwidth}%
          \fi
        }%
        \ifx\FOborderafterstyle\att@solid
           {\color{\FOborderaftercolor}\hrule\@height\FOborderafterwidth}\fi
        }%
        \vskip\FOmarginbottom
     }%
     \hskip\FOmarginright
    }%
   }%
}

\def\FOBoxedBlock#1{%
 \ifdim\@tempdimb=\z@
    \setbox0=\hbox{#1}\@tempdimb\wd0
%\typeout{report \the\CurrentCellWidth}%
 \else
    \@tempdimb#1%
 \fi
 \advance\@tempdimb by -\FOpaddingstart
 \advance\@tempdimb by -\FOpaddingend
 \ifx\FOborderstartstyle\att@solid\advance\@tempdimb by -\FOborderstartwidth\fi
 \ifx\FOborderendstyle\att@solid\advance\@tempdimb by -\FOborderendwidth\fi
 \advance\@tempdimb by -\FOmarginright
 \advance\@tempdimb by -\FOmarginleft
 \begin{lrbox}{\BlockBox}%
 \vbox\bgroup
 \hsize\the\@tempdimb
 \FOSetFont{tableblock}%
 \color@begingroup
 \ifx\FOwhitespace\att@pre\obeyspaces\obeylines\fi
 \ifx\FOwhitespacecollapse\att@false\obeyspaces\fi
 \ifx\FOwrapoption\att@nowrap\obeylines\fi
 \parindent\FOtextindent
 \Quadding
 \strut
 }

\def\FOEndBoxedBlock{%
 \par
 \color@endgroup
 \egroup
 \end{lrbox}%
 \@tempdimb\FOmargintop
 \advance\@tempdimb\FOpaddingbefore
 \ifx\FOborderbeforestyle\att@solid\advance\@tempdimb\FOborderbeforewidth\fi
% \advance\@tempdimb by \dp\BlockBox
%\typeout{BLOCK. Padding \FOpaddingbefore,\FOpaddingafter,\FOpaddingstart,\FOpaddingend; Border \FOborderbeforewidth,\FOborderafterwidth,\FOborderstartwidth,\FOborderendwidth; lower by \the\@tempdimb, margin \FOmargintop,\FOmarginbottom,\FOmarginleft,\FOmarginright}%
\@tempdimc\wd\BlockBox
\advance\@tempdimc by \FOpaddingstart
\advance\@tempdimc by \FOpaddingend
\FOtempdim\FOmarginleft
\advance\FOtempdim by \FOtextindent
\hbox{%
    \lower\@tempdimb
     \hbox{%
      \kern\FOtempdim
      \vbox{%
        \vskip\FOmargintop
        \vbox{%
        \ifx\FOborderbeforestyle\att@solid
           {\color{\FOborderbeforecolor}\hrule\@height\FOborderbeforewidth}%
        \fi
        \hbox{%
          \ifx\FOborderstartstyle\att@solid
            {\color{\FOborderstartcolor}\vrule\@width\FOborderstartwidth}\fi
          \ifx\FObackgroundcolor\att@transparent
          \else
           {\color{\FObackgroundcolor}\vrule\@width\@tempdimc\kern-\@tempdimc}%
          \fi
            \vbox{%
              \vskip\FOpaddingbefore
               \hbox{\kern\FOpaddingstart\box\BlockBox\kern\FOpaddingend}%
              \vskip\FOpaddingafter
              }%
          \ifx\FOborderendstyle\att@solid
           {\color{\FOborderendcolor}\vrule\@width\FOborderendwidth}\fi
        }%
        \ifx\FOborderafterstyle\att@solid
           {\color{\FOborderaftercolor}\hrule\@height\FOborderafterwidth}\fi
        }%
        \vskip\FOmarginbottom
     }%
     \kern\FOmarginright
    }%
   }%
}

\def\OldTableCell#1{%
    \ifx\FOendsrow\att@true
     \gdef\w@@t{\\}%
    \else
     \gdef\w@@t{\tabcellsep}%
    \fi
    \ifx\FOstartsrow\att@true
     \gdef\w@@@t{\\}%
    \else
     \gdef\w@@@t{}%
    \fi
    \xdef\MyRows{\FOnumberrowsspanned}%
    \xdef\MyCols{\FOnumbercolumnsspanned}%
    \ifnum\MyCols>1
     \gdef\w@t{\multicolumn{\MyCols}{l}{#1}\w@@t}%
    \else
     \ifnum\MyRows>1
      \gdef\w@t{\sbox{\FOBOX}{\hbox{#1}}%
      \@tempdima\ht\FOBOX
      \advance\@tempdima by -\baselineskip
      \raisebox{-\@tempdima}[\z@][\z@]{\usebox{\FOBOX}}\w@@t}%
     \else
      \gdef\w@t{\w@@@t#1\w@@t}%
     \fi
    \fi
    \aftergroup\w@t
}
%-------------------------------------------
% utility macros
\def\protectCS#1{%
 \begingroup
       \utfeight@protect@chars
       \xdef\FOtempCS{#1}%
 \endgroup
 \let#1\FOtempCS}%
\def\GrabFileName#1:#2\@nil{%
 \DEBUG{Graphic #1 +  #2}%
 \xdef\FOsrcname{#1}%
}
\def\NColumns{1}
\def\Pass#1\\{\expandafter\@Pass#1}
\def\@Pass#1|#2|#3|#4|{%
 \columnsep=#1
 \def\NColumns{#2}%
 \def\Marginbottom{#3}%
 \def\Margintop{#4}%
 }
\def\FOfiletest#1#2#3#4#5#6#7#8\@{%
  \def\@tempa{#1#2#3#4#5#6#7}%
  \def\@tempb{#1#2#3#4#5}%
  \def\@tempc{#1#2#3#4}%
  \ifx\@tempa\file@prefix
    \xdef\FOsrcname{#8}%
  \else
   \ifx\@tempb\file@shortprefix
      \xdef\FOsrcname{#6#7#8}%
   \else
    \ifx\@tempc\file@urlprefix
      \expandafter\FOurlfiletest#5#6#7#8\@empty\@empty\@empty\@empty\@empty\@empty\@empty\@empty\@empty\@empty
    \else
      \xdef\FOsrcname{#1#2#3#4#5#6#7#8}%
    \fi
   \fi
  \fi}

\def\FOurlfiletest#1#2#3#4#5#6#7#8){%
  \def\@tempa{#1#2#3#4#5#6#7}%
  \def\@tempb{#1#2#3#4#5}%
  \ifx\file@prefix\@tempa
    \xdef\FOsrcname{#8}%
  \else
   \ifx\@tempb\file@shortprefix
      \xdef\FOsrcname{#6#7#8}%
   \else
      \xdef\FOsrcname{#1#2#3#4#5#6#7#8}%
   \fi
  \fi}
{\catcode`\%=13
\gdef\percenttest#1%#2#3\@{\ifx#2\relax\def\percentval{#1}\expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\gdef\TablePercentToDimen#1{\expandafter\percenttest#1\relax%.\@
  {\@tempdimb\percentval pt\relax\divide\@tempdimb by 100
   \edef\SCALE{\strip@pt\@tempdimb}\global\@tempdima=\SCALE\TableWidth}{\global\@tempdima#1}
}
\gdef\PercentToDimen#1{\expandafter\percenttest#1\relax%.\@
  {\@tempdimb\percentval pt\relax\divide\@tempdimb by 100
   \edef\SCALE{\strip@pt\@tempdimb}\global\@tempdima=\SCALE\hsize}{\global\@tempdima#1}
}
\gdef\FOSetGWidth{\expandafter\percenttest\FOcontentwidth\relax%.\@
  {\@tempdima\percentval pt\relax\divide\@tempdima by 100
  \edef\WSCALE{\strip@pt\@tempdima}\setkeys{Gin}{width=\WSCALE\Gin@nat@width}}{\setkeys{Gin}{width=\FOcontentwidth}}}

\gdef\FOSetGHeight{\expandafter\percenttest\FOcontentheight\relax%.\@
  {\@tempdima\percentval pt\relax\divide\@tempdima by 100 
  \edef\HSCALE{\strip@pt\@tempdima}\setkeys{Gin}{height=\HSCALE\Gin@nat@height}}{\setkeys{Gin}{height=\FOcontentheight}}}

\gdef\PlayWithFSize#1{\@default\f@size pt
  \expandafter\percenttest#1\relax%.\@
      {\dimen@0.01\@default
     \multiply\dimen@\percentval\relax}{\dimen@#1}\edef\FOfontsizefinal{\the\dimen@}}
\gdef\PlayWithShift{\expandafter\percenttest\FOverticalalign\relax%.\@
      {\dimen@0.01\baselineskip\multiply\dimen@\percentval\relax}{\dimen@\FOverticalalign}}
}
\def\strip@pt@and@otherjunk#1{\expandafter\rem@ptetc\the#1!} 
\begingroup
  \catcode`P=12
  \catcode`T=12
  \lowercase{\endgroup
  \gdef\rem@ptetc#1.#2PT#3!{#1\ifnum#2>\z@.#2\fi}%
}          
\catcode`\/\active

\def\@basiclink#1//#2\@nil#3\@nil#4\@nil{%
    {%
\ifx\\#2\\%
  \href{#4}{\FO@inlinesequence{#1}}%
\else
  \href{#4}{\FO@inlinesequence{\XURL{#3}}}%
\fi
   }%
}
\catcode`\/=12
%
\def\BlankPage{%
 \def\@thehead{\csname\FirstHead\endcsname}%
 \def\@thefoot{\csname\FirstTail\endcsname}%
 \let\@themargin\oddsidemargin
 \def\headheight{\FirstHeadExtent}%
 \def\tailheight{\FirstTailExtent}%
 \mark{}%
 \DEBUG{Blank Page \the\c@page}%
 \hbox{}
}
%-----------------------------------------------
% longtable
\LTpre\z@
\LTpost-10\p@
\def\LTleft@center{\LTleft=\FOmarginleft plus 1.0fill}
\def\LTright@center{\LTright=\FOmarginright plus 1.0fill}
\def\LTleft@start{\LTleft=\FOmarginleft}
\def\LTright@start{\LTright=\fill}
\def\LTleft@end{\LTleft=\fill}
\def\LTright@end{\LTright=\FOmarginright}
\def\LTleft@justify{\LTleft=\fill}
\def\LTright@justify{\LTright=\fill}
\gdef\LeftMargin{\FOmarginleft}
\gdef\RightMargin{\FOmarginright}
\gdef\TopMargin{\Margintop}
\gdef\BottomMargin{\Marginbottom}
\gdef\EndIndent{\ifx\FOendindent\att@labelend\z@\else\FOendindent\fi}
\gdef\StartIndent{\ifx\FOstartindent\att@bodystart\z@\else\FOstartindent\fi}
\gdef\OddTail {}
\gdef\OddHead {}
\gdef\EvenTail {}
\gdef\EvenHead {}
\gdef\FirstTail {}
\gdef\FirstHead {}
\gdef\OddTailExtent{\z@}
\gdef\OddHeadExtent{\z@}
\gdef\EvenTailExtent{\z@}
\gdef\EvenHeadExtent{\z@}
\gdef\FirstTailExtent{\z@}
\gdef\FirstHeadExtent{\z@}

\DefineCharacter{8232}{2028}{\newline}
\DefineCharacter{8208}{2010}{-\/}
\def\XURL{\begingroup \urlstyle{same}\Url}
\def\T@pageref#1{%
  \expandafter\@setref\csname r@#1\endcsname\@secondoffive{#1}%
}           
\let\@@ReadBookmarks\ReadBookmarks
\def\ReadBookmarks{{\let\InputIfFileExists\@input\@@ReadBookmarks}}
\def\XReadBookmarks{%
  \begingroup
    \escapechar=`\\%
    \let\escapechar\@gobble %
    \def\@@BOOKMARK [##1][##2]##3##4##5{\calc@bm@number{##5}}%
    \@input{\jobname.out}%
    \ifx\WriteBookmarks\relax
      \global\let\WriteBookmarks\relax
    \fi
    \def\@@BOOKMARK[##1][##2]##3##4##5{%
      \def\Hy@temp{##4}%
      \pdfoutline goto
        name{##3}%
        count ##2\check@bm@number{##3}{%
          \expandafter\strip@prefix\meaning\Hy@temp
        }%
   }%
   {%
    \def\WriteBookmarks{0}%
    \@input{\jobname.out}%
   }%
   %{\escapechar\m@ne\InputIfFileExists{\jobname.out}{}{}}%
   \ifx\WriteBookmarks\relax\else
     \if@filesw\immediate\openout\@outlinefile=\jobname.out
      \ifHy@typexml
       \immediate\write\@outlinefile{<relaxxml>\relax}%
      \fi
     \fi
   \fi
   \endgroup
}

\def\TableHeader{}
\def\DECO@{\@firstofone}
\def\DECO@blink{\uwave}
\def\DECO@underline{\uline}
\expandafter\def\csname DECO@line-through\endcsname{\sout}
\def\QuaddingStart{%
 \ifx\FOtextalignlast\att@relative
   \csname startQ@\FOtextalign\endcsname
 \else
   \csname startQ@\FOtextalignlast\endcsname
 \fi
}%
\def\QuaddingEnd{%
 \ifx\FOtextalignlast\att@relative
   \csname endQ@\FOtextalign\endcsname
 \else
   \csname endQ@\FOtextalignlast\endcsname
 \fi
}%
\def\Quadding{%
 \ifx\FOtextalignlast\att@relative
   \csname Q@\FOtextalign\endcsname
 \else
   \csname Q@\FOtextalignlast\endcsname
 \fi
}%
% page number compression (by David Carlisle)

\def\fopagecitation{\pageref{\FOrefid}}
%was \hyperlink{\FOrefid}{\pageref{\FOrefid}}}
\newcount\sortcount
\newtoks\sorttoks
\def\fosortpagecitation{%
   \setbox0\hbox{\global\sortcount=0\expandafter\expandafter\expandafter
   \@secondoffive\csname r@\FOrefid\endcsname
      \relax\relax\relax\relax\relax}
    \let\@elt\fosort@elt
    \global\sorttoks\expandafter{\expandafter}\the\sorttoks
    \ifnum\sortcount<\maxdimen
   \global\sorttoks\expandafter{%
       \the\expandafter\sorttoks\expandafter\@elt\expandafter{\the\sortcount}}
  \fi
    }

\def\fosort@elt#1{%
 \ifnum#1>\sortcount
   \global\sorttoks\expandafter{\the\expandafter\sorttoks\expandafter\@elt
       \expandafter{\the\sortcount}\@elt{#1}}%
  \global\sortcount\maxdimen
  \else
   \ifnum#1<\sortcount
   \global\sorttoks\expandafter{\the\sorttoks\@elt{#1}}%
   \fi
 \fi
}

\gdef\focompress@elt#1{%
 \global\advance\sortcount\@ne
 \ifnum#1=\sortcount
   \ifx\foheld\relax
      \edef\foheld{#1}%
    \else
       \def\foheld{\textendash#1}%
   \fi
  \else
   \foheld\fosep#1   
 \fi
 \global\sortcount#1
 \def\fosep{, }%
} 

% headers
\def\FirstHead{\csname right-xsl-before\endcsname}
\def\FirstFoot{\csname right-xsl-after\endcsname}
\expandafter\def\csname left-xsl-before\endcsname{}
\expandafter\def\csname left-xsl-after\endcsname{}
\expandafter\def\csname right-xsl-before\endcsname{}
\expandafter\def\csname right-xsl-after\endcsname{}
\@ifundefined{pdfoutput}{}{\def\pdfBorderAttrs{/Border [0 0 0]}}

%color
\def\@declaredcolor#1{%
  \@ifundefined{\string\color @#1}%
   {\expandafter\HTMLXColor#1000000\\{#1}}%
   {}%
   \expandafter\let\expandafter\current@color
     \csname\string\color @#1\endcsname
     \set@color
  \ignorespaces}

\def\HTMLXColor#1#2#3#4#5#6#7#8\\#9{%
% \typeout{Defining color #9 as RGB "#2#3, "#4#5, "#6#7}%
 \toks@{\definecolor{#9}{RGB}}%
\uppercase{\the\toks@{"#2#3, "#4#5, "#6#7}}%
}
\def\HTMLColor#1#2#3#4#5#6#7#8{%
 \definecolor{#1}{RGB}{"#3#4, "#5#6, "#7#8}}
\HTMLColor{aqua}.00FFFF
\HTMLColor{black}.000000
\HTMLColor{blue}.0000FF
\HTMLColor{fuchsia}.FF00FF
\HTMLColor{gray}.808080    
\HTMLColor{green}.008000
\HTMLColor{lime}.00FF00
\HTMLColor{maroon}.800000
\HTMLColor{navy}.000080
\HTMLColor{olive}.808000
\HTMLColor{purple}.800080
\HTMLColor{red}.FF0000
\HTMLColor{silver}.C0C0C0
\HTMLColor{teal}.008080
\HTMLColor{white}.FFFFFF
\HTMLColor{yellow}.FFFF00

\definecolor{orange}{cmyk}{0,0.61,0.87,0}
    \long\def\@firstoffive#1#2#3#4#5{#1}%
    \long\def\@secondoffive#1#2#3#4#5{#2}%
    \long\def\@thirdoffive#1#2#3#4#5{#3}%
    \long\def\@fourthoffive#1#2#3#4#5{#4}%
    \long\def\@fifthoffive#1#2#3#4#5{#5}%

\expandafter\let\csname Format-1\endcsname\@arabic
\expandafter\let\csname Format-i\endcsname\@roman
\expandafter\let\csname Format-I\endcsname\@Roman
\expandafter\let\csname Format-a\endcsname\@alph
\expandafter\let\csname Format-A\endcsname\@Alph

\def\FOgeneratePage#1#2\@null{\csname Format-#1\endcsname{\c@page}#2}

\def\@item[#1]{%
  \if@noparitem
    \@donoparitem
  \else
    \if@inlabel
      \indent \par
    \fi
    \ifhmode
      \unskip\unskip \par
    \fi
    \if@newlist
% removed this test 2000/11/05. always put in topsep.
%      \if@nobreak
%        \@nbitem
%      \else
        \addpenalty\@beginparpenalty
        \addvspace\@topsep
        \addvspace{-\parskip}%
%      \fi
    \else
      \addpenalty\@itempenalty
      \addvspace\itemsep
    \fi
    \global\@inlabeltrue
  \fi
  \global\everypar{%
    \@minipagefalse
    \global\@newlistfalse
    \if@inlabel
      \global\@inlabelfalse
      {\setbox\z@\lastbox
       \ifvoid\z@
         \kern-\itemindent
       \fi}%
      \box\@labels
      \penalty\z@
    \fi
    \if@nobreak
      \global\@nobreakfalse
      \clubpenalty \@M
    \else
      \clubpenalty \@clubpenalty
      \global\everypar{}%
    \fi}%
  \if@noitemarg
    \@noitemargfalse
    \if@nmbrlist
      \refstepcounter\@listctr
    \fi
  \fi
  \sbox\@tempboxa{\makelabel{#1}}%
%\typeout{LIST at \the\inputlineno, \the\itemindent, \the\labelwidth, \the\wd\@tempboxa}%
  \global\setbox\@labels\hbox{%
    \unhbox\@labels
    \hskip \itemindent
    \hskip -\labelwidth
    \hskip -\labelsep
    \ifdim \wd\@tempboxa >\labelwidth
      \box\@tempboxa
    \else
      \hbox to\labelwidth {\unhbox\@tempboxa}%
    \fi
    \hskip \labelsep}%
  \ignorespaces}


% support for markers
\gdef\FOmarks{}

\gdef\FOaddmarker#1#2{%
 \ifx\relax#1
 \else
   \def\FOtemp{#1}%
   \ifx\FOtemp\FOmarkerclassname
   \else
        \toks@\expandafter{\the\toks@{#1}{#2}}%
   \fi
   \expandafter\FOaddmarker
 \fi}
   

\gdef\FOgetmarker#1#2{%
  \ifx\relax#1
  \DEBUG{unknown mark \FOretrieveclassname, at \the\inputlineno}%
  \else
   \def\FOtemp{#1}%
    \ifx\FOtemp\FOthisretrieveclassname
%      \typeout{\the\inputlineno: Retrieve mark (\FOretrieveposition):
%      \FOthisretrieveclassname: #2}%
      \FOmarkergobble{#2}%
     \fi
   \expandafter\FOgetmarker
  \fi}
   
\gdef\FOmarkergobble#1#2\relax\relax{\fi\fi#1}

% linebreak
\def\FOLINEBREAK{%
\ifnum\FOTableNesting>0
\else
 \\
\fi
}


% vertical spacing
\newskip\FOafterskip
\def\FOvspaceafter{%
\ifFOinOutput
\else
  \ifnum\FOTableNesting>0
  \else
    \ifx\@empty\FOspaceafter
      \@tempdima\FOspaceafteroptimum
      \advance\@tempdima by -\FOspaceafterminimum
      \@tempdimb\FOspaceafteroptimum
      \advance\@tempdimb by \FOspaceaftermaximum
      \FOafterskip\FOspaceafteroptimum plus \@tempdimb minus \@tempdima
    \else
      \FOafterskip\FOspaceafter
    \fi
   \@tempswafalse
   \ifx\FOkeepwithnext\att@always\@tempswatrue\fi
   \ifx\FOkeepwithnextColumn\att@always\@tempswatrue\fi
   \ifx\FOkeepwithnextPage\att@always\@tempswatrue\fi
   \if@tempswa\addpenalty{\@M}\fi
   \addvspace\FOafterskip
  \fi
\fi
}

\def\FOvspacebefore{%
\ifFOinOutput
\else
    \ifx\@empty\FOspacebefore
      \@tempdima\FOspacebeforeoptimum
      \advance\@tempdima by -\FOspacebeforeminimum
      \@tempdimb\FOspacebeforeoptimum
      \advance\@tempdimb by \FOspacebeforemaximum
      \@tempskipa\FOspacebeforeoptimum plus \@tempdimb minus \@tempdima
    \else
      \@tempskipa\FOspacebefore
    \fi
%\typeout{SPACE BEFORE \the\inputlineno: \the\@tempskipa, \FOspacebeforeminimum/\FOspacebeforemaximum/\FOspacebeforeoptimum}%
 \ifnum\FOTableNesting>0
   \rule{\z@}{\@tempskipa}%
 \else
   \@tempswafalse
   \ifx\FOkeepwithnext\att@always\@tempswatrue\fi
   \ifx\FOkeepwithnextColumn\att@always\@tempswatrue\fi
   \ifx\FOkeepwithnextPage\att@always\@tempswatrue\fi
   \if@tempswa\addpenalty\@secpenalty\fi
   \addvspace\@tempskipa
 \fi
\fi
\def\FOspacebefore{\z@}%
}

% lets do some setup
% setup
\paperwidth211mm
\paperheight297mm
\hoffset-1in
\voffset-1in
\def\fps@table{!htbp}
\def\fps@figure{!htbp}
\parindent\z@
\parskip\z@
\emergencystretch 3em
\tabcolsep3pt
\hbadness=4000
\hyphenpenalty=400
\pretolerance=500
\relpenalty=500
\tolerance=1000
\vbadness=3000
\widowpenalty=8000
\clubpenalty=8000
\@twosidetrue
\fboxsep0pt
\setcounter{topnumber}{5}
\renewcommand\topfraction{.9}
\setcounter{bottomnumber}{12}
\renewcommand\bottomfraction{.9}
\setcounter{totalnumber}{6}
\renewcommand\textfraction{.1}
\def\FOpdfsetpagesize#1#2{%
 \@ifundefined{pdfoutput}{}{%
   \global\pdfpagewidth\paperwidth
   \global\pdfpageheight\paperheight
    \DEBUG{Setting pdf size to \the\pdfpagewidth, \the\pdfpageheight}%
    }%
}
\let\SpecialOffset\z@
% and now read the .cfg
\openin\@inputcheck fotex.cfg
\ifeof\@inputcheck\relax    
\else
  \closein\@inputcheck
  \input{fotex.cfg}
\fi
\begingroup
\catcode`\^^M\active\catcode`\ \active\gdef\@resetactivechars{\def^^M{<m>}\def {<s>}}\endgroup
%\catcode`\^^M\active\gdef\@resetactivechars{\def^^M{x}}\endgroup

\def\@outputpage{%
\begingroup           % the \endgroup is put in by \aftergroup
  \let \protect \noexpand
%  \@resetactivechars
  \@parboxrestore
  \shipout \vbox{%
    \set@typeset@protect
    \aftergroup \endgroup
    \aftergroup \set@typeset@protect
                                % correct? or just restore by ending
                                % the group?
 \if@specialpage
    \global\@specialpagefalse
    \def\@thehead{\csname\FirstHead\endcsname}%
    \def\@thefoot{\csname\FirstTail\endcsname}%
    \let\@themargin\oddsidemargin
    \def\headheight{\FirstHeadExtent}%
    \def\tailheight{\FirstTailExtent}%
 \else
      \ifodd\count\z@ 
         \def\@thehead{\csname\OddHead\endcsname}%
         \def\@thefoot{\csname\OddTail\endcsname}%
         \let\@themargin\oddsidemargin
         \def\headheight{\OddHeadExtent}%
         \def\tailheight{\OddTailExtent}%
      \else 
         \def\@thehead{\csname\EvenHead\endcsname}%
         \def\@thefoot{\csname\EvenTail\endcsname}%
         \let\@themargin\evensidemargin
         \def\headheight{\EvenHeadExtent}%
         \def\tailheight{\EvenTailExtent}%
      \fi
 \fi
 \@tempdima\textwidth
 \advance\@tempdima by -\FOheadindent
  \reset@font
  \normalsize
  \normalsfcodes
  \let\label\@gobble
  \let\index\@gobble
  \let\glossary\@gobble
  \baselineskip\z@skip \lineskip\z@skip \lineskiplimit\z@
   \@begindvi
    \vskip \topmargin
    \moveright\@themargin \vbox {%
      \setbox\@tempboxa \vbox to\headheight{%
        \color@hbox
          \normalcolor
        \hb@xt@\textwidth{\hfill\llap{\hb@xt@\@tempdima{\@thehead}}}%
        \color@endbox
        \vfil
        }%
      \dp\@tempboxa \z@
      \box\@tempboxa
      \vskip \headsep
      \box\@outputbox
      \baselineskip \footskip
      \vskip \bottommargin
 \@tempdima\textwidth
 \advance\@tempdima by -\FOheadindent
      \setbox\@tempboxa \vbox to\tailheight{%
        \color@hbox
          \normalcolor
         \hb@xt@\textwidth{\hfill\llap{\hb@xt@\@tempdima{\@thefoot}}}%
        \color@endbox
        \vfil
        }%
      \dp\@tempboxa \z@
      \box\@tempboxa
      }%
    }%
  \global \@colht \textheight
  \stepcounter{page}%
  \let\firstmark\botmark
}

%%%%
\def\FO@character#1{%
\ifx\FOverticalalign\att@baseline
  #1%
\else
 \ifx\FOverticalalign\att@super
   \textsuperscript{#1}%
 \else
    \ifx\FOverticalalign\att@sub
      \textsubscript{#1}%
    \else
      \PlayWithShift
      \raisebox{\dimen@}{#1}%
    \fi
 \fi
\fi
}
\def\FO@inlinesequence#1{%
 \FOSetFont{normal}%
\ifx\FOverticalalign\att@baseline
  \csname DECO@\FOtextdecoration\endcsname{\FOlabel#1}%
\else
 \ifx\FOverticalalign\att@super
   \textsuperscript{\csname DECO@\FOtextdecoration\endcsname{\FOlabel#1}}%
 \else
    \ifx\FOverticalalign\att@sub
      \textsubscript{\csname DECO@\FOtextdecoration\endcsname{\FOlabel#1}}%
    \else
      \PlayWithShift
      \raisebox{\dimen@}{\csname DECO@\FOtextdecoration\endcsname{\FOlabel#1}}%
    \fi
 \fi
\fi
}
\def\FOboxedsequence#1{%
\FOSetFont{normal}%
\ifx\FOborderwidth\@empty\else\fboxrule\FOborderwidth\fi
\ifx\FOverticalalign\att@baseline
 \fbox{\csname DECO@\FOtextdecoration\endcsname{\FOlabel#1}}%
\else
 \ifFOSuper
     \fbox{\textsuperscript{\FOlabel#1}}%
 \else
     \ifFOSub
       \fbox{\textsubscript{\FOlabel#1}}%
     \else
       \PlayWithShift
       \fbox{\raisebox{\dimen@}{\FOlabel#1}}%
     \fi
 \fi
\fi
}
%
\def\FOSetStatic{\expandafter\@SetStatic\FOtextindent\\}
\def\@SetStatic#1\\{\expandafter\@@SetStatic\FOfontsize\\{#1}}
\def\@@SetStatic#1\\#2{\expandafter\@@@SetStatic\FOfontweight\\{#1}{#2}}
\def\@@@SetStatic#1\\#2#3{\expandafter\@@@@SetStatic\FOfontvariant\\{#1}{#2}{#3}}
\def\@@@@SetStatic#1\\#2#3#4{\expandafter\@@@@@SetStatic\FOfontstyle\\{#1}{#2}{#3}{#4}}
\def\@@@@@SetStatic#1\\#2#3#4#5{\expandafter\@@@@@@SetStatic\FOfontstretch\\{#1}{#2}{#3}{#4}{#5}}
\def\@@@@@@SetStatic#1\\#2#3#4#5#6{\expandafter\@@@@@@@SetStatic\FOfontfamily\\{#1}{#2}{#3}{#4}{#5}{#6}}

\expandafter\def\csname Static:DummyRegion\endcsname{}
\def\@@@@@@@SetStatic#1\\#2#3#4#5#6#7#8#9{%
  \DEBUG{ set up static area Static:#9 [#8]}%
   \expandafter\gdef\csname Static:#9\endcsname{%
     {%
      {\def\XML@parent{}\global\FOinOutputtrue
       \def\FOwhitespacecollapse{true}%
       \def\FOwrapoption{wrap}%
       \def\FOtextalign{start}%
       \def\FOfontfamily{#1}%
       \def\FOfontsize{#6}%
       \def\FOfontstretch{#2}%
       \def\FOfontvariant{#4}%
       \def\FOfontweight{#5}%
       \def\FOfontstyle{#3}#8\global\FOinOutputfalse}}}%
}

\let\olditem\item
\def\item{\if@inlabel\leavevmode\fi\olditem}
\def\FOlabel{%
 \ifx\@empty\FOid\else
 % \typeout{Hypertext label \FOid, at \the\inputlineno}%
  \@bsphack
  \protected@write\@mainaux{}%
    {\string\newlabel{\FOid}{{}{\expandafter\FOgeneratePage\FOformat\@null}{}{\FOid}{}}}%
  \@esphack
  \hyper@@anchor{\FOid}{\relax}%
  \global\let\FOid\@empty
 \fi
}

\def\FOListBlock{%
   \FOSetFont{normal}%
   \get@external@font\xdef\FOlistlabelfont{\external@font}%
   \ifx\@empty\FOspacebefore
      \@tempdima\FOspacebeforeoptimum
      \advance\@tempdima by -\FOspacebeforeminimum
      \@tempdimb\FOspacebeforeoptimum
      \advance\@tempdimb by \FOspacebeforemaximum
      \itemsep\FOspacebeforeoptimum plus \@tempdimb minus \@tempdima
    \else
      \itemsep\FOspacebefore
    \fi
  \itemindent=\FOstartindent
  \leftmargin=\FOprovisionaldistancebetweenstarts
  \rightmargin=\FOmarginright
  \labelwidth=\FOprovisionaldistancebetweenstarts
  \advance\labelwidth by -\FOprovisionallabelseparation
  \expandafter\csname List\FOtextalign\endcsname
%\typeout{List at \the\inputlineno: labelwidth: \the\labelwidth, 
% labelsep: \the\labelsep, leftmargin: \the\leftmargin, itemindent 
% \the\itemindent, makelabel: \meaning\makelabel, 
% itemsep: \the\itemsep, \FOtextalign}%
}

\def\FOOutputBlock{%
 \FOSetFont{output}%
 \ifFOBlockGrab
   \FOBoxedBlock{\textwidth}%
 \fi
 \ifx\FOtextalignlast\att@relative
   \csname startQ@\FOtextalign\endcsname
   \csname Q@\FOtextalign\endcsname
 \else
   \csname startQ@\FOtextalignlast\endcsname
   \csname Q@\FOtextalignlast\endcsname
 \fi
}

\def\FONormalBlock{%
  \let\@x\relax
  \ifnum\FOTableNesting>0
   \ifx\FOtextalign\att@centered
       \centering
   \fi
   \let\@x\relax
   \FOSetFont{normalblock}%
   \vrule height \f@baselineskip depth \z@ width \z@ 
  \else
    \ifnum\FOinList>0
      \FOlabel
      \ifFOListInnerPar\par\FOvspacebefore\fi
      \ifx\FOwhitespace\att@pre\obeyspaces\obeylines\fi
      \ifx\FOwhitespacecollapse\att@false\obeyspaces\fi
      \ifx\FOwrapoption\att@nowrap\obeylines\fi
    \else
      \ifx\FObreakbefore\att@page
        \let\tempID\FOid
        \penalty -\@M
        \let\FOid\tempID
      \else
        \ifx\FObreakbefore\att@oddpage
        \let\tempID\FOid
        \penalty -\@M
        \ifodd\c@page\else\BlankPage\newpage\fi
        \let\FOid\tempID
        \fi
      \fi
      \par
      \FOlabel
      \Quadding
      \ifFOBlockGrab
        \FOBoxedBlock{\linewidth}%
      \else
        \FOBorderTop
        \ifdim\FOpaddingbefore>\z@
         \vskip\FOpaddingbefore
        \fi
        \FOvspacebefore
        \parindent\FOtextindent
        \advance\leftskip by  \FOpaddingstart
        \advance\leftskip by  \FOmarginleft
        \advance\rightskip by \FOpaddingend
        \advance\rightskip by \FOmarginright
      \fi
%      \par
      \ifx\FOwhitespace\att@pre\obeyspaces\obeylines\fi
      \ifx\FOwhitespacecollapse\att@false\obeyspaces\fi
      \ifx\FOwrapoption\att@nowrap\obeylines\fi
    \fi
    \FOSetFont{normal}%
  \fi
\@x
}

\def\FOEndOutputBlock{%
 \ifx\FOtextalignlast\att@relative
   \csname endQ@\FOtextalign\endcsname
 \else
   \csname endQ@\FOtextalignlast\endcsname
 \fi
 \ifFOBlockGrab
       \FOEndBoxedBlock
 \fi
 \par
}
\def\FOEndBlock{%
  \ifx\XML@parent\FOListItemLabel
  \else
    \ifnum\FOinList>0
      \ifFOListInnerPar\par\fi
    \else
       \ifnum\FOTableNesting>0
       \else
         \FOEndBlockTwo
       \fi
    \fi
   \fi
}

\def\FOEndBlockTwo{%
  \par
   \ifFOBlockGrab
       \FOEndBoxedBlock
   \else
        \ifdim\FOpaddingafter>\z@
         \vskip\FOpaddingafter
        \fi
        \FOBorderBottom
   \fi
   \ifx\FObreakafter\att@page
        \penalty -\@M
   \else
        \ifx\FObreakafter\att@oddpage
            \cleardoublepage
        \fi
   \fi
   \@tempswafalse
   \ifx\FOkeepwithnext\att@always\@tempswatrue\fi
   \ifx\FOkeepwithnextColumn\att@always\@tempswatrue\fi
   \ifx\FOkeepwithnextPage\att@always\@tempswatrue\fi
   \if@tempswa\nobreak\fi
   \FOvspaceafter
   \if@tempswa\@afterheading\fi
}


\def\FOStartGrab#1{%
         \@tempdima#1
         \XFOstartindent\FOstartindent
         \ifnum\XFOstartindent=\z@
         \else
          \advance\XFOstartindent by -\FOmarginleft
          \advance\XFOstartindent by -\FOborderstartwidth
          \advance\XFOstartindent by -\FOpaddingstart
          \advance\@tempdima by -\XFOstartindent
         \fi
         \advance\@tempdima by -\FOmarginleft
         \advance\@tempdima by -\FOborderstartwidth
         \advance\@tempdima by -\FOpaddingstart
         \XFOendindent\FOendindent
         \ifx\FOstartindent\att@bodystart
           \let\FOstartindent\z@
         \fi
         \ifx\FOendindent\att@labelend
           \let\FOendindent\z@
         \fi
         \ifnum\XFOendindent=\z@
         \else
          \advance\XFOendindent by -\FOpaddingend
          \advance\XFOendindent by -\FOmarginright
          \advance\XFOendindent by -\FOborderendwidth
          \advance\@tempdima by -\XFOendindent
         \fi
         \advance\@tempdima by -\FOpaddingend
         \advance\@tempdima by -\FOmarginright
         \advance\@tempdima by -\FOborderendwidth
%\typeout{Block at\the\inputlineno,Padding:\FOpaddingstart/\FOpaddingend,Border:\FOborderstartwidth/\FOborderendwidth,Margin:\FOmarginleft/\FOmarginleft,Indent:\FOstartindent/\FOendindent, \the\XFOstartindent/\the\XFOendindent}%
%
         \begin{lrbox}{\BlockBox}%
         \begin{minipage}[b]{\@tempdima}%
         \vskip\FOpaddingbefore
         \parindent\FOtextindent\leftskip\z@\rightskip\z@
}
\def\FOEndGrab#1{%
  \vspace*{\FOpaddingafter}%
  \end{minipage}%
  \end{lrbox}%
%\typeout{Grabbed Block at\the\inputlineno,Padding:\FOpaddingstart/\FOpaddingend,|\FOpaddingbefore/\FOpaddingafter, Border:\FOborderstartwidth/\FOborderendwidth,Margin:\FOmarginleft/\FOmarginleft,Indent:\FOstartindent/\FOendindent, \the\XFOstartindent/\the\XFOendindent}%
  \FOvspacebefore
  \@tempdima\ht\BlockBox
%  \advance\@tempdima by \FOpaddingbefore
%  \advance\@tempdima by \FOpaddingafter
  \advance\@tempdima by \FOborderbeforewidth
  \advance\@tempdima by \FOborderafterwidth
  \ifx\FOborderstyle\att@solid
   \ifx\FObackgroundcolor\att@transparent
     \fboxrule\FOborderwidth
     \fboxsep\FOpadding
     \vbox to \@tempdima{\hsize#1\parindent\z@\vfil
       \hbox{\hfil\fbox{\usebox{\BlockBox}}\hfil}\vfil}%
   \else
    \vbox to \@tempdima{\hsize#1\vfil\fboxsep\FOpadding\fboxrule\FOborderwidth
     \hbox{\hfil\fcolorbox{\FObordercolor}{\FObackgroundcolor}%
       {\box\BlockBox}\hfil}\vfil}%
   \fi
  \else
   \vbox to \@tempdima{\hsize#1\parindent\z@\vfil
   \ifdim\FOborderbeforewidth>\z@
    {\color{\FOborderbeforecolor}%
    \vrule width #1 depth \z@ height \FOborderbeforewidth}%
   \fi
   \hbox{%
   \hskip\XFOstartindent
   \hskip\FOmarginleft
   \ifdim\FOborderstartwidth>\z@
      {\color{\FOborderstartcolor}%
     \vrule width \FOborderstartwidth height \the\@tempdima}%
   \fi
   \hskip\FOpaddingstart
   \ifx\FObackgroundcolor\att@transparent
      \hbox{\box\BlockBox}%
   \else
      \colorbox{\FObackgroundcolor}%
              {\box\BlockBox}%
   \fi
   \hskip\FOpaddingend
   \ifdim\FOborderendwidth>\z@
    {\color{\FOborderendcolor}%
    \vrule width \FOborderendwidth depth \z@ height
      \the\@tempdima}%
   \fi
   \hskip\FOmarginright
   \hskip\XFOendindent
   }%
   \ifdim\FOborderafterwidth>\z@
    {\color{\FOborderaftercolor}%
     \vrule width #1 depth \z@ height \FOborderafterwidth }%
   \fi
   \vfil
   }%
  \fi
}

\def\FOBorderBottom{%
  \ifx\FOborderafterstyle\att@solid
   \ifx\FOborderafterwidth\att@thin\def\FOborderafterwidth{0.4pt}\fi
   \ifx\FOborderafterwidth\att@medium\def\FOborderafterwidth{0.8pt}\fi
   \ifx\FOborderafterwidth\att@thick\def\FOborderafterwidth{1.2pt}\fi
  \else
   \def\FOborderafterwidth{\z@}%
  \fi
  \ifx\FOborderbeforestyle\att@solid
   \ifx\FOborderbeforewidth\att@thin\def\FOborderbeforewidth{0.4pt}\fi
   \ifx\FOborderbeforewidth\att@medium\def\FOborderbeforewidth{0.8pt}\fi
   \ifx\FOborderbeforewidth\att@thick\def\FOborderbeforewidth{1.2pt}\fi
   \FOBlockGrabtrue
  \else
   \def\FOborderbeforewidth{\z@}%
  \fi
   \ifdim\FOborderafterwidth>\z@
    \ifx\FOborderafterstyle\att@solid
      {\color{\FObordercolor}\hrule height \FOborderafterwidth}%
    \fi
   \fi
}

\def\FOBorderTop{%
  \ifdim\FOborderbeforewidth>\z@
   \ifx\FOborderbeforestyle\att@solid
    {\color{\FObordercolor}\hrule height \FOborderbeforewidth}%
   \fi
 \fi
}

\def\FOfootnotemark{\protect\@FOfootnotemark}
\def\@FOfootnotemark#1{% tag
    \def\@thefnmark{#1}%
    \expandafter\let\csname p@footnote\endcsname\relax
    \@footnotemark%
}
\def\FOfootnotetext{\protect\@FOfootnotetext}
\def\@FOfootnotetext#1#2{% plain tag and text, no interpretation
  \def\@thefnmark{#1}%
  \expandafter\let\csname p@footnote\endcsname\relax
  \@footnotetext{\FOlabel#2}}

\def\FOplainfootmark#1{#1}
\long\def\FOplainfoottext#1{\insert\footins{%
    \reset@font\footnotesize
    \interlinepenalty\interfootnotelinepenalty
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
    \color@begingroup
    #1\unskip\ifhmode\nobreak\fi\vskip\lineskip
    \color@endgroup}%
}
\ColSpecs={}%
\NCols0
\RowCount0
\def\doTable#1\\#2{%
  \par
  \advance\leftskip by  \FOpaddingstart
  \advance\rightskip by \FOpaddingend
  \advance\rightskip by \FOmarginright
  \advance\leftskip by  \FOmarginleft
  \FOSetFont{normal}%
  \csname LTleft@\FOtextalign\endcsname
  \csname LTright@\FOtextalign\endcsname
%\typeout{LT: \FOtextalign, \the\LTleft, \the\LTright}%
  \FOlabel
  \ifnum\NColumns>1
    \tabular{#1}
  \else
    \ifnum\FOTableNesting>1
      \tabular{#1}%
    \else
      \longtable{#1}%
    \fi
  \fi
  #2}

\newdimen\@default
\@default=10pt

% set up hyphenation and font-related things
\def\LastLanguage{(undefined)}
\selectlanguage{english}

\def\LoadLanguage#1{%
 \begingroup\utfeight@protect@chars\xdef\newL{#1}\endgroup
% \@ifundefined{L@\newL}{%
%  \DEBUG{WARNING: unknown language \newL, loading english}%
%  \csname L@us\endcsname
% }{%
  \ifx\newL\LastLanguage
  \else
    \DEBUG{\the\inputlineno: hyphenation \newL, to replace \LastLanguage}%
    \csname L@\newL\endcsname
  \fi
%}
\edef\LastLanguage{\newL}}

\def\FOSetHyphenation{%
  \ifx\FOhyphenate\att@true
     \LoadLanguage{\FOlanguage}%
     \hyphenpenalty=\exhyphenpenalty
  \else
      \hyphenpenalty=10000
  \fi
}
\def\FOSetFont#1{%
 \FOSetHyphenation
 \edef\LaTeXshape{\csname Width@\FOfontstretch\endcsname
      \csname Weight@\FOfontweight\endcsname}%
 \ifx\LaTeXshape\@empty\def\LaTeXshape{m}\fi
\edef\fFamName{\FOfontfamily}%
%\typeout{#1 At \the\inputlineno, \FOfontweight, \FOfontstyle,
%  \FOfontsize, \FOtextalign, \LaTeXshape}%
 \edef\f@series{\LaTeXshape}%
 \edef\f@shape{\csname Posture@\FOfontstyle\endcsname}%
 \ifx\FOfontvariant\att@smallcaps
   \def\f@shape{sc}%
 \fi
 \let\f@family\relax
 \@for\FOfoo:=\FOfontfamily\do{%
    \ifx\f@family\relax
    \expandafter\let\expandafter\f@family
         \csname Family@\FOfoo\endcsname
    \fi}%
    \ifx\f@family\relax
      \def\f@family{\csname Family@\Defaultx@fontfamily\endcsname}%
    \fi
 \FOSetFontSize
 \selectfont
 \ifx\FOcolor\@empty
 \else
   \color{\FOcolor}%
 \fi
}
\expandafter\def\csname size-xx-small\endcsname{7pt}
\expandafter\def\csname size-x-small\endcsname{8pt}
\expandafter\def\csname size-small\endcsname{9pt}
\expandafter\def\csname size-medium\endcsname{10pt}
\expandafter\def\csname size-large\endcsname{14.4pt}
\expandafter\def\csname size-x-large\endcsname{18pt}
\expandafter\def\csname size-xx-large\endcsname{20pt}
\def\computeFOfontsize{%
  \expandafter\ifx\csname size-\FOfontsize\endcsname\relax
    \PlayWithFSize\FOfontsize
  \else
    \edef\FOfontsizefinal{\csname size-\FOfontsize\endcsname}%
  \fi
}
\def\FOSetFootFont{%
 \computeFOfontsize
 \ifx\FOlineheight\att@normal
   \@tempdima\FOfontsizefinal
   \multiply\@tempdima by 12
   \divide\@tempdima by 10
   \set@fontsize\FOfootnotesize{\FOfontsizefinal}{\@tempdima}%
 \else
   \@setfontsize\FOfootnotesize{\FOfontsizefinal}{\FOlineheight}%
 \fi
}
\def\FOSetFontSize{%
 \computeFOfontsize
 \ifx\FOlineheight\att@normal
   \@tempdima\FOfontsizefinal
   \multiply\@tempdima by 12
   \divide\@tempdima by 10
   \set@fontsize\baselinestretch{\FOfontsizefinal}{\@tempdima}%
 \else
   \set@fontsize\baselinestretch{\FOfontsizefinal}{\FOlineheight}%
 \fi
}

\DeclareRobustCommand*\textsubscript[1]{%
  \@textsubscript{\selectfont#1}}
\def\@textsubscript#1{%
  {\m@th\ensuremath{_{\mbox{\fontsize\sf@size\z@#1}}}}}
\def\reserved@e{}
\def\FOSetPage{%
 \bottommargin\Marginbottom
 \headsep\Margintop
 \topmargin\MasterTopMargin
 \advance\topmargin by \SpecialOffset
 \textheight\paperheight
 \textwidth\paperwidth
 \advance\textheight by -\FirstHeadExtent
 \advance\textheight by -\FirstTailExtent
 \advance\textheight by -\MasterTopMargin
 \advance\textheight by -\Margintop
 \advance\textheight by -\MasterBottomMargin
 \advance\textheight by -\Marginbottom
 \advance\textwidth by -\MasterLeftMargin
 \advance\textwidth by -\MasterRightMargin
 \FOpdfsetpagesize{\paperwidth}{\paperheight}
 \@colht\textheight
 \@colroom\textheight
 \vsize\textheight
 \linewidth\textwidth
 \columnwidth\textwidth
 \hsize\columnwidth \linewidth\hsize
 \def\headheight{12pt}%
    \DEBUG{Page size is \the\textwidth/\the\textheight,
  on paper   \the\paperwidth/\the\paperheight,^^J
  with paper margins \the\MasterRightMargin/\the\MasterLeftMargin,
  and region margins \the\topmargin/\the\MasterBottomMargin;^^J
  footskip is \the\footskip, headsep is \the\headsep^^J
  evensidemargin \the\evensidemargin, oddsidemargin \the\oddsidemargin}%
  \global\@specialpagetrue
}
% don't ask
\def\supppdf{supp-pdf}
\let\FOinputIfFileExists\InputIfFileExists
\def\InputIfFileExists#1#2#3{%
 {\def\@tempa{#1}\ifx\@tempa\supppdf\else
   \FOinputIfFileExists{#1}{#2}{#3}\fi}}
%\catcode`^^M=10
\providecommand\textasciitilde{~}

\define@key{Gin}{scale}{%
  \if@tempswa
    \edef\@tempa{\toks@{\noexpand\Gscale@box{#1}[#1]{\the\toks@}}}%
    \@tempa
  \else
    \def\Gin@req@sizes{%
      \def\Gin@scalex{#1}\let\Gin@scaley\Gin@exclamation
      \Gin@req@height\Gin@scalex\Gin@nat@height
      \Gin@req@width\Gin@scalex\Gin@nat@width}%
  \fi
  \@tempswatrue}


\def\usewhitespace{%
 \UnicodeCharacter{13}{ \ignorespaces}%
 \UnicodeCharacter{32}{ \ignorespaces}%
 \UnicodeCharacter{9}{ \ignorespaces}%
}
\def\ignorewhitespace{%
 \UnicodeCharacter{13}{}%
 \UnicodeCharacter{32}{}%
 \UnicodeCharacter{9}{}%
}

% taken from Heiko Oberdiek's epstopdf.sty
% but the redefinitions need to be global
\global\let\orgGin@setfile\Gin@setfile
\global\def\Gin@setfile#1#2#3{%
  \if`\@car #3\relax\@nil
    \let\Gin@base\filename@base
    \immediate\write18{\@cdr #3\@empty\@nil}%
    \orgGin@setfile{#1}{#2}{\filename@base #2}%
  \else
    \orgGin@setfile{#1}{#2}{#3}%
  \fi
}

% support .gif and .eps
\g@addto@macro\Gin@extensions{,.eps}
\g@addto@macro\Gin@extensions{,.gif}
\@namedef{Gin@rule@.eps}#1{{pdf}{.pdf}{`epstopdf #1}}
\@namedef{Gin@rule@.gif}#1{{png}{.png}{`giftopng #1}}

\endinput
