\makeatletter

% Development notes at
% http://docutils.python-hosting.com/wiki/NewLatex


\providecommand{\Dprinting}{false}


\providecommand{\DSearly}{}
\providecommand{\DSlate}{}

\providecommand{\Ddocumentclass}{scrartcl}
\providecommand{\Ddocumentoptions}{a4paper}

\documentclass[\Ddocumentoptions]{\Ddocumentclass}

\DSearly


\providecommand{\DSfontencoding}{
  % Set up font encoding.
  % AE is a T1-emulation.  It provides most characters and features
  % as T1-encoded fonts but doesn't use ugly bitmap fonts.
  \usepackage{ae}
  % Provide the characters not contained in AE from EC bitmap fonts.
  \usepackage{aecompl}
  % Guillemets ("<<", ">>") in AE.
  \usepackage{aeguill}
}


\providecommand{\DSsymbols}{%
  % Fix up symbols.
  % The Euro symbol in Computer Modern looks, um, funny.  Let's get a
  % proper Euro symbol.
  \RequirePackage{eurosym}%
  \renewcommand{\texteuro}{\euro}%
}


% Taken from
% <http://groups.google.de/groups?selm=1i0n5tgtplti420e1omp4pctlv19jpuhbb%404ax.com>
% and modified.  Used with permission.
\providecommand{\Dprovidelength}[2]{%
  \begingroup%
    \escapechar\m@ne%
    \xdef\@gtempa{{\string#1}}%
  \endgroup%
  \expandafter\@ifundefined\@gtempa%
  {\newlength{#1}\setlength{#1}{#2}}%
  {}%
}

\providecommand{\Dprovidecounter}[1]{%
  % Like \newcounter except that it doesn't crash if the counter
  % already exists.
  \@ifundefined{c@#1}{\newcounter{#1}}{}
}

\Dprovidelength{\Dboxparindent}{\parindent}
\providecommand{\Dmakeboxminipage}[1]{%
  % Make minipage for use in a box created by \Dmakefbox.
  \begin{minipage}[t]{0.9\linewidth}%
    \setlength{\parindent}{\Dboxparindent}%
    #1%
  \end{minipage}%
}
\providecommand{\Dmakefbox}[1]{%
  % Make a centered, framed box.  Useful e.g. for admonitions.
  \vspace{0.4\baselineskip}%
  \begin{center}%
    \fbox{\Dmakeboxminipage{#1}}%
  \end{center}%
  \vspace{0.4\baselineskip}%
}
\providecommand{\Dmakebox}[1]{%
  % Make a centered, frameless box.  Useful e.g. for block quotes.
  % Do not use minipages here, but create pseudo-lists to allow
  % page-breaking.  (Don't use KOMA-script's addmargin environment
  % because it messes up bullet lists.)
  \Dmakelistenvironment{}{}{%
    \setlength{\parskip}{0pt}%
    \setlength{\parindent}{\Dboxparindent}%
    \item{#1}%
  }%
}


\RequirePackage{ifthen}
\providecommand{\Dfrenchspacing}{true}
\ifthenelse{\equal{\Dfrenchspacing}{true}}{\frenchspacing}{}


\Dprovidelength{\Dblocklevelvspace}{%
  % Space between block-level elements other than paragraphs.
  0.7\baselineskip plus 0.3\baselineskip minus 0.2\baselineskip%
}
\providecommand{\Dauxiliaryspace}{%
  \ifthenelse{\equal{\Dneedvspace}{true}}{\vspace{\Dblocklevelvspace}}{}%
  \par\noindent%
}
\providecommand{\Dparagraphspace}{\par}
\providecommand{\Dneedvspace}{true}


\providecommand{\DSlinks}{
  % Targets and references.
  \RequirePackage[colorlinks=false,pdfborder={0 0 0}]{hyperref}

  \providecommand{\Draisedlink}[1]{\Hy@raisedlink{##1}}
  
  % References.
  % We're assuming here that the "refid" and "refuri" attributes occur
  % only in inline context (in TextElements).
  \providecommand{\DArefid}[5]{%
    \ifthenelse{\equal{##4}{reference}}{%
      \Dexplicitreference{\###3}{##5}%
    }{%
      % If this is not a target node (targets with refids are
      % uninteresting and should be silently dropped).
      \ifthenelse{\not\equal{##4}{target}}{%
        % If this is a footnote reference, call special macro.
        \ifthenelse{\equal{##4}{footnotereference}}{%
          \Dimplicitfootnotereference{\###3}{##5}%
        }{%
          \ifthenelse{\equal{##4}{citationreference}}{%
            \Dimplicitcitationreference{\###3}{##5}%
          }{%
            \Dimplicitreference{\###3}{##5}%
          }%
        }%
      }{}%
    }%
  }
  \providecommand{\DArefuri}[5]{%
    \ifthenelse{\equal{##4}{target}}{%
      % Hyperlink targets can (and should be) ignored because they are
      % invisible.
    }{%
      % We only have explicit URI references, so one macro suffices.
      \Durireference{##3}{##5}%
    }%
  }
  % Targets.
  \providecommand{\DAids}[5]{%
    \label{##3}%
    \ifthenelse{\equal{##4}{footnotereference}}{%
      {%
        \renewcommand{\HyperRaiseLinkDefault}{%
          % Dirty hack to make backrefs to footnote references work.
          % For some reason, \baselineskip is 0pt in fn references.
          0.5\Doriginalbaselineskip%
        }%
        \Draisedlink{\hypertarget{##3}{}}##5%
      }%
    }{%
      \Draisedlink{\hypertarget{##3}{}}##5%
    }%
  }
  % Color in references.
  \RequirePackage{color}
  \providecommand{\Dimplicitreference}[2]{%
    % Create implicit reference to ID.  Implicit references occur
    % e.g. in TOC-backlinks of section titles.  Parameters:
    % 1. Target.
    % 2. Link text.
    \href{##1}{##2}%
  }
  \providecommand{\Dimplicitfootnotereference}[2]{%
    % Ditto, but for the special case of footnotes.
    % We want them to be rendered like explicit references.
    \Dexplicitreference{##1}{##2}%
  }
  \providecommand{\Dimplicitcitationreference}[2]{%
    % Ditto for citation references.
    \Dimplicitfootnotereference{##1}{##2}%
  }
  \ifthenelse{\equal{\Dprinting}{true}}{
    \providecommand{\Dexplicitreferencecolor}{black}
  }{
    \providecommand{\Dexplicitreferencecolor}{blue}
  }
  \providecommand{\Dexplicitreference}[2]{%
    % Create explicit reference to ID, e.g. created with "foo_".
    % Parameters:
    % 1. Target.
    % 2. Link text.
    \href{##1}{{\color{\Dexplicitreferencecolor}##2}}%
  }
  \providecommand{\Durireferencecolor}{\Dexplicitreferencecolor}
  \providecommand{\Durireference}[2]{%
    % Create reference to URI.  Parameters:
    % 1. Target.
    % 2. Link text.
    \href{##1}{{\color{\Durireferencecolor}##2}}%
  }
}


\providecommand{\DSlanguage}{%
  % Set up babel.
  \ifthenelse{\equal{\Dlanguagebabel}{}}{}{
    \RequirePackage[\Dlanguagebabel]{babel}
  }
}




\providecommand{\DAclasses}[5]{%
  \Difdefined{DN#4C#3}{%
    % Pass only contents, nothing else!
    \csname DN#4C#3\endcsname{#5}%
  }{%
    \Difdefined{DC#3}{%
      \csname DC#3\endcsname{#5}%
    }{%
      #5%
    }%
  }%
}

\providecommand{\Difdefined}[3]{\@ifundefined{#1}{#3}{#2}}

\providecommand{\Dattr}[5]{%
  % Global attribute dispatcher.
  % Parameters:
  % 1. Attribute number.
  % 2. Attribute name.
  % 3. Attribute value.
  % 4. Node name.
  % 5. Node contents.
  \Difdefined{DN#4A#2V#3}{%
    \csname DN#4A#2V#3\endcsname{#1}{#2}{#3}{#4}{#5}%
  }{\Difdefined{DN#4A#2}{%
    \csname DN#4A#2\endcsname{#1}{#2}{#3}{#4}{#5}%
  }{\Difdefined{DA#2V#3}{%
    \csname DA#2V#3\endcsname{#1}{#2}{#3}{#4}{#5}%
  }{\Difdefined{DA#2}{%
    \csname DA#2\endcsname{#1}{#2}{#3}{#4}{#5}%
  }{#5%
  }}}}%
}

\providecommand{\DNparagraph}[1]{%
  \ifthenelse{\equal{\Dparagraphindented}{true}}{\indent}{\noindent}%
  #1%
}
\providecommand{\Dformatboxtitle}[1]{{\Large\textbf{#1}}}
\providecommand{\Dformatboxsubtitle}[1]{{\large\textbf{#1}}}
\providecommand{\Dtopictitle}[1]{%
  \Difinsidetoc{\vspace{1em}\par}{}%
  \noindent\Dformatboxtitle{#1}%
  \ifthenelse{\equal{\Dhassubtitle}{false}}{\vspace{1em}}{\vspace{0.5em}}%
  \par%
}
\providecommand{\Dtopicsubtitle}[1]{%
  \noindent\Dformatboxsubtitle{#1}%
  \vspace{1em}%
  \par%
}
\providecommand{\Dsidebartitle}[1]{\Dtopictitle{#1}}
\providecommand{\Dsidebarsubtitle}[1]{\Dtopicsubtitle{#1}}
\providecommand{\Ddocumenttitle}[1]{%
  \begin{center}{\Huge#1}\end{center}%
  \ifthenelse{\equal{\Dhassubtitle}{true}}{\vspace{0.1cm}}{\vspace{1cm}}%
}
\providecommand{\Ddocumentsubtitle}[1]{%
  \begin{center}{\huge#1}\end{center}%
  \vspace{1cm}%
}
% Can be overwritten by user stylesheet.
\providecommand{\Dformatsectiontitle}[1]{#1}
\providecommand{\Dformatsectionsubtitle}[1]{\Dformatsectiontitle{#1}}
\providecommand{\Dbookmarksectiontitle}[1]{%
  % Return text suitable for use in \section*, \subsection*, etc.,
  % containing a PDF bookmark.  Parameter:  The title (as node tree).
  \Draisedlink{\Dpdfbookmark{\Dtitleastext}}%
  #1%
}
\providecommand{\Dsectiontitlehook}[1]{#1}
\providecommand{\Dsectiontitle}[1]{%
  \Dsectiontitlehook{%
    \Ddispatchsectiontitle{\Dbookmarksectiontitle{\Dformatsectiontitle{#1}}}%
  }%
}
\providecommand{\Ddispatchsectiontitle}[1]{%
  \@ifundefined{Dsectiontitle\roman{Dsectionlevel}}{%
    \Ddeepsectiontitle{#1}%
  }{%
    \csname Dsectiontitle\roman{Dsectionlevel}\endcsname{#1}%
  }%
}
\providecommand{\Ddispatchsectionsubtitle}[1]{%
  \Ddispatchsectiontitle{#1}%
}
\providecommand{\Dsectiontitlei}[1]{\section*{#1}}
\providecommand{\Dsectiontitleii}[1]{\subsection*{#1}}
\providecommand{\Ddeepsectiontitle}[1]{%
  % Anything below \subsubsection (like \paragraph or \subparagraph)
  % is useless because it uses the same font.  The only way to
  % (visually) distinguish such deeply nested sections is to use
  % section numbering.
  \subsubsection*{#1}%
}
\providecommand{\Dsectionsubtitlehook}[1]{#1}
\Dprovidelength{\Dsectionsubtitleraisedistance}{0.7em}
\providecommand{\Dsectionsubtitlescaling}{0.85}
\providecommand{\Dsectionsubtitle}[1]{%
  \Dsectionsubtitlehook{%
    % Move the subtitle nearer to the title.
    \vspace{-\Dsectionsubtitleraisedistance}%
    % Don't create a PDF bookmark.
    \Ddispatchsectionsubtitle{%
      \Dformatsectionsubtitle{\scalebox{\Dsectionsubtitlescaling}{#1}}%
    }%
  }%
}
% Boolean variable.
\providecommand{\Dhassubtitle}{false}
\providecommand{\DNtitle}[1]{%
  \csname D\Dparent title\endcsname{#1}%
}
\providecommand{\DNsubtitle}[1]{%
  \csname D\Dparent subtitle\endcsname{#1}%
}
\newcounter{Dpdfbookmarkid}
\setcounter{Dpdfbookmarkid}{0}
\providecommand{\Dpdfbookmark}[1]{%
  % Temporarily decrement Desctionlevel counter.
  \addtocounter{Dsectionlevel}{-1}%
  %\typeout{\arabic{Dsectionlevel}}%
  %\typeout{#1}%
  %\typeout{docutils\roman{Dpdfbookmarkid}}%
  %\typeout{}%
  \pdfbookmark[\arabic{Dsectionlevel}]{#1}{docutils\arabic{Dpdfbookmarkid}}%
  \addtocounter{Dsectionlevel}{1}%
  \addtocounter{Dpdfbookmarkid}{1}%
}

%\providecommand{\DNliteralblock}[1]{\begin{quote}\ttfamily\raggedright#1\end{quote}}
\providecommand{\DNliteralblock}[1]{%
  \Dmakelistenvironment{}{%
    \ifthenelse{\equal{\Dinsidetabular}{true}}{%
      \setlength{\leftmargin}{0pt}%
    }{}%
    \setlength{\rightmargin}{0pt}%
  }{%
    \raggedright\item\noindent\nohyphens{\textnhtt{#1\Dfinalstrut}}%
  }%
}
\providecommand{\DNdoctestblock}[1]{%
  % Treat doctest blocks the same as literal blocks.
  \DNliteralblock{#1}%
}
\RequirePackage{hyphenat}
\providecommand{\DNliteral}[1]{\textnhtt{#1}}
\providecommand{\DNemphasis}[1]{\emph{#1}}
\providecommand{\DNstrong}[1]{\textbf{#1}}
\providecommand{\Dvisitdocument}{\begin{document}\noindent}
\providecommand{\Ddepartdocument}{\end{document}}
\providecommand{\DNtopic}[1]{%
  \ifthenelse{\equal{\DcurrentNtopicAcontents}{1}}{%
    \addtocounter{Dtoclevel}{1}%
    \par\noindent%
    #1%
    \addtocounter{Dtoclevel}{-1}%
  }{%
    \par\noindent%
    \Dmakebox{#1}%
  }%
}
\providecommand{\Dformatrubric}[1]{\textbf{#1}}
\Dprovidelength{\Dprerubricspace}{0.3em}
\providecommand{\DNrubric}[1]{%
  \vspace{\Dprerubricspace}\par\noindent\Dformatrubric{#1}\par%
}

\providecommand{\Dbullet}{}
\providecommand{\Dsetbullet}[1]{\renewcommand{\Dbullet}{#1}}
\providecommand{\DNbulletlist}[1]{%
  \Difinsidetoc{%
    \Dtocbulletlist{#1}%
  }{%
    \Dmakelistenvironment{\Dbullet}{}{#1}%
  }%
}
\renewcommand{\@pnumwidth}{2.2em}
\providecommand{\DNlistitem}[1]{%
  \Difinsidetoc{%
    \ifthenelse{\equal{\theDtoclevel}{1}\and\equal{\Dlocaltoc}{false}}{%
      {%
        \par\addvspace{1em}\noindent%
        \sectfont%
        #1\hfill\pageref{\DcurrentNlistitemAtocrefid}%
      }%
    }{%
      \@dottedtocline{0}{\Dtocindent}{0em}{#1}{%
        \pageref{\DcurrentNlistitemAtocrefid}%
      }%
    }%
  }{%
    \item{#1}%
  }%
}
\providecommand{\DNenumeratedlist}[1]{#1}
\newcounter{Dsectionlevel}
\providecommand{\Dvisitsectionhook}{}
\providecommand{\Ddepartsectionhook}{}
\providecommand{\Dvisitsection}{%
  \addtocounter{Dsectionlevel}{1}%
  \Dvisitsectionhook%
}
\providecommand{\Ddepartsection}{%
  \Ddepartsectionhook%
  \addtocounter{Dsectionlevel}{-1}%
}

% Using \_ will cause hyphenation after _ even in \textnhtt-typewriter
% because the hyphenat package redefines \_.  So we use
% \textunderscore here.
\providecommand{\Dtextunderscore}{\textunderscore}

\providecommand{\Dtextinlineliteralfirstspace}{{ }}
\providecommand{\Dtextinlineliteralsecondspace}{{~}}

\Dprovidelength{\Dlistspacing}{0.8\baselineskip}

\providecommand{\Dsetlistrightmargin}{%
  \ifthenelse{\lengthtest{\linewidth>12em}}{%
    % Equal margins.
    \setlength{\rightmargin}{\leftmargin}%
  }{%
    % If the line is narrower than 10em, we don't remove any further
    % space from the right.
    \setlength{\rightmargin}{0pt}%
  }%
}
\providecommand{\Dresetlistdepth}{false}
\Dprovidelength{\Doriginallabelsep}{\labelsep}
\providecommand{\Dmakelistenvironment}[3]{%
  % Make list environment with support for unlimited nesting and with
  % reasonable default lengths.  Parameters:
  % 1. Label (same as in list environment).
  % 2. Spacing (same as in list environment).
  % 3. List contents (contents of list environment).
  \ifthenelse{\equal{\Dinsidetabular}{true}}{%
    % Unfortunately, vertical spacing doesn't work correctly when
    % using lists inside tabular environments, so we use a minipage.
    \begin{minipage}[t]{\linewidth}%
  }{}%
    {%
      \renewcommand{\Dneedvspace}{false}%
      % \parsep0.5\baselineskip
      \renewcommand{\Dresetlistdepth}{false}%
      \ifnum \@listdepth>5%
      \protect\renewcommand{\Dresetlistdepth}{true}%
      \@listdepth=5%
      \fi%
      \begin{list}{%
          #1%
        }{%
          \setlength{\itemsep}{0pt}%
          \setlength{\partopsep}{0pt}%
          \setlength{\topsep}{0pt}%
                                  % List should take 90% of total width.
          \setlength{\leftmargin}{0.05\linewidth}%
          \ifthenelse{\lengthtest{\leftmargin<1.8em}}{%
            \setlength{\leftmargin}{1.8em}%
          }{}%
          \setlength{\labelsep}{\Doriginallabelsep}%
          \Dsetlistrightmargin%
          #2%
        }{%
          #3%
        }%
      \end{list}%
      \ifthenelse{\equal{\Dresetlistdepth}{true}}{\@listdepth=5}{}%
    }%
  \ifthenelse{\equal{\Dinsidetabular}{true}}{\end{minipage}}{}%
}
\providecommand{\Dfinalstrut}{\@finalstrut\@arstrutbox}
\providecommand{\DAlastitem}[5]{#5\Dfinalstrut}

\Dprovidelength{\Ditemsep}{0pt}
\providecommand{\Dmakeenumeratedlist}[6]{%
  % Make enumerated list.
  % Parameters:
  % - prefix
  % - type (\arabic, \roman, ...)
  % - suffix
  % - suggested counter name
  % - start number - 1
  % - list contents
  \newcounter{#4}%
  \Dmakelistenvironment{#1#2{#4}#3}{%
    % Use as much space as needed for the label.
    \setlength{\labelwidth}{10em}%
    % Reserve enough space so that the label doesn't go beyond the
    % left margin of preceding paragraphs.  Like that:
    %
    %    A paragraph.
    %
    %   1. First item.
    \setlength{\leftmargin}{2.5em}%
    \Dsetlistrightmargin%
    \setlength{\itemsep}{\Ditemsep}%
    % Use counter recommended by Python module.
    \usecounter{#4}%
    % Set start value.
    \addtocounter{#4}{#5}%
  }{%
    % The list contents.
    #6%
  }%
}


% Single quote in literal mode.  \textquotesingle from package
% textcomp has wrong width when using package ae, so we use a normal
% single curly quote here.
\providecommand{\Dtextliteralsinglequote}{'}


% "Tabular lists" are field lists and options lists (not definition
% lists because there the term always appears on its own line).  We'll
% use the terminology of field lists now ("field", "field name",
% "field body"), but the same is also analogously applicable to option
% lists.
%
% We want these lists to be breakable across pages.  We cannot
% automatically get the narrowest possible size for the left column
% (i.e. the field names or option groups) because tabularx does not
% support multi-page tables, ltxtable needs to have the table in an
% external file and we don't want to clutter the user's directories
% with auxiliary files created by the filecontents environment, and
% ltablex is not included in teTeX.
%
% Thus we set a fixed length for the left column and use list
% environments.  This also has the nice side effect that breaking is
% now possible anywhere, not just between fields.
%
% Note that we are creating a distinct list environment for each
% field.  There is no macro for a whole tabular list!
\Dprovidelength{\Dtabularlistfieldnamewidth}{6em}
\Dprovidelength{\Dtabularlistfieldnamesep}{0.5em}
\providecommand{\Dinsidetabular}{false}
\providecommand{\Dsavefieldname}{}
\providecommand{\Dsavefieldbody}{}
\Dprovidelength{\Dusedfieldnamewidth}{0pt}
\Dprovidelength{\Drealfieldnamewidth}{0pt}
\providecommand{\Dtabularlistfieldname}[1]{\renewcommand{\Dsavefieldname}{#1}}
\providecommand{\Dtabularlistfieldbody}[1]{\renewcommand{\Dsavefieldbody}{#1}}
\Dprovidelength{\Dparskiptemp}{0pt}
\providecommand{\Dtabularlistfield}[1]{%
  {%
    % This only saves field name and field body in \Dsavefieldname and
    % \Dsavefieldbody, resp.  It does not insert any text into the
    % document.
    #1%
    % Recalculate the real field name width everytime we encounter a
    % tabular list field because it may have been changed using a
    % "raw" node.
    \setlength{\Drealfieldnamewidth}{\Dtabularlistfieldnamewidth}%
    \addtolength{\Drealfieldnamewidth}{\Dtabularlistfieldnamesep}%
    \Dmakelistenvironment{%
      \makebox[\Drealfieldnamewidth][l]{\Dsavefieldname}%
    }{%
      \setlength{\labelwidth}{\Drealfieldnamewidth}%
      \setlength{\leftmargin}{\Drealfieldnamewidth}%
      \setlength{\rightmargin}{0pt}%
      \setlength{\labelsep}{0pt}%
    }{%
      \item%
      \settowidth{\Dusedfieldnamewidth}{\Dsavefieldname}%
      \setlength{\Dparskiptemp}{\parskip}%
      \ifthenelse{%
        \lengthtest{\Dusedfieldnamewidth>\Dtabularlistfieldnamewidth}%
      }{%
        \mbox{}\par%
        \setlength{\parskip}{0pt}%
      }{}%
      \Dsavefieldbody%
      \setlength{\parskip}{\Dparskiptemp}%
      %XXX Why did we need this?
      %\@finalstrut\@arstrutbox%
    }%
    \par%
  }%
}

\providecommand{\Dformatfieldname}[1]{\textbf{#1:}}
\providecommand{\DNfieldlist}[1]{#1}
\providecommand{\DNfield}[1]{\Dtabularlistfield{#1}}
\providecommand{\DNfieldname}[1]{%
  \Dtabularlistfieldname{%
    \Dformatfieldname{#1}%
  }%
}
\providecommand{\DNfieldbody}[1]{\Dtabularlistfieldbody{#1}}

\providecommand{\Dformatoptiongroup}[1]{%
  % Format option group, e.g. "-f file, --input file".
  \texttt{#1}%
}
\providecommand{\Dformatoption}[1]{%
  % Format option, e.g. "-f file".
  % Put into mbox to avoid line-breaking at spaces.
  \mbox{#1}%
}
\providecommand{\Dformatoptionstring}[1]{%
  % Format option string, e.g. "-f".
  #1%
}
\providecommand{\Dformatoptionargument}[1]{%
  % Format option argument, e.g. "file".
  \textsl{#1}%
}
\providecommand{\Dformatoptiondescription}[1]{%
  % Format option description, e.g.
  % "\DNparagraph{Read input data from file.}"
  #1%
}
\providecommand{\DNoptionlist}[1]{#1}
\providecommand{\Doptiongroupjoiner}{,{ }}
\providecommand{\Disfirstoption}{%
  % Auxiliary macro indicating if a given option is the first child
  % of its option group (if it's not, it has to preceded by
  % \Doptiongroupjoiner).
  false%
}
\providecommand{\DNoptionlistitem}[1]{%
  \Dtabularlistfield{#1}%
}
\providecommand{\DNoptiongroup}[1]{%
  \renewcommand{\Disfirstoption}{true}%
  \Dtabularlistfieldname{\Dformatoptiongroup{#1}}%
}
\providecommand{\DNoption}[1]{%
  % If this is not the first option in this option group, add a
  % joiner.
  \ifthenelse{\equal{\Disfirstoption}{true}}{%
    \renewcommand{\Disfirstoption}{false}%
  }{%
    \Doptiongroupjoiner%
  }%
  \Dformatoption{#1}%
}
\providecommand{\DNoptionstring}[1]{\Dformatoptionstring{#1}}
\providecommand{\DNoptionargument}[1]{{ }\Dformatoptionargument{#1}}
\providecommand{\DNdescription}[1]{%
  \Dtabularlistfieldbody{\Dformatoptiondescription{#1}}%
}

\providecommand{\DNdefinitionlist}[1]{%
  \begin{description}%
    \parskip0pt%
    #1%
  \end{description}%
}
\providecommand{\DNdefinitionlistitem}[1]{%
  % LaTeX expects the label in square brackets; we provide an empty
  % label.
  \item[]#1%
}
\providecommand{\Dformatterm}[1]{#1}
\providecommand{\DNterm}[1]{\hspace{-5pt}\Dformatterm{#1}}
% I'm still not sure what's the best rendering for classifiers.  The
% colon syntax is used by reStructuredText, so it's at least WYSIWYG.
% Use slanted text because italic would cause too much emphasis.
\providecommand{\Dformatclassifier}[1]{\textsl{#1}}
\providecommand{\DNclassifier}[1]{~:~\Dformatclassifier{#1}}
\providecommand{\Dformatdefinition}[1]{#1}
\providecommand{\DNdefinition}[1]{\par\Dformatdefinition{#1}}

\providecommand{\Dlineblockindentation}{2.5em}
\providecommand{\DNlineblock}[1]{%
  \Dmakelistenvironment{}{%
    \ifthenelse{\equal{\Dparent}{lineblock}}{%
      % Parent is a line block, so indent.
      \setlength{\leftmargin}{\Dlineblockindentation}%
    }{%
      % At top level; don't indent.
      \setlength{\leftmargin}{0pt}%
    }%
    \setlength{\rightmargin}{0pt}%
    \setlength{\parsep}{0pt}%
  }{%
    #1%
  }%
}
\providecommand{\DNline}[1]{\item#1}


\providecommand{\DNtransition}{%
  \raisebox{0.25em}{\parbox{\linewidth}{\hspace*{\fill}\hrulefill\hrulefill\hspace*{\fill}}}%
}


\providecommand{\Dformatblockquote}[1]{%
  % Format contents of block quote.
  % This occurs in block-level context, so we cannot use \textsl.
  {\slshape#1}%
}
\providecommand{\Dformatattribution}[1]{---\textup{#1}}
\providecommand{\DNblockquote}[1]{%
  \Dmakebox{%
    \Dformatblockquote{#1}
  }%
}
\providecommand{\DNattribution}[1]{%
  \par%
  \begin{flushright}\Dformatattribution{#1}\end{flushright}%
}


% Sidebars:
\RequirePackage{picins}
% Vertical and horizontal margins.
\Dprovidelength{\Dsidebarvmargin}{0.5em}
\Dprovidelength{\Dsidebarhmargin}{1em}
% Padding (space between contents and frame).
\Dprovidelength{\Dsidebarpadding}{1em}
% Frame width.
\Dprovidelength{\Dsidebarframewidth}{2\fboxrule}
% Position ("l" or "r").
\providecommand{\Dsidebarposition}{r}
% Width.
\Dprovidelength{\Dsidebarwidth}{0.45\linewidth}
\providecommand{\DNsidebar}[1]{
  \parpic[\Dsidebarposition]{%
    \begin{minipage}[t]{\Dsidebarwidth}%
      % Doing this with nested minipages is ugly, but I haven't found
      % another way to place vertical space before and after the fbox.
      \vspace{\Dsidebarvmargin}%
      {%
        \setlength{\fboxrule}{\Dsidebarframewidth}%
        \setlength{\fboxsep}{\Dsidebarpadding}%
        \fbox{%
          \begin{minipage}[t]{\linewidth}%
            \setlength{\parindent}{\Dboxparindent}%
            #1%
          \end{minipage}%
        }%
      }%
      \vspace{\Dsidebarvmargin}%
    \end{minipage}%
  }%
}


% Citations and footnotes.
\providecommand{\Dformatfootnote}[1]{%
  % Format footnote.
  {%
    \footnotesize#1%
    % \par is necessary for LaTeX to adjust baselineskip to the
    % changed font size.
    \par%
  }%
}
\providecommand{\Dformatcitation}[1]{\Dformatfootnote{#1}}
\Dprovidelength{\Doriginalbaselineskip}{0pt}
\providecommand{\DNfootnotereference}[1]{%
  {%
    % \baselineskip is 0pt in \textsuperscript, so we save it here.
    \setlength{\Doriginalbaselineskip}{\baselineskip}%
    \textsuperscript{#1}%
  }%
}
\providecommand{\DNcitationreference}[1]{{[}#1{]}}
\Dprovidelength{\Dfootnotesep}{3.5pt}
\providecommand{\Dsetfootnotespacing}{%
  % Spacing commands executed at the beginning of footnotes.
  \setlength{\parindent}{0pt}%
  \hspace{1em}%
}
\providecommand{\DNfootnote}[1]{%
  % See ltfloat.dtx for details.
  {%
    \insert\footins{%
      \vspace{\Dfootnotesep}%
      \Dsetfootnotespacing%
      \Dformatfootnote{#1}%
    }%
  }%
}
\providecommand{\DNcitation}[1]{\DNfootnote{#1}}
\providecommand{\Dformatfootnotelabel}[1]{%
  % Keep \footnotesize in footnote labels (\textsuperscript would
  % reduce the font size even more).
  \textsuperscript{\footnotesize#1{ }}%
}
\providecommand{\Dformatcitationlabel}[1]{{[}#1{]}{ }}
\providecommand{\Dformatmultiplebackrefs}[1]{%
  % If in printing mode, do not write out multiple backrefs.
  \ifthenelse{\equal{\Dprinting}{true}}{}{\textsl{#1}}%
}
\providecommand{\Dthislabel}{}
\providecommand{\DNlabel}[1]{%
  \renewcommand{\Dthislabel}{#1}
  \ifthenelse{\not\equal{\Dsinglebackref}{}}{%
    \let\Doriginallabel=\Dthislabel%
    \def\Dthislabel{%
      \Dsinglefootnotebacklink{\Dsinglebackref}{\Doriginallabel}%
    }%
  }{}%
  \ifthenelse{\equal{\Dparent}{footnote}}{%
    % Footnote label.
    \Dformatfootnotelabel{\Dthislabel}%
  }{%
    \ifthenelse{\equal{\Dparent}{citation}}{%
      % Citation label.
      \Dformatcitationlabel{\Dthislabel}%
    }{}%
  }%
  % If there are multiple backrefs, add them now.
  \Dformatmultiplebackrefs{\Dmultiplebackrefs}%
}
\providecommand{\Dsinglefootnotebacklink}[2]{%
  % Create normal backlink of a footnote label.  Parameters:
  % 1. ID.
  % 2. Link text.
  % Treat like a footnote reference.
  \Dimplicitfootnotereference{\##1}{#2}%
}
\providecommand{\Dmultifootnotebacklink}[2]{%
  % Create generated backlink, as in (1, 2).  Parameters:
  % 1. ID.
  % 2. Link text.
  % Treat like a footnote reference.
  \Dimplicitfootnotereference{\##1}{#2}%
}
\providecommand{\Dsinglecitationbacklink}[2]{\Dsinglefootnotebacklink{#1}{#2}}
\providecommand{\Dmulticitationbacklink}[2]{\Dmultifootnotebacklink{#1}{#2}}


\RequirePackage{longtable}
\providecommand{\Dmaketable}[2]{%
  % Make table.  Parameters:
  % 1. Table spec (like "|p|p|").
  % 2. Table contents.
  {%
    \ifthenelse{\equal{\Dinsidetabular}{true}}{%
      % Inside longtable; we cannot have nested longtables.
      \begin{tabular}{#1}%
        \hline%
        #2%
      \end{tabular}%
    }{%
      \renewcommand{\Dinsidetabular}{true}%
      \begin{longtable}{#1}%
        \hline%
        #2%
      \end{longtable}%
    }%
  }%
}
\providecommand{\DNthead}[1]{%
  #1%
  \endhead%
}
\providecommand{\DNrow}[1]{%
  #1\tabularnewline%
  \hline%
}
\providecommand{\Dinsidemulticolumn}{false}
\providecommand{\Dcompensatingmulticol}[3]{%
  \multicolumn{#1}{#2}{%
    {%
      \renewcommand{\Dinsidemulticolumn}{true}%
      % Compensate for weird missing vertical space at top of paragraph.
      \raisebox{-2.5pt}{#3}%
    }%
  }%
}
\providecommand{\Dcolspan}[2]{%
  % Take care of the morecols attribute (but incremented by 1).
  &%
  \Dcompensatingmulticol{#1}{l|}{#2}%
}
\providecommand{\Dcolspanleft}[2]{%
  % Like \Dmorecols, but called for the leftmost entries in a table
  % row.
  \Dcompensatingmulticol{#1}{|l|}{#2}%
}
\providecommand{\Dsubsequententry}[1]{%
  &#1%
}
\providecommand{\DNentry}[1]{%
  % The following sequence adds minimal vertical space above the top
  % lines of the first cell paragraph, so that vertical space is
  % balanced at the top and bottom of table cells.
  \ifthenelse{\equal{\Dinsidemulticolumn}{false}}{%
    \vspace{-1em}\vspace{-\parskip}\par%
  }{}%
  #1%
  % No need to add an ampersand ("&"); that's done by \Dsubsequententry.
}
\providecommand{\DAtableheaderentry}[5]{\Dformattableheaderentry{#5}}
\providecommand{\Dformattableheaderentry}[1]{{\bfseries#1}}


\providecommand{\DNsystemmessage}[1]{%
  {%
    \ifthenelse{\equal{\Dprinting}{false}}{\color{red}}{}%
    \bfseries%
    #1%
  }%
}


\providecommand{\Dinsidehalign}{false}
\newsavebox{\Dalignedimagebox}
\Dprovidelength{\Dalignedimagewidth}{0pt}
\providecommand{\Dhalign}[2]{%
  % Horizontally align the contents to the left or right so that the
  % text flows around it.
  % Parameters:
  % 1. l or r
  % 2. Contents.
  \renewcommand{\Dinsidehalign}{true}%
  % For some obscure reason \parpic consumes some vertical space.
  \vspace{-3pt}%
  % Now we do something *really* ugly, but this enables us to wrap the
  % image in a minipage while still allowing tight frames when
  % class=border (see \DNimageCborder).
  \sbox{\Dalignedimagebox}{#2}%
  \settowidth{\Dalignedimagewidth}{\usebox{\Dalignedimagebox}}%
  \parpic[#1]{%
    \begin{minipage}[b]{\Dalignedimagewidth}%
      % Compensate for previously added space, but not entirely.
      \vspace*{2.0pt}%
      \vspace*{\Dfloatimagetopmargin}%
      \usebox{\Dalignedimagebox}%
      \vspace*{1.5pt}%
      \vspace*{\Dfloatimagebottommargin}%
    \end{minipage}%
  }%
  \renewcommand{\Dinsidehalign}{false}%
}


\RequirePackage{graphicx}
% Maximum width of an image.
\providecommand{\Dimagemaxwidth}{\linewidth}
\providecommand{\Dfloatimagemaxwidth}{0.5\linewidth}
% Auxiliary variable.
\Dprovidelength{\Dcurrentimagewidth}{0pt}
\providecommand{\DNimageAalign}[5]{%
  \ifthenelse{\equal{#3}{left}}{%
    \Dhalign{l}{#5}%
  }{%
    \ifthenelse{\equal{#3}{right}}{%
      \Dhalign{r}{#5}%
    }{%
      \ifthenelse{\equal{#3}{center}}{%
        % Text floating around centered figures is a bad idea.  Thus
        % we use a center environment.  Note that no extra space is
        % added by the writer, so the space added by the center
        % environment is fine.
        \begin{center}#5\end{center}%
      }{%
        #5%
      }%
    }%
  }%
}
% Base path for images.
\providecommand{\Dimagebase}{}
% Auxiliary command.  Current image path.
\providecommand{\Dimagepath}{}
\providecommand{\DNimageAuri}[5]{%
  % Insert image.  We treat the URI like a path here.
  \renewcommand{\Dimagepath}{\Dimagebase#3}%
  \Difdefined{DcurrentNimageAwidth}{%
    \Dwidthimage{\DcurrentNimageAwidth}{\Dimagepath}%
  }{%
    \Dsimpleimage{\Dimagepath}%
  }%
}
\Dprovidelength{\Dfloatimagevmargin}{0pt}
\providecommand{\Dfloatimagetopmargin}{\Dfloatimagevmargin}
\providecommand{\Dfloatimagebottommargin}{\Dfloatimagevmargin}
\providecommand{\Dwidthimage}[2]{%
  % Image with specified width.
  % Parameters:
  % 1. Image width.
  % 2. Image path.
  % Need to make bottom-alignment dependent on align attribute (add
  % functional test first).  Need to observe height attribute.
  %\begin{minipage}[b]{#1}%
    \includegraphics[width=#1,height=\textheight,keepaspectratio]{#2}%
  %\end{minipage}%
}  
\providecommand{\Dcurrentimagemaxwidth}{}
\providecommand{\Dsimpleimage}[1]{%
  % Insert image, without much parametrization.
  \settowidth{\Dcurrentimagewidth}{\includegraphics{#1}}%
  \ifthenelse{\equal{\Dinsidehalign}{true}}{%
    \renewcommand{\Dcurrentimagemaxwidth}{\Dfloatimagemaxwidth}%
  }{%
    \renewcommand{\Dcurrentimagemaxwidth}{\Dimagemaxwidth}%
  }%
  \ifthenelse{\lengthtest{\Dcurrentimagewidth>\Dcurrentimagemaxwidth}}{%
    \Dwidthimage{\Dcurrentimagemaxwidth}{#1}%
  }{%
    \Dwidthimage{\Dcurrentimagewidth}{#1}%
  }%
}
\providecommand{\Dwidthimage}[2]{%
  % Image with specified width.
  % Parameters:
  % 1. Image width.
  % 2. Image path.
  \Dwidthimage{#1}{#2}%
}

% Figures.
\providecommand{\DNfigureAalign}[5]{%
  % Hack to make it work Right Now.
  %\def\DcurrentNimageAwidth{\DcurrentNfigureAwidth}%
  %
    %\def\DcurrentNimageAwidth{\linewidth}%
    \DNimageAalign{#1}{#2}{#3}{#4}{%
      \begin{minipage}[b]{0.4\linewidth}#5\end{minipage}}%
    %\let\DcurrentNimageAwidth=\relax%
  %
  %\let\DcurrentNimageAwidth=\relax%
}
\providecommand{\DNcaption}[1]{\par\noindent{\slshape#1}}
\providecommand{\DNlegend}[1]{\Dauxiliaryspace#1}

\providecommand{\DCborder}[1]{\fbox{#1}}
% No padding between image and border.
\providecommand{\DNimageCborder}[1]{\frame{#1}}


% Need to replace with language-specific stuff.  Maybe look at
% csquotes.sty and ask the author for permission to use parts of it.
\providecommand{\Dtextleftdblquote}{``}
\providecommand{\Dtextrightdblquote}{''}

% Table of contents:
\Dprovidelength{\Dtocininitialsectnumwidth}{2.4em}
\Dprovidelength{\Dtocadditionalsectnumwidth}{0.7em}
% Level inside a table of contents.  While this is at -1, we are not
% inside a TOC.
\Dprovidecounter{Dtoclevel}%
\setcounter{Dtoclevel}{-1}
\providecommand{\Dlocaltoc}{false}%
\providecommand{\DNtopicClocal}[1]{%
  \renewcommand{\Dlocaltoc}{true}%
  \addtolength{\Dtocsectnumwidth}{2\Dtocadditionalsectnumwidth}%
  \addtolength{\Dtocindent}{-2\Dtocadditionalsectnumwidth}%
  #1%
  \addtolength{\Dtocindent}{2\Dtocadditionalsectnumwidth}%
  \addtolength{\Dtocsectnumwidth}{-2\Dtocadditionalsectnumwidth}%
  \renewcommand{\Dlocaltoc}{false}%
}
\Dprovidelength{\Dtocindent}{0pt}%
\Dprovidelength{\Dtocsectnumwidth}{\Dtocininitialsectnumwidth}
% Compensate for one additional TOC indentation space so that the
% top-level is unindented.
\addtolength{\Dtocsectnumwidth}{-\Dtocadditionalsectnumwidth}
\addtolength{\Dtocindent}{-\Dtocsectnumwidth}
\providecommand{\Difinsidetoc}[2]{%
  \ifthenelse{\not\equal{\theDtoclevel}{-1}}{#1}{#2}%
}
\providecommand{\DNgeneratedCsectnum}[1]{%
  \Difinsidetoc{%
    % Section number inside TOC.
    \makebox[\Dtocsectnumwidth][l]{#1}%
  }{%
    % Section number inside section title.
    #1\quad%
  }%
}
\providecommand{\Dtocbulletlist}[1]{%
  \addtocounter{Dtoclevel}{1}%
  \addtolength{\Dtocindent}{\Dtocsectnumwidth}%
  \addtolength{\Dtocsectnumwidth}{\Dtocadditionalsectnumwidth}%
  #1%
  \addtolength{\Dtocsectnumwidth}{-\Dtocadditionalsectnumwidth}%
  \addtolength{\Dtocindent}{-\Dtocsectnumwidth}%
  \addtocounter{Dtoclevel}{-1}%
}


% For \Dpixelunit, the length value is pre-multiplied with 0.75, so by
% specifying "pt" we get the same notion of "pixel" as graphicx.
\providecommand{\Dpixelunit}{pt}
% Normally lengths are relative to the current linewidth.
\providecommand{\Drelativeunit}{\linewidth}


%\RequirePackage{fixmath}
%\RequirePackage{amsmath}


\DSfontencoding
\DSlanguage
\DSlinks
\DSsymbols
\DSlate

\makeatother
