%%
%% This is file `polyglot.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% polyglot.dtx  (with options: `preload')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from polyglot.def.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file polyglot.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)

\def\fileversion{1.1}
\def\filedate{September 1, 1997}
\def\docdate{September 1, 1997}


\chardef\f@@r=4
\newcount\pg@count

\def\pg@@{pg-}
\def\pg@@text{pg-text-}
\def\pg@@math{pg-math-}

\def\pg@flag#1{\csname\pg@@#1-flag\endcsname}
\def\pg@@flag#1{\pg@@#1-flag}

\def\pg@last{{}{}}

\def\pg@err#1{\PackageError{polyglot}{#1}%
  {See polyglot documentation for explanation}}


\AtBeginDocument{\if@filesw\else
  \def\pg@file@setup#1#2#3{}%
  \let\pg@file@write\@gobble
  \let\pg@file@ends\relax\fi}

\def\pg@bug@err#1{\pg@err{Bug found (#1)}}


\def\pg@add@to#1{%
  \@ifundefined{\pg@@flag{#1}}%
    {\pg@err{Unknown group}}
    {\@ifundefined{pg@no#1}%
      {\@ifundefined{\pg@@\thelanguage-#1}%
        {\expandafter\let\csname\pg@@\thelanguage-#1\endcsname\@empty}%
        \@empty
       \expandafter\pg@after
            \csname\pg@@\thelanguage-#1\expandafter\endcsname}\@gobble}}

\@onlypreamble\pg@add@to

\def\pg@after#1#2{%
  \expandafter\def\expandafter#1\expandafter{#1#2}}

\def\pg@to@list#1{\@ifundefined{languagelist}%
  {\edef\languagelist{#1}}%
  {\edef\languagelist{\languagelist,#1}}}

\@onlypreamble\pg@to@list

\def\pg@process#1#2{%
  \begingroup\edef\pg@a{\endgroup
    \noexpand\pg@xproc\noexpand#1#2,\noexpand\@nil,}\pg@a}
\def\pg@xproc#1#2,{\ifx\@nil#2\else
  #1{#2}\expandafter\pg@xproc\expandafter#1\fi}

\def\pg@idend#1{#1\egroup}


\long\def\pg@cmd#1#2{%
  \pg@@
  \expandafter\ifx\csname\pg@@?#1\endcsname\relax#1%
    \else\expandafter\ifx\csname\pg@@#1-\string#2\endcsname\relax
      \csname\pg@@?#1\endcsname
    \else#1\fi\fi-\string#2}


\def\pg@ifno#1#2#3#4{%
  \if#1n\if#2o#3\else\@firstoftwo\fi\else#4\fi}

\def\pg@step{\afterassignment\pg@groups\def\pg@elt##1}

\def\selectlanguage{%
  \@ifstar{\pg@sel@i*}{\pg@sel@i{}}}

\def\pg@sel@i#1{\begingroup\catcode`\ =9 %
  \@ifnextchar[{\pg@sel@ii{#1}{}}{\pg@sel@ii{#1}{}[]}}

\def\pg@sel@ii#1#2[#3]#4{%
  \endgroup
  \if!#1!%
    \edef\pg@a{{\expandafter\@firstoftwo\pg@last}{[#3]{#4}}}%
  \else
    \def\pg@a{{[#3]{#4}}{}}%
  \fi
  \ifx\pg@a\pg@last\else
    \let\pg@last\pg@a
    \aftergroup\pg@file@ends
    \pg@file@setup{#1}{#3}{#4}%
    \pg@sel@iii#1[#3]{#4}%
  \fi#2}

\def\pg@sel@iii#1[#2]#3{%
  \@ifundefined{pgh@#3}%
    {\pg@err{Unknown language}\language\z@}%
    {\language\csname pgh@#3\endcsname}%
  \pg@step{\ifcase\pg@flag{##1}\or\or
    \@gobble\or\pg@disable{##1}\else
    \advance\pg@flag{##1}-\tw@\fi}%
  \let\thelanguage\pg@main
  \def\pg@elt##1{\pg@a##1\pg@a}%
  \if!#1!%
    \def\pg@a##1##2##3\pg@a{%
      \pg@ifno##1##2%
        {\pg@ifgroup{##3}{\advance\pg@flag{##3}\f@@r}}%
        {\pg@ifgroup{##1##2##3}%
          {\pg@after\pg@d{\pg@elt{##1##2##3}}%
           \advance\pg@flag{##1##2##3}\f@@r}}}%
    \let\pg@d\@empty
    \if!#2!\pg@text@groups\else
      \pg@process\pg@elt{#2}\fi
    \pg@step{\ifnum\pg@flag{##1}=\tw@\pg@enable{##1}\fi}%
    \pg@step{\ifnum\pg@flag{##1}=\f@@r\pg@disable{##1}\fi}%
    \pg@step{\pg@count\pg@flag{##1}%
      \pg@flag{##1}\ifnum\pg@count>\thr@@\f@@r\else\z@\fi
      \ifodd\pg@count\advance\pg@flag{##1}\@ne\fi}%
    \edef\thelanguage{#3}%
    \def\pg@elt##1{\pg@enable{##1}\advance\pg@flag{##1}-\tw@}%
    \pg@d\let\pg@d\@undefined
  \else
    \pg@step{\ifnum\pg@flag{##1}=\z@\pg@disable{##1}\fi}%
    \def\pg@elt##1{\pg@a##1\pg@a}%
    \if!#2!\else%
      \def\pg@a##1##2##3\pg@a{%
        \pg@ifno##1##2%
          {\pg@ifgroup{##3}{\advance\pg@flag{##3}-\@m}}% Just a mark
          {\pg@err{Invalid option skipped}{}}}%
      \pg@process\pg@elt{#2}%
    \fi
    \edef\pg@main{#3}%
    \edef\thelanguage{#3}%
    \pg@step{\ifnum\pg@flag{##1}<\z@\pg@flag{##1}\@ne
      \else\pg@flag{##1}\z@\pg@enable{##1}\fi}%
  \fi}

\def\uselanguage{\bgroup\begingroup\catcode`\ =9
   \@ifnextchar[{\pg@sel@ii{}\pg@idend}%
     {\pg@sel@ii{}\pg@idend[]}}

\def\unselectlanguage{\@ifstar{\selectlanguage[]{\pg@main}}%
  {\pg@unsel@i\pg@unsel@ii}}

\def\pg@unsel@i{%
  \c@pg@depth\z@\pg@file@ends
   \def\pg@elt##1{%
     \expandafter\let\csname\pg@@slot##1\endcsname\@empty}%
   \pg@elt{}\pg@streams}

\def\pg@unsel@ii{%
  \language\z@
  \pg@step{\ifcase\pg@flag{##1}\or\or
    \@gobble\or\pg@disable{##1}\fi}%
  \pg@step{\ifnum\pg@flag{##1}=\z@\pg@disable{##1}\fi}%
  \pg@step{\pg@flag{##1}\@ne}%
  \let\thelanguage\@empty\let\pg@main\@empty
  \def\pg@last{{}{}}}

\def\pg@enable#1{%
  \let\pg@switch\@firstoftwo
  \def\pg@group{#1}%
  \edef\pg@a{\csname\pg@@?\thelanguage\endcsname}%
  \expandafter\edef\csname\pg@@/#1\endcsname
      {\edef\noexpand\thelanguage{\pg@a}%
       \expandafter\noexpand\csname\pg@@\pg@a-#1\endcsname}%
  \def\pg@b##1\pg@b{%
    \let\thelanguage\pg@a
    \@nameuse{\pg@@\thelanguage-#1}%
    \edef\thelanguage{##1}%
    \expandafter\pg@after\csname\pg@@/#1\endcsname
      {\edef\thelanguage{##1}%
       \csname\pg@@##1-#1\endcsname}%
    \@nameuse{\pg@@\thelanguage-#1}}%
  \expandafter\pg@b\thelanguage\pg@b}

\def\pg@disable#1{%
  \let\pg@switch\@secondoftwo
  \csname\pg@@/#1\endcsname
  \expandafter\let\csname\pg@@/#1\endcsname\relax}

\def\pg@sel@opt{%
  \@tempswatrue
  \def\pg@d##1{\@ifundefined{pgh@##1}\@empty
      {\if@tempswa
       \PackageInfo{polyglot}%
             {Selecting document language:\MessageBreak
              ##1\@gobble}%
       \selectlanguage*{##1}\@tempswafalse\fi}}%
  \ifx\@classoptionslist\@empty\else
    \pg@process\pg@d\@classoptionslist\fi
  \ifx\@curroptions\@empty\else
    \if@tempswa\pg@process\pg@d\@curroptions\fi\fi
  \let\pg@d\@undefined}

\@onlypreamble\pg@sel@opt


\let\pg@immediate\relax

\def\pg@@slot{pg@slot@}

\def\pg@file@setup#1#2#3{%
  \advance\c@pg@depth\@ne
  \def\pg@elt##1{%
     \expandafter\pg@after\csname\pg@@slot##1\endcsname
       {\addtocounter{\pg@@slot\the\pg@count}\@ne
        \pg@immediate\write\pg@count
          {\pg@begin\noexpand\selectlanguage#1[#2]{#3}}}}%
  \pg@elt\@empty\pg@streams}

\def\pg@file@write#1{%
   \pg@count=#1\relax
   \@ifundefined{c@\pg@@slot\the\pg@count}%
     {\newcounter{\pg@@slot\the\pg@count}%
      \pg@slot@\let\pg@elt\relax
      \xdef\pg@streams{\pg@streams\pg@elt{\the\pg@count}}}{}%
     {\@nameuse{\pg@@slot\the\pg@count}}%
   \expandafter\gdef\csname\pg@@slot\the\pg@count\endcsname{}}

\def\pg@file@ends{%
  \def\pg@elt##1%
    {\ifnum\value{\pg@@slot##1}>\c@pg@depth
     \pg@immediate\write##1{\pg@end}%
     \addtocounter{\pg@@slot##1}\m@ne
     \expandafter\pg@elt\else\expandafter\@gobble\fi{##1}}%
  \pg@streams\let\pg@elt\relax}%

\let\pg@streams\@empty
\let\pg@slot@\@empty

\let\pg@begin\begingroup
\let\pg@end\endgroup

\newcounter{pg@depth}

\AtEndDocument{\unselectlanguage
  \let\pg@immediate\immediate}


\long\def\protected@write#1#2#3{%
  \pg@file@write{#1}%
  \begingroup
    \let\thepage\relax
    #2%
    \let\LanguageLigature\string
    \let\protect\@unexpandable@protect
    \edef\reserved@a{\write#1{#3}}%
    \reserved@a
    \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi}

\long\def\@writefile#1#2{%
  \@ifundefined{tf@#1}\relax
    {\pg@file@write{\csname tf@#1\endcsname}%
     \@temptokena{#2}%
     \pg@immediate\write\csname tf@#1\endcsname{\the\@temptokena}}}

\def\@lbibitem[#1]#2{\item[\@biblabel{#1}\hfill]%
  \if@filesw
    \protected@write\@auxout{}%
      {\string\bibcite{#2}{\protect\pg@ensure\pg@last#1}}%
  \fi\ignorespaces}

\def\DeclareLanguageCommand#1#2{%
  \@ifundefined{\pg@cmd\thelanguage{#1}}%
   {\pg@add@to{#2}{\pg@switch@cmd#1}%
    \expandafter\newcommand
      \csname\pg@@\thelanguage-\string#1\endcsname}%
   {\pg@bug@err3}}

\@onlypreamble\DeclareLanguageCommand

\def\pg@switch@cmd#1{%
  \pg@switch
    {\ifx#1\@undefined
       \expandafter\pg@after
         \csname\pg@@/\pg@group\endcsname{\let#1\@undefined}%
     \fi}{}%
  \let\pg@c=#1%
  \expandafter\let\expandafter
    #1\csname\pg@@\thelanguage-\string#1\endcsname
  \expandafter\let
    \csname\pg@@\thelanguage-\string#1\endcsname=\pg@c}

\def\SetLanguageVariable#1#2{%
  \@ifundefined{\pg@cmd\thelanguage{#1}}%
   {\pg@add@to{#2}{\pg@switch@var{#1}}
    \@namedef{\pg@@\thelanguage-\string#1}}%
   {\pg@bug@err3}}

\@onlypreamble\SetLanguageVariable

\def\pg@switch@var#1{%
  \edef\pg@c{\the#1}%
  #1=\csname\pg@@\thelanguage-\string#1\endcsname\relax
  \expandafter\edef\csname\pg@@\thelanguage-\string#1\endcsname{\pg@c}}


\def\SetLanguageCode#1#2#3{\pg@count=#3\relax
  \edef\pg@a{\noexpand\SetLanguageVariable
       {\noexpand#1\the\pg@count}}%
  \pg@a{#2}}

\@onlypreamble\SetLanguageCode

\begingroup
\catcode`~=\active
\gdef\DeclareLanguageSymbolCommand#1#2{%
  \SetLanguageCode{\catcode}{#2}{`#1}{\active}%
  \def\pg@a{#2}%
  \begingroup \lccode`~=`#1 \lccode`#1=`#1
  \lowercase{\endgroup
    \pg@add@to\pg@a{\UpdateSpecial{#1}}%
    \DeclareLanguageCommand{~}\pg@a}}
\endgroup

\@onlypreamble\DeclareLanguageSymbolCommand


\def\DeclareLanguage#1{%
  \def\thelanguage{!#1}%
  \@namedef{\pg@@?#1}{!#1}%
  \def\pg@main{!#1}}

\def\DeclareDialect#1{%
  \expandafter\let\csname\pg@@?#1\endcsname\pg@main}

\@onlypreamble\DeclareLanguage
\@onlypreamble\DeclareDialect

\def\SetLanguage#1{%
  \@ifundefined{\pg@@?#1}%
     {\pg@bug@err4}%
     {\edef\thelanguage{!#1}}}

\def\SetDialect#1{
  \@ifundefined{\pg@@?#1}%
     {\pg@bug@err4}%
     {\edef\thelanguage{#1}}}

\@onlypreamble\SetLanguage
\@onlypreamble\SetDialect


\def\pg@ifgroup#1{\@ifundefined{\pg@@flag{#1}}%
  {\pg@bug@err1\@gobble}}

\def\DeclareLanguageGroup{%
  \@ifstar{\pg@newgroup\pg@c}%
          {\pg@newgroup\pg@text@groups}}

\def\pg@newgroup#1#2{%
  \def\pg@a##1##2##3\pg@a{%
    \pg@ifno##1##2}%
  \pg@a#2\pg@a
    {\pg@bug@err2}%
    {\@ifundefined{\pg@@flag{#2}}%
       {\pg@after\pg@groups{\pg@elt{#2}}%
        \pg@after#1{\pg@elt{#2}}%
        \expandafter\newcount\csname\pg@@flag{#2}\endcsname
        \pg@flag{#2}\@ne}%
       {\PackageInfo{polyglot}%
         {Ignoring group declaration: #2.^^J%
          Already declared\@gobble}}}}

\@onlypreamble\DeclareLanguageGroup
\@onlypreamble\pg@newgroup

\let\pg@groups\@empty
\let\pg@text@groups\@empty
\let\pg@c\@empty

\DeclareLanguageGroup*{names}
\DeclareLanguageGroup*{layout}
\DeclareLanguageGroup*{date}

\DeclareLanguageGroup{ligatures}
\DeclareLanguageGroup{text}
\DeclareLanguageGroup{tools}


\def\DeclareDateFunctionDefault#1{%
  \expandafter\providecommand\csname\pg@@ DF-#1\endcsname}

\def\DeclareDateFunction#1{%
  \expandafter\DeclareLanguageCommand
    \csname\pg@@ DF-#1\endcsname{date}}

\@onlypreamble\DeclareDateFunctionDefault
\@onlypreamble\DeclareDateFunction

\begingroup
\catcode`<=\active
\gdef\DeclareDateCommand#1{%
  \begingroup
  \let\protect\@unexpandable@protect
  \catcode`<=\active
  \def<##1>{\expandafter\noexpand\csname\pg@@ DF-##1\endcsname}%
  \def\pg@a{%
   \edef\pg@b{\endgroup%
    \noexpand\DeclareLanguageCommand{\noexpand#1}{date}{\pg@c}}
    \pg@b}%
  \afterassignment\pg@a\def\pg@c}
\endgroup

\@onlypreamble\DeclareDateCommand

\newcount\weekday

\let\c@day\day
\let\c@weekday\weekday
\let\c@month\month
\let\c@year\year

\def\SetWeekDay{\pg@count=\year\divide\pg@count4
  \weekday=\pg@count
  \multiply\pg@count4
  \advance\pg@count-\year
  \ifnum\pg@count=\z@
        \ifnum\month<\thr@@\advance\weekday -1\fi\fi
  \advance\weekday\year
  \advance\weekday-1899
  \advance\weekday\ifcase\month\or0 \or31 \or59 \or90 \or120
        \or151 \or181 \or212 \or243 \or293 \or304 \or334 \fi
  \advance\weekday\day
  \pg@count=\weekday
  \divide\pg@count7
  \multiply\pg@count7
  \advance\weekday-\pg@count
  \advance\weekday\@ne}

\SetWeekDay

\DeclareDateFunctionDefault{d}{\the\day}
\DeclareDateFunctionDefault{dd}{\ifnum\day<10 0\fi\the\day}

\DeclareDateFunctionDefault{m}{\the\month}
\DeclareDateFunctionDefault{mm}{\ifnum\month<10 0\fi\the\month}

\DeclareDateFunctionDefault{yy}{\expandafter\@gobbletwo\the\year}
\DeclareDateFunctionDefault{yyyy}{\the\year}


\def\pg@lig{\ifcase\pg@flag{ligatures}\pg@main\or\or
    \@gobble\or\thelanguage\fi}

\def\pg@cs@lig{%
  \ifmmode\expandafter\pg@math@ligature
  \else\expandafter\pg@text@ligature\fi}

\def\LanguageLigature{%
  \ifx\protect\@unexpandable@protect
    \expandafter\noexpand
  \else\ifx\protect\@typeset@protect
    \expandafter\expandafter\expandafter\pg@cs@lig
  \else\expandafter\expandafter\expandafter\protect
  \fi\fi}

\begingroup
\catcode`~=\active
\gdef\DeclareLigature#1{%
  \pg@add@to{ligatures}{\pg@switch{\pg@set@lig{#1}}{}}%
  \begingroup \lccode`~=`#1 \lccode`#1=`#1
  \lowercase{\endgroup
    \DeclareLanguageSymbolCommand{#1}{ligatures}%
             {\LanguageLigature~}}}
\endgroup

\@onlypreamble\DeclareLigature


\def\DeclareLigatureCommand#1#2{%
  \@ifnextchar[%
    {\pg@declare@lig{#1}{#2}}%
    {\pg@declare@lig{#1}{#2}[]}}

\def\pg@declare@lig#1#2[#3]{%
  \@ifundefined{\pg@cmd\thelanguage{#1}}%
    {\DeclareLigature{#1}}\@empty
  \@ifundefined{\pg@cmd\thelanguage{#1-\string#2}}%
   {\@namedef{\pg@@\thelanguage-\string#1-\string#2}}%
   {\pg@bug@err3}}

\@onlypreamble\DeclareLigatureCommand


\begingroup
\catcode`\$=3 \catcode`\&=4
\catcode`\#=6
\catcode`\^=7 \catcode`\_=8
\catcode`\ =10 \gdef\pg@space{ }
\catcode`\^^L=11 \catcode`\^^O=12
\catcode`\~=13
\gdef\pg@set@lig#1{\begingroup
  \lccode`^^L=`#1 \lccode`^^O=`#1 \lccode`~=`#1 \lccode`#1=`#1
  \lowercase{\endgroup
  \edef\pg@b{\noexpand\let
      \expandafter\noexpand\csname\pg@@text\string#1\endcsname
    \ifcase\catcode`#1 \or\or\or$\or&\or
      \or####\or^\or_\or\or\noexpand\pg@space
      \or ^^L\or^^O\or\noexpand~\or\or^^O\fi}%
    \pg@b\@gobbletwo\pg@lig@err{\string#1}%
    \expandafter\let\csname\pg@@math\string#1\expandafter
      \endcsname\csname\pg@@text\string#1\endcsname
    \ifnum\catcode`#1>10 \ifnum\catcode`#1<13 \ifnum\mathcode`#1="8000
      \expandafter\let\csname\pg@@math\string#1\endcsname=~%
    \fi\fi\fi}}
\endgroup

\def\pg@lig@err{\pg@err{Bad ligature}}


\begingroup
\catcode`\%=12 \catcode`\&=14
\long\gdef\pg@text@ligature#1#2{&
  \expandafter\if\expandafter%\@gobble#2%\@empty
    \expandafter\pg@ligature\expandafter#1&
  \else
    \csname\pg@@text\string#1\expandafter\endcsname
  \fi{#2}}
\endgroup

\long\def\pg@ligature#1#2{%
  \expandafter\ifx\csname\pg@cmd\pg@lig{#1-\string#2}\endcsname\relax
    \csname\pg@@text\string#1\expandafter\endcsname\expandafter#2%
  \else
    \csname\pg@cmd\pg@lig{#1-\string#2}\expandafter\endcsname
  \fi}

\long\def\pg@math@ligature#1{%
  \@nameuse{\pg@@math\string#1}}

\def\UpdateSpecial#1{\expandafter\pg@update@special
  \csname\string#1\endcsname}

\def\pg@update@special#1{%
  \def\pg@b##1##2{\ifnum`#1=`##2 \else
     \noexpand##1\noexpand##2\fi}%
  \def\pg@c##1##2{\ifnum\catcode`##2<\active
     \ifnum\catcode`##2>10 \else\@firstoftwo\fi
       \else\noexpand##1\noexpand##2\fi}%
  \def\do{\pg@b\do}%
  \def\@makeother{\pg@b\@makeother}%
  \edef\dospecials{\dospecials\pg@c\do#1}%
  \edef\@sanitize{\@sanitize\pg@c\@makeother#1}%
  \let\do\relax
  \def\@makeother##1{\catcode`##1=12\relax}}

\begingroup
\catcode`*=\active \catcode`^=7
\catcode`~=\active \catcode`'=12
\lccode`*=`^ \lccode`^=`^ \lccode`~=`' \lccode`'=`'
\lowercase{%
\gdef\pr@m@s{%
  \ifx~\@let@token\let\@let@token='\fi
  \ifx*\@let@token\let\@let@token=^\fi
  \ifx'\@let@token
    \expandafter\pr@@@s
  \else\ifx^\@let@token
      \expandafter\expandafter\expandafter\pr@@@t
  \else
      \egroup
  \fi\fi}}
\endgroup


\begingroup
\catcode`"=12 \catcode`'=12 \catcode``=12
\gdef\hexnumber{"}
\gdef\octalnumber{'}
\gdef\charnumber{`}
\endgroup

\def\allowhyphens{\ifhmode\nobreak\hskip\z@skip\fi}

\providecommand\@tabacckludge[1]{%
  \expandafter\@changed@cmd\csname#1\endcsname\relax}

\def\ensurelanguage{\ifx\glossary\relax
  \protect\pg@ensure\pg@last\fi}

\def\pg@ensure#1#2{%
  \def\pg@a{{#1}{#2}}%
  \ifx\pg@a\pg@last\else
    \def\pg@a{#1}%
    \ifx\pg@a\@empty\def\pg@c{\pg@unsel@ii}\else
      \def\pg@c{\pg@sel@iii*#1}\fi
    \def\pg@a{#2}%
    \ifx\pg@a\@empty\else
     \def\pg@a{#1}\edef\pg@b{\expandafter\@firstoftwo\pg@last}%
     \ifx\pg@b\pg@a\expandafter\def\else\expandafter\pg@after\fi
     \pg@c{\pg@sel@iii{}#2}%
    \fi
    \expandafter\pg@c
  \fi}

\def\ensuredcommand#1#2{%
  \expandafter\gdef\expandafter#1\expandafter
    {\expandafter{\expandafter\pg@ensure\pg@last#2}}}


\def\markboth#1#2{%
     \gdef\@themark{{\ensurelanguage#1}{\ensurelanguage#2}}{%
     \let\protect\@unexpandable@protect
     \let\label\relax \let\index\relax \let\glossary\relax
     \mark{\@themark}}\if@nobreak\ifvmode\nobreak\fi\fi}

\def\@markright#1#2#3{%
  \gdef\@themark{{#1}{\ensurelanguage#3}}}


\def\DeclareLanguageCompositeCommand#1#2#3{%
  \pg@add@to{text}{\pg@composite{#1}{#2}}%
  \expandafter\DeclareLanguageCommand
    \csname\expandafter\string\csname#2\endcsname
    \string#1-\string#3\endcsname{text}}

\def\pg@composite#1#2{%
  \@ifundefined{\pg@cmd\thelanguage{#1}}%
    {\expandafter\let\csname\pg@@\thelanguage-\string#1\endcsname#1%
     \expandafter\pg@after\csname\pg@@/text\endcsname
         {\expandafter\let\expandafter
            #1\csname\pg@@\thelanguage-\string#1\endcsname}}{}%
  \expandafter\let\expandafter\reserved@a\csname#2\string#1\endcsname
  \expandafter\expandafter\expandafter\ifx
  \expandafter\@car\reserved@a\relax\relax\@nil \@text@composite \else
      \edef\reserved@b##1{%
         \def\expandafter\noexpand
            \csname#2\string#1\endcsname####1{%
               \noexpand\@text@composite
               \expandafter\noexpand\csname#2\string#1\endcsname
               ####1\noexpand\@empty\noexpand\@text@composite
               {##1}}}%
      \expandafter\reserved@b\expandafter{\reserved@a{##1}}%
   \fi}

\@onlypreamble\DeclareLanguageCompositeCommand


\def\DeclareLanguageTextCommand#1#2{%
  \@ifundefined{\pg@cmd\thelanguage{#1}}%
    {\DeclareLanguageCommand{#1}{text}%
                           {\pg@text@cmd{#1}{#2}}%
     \expandafter\DeclareLanguageCommand
       \csname#2\string#1\endcsname{text}}%
    {\expandafter\let\expandafter\pg@a
       \csname\pg@@\thelanguage-\string#1\endcsname
     \expandafter\in@\expandafter\pg@text@cmd
       \expandafter{\pg@a}%
     \ifin@\def\pg@a{\expandafter\DeclareLanguageCommand
       \csname#2\string#1\endcsname{text}}%
       \expandafter\pg@a
     \else\pg@bug@err3\fi}}

\@onlypreamble\DeclareLanguageTextCommand

\def\pg@text@cmd#1#2{%
  \csname#2-cmd\expandafter\endcsname
  \expandafter#1%
  \csname#2\string#1\endcsname}


\def\pg@extensions#1{%
  \edef\cdp@elt##1##2##3##4{%
    \def\noexpand\DeclareCompositeLanguageCommand####1{%
      \noexpand\pg@composite{####1}{##1}}%
    \def\noexpand\DeclareTextLanguageCommand####1{%
      \noexpand\pg@text{####1}{##1}}%
    \noexpand\InputIfFileExists{#1.##1}{}{}}%
  \cdp@list}


\everyjob\expandafter{\the\everyjob\SetWeekDay}


\@onlypreamble\PreLoadPatterns
\@onlypreamble\SetPatterns
\@onlypreamble\PreLoadLanguage
\@onlypreamble\LoadLanguage
\@onlypreamble\pg@input
\@onlypreamble\pg@load

\endinput
%%
%% End of file `polyglot.def'.