%%RCS: $Id: fotex.ltx,v 1.9 1999/12/21 11:40:37 rahtz Exp rahtz $
%% File: fotex.ltx Copyright 1999 Sebastian Rahtz
%%
%% This package may be distributed under the terms of the LaTeX Project Public
%% License, as described in lppl.txt in the base LaTeX distribution.
%% Either version 1.0 or, at your option, any later version.
%%
%% I am very grateful to David Carlisle for all the good ideas, code
%% fragments and advice.
%%
\documentclass{article}
\RequirePackage{keyval}
\RequirePackage{graphicx}
\RequirePackage{array}
\RequirePackage{longtable}
\RequirePackage[normalem]{ulem}
\RequirePackage{color}
\RequirePackage{typexml}
\def\XMLdefEMPTY<#1>#2{%
 \XMLdefempty<#1/>{#2}%
 \XMLdef</#1>{}%
 \XMLdef<#1>{#2}%
}
\RequirePackage{times}
\RequirePackage{utfeight}
\RequirePackage{mlnames}
\def\DefineCharacter#1#2#3{\expandafter\def\csname!#2\endcsname{#3}}
\RequirePackage{unicode}
\input ucharacters.sty
\DefineCharacter{8412}{2028}{\\}
\RequirePackage{url}
\newcommand\XURL{\begingroup \urlstyle{same}\Url}
\RequirePackage[%
   pdfborder={0 0 0},
   implicit=false,
%   linkbordercolor={0 0 0},
%   urlbordercolor={0 0 0},
%   pagebordercolor={0 0 0},
%   filebordercolor={0 0 0},
%   citebordercolor={0 0 0},
  typexml]{hyperref}[1999/08/11]
\makeatletter
\def\pdfBorderAttrs{/Border [0 0 0]}%
\definecolor{orange}{cmyk}{0,0.61,0.87,0}
%%%%
\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@twoside
 \@tempdima\textwidth
 \advance\@tempdima by -\XML@headindent
 \if@specialpage
    \global\@specialpagefalse
    \def\@thehead{\csname first-xsl-before\endcsname}%
    \def\@thefoot{\csname first-xsl-after\endcsname}%
    \let\@themargin\oddsidemargin
  \else
      \ifodd\count\z@ 
         \def\@thehead{\csname right-xsl-before\endcsname}%
         \def\@thefoot{\csname right-xsl-after\endcsname}%
         \let\@themargin\oddsidemargin
      \else 
         \def\@thehead{\csname left-xsl-before\endcsname}%
         \def\@thefoot{\csname left-xsl-after\endcsname}%
         \let\@themargin\evensidemargin
      \fi
  \fi
\else
    \def\@thehead{\csname right-xsl-before\endcsname}%
    \def\@thefoot{\csname right-xsl-after\endcsname}%
    \let\@themargin\oddsidemargin
\fi
  \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{%
        \vfil
        \color@hbox
          \normalcolor
          \hb@xt@\textwidth{\hfill\llap{\hb@xt@\@tempdima{\@thehead}}}%
        \color@endbox
        }%                        %% 22 Feb 87
      \dp\@tempboxa \z@
      \box\@tempboxa
      \vskip \headsep
      \box\@outputbox
      \baselineskip \footskip
      \color@hbox
        \normalcolor
          \hb@xt@\textwidth{\hfill\llap{\hb@xt@\@tempdima{\@thefoot}}}%
      \color@endbox
      }%
    }%
  \global \@colht \textheight
  \stepcounter{page}%
  \let\firstmark\botmark
}

%%%%
\newif\ifXMLForceInline
\newif\ifXMLFopHeaders
\newif\ifXMLBox
\newif\ifXMLDefiningPage
\newif\ifXMLKeep
\newif\ifXMLNoWrap
\newif\ifXMLObeySpace
\newif\ifXMLSub
\newif\ifXMLSuper
\newif\ifXMLfirstpage
\newif\ifXMLinLayout
\newif\ifXMLinList
\newif\ifXMLinListLabel
\newif\ifXMLinOutput
\newif\ifXMLinTable
\newif\ifXMLneedspecialpage
\XMLFopHeadersfalse
\XMLBoxfalse
\XMLDefiningPagefalse
\XMLNoWrapfalse
\XMLObeySpacefalse
\XMLSubfalse
\XMLSuperfalse
\XMLfirstpagetrue
\XMLinLayoutfalse
\XMLinListLabelfalse
\XMLinListfalse
\XMLinOutputfalse
\XMLinTablefalse
\XMLForceInlinefalse
\def\att@NaN{NaN}
\def\att@none{none}
\def\att@normal{normal}
\def\att@solid{solid}
\def\att@smallcaps{small-caps}
\def\att@super{super}
\def\att@sub{sub}
\def\att@nowrap{no-wrap}
\def\att@preserve{preserve}
\def\att@page{page}
\def\att@oddpage{odd-page}
\def\att@true{true}

% defaults
\def\QuaddingStart{\startQ@justified}
\def\QuaddingEnd{\endQ@justified}
\def\Quadding{\Q@justified}
\def\XMLid{}
\def\Defaultx@fontfamily{Times-Roman}
\def\XML@fontsize{10pt}
\def\XML@fontweight{normal}
\def\XML@fontvariant{normal}
\def\XML@lineheight{-1\p@}
\def\XML@fontstretch{normal}
\def\XML@fontfamily{ptm}
\def\XML@spacebefore{\z@}
\def\XML@spacebeforeminimum{\z@}
\def\XML@spacebeforemaximum{\z@}
\def\XML@spacebeforeoptimum{\z@}
\def\XML@spaceafter{\z@}
\def\XML@spaceafterminimum{\z@}
\def\XML@spaceaftermaximum{\z@}
\def\XML@spaceafteroptimum{\z@}
\def\XML@textindent{\z@}
\def\XML@headindent{\z@}
\def\XML@deco{\@firstofone}
\def\StartIndent{\z@}
\def\EndIndent{\z@}
\def\XML@color{}
\def\XML@scale{1}
\def\XML@labelsep{6pt}
\def\XML@listindent{24pt}
\def\XML@NColumnsSpanned{1}
\def\XML@RuleLeaders{\leaders\hrule height \XML@RuleThickness\hfill}
\def\XML@RuleThickness{1\p@}
\def\XMLInitialPageNumber{-99999}
\parindent\z@
\parskip\z@
\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{}
\def\HeaderMargin{\z@}
\def\FooterMargin{\z@}
\def\LeftMargin{\z@}
\def\RightMargin{\z@}
\def\TopMargin{\z@}
\def\BottomMargin{\z@}
\def\PageWidth{211mm}
\def\PageHeight{297mm}
\def\TextAlign{justified}
\def\MasterLeftMargin{\z@}
\def\MasterRightMargin{\z@}
\def\ShowFO#1{\typeout{|\the\inputlineno: Start #1}}%
\def\ShowEndFO#1{\typeout{|\the\inputlineno: End #1}}%
\def\ShowAttribute#1#2{%
 \typeout{|    #1: #2}%
}
\XMLdef<relax>{\relax}
%
% Load MathML
\input{mathml.ltx}
% Fotex-escape objects
\XMLdefempty<fotex:bookmark/>{}
\XMLdef<fotex:bookmark>{\XMLattributes\XMLgrabber{fotex:bookmark}\FotexBookMark}
\def\FotexBookMark#1{%
  \pdfbookmark[\FoTeX@BookMarkLevel]{#1}{\FoTeX@BookMarkLabel}%
}
\define@key{XML}{xmlns:fotex}{}
\define@key{XML}{fotex-bookmark-level}{\def\FoTeX@BookMarkLevel{#1}}
\define@key{XML}{fotex-bookmark-label}{\def\FoTeX@BookMarkLabel{#1}}
%
\define@key{XML}{xmlns:fop}{}
\define@key{XML}{fop:master}{\XMLFopHeaderstrue\def\XML@FopMaster{#1}}
%
% XSL FO  Formatting objects
\XMLdefEMPTY<fo:display-rule>{\bgroup\XMLattributes\hrule height \XML@RuleThickness\egroup}
\XMLdefEMPTY<fo:inline-rule>{\bgroup\XMLattributes\XML@RuleLeaders\egroup}
%
\XMLdef<fo:simple-link>{\XMLattributes\XMLgrabber{fo:simple-link}{\XML@simplelink}}
{\catcode`\#=12\gdef\XMLhash{#}}
\let\XML@extdest\@empty
\let\XML@intdest\@empty
\def\XML@simplelink#1{%
 \ifx\XML@extdest\@empty
   \hyperlink{\XML@intdest}{#1}%
   \let\XML@intdest\@empty
 \else
   \expandafter\@simplelink\XML@extdest\@nil#1:\@nil%
   \let\XML@extdest\@empty
 \fi
}

\def\@simplelink#1\@nil#2:#3\@nil{%
    \ifx\\#3\\%
     \href{#1}{#2}%
    \else
     \href{#1}{\XURL{#2:#3}}%
    \fi
}
\XMLdef</fo:simple-link>{}
\XMLdef<fo:block>{%
  \ifXMLinListLabel
     \def\@x{\ListLabelBlock}%
  \else
     \def\@x{\XMLBlock}%
  \fi
  \@x
}

\XMLdefempty<fo:block/>{%
    \XMLBlock
    \par\ifXMLKeep\penalty\@M\fi
    \vspaceafter
    \egroup
}
\def\XMLBlock{%
\bgroup
\ifXMLinList
 \def\QuaddingStart{\startQ@justified}%
 \def\QuaddingEnd{\endQ@justified}%
 \def\Quadding{\Q@justified}%
 \def\TextAlign{justified}%
\fi
\ifXMLinOutput
 \XMLattributes
 \def\@x{\QuaddingStart\SetFont}%
\else
\ifXMLinTable
 \let\@x\@empty
\else
  \let\@x\relax
    \XMLattributes
    \XMLlabel{\XMLid}%
    \ifXMLinList
      \par
    \else
      \par
      \parindent\XML@textindent%
      \vspacebefore
      \ifXMLNoWrap\obeylines\fi
%      \ifXMLObeySpace\obeyspaces\fi
    \fi
    \SetFont
    \Quadding
  \fi
\fi
\@x
}
\XMLdef</fo:block>{%
 \ifXMLinOutput
  \QuaddingEnd
 \fi
 \ifXMLinList
    \par
 \else
    \par\ifXMLKeep\penalty\@M\fi
    \vspaceafter
 \fi
 \egroup
}
%
\XMLdef<fo:inline-included-container>{\XMLForceInlinetrue}
\XMLdef</fo:inline-included-container>{\XMLForceInlinefalse}
\XMLdef<fo:display-sequence>{\bgroup\XMLattributes}
\XMLdef</fo:display-sequence>{\egroup}
\XMLdefempty<fo:inline-sequence/>{}
\XMLdef<fo:inline-sequence>{\bgroup\XMLattributes\XMLgrabber{fo:inline-sequence}\XML@inlinesequence}
\def\XML@inlinesequence#1{%
 \ifXMLBox\XML@boxedsequence{#1}\else\XML@@inlinesequence{#1}\fi
 \egroup
}
\def\XML@@inlinesequence#1{%
 \SetFont 
 \ifXMLSuper\textsuperscript{\XML@deco{#1}}%
  \else
    \ifXMLSub\textsubscript{\XML@deco{#1}}%
    \else
      \XML@deco{#1}%
    \fi
  \fi
}
\def\XML@boxedsequence#1{%
 \SetFont 
 \fbox{%
 \ifXMLSuper\textsuperscript{#1}%
   \else
     \ifXMLSub\textsubscript{#1}%
     \else
       #1%
     \fi
 \fi
}%
}
\XMLdef</fo:inline-sequence>{}
\XMLdef</fo:character>{}
\XMLdef<fo:character>{{\def\^^M{\\}\XMLattributes}}
\XMLdefempty<fo:character/>{\XMLattributes}
\XMLdef<fo:character>{\XMLattributes}
\XMLdef</fo:character>{}
\XMLdef<fo:layout-master-set>{\ShowFO{fo:layout-master-set}\XMLattributes}
\XMLdef</fo:layout-master-set>{\ShowEndFO{fo:layout-master-set}}
\XMLdef<fo:page-sequence>{%
 \bgroup
 \XMLattributes
}
\XMLdef</fo:page-sequence>{%
 \clearpage
 \egroup
}
\XMLdef<fo:flow>{%
\bgroup\XMLattributes} 
\XMLdef</fo:flow>{\egroup}

\XMLdef<fo:root>{%
  \begin{document}%
  \typeout{Passive TeX project: fotex format, Sebastian Rahtz:
    1999/08/11}%
  \pagestyle{empty}
  \XMLattributes
}
\XMLdef</fo:root>{%
        \end{document}%
}
\XMLdefEMPTY<fo:sequence-specifier-repeating>{}
\XMLdef<fo:sequence-specification>{%
   \XMLneedspecialpagefalse
   \XMLattributes
}
\XMLdef</fo:sequence-specification>{%
 \ifXMLfirstpage
 \else
  \if@twoside
    \cleardoublepage
  \else
    \clearpage
  \fi
 \fi
 \ifnum\XMLInitialPageNumber>-99999
   \setcounter{page}{\XMLInitialPageNumber}%
 \fi
 \ifXMLneedspecialpage\@specialpagetrue\XMLneedspecialpagefalse\fi
 \XMLSetPage
}
\XMLdef<fo:simple-page-master>{%
   \XMLDefiningPagetrue
   \XMLattributes
   \XMLDefiningPagefalse
}
\XMLdef</fo:simple-page-master>{}
\def\@staticafter{xsl-after}
\def\@staticbefore{xsl-before}
\def\@staticstart{xsl-start}
\newsavebox{\foo}
\XMLdefempty<fo:static-content/>{%
\bgroup
  \XMLattributes
  \XML@staticcontent{}%
}
\XMLdef<fo:static-content>{%
 \bgroup
 \XMLattributes
 \XMLgrabber{fo:static-content}{\XML@staticcontent}}
%
\def\SetStatic{\expandafter\@SetStatic\XML@textindent\\}
\def\@SetStatic#1\\{\expandafter\@@SetStatic\XML@fontsize\\{#1}}
\def\@@SetStatic#1\\#2{\expandafter\@@@SetStatic\XML@fontweight\\{#1}{#2}}
\def\@@@SetStatic#1\\#2#3{\expandafter\@@@@SetStatic\XML@fontvariant\\{#1}{#2}{#3}}
\def\@@@@SetStatic#1\\#2#3#4{\expandafter\@@@@@SetStatic\XML@lineheight\\{#1}{#2}{#3}{#4}}
\def\@@@@@SetStatic#1\\#2#3#4#5{\expandafter\@@@@@@SetStatic\XML@fontstretch\\{#1}{#2}{#3}{#4}{#5}}
\def\@@@@@@SetStatic#1\\#2#3#4#5#6{\expandafter\@@@@@@@SetStatic\XML@fontfamily\\{#1}{#2}{#3}{#4}{#5}{#6}}

\def\@@@@@@@SetStatic#1\\#2#3#4#5#6#7#8#9{%
   \expandafter\gdef\csname#9\endcsname{%
     {%
      \def\XML@fontfamily{#1}%
      \def\XML@fontstretch{#2}%
      \def\XML@lineheight{#3}%
      \def\XML@fontvariant{#4}%
      \def\XML@fontweight{#5}%
      \def\XML@fontsize{#6}%
      \def\XML@textindent{#7}%
      \XMLinListLabelfalse\XMLinOutputtrue#8}}%
}

\def\XML@staticcontent#1{%xsl-after, xsl-before, xsl-start
 \ifXMLFopHeaders
      \SetStatic{#1}{\XML@FopMaster-\XML@flowname}%
 \else
   \ifx\XML@flowname\@staticafter
     \SetStatic{#1}{left-xsl-after}%
     \SetStatic{#1}{right-xsl-after}%
   \else
    \ifx\XML@flowname\@staticbefore
      \SetStatic{#1}{left-xsl-before}%
      \SetStatic{#1}{right-xsl-before}%
    \else
       \ifx\XML@flowname\@staticstart
       \fi
    \fi
   \fi
 \fi
 \egroup
}
\XMLdef</fo:static-content>{\ShowEndFO{fo:static-content}}
\XMLdefEMPTY<fo:page-number>{\thepage}
\XMLdefEMPTY<fo:region-after>{}
\XMLdefEMPTY<fo:region-before>{}
\XMLdefempty<fo:region-body/>{\XMLinLayouttrue\XMLattributes\XMLinLayoutfalse}
\XMLdef<fo:region-body>{\XMLinLayouttrue\XMLattributes}
\XMLdef</fo:region-body>{\XMLinLayoutfalse}
\XMLdefEMPTY<fo:sequence-specifier-alternating>{\XMLattributes\@twosidetrue}
\XMLdefEMPTY<fo:sequence-specifier-single>{\@twosidefalse}
\XMLdef<fo:list-block>{%
 \bgroup
 \ifXMLinList\leavevmode\fi
 \XMLinListtrue
 \XMLattributes
 \SetFont
 \begin{list}{}{%
  \Liststart
  \labelsep\XML@labelsep
  \topsep\XML@spacebefore
  \itemsep\z@
  \leftmargin=\XML@listindent
  \rightmargin=\RightMargin}%
  \def\XML@spacebefore{\z@}%
}
\XMLdef</fo:list-block>{%
 \end{list}%
 \XMLinListfalse
 \egroup
}
\XMLdef<fo:list-item-body>{\XMLinListLabelfalse}
\XMLdef</fo:list-item-body>{}
\XMLdef<fo:list-item-label>{%
 {\XMLattributes\SetFont\get@external@font\xdef\XML@listlabelfont{\external@font}}%
 \XMLgrabber{fo:list-item-label}{\Item}}
\let\olditem\item
\def\item{\if@inlabel\leavevmode\fi\olditem}
\def\Item#1{\XMLinListLabeltrue#1}
\def\XMLlabel#1{% label name
\ifx\XMLid\@empty
\else
  \@bsphack
  \protected@write\@mainaux{}%
    {\string\newlabel{#1}{{}{\thepage}{}{#1}{}}}%
  \@esphack
  \hyper@@anchor{#1}{\relax}%
  \global\let\XMLid\@empty
\fi
}
\def\ListLabelBlock{%
 \XMLattributes
 \XMLgrabber{fo:block}{\ITEM}%
}
\def\ITEM#1{%
  \def\XML@tempa{#1}%
  \itemsep\XML@spacebefore
  \leftmargin=\XML@listindent
  \rightmargin=\RightMargin
  \labelwidth=\XML@listindent
  \advance\labelwidth by -\XML@labelsep
  \expandafter\csname List\TextAlign\endcsname
%\typeout{List: labelwidth: \the\labelwidth, labealsep: \the\labelsep,
%  leftmargin: \the\leftmargin, and \meaning\makelabel, \TextAlign}%
   \item[{\font\foo=\XML@listlabelfont\foo\XML@tempa}]
}

\XMLdef</fo:list-item-label>{}
\XMLdef<fo:list-item>{\bgroup\XMLattributes}% 
\XMLdef</fo:list-item>{\egroup}             %
\XMLdefEMPTY<fo:page-number-citation>{{%
  \XMLattributes
  \hyperlink{\XMLrefid}{\pageref{\XMLrefid}}%
}}
\XMLdefEMPTY<fo:inline-graphic>{\InlineGraphic}
\XMLdefEMPTY<fo:display-graphic>{\DisplayGraphic}
\def\DisplayGraphic{\bgroup\XMLattributes
\ifXMLBox
   \fbox{\includegraphics[scale=\XML@scale]{\Hrefname}}% 
\else
   \includegraphics[scale=\XML@scale]{\Hrefname}%
\fi
\par\egroup
}
\def\InlineGraphic{\bgroup\XMLattributes
   \includegraphics{\Hrefname}\egroup}
\XMLdef<fo:table-caption>{\XMLattributes}
\XMLdef</fo:table-caption>{\par}
\XMLdef<fo:float>{\XMLattributes\begin{figure}\XMLlabel{\XMLid}}
\XMLdef</fo:float>{\end{figure}}
\XMLdef<fo:footnote-citation>{\XMLattributes\XMLgrabber{fo:footnote-citation}{\Foot}}
\def\Foot#1{\XMLfootnotemark{#1}\gdef\FootNumber{#1}}
\XMLdef</fo:footnote-citation>{}
\XMLdef<fo:footnote>{%
  \bgroup
  \XMLattributes
% \SetFootFont
  \XMLgrabber{fo:footnote}{\XMLfootnotetext{\FootNumber}}%
}
\def\XMLfootnotemark{\protect\@XSLfootnotemark}
\def\@XSLfootnotemark#1{% tag
    \def\@thefnmark{#1}%
    \expandafter\let\csname p@footnote\endcsname\relax
    \@footnotemark%
}
\def\XMLfootnotetext{\protect\@XSLfootnotetext}
\def\@XSLfootnotetext#1#2{% plain tag and text, no interpretation
  \def\@thefnmark{#1}%
  \expandafter\let\csname p@footnote\endcsname\relax
  \@footnotetext{\XMLlabel{\XMLid}#2}%
  \egroup
}
\XMLdefEMPTY<fo:table-column>{}
\XMLdef<fo:table-caption>{\XMLattributes}
\XMLdef</fo:table-caption>{\par}
\XMLdef<fo:table>{}
\XMLdef</fo:table>{}
\XMLdef</fo:footnote>{}
\XMLdef<fo:table-and-caption>{%
\RowCount0
\ifXMLForceInline
  \vspace{12pt}%
\else
  \begin{table}\XMLattributes\XMLlabel{\XMLid}
\fi
}
\XMLdef</fo:table-and-caption>{%
\ifXMLForceInline
  \vspace{12pt}%
\else
  \end{table}
\fi
}
\newcount\RowCount
\XMLdefempty<fo:table-body/>{\\%\hline
\let\w@t\relax
\ifXMLinTable
 \def\w@t{\end{longtable}}
\fi
\w@t
\XMLinTablefalse
}
\XMLdef<fo:table-body>{%
\ifXMLinTable
\else
  \XMLinTabletrue\XMLattributes
  \begin{longtable}{*{99}{l}}%\hline\rule{\z@}{12\p@}%
\fi
}
\XMLdef</fo:table-body>{%
\\%\hline
\let\w@t\relax
\ifXMLinTable
 \def\w@t{\end{longtable}}
\fi
\w@t
\XMLinTablefalse
}
\XMLdef<fo:table-header>{\XMLinTabletrue\XMLattributes
   \begin{longtable}{*{99}{l}}\hline\rule{\z@}{12\p@}}
\XMLdef</fo:table-header>{\\\hline\rule{\z@}{12\p@}\RowCount0}
\XMLdefempty<fo:table-cell/>{\XMLattributes\XMLTableCell{}}
\XMLdef<fo:table-cell>{\XMLattributes\XMLgrabber{fo:table-cell}\XMLTableCell}
\def\XMLTableCell#1{%
 \ifnum\XML@NColumnsSpanned>1
   \typeout{COLS [\XML@NColumnsSpanned] with #1}%
   \gdef\w@t{\multicolumn{\XML@NColumnsSpanned}{l}{#1}}%
 \else
   \gdef\w@t{#1}%
 \fi
 &\w@t
 \global\let\w@t\relax
}
\XMLdef</fo:table-cell>{}
\XMLdef<fo:table-row>{\ifnum\RowCount>0\def\w@t{\\}\else\let\w@t\relax\fi\w@t}
\XMLdef</fo:table-row>{\global\advance\RowCount by 1}
\XMLdefempty<input/>{\XMLattributes\input{\@filename}}
%% Characteristics
% top-level
\define@key{XML}{xmlns:fo}{\ShowAttribute{xmlns:fo}{#1}}
\define@key{XML}{page-master-first}{% 
 \XMLneedspecialpagetrue
}
\define@key{XML}{page-master-odd}{}
\define@key{XML}{page-master-even}{}
\define@key{XML}{page-master-name}{\def\XMLPageMasterName{#1}}
\define@key{XML}{initial-page-number}{\def\XMLInitialPageNumber{#1}}
\define@key{XML}{flow-name}{% xsl-after, xsl-before, xsl-start
  \def\XML@flowname{#1}%
}

\def\rule@style@dotted{dotted}
\def\rule@style@dashed{dashed}
\define@key{XML}{rule-style}{% solid, dashed, dotted
 \def\@xx{#1}%
 \ifx\@xx\rule@style@dashed
    \def\XML@RuleLeaders{\cleaders\hbox{$\m@th \mkern1.5mu-\mkern1.5mu$}\hfil}%
 \else
  \ifx\@xx\rule@style@dotted
    \def\XML@RuleLeaders{\cleaders\hbox{$\m@th \mkern1.5mu.\mkern1.5mu$}\hfil}%
  \fi
 \fi
}
\define@key{XML}{rule-thickness}{\def\XML@RuleThickness{#1}}
\define@key{XML}{margin}{}
\define@key{XML}{column-gap}{}
\define@key{XML}{border}{}
\define@key{XML}{padding}{}
\define@key{XML}{inhibit-line-breaks}{}

% Tabular
\define@key{XML}{n-columns-spanned}{%
\def\@tempa{#1}\ifx\@tempa\att@NaN\else\let\XML@NColumnsSpanned\@tempa\fi}
\define@key{XML}{n-rows-spanned}{\ShowAttribute{n-rows-spanned}{#1}}
% character
\define@key{XML}{character}{#1}
%
% inline
\define@key{XML}{border-style}{%
 \def\@tempa{#1}%
 \ifx\@tempa\att@solid
   \XMLBoxtrue
 \fi
}
\define@key{XML}{vertical-align}{%
 \def\@tempa{#1}%
 \ifx\@tempa\att@super
   \XMLSupertrue
 \else
    \ifx\@tempa\att@sub
      \XMLSubtrue
    \fi
 \fi
}
\define@key{XML}{href}{\def\Hrefname{#1}}
\define@key{XML}{scale}{\def\XML@scale{#1}}
\define@key{XML}{color}{\def\XML@color{#1}}
\define@key{XML}{external-destination}{\def\XML@extdest{#1}}
\define@key{XML}{internal-destination}{\def\XML@intdest{#1}}
\define@key{XML}{filename}{\def\@filename{#1}}
\define@key{XML}{ref-id}{\def\XMLrefid{#1}}
\define@key{XML}{id}{\def\XMLid{#1}}
%
% Lists
\define@key{XML}{provisional-distance-between-starts}{\def\XML@listindent{#1}}
\define@key{XML}{provisional-label-separation}{\def\XML@labelsep{#1}}
% block
\define@key{XML}{wrap-option}{%
 \def\@tempa{#1}\ifx\@tempa\att@nowrap
    \XMLNoWraptrue
 \else
    \XMLNoWrapfalse
 \fi
}
\define@key{XML}{whitespace-treatment}{%
 \def\@tempa{#1}\ifx\@tempa\att@preserve
    \XMLObeySpacetrue
 \else
    \XMLObeySpacefalse
 \fi
}
\define@key{XML}{white-space-treatment}{%
 \def\@tempa{#1}\ifx\@tempa\att@preserve
    \XMLObeySpacetrue
 \else
    \XMLObeySpacefalse
 \fi
}
\define@key{XML}{text-indent}{%
  \def\XML@textindent{#1}%
}
\define@key{XML}{margin-bottom}{%
  \ifXMLinLayout
   \def\FooterMargin{#1}%
  \else
   \def\BottomMargin{#1}%
  \fi
}
\define@key{XML}{margin-top}{%
  \ifXMLinLayout
   \def\HeaderMargin{#1}%
  \else
   \def\TopMargin{#1}%
  \fi
}
\define@key{XML}{margin-left}{%
  \ifXMLDefiningPage
    \def\MasterLeftMargin{#1}%
  \else
    \def\LeftMargin{#1}%
  \fi
}
\define@key{XML}{margin-right}{%
  \ifXMLDefiningPage
    \def\MasterRightMargin{#1}%
  \else
    \def\RightMargin{#1}%
  \fi
}
\define@key{XML}{start-indent}{\def\StartIndent{#1}}
\define@key{XML}{end-indent}{\def\EndIndent{#1}}
\define@key{XML}{space-before.optimum}{\def\XML@spacebefore{#1}}
\define@key{XML}{space-before.maximum}{\def\XML@spacebeforemaximum{#1}}
\define@key{XML}{space-before.minimum}{\def\XML@spacebeforeminimum{#1}}
\define@key{XML}{space-after.optimum}{\def\XML@spaceafter{#1}}
\define@key{XML}{space-after.maximum}{\def\XML@spaceaftermaximum{#1}}
\define@key{XML}{space-after.minimum}{\def\XML@spaceafterminimum{#1}}
\define@key{XML}{space-after}{\def\XML@spaceafter{#1}}
\define@key{XML}{space-before}{\def\XML@spacebefore{#1}}

% keeps and breaks

\define@key{XML}{keep-with-next}{%
  \def\@tempa{#1}%
  \ifx\@tempa\att@true
    \XMLKeeptrue
  \else
    \XMLKeepfalse
  \fi
}
\define@key{XML}{break-after}{}
\define@key{XML}{break-before}{%
  \def\@tempa{#1}%
  \ifx\@tempa\att@page
    \penalty -\@M
  \fi
  \ifx\@tempa\att@oddpage
    \cleardoublepage
  \fi
}
\define@key{XML}{text-align-last}{%
   \def\QuaddingStart{\csname startQ@#1\endcsname}%
   \def\QuaddingEnd{\csname endQ@#1\endcsname}%
   \def\Quadding{\csname Q@#1\endcsname}%
}
\define@key{XML}{text-align}{%
   \def\TextAlign{#1}%
   \def\QuaddingStart{\csname startQ@#1\endcsname}%
   \def\QuaddingEnd{\csname endQ@#1\endcsname}%
   \def\Quadding{\csname Q@#1\endcsname}%
}

% font-related

\define@key{XML}{font-family}{\def\XML@fontfamily{#1}}
\AtBeginDocument{\InputIfFileExists{fotex.cfg}{}{}}

%%% %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%% %%%%%%%%%%%%%
%%% MUST USE | FOR COMMENT AFTER THIS POINT!!!!!!!!!!!!!!
%%% %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%% %%%%%%%%%%%%%
\catcode`\|=\catcode`\%
\catcode`\%=12
\def\percenttest#1%#2#3\@{|
  \ifx#2\relax
    \def\percentval{#1}|
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\newdimen\@default
\@default=10pt
\define@key{XML}{font-size}{|
  \@default\f@size pt
  \percenttest#1\relax%.\@
      {\dimen@0.01\@default
       \multiply\dimen@\percentval\relax}|
      {\dimen@#1}|
  \edef\XML@fontsize{\the\dimen@}}
\define@key{XML}{font-stretch}{\def\XML@fontstretch{#1}}
\define@key{XML}{line-height}{|
  \def\@tempa{#1}|
  \ifx\@tempa\att@normal
    \def\XML@lineheight{-1\p@}|
  \else
    \def\XML@lineheight{#1}|
  \fi
}
\define@key{XML}{font-style}{\edef\f@shape{\csname Posture@#1\endcsname}}
\define@key{XML}{font-weight}{\edef\XML@fontweight{#1}}
\define@key{XML}{font-variant}{\edef\XML@fontvariant{#1}}
\define@key{XML}{text-decoration}{|
   \def\XML@deco{\csname DECO@#1\endcsname}|
}
\def\DECO@blink{\uwave}
\expandafter\def\csname DECO@line-through\endcsname{\sout}
| set up font-related things
\def\SetFont{|
 \edef\LaTeXshape{\csname Width@\XML@fontstretch\endcsname
      \csname Weight@\XML@fontweight\endcsname}|
 \ifx\LaTeXshape\@empty\def\LaTeXshape{m}\fi
 \edef\f@series{\LaTeXshape}|
 \ifx\XML@fontvariant\att@smallcaps
   \def\f@shape{sc}|
 \fi
 \let\f@family\relax
 \@for\XML@foo:=\XML@fontfamily\do{|
    \ifx\f@family\relax
    \expandafter\let\expandafter\f@family
         \csname Family@\XML@foo\endcsname
    \fi}|
    \ifx\f@family\relax
      \def\f@family{\csname Family@\Defaultx@fontfamily\endcsname}|
    \fi
 \SetFontSize
 \selectfont
 \ifx\XML@color\@empty
 \else
   \color{\XML@color}|
 \fi
}
\def\SetFootFont{|
 \ifdim\XML@lineheight<\z@
   \@tempdima\XML@fontsize
   \multiply\@tempdima by 12
   \divide\@tempdima by 10
   \set@fontsize\XML@footnotesize{\XML@fontsize}{\@tempdima}|
 \else
   \@setfontsize\XML@footnotesize{\XML@fontsize}{\XML@lineheight}|
 \fi
}
\def\SetFontSize{|
 \ifdim\XML@lineheight<\z@
   \@tempdima\XML@fontsize
   \multiply\@tempdima by 12
   \divide\@tempdima by 10
 \else
   \@tempdima\XML@lineheight
 \fi
 \set@fontsize\baselinestretch{\XML@fontsize}{\@tempdima}|
| \typeout{FONT SIZE SET to \XML@fontsize/\the\@tempdima}|
}
\DeclareRobustCommand*\textsubscript[1]{|
  \@textsubscript{\selectfont#1}}
\def\@textsubscript#1{|
  {\m@th\ensuremath{_{\mbox{\fontsize\sf@size\z@#1}}}}}
\def\vspaceafter{|
\ifXMLinOutput\else
\ifXMLinTable
\else
   \@tempdima\XML@spaceafter
   \advance\@tempdima by -\XML@spaceafterminimum
   \@tempdimb\XML@spaceafter
   \advance\@tempdimb by \XML@spaceaftermaximum
   \vskip\XML@spaceafter plus \@tempdimb minus \@tempdima
\fi
\fi
}
\def\XMLLINEBREAK{|
\ifXMLinTable
\else
 \\
\fi
}
\def\vspacebefore{|
\ifXMLinOutput\else
\ifXMLinTable
\else
   \@tempdima\XML@spacebefore
   \advance\@tempdima by -\XML@spacebeforeminimum
   \@tempdimb\XML@spacebefore
   \advance\@tempdimb by \XML@spacebeforemaximum
   \vskip\XML@spacebefore plus \@tempdimb minus \@tempdima
\fi
\fi
  \def\XML@spacebefore{\z@}|
}
\def\reserved@e{}
\def\XMLSetPage{|
 \footskip\FooterMargin
 \oddsidemargin\MasterLeftMargin
 \evensidemargin\MasterLeftMargin
 \topmargin\TopMargin
 \headsep\HeaderMargin
 \paperwidth\PageWidth
 \paperheight\PageHeight
 \textheight\paperheight
 \textwidth\paperwidth
 \advance\textheight by -\TopMargin
 \advance\textheight by -\HeaderMargin
 \advance\textheight by -\BottomMargin
 \advance\textheight by -\FooterMargin
 \advance\textwidth by -\MasterLeftMargin
 \advance\textwidth by -\MasterRightMargin
 \ifx\pdfoutput\@undefined
 \else
   \typeout{Setting pdf size to \the\pdfpagewidth, \the\pdfpageheight}|
   \global\pdfpagewidth\paperwidth
   \global\pdfpageheight\paperheight
 \fi
 \@colht\textheight
 \@colroom\textheight
 \vsize\textheight
 \linewidth\textwidth
 \columnwidth\textwidth
 \hsize\columnwidth \linewidth\hsize
 \def\headheight{12pt}|
 \typeout{Page size is \the\textwidth/\the\textheight,
 on paper   \the\paperwidth/\the\paperheight,
 with margins \MasterRightMargin/\MasterLeftMargin,
 and \TopMargin/\BottomMargin;
and footermargin is \the\footskip, and headsep is
\the\headsep}|
 \global\XMLfirstpagefalse
}
\hoffset-1in
\voffset-1.75in
\clubpenalty=8000                 | 'orphan line' at bottom of page.
\emergencystretch 3em
\hbadness=4000
\hyphenpenalty=400
\pretolerance=500
\relpenalty=500
\tolerance=1000
\vbadness=3000
\widowpenalty=10000               | 'Widow line' at top of page.
\define@key{XML}{'Times New Roman'}[true]{}
\define@key{XML}{serif}[true]{}
| dont ask
\def\supppdf{supp-pdf}
\let\XMLInputIfFileExists\InputIfFileExists
\def\InputIfFileExists#1#2#3{|
 {\def\@tempa{#1}\ifx\@tempa\supppdf\else
   \XMLInputIfFileExists{#1}{#2}{#3}\fi}}
|\catcode`^^M=10
\catcode`\%=\catcode`\|
\catcode`\|=12
\providecommand\textasciitilde{~}
\endinput
