%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is a template for a documentation file for MuPAD.
% It's inspired from the template used in the MuPAD documentation
% directory DOC/LIB/template.te_
%
% Usage:
% \MuPADdocument{package name}{package documentation dir}{language}{format}
% Possible values for language: eng (and de, but this is not used)
% Possible values for format: a4, hytexlarge, html4
%
% Example:
% Just put the following two lines in a file:
% \include{template}
% \MuPADdocument{combinat}{lib/COMBINAT/DOC/}{eng}{a4}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeatletter

\newcommand{\MuPADdocument}[4]{
  \documentclass[a4paper%
    % If the fourth argument is (or starts with--bad thing) ``html4'',
    % include option ``html4'':
    \if 4\if l\if m\if t\if h#4,html4\fi\fi\fi\fi\fi
  ]{scrartcl}

  \usepackage{ifpdf}
  \usepackage[latin1]{inputenc}
  \usepackage[T1]{fontenc}
  \ifpdf
    \usepackage{ae}
  \fi
  \usepackage{amssymb}
  \usepackage{amsmath}
  \usepackage{Mfonts}
  \usepackage[autobutton,#4]{Mhelp}
  \usepackage{booktabs}
  \ifhypermode
  \usepackage{beton}
  \usepackage{euler}
  \fi
  %\usepackage{changebar}
  \usepackage{rotating}

  \advance\topsep by 2pt\relax

  \def\Mpackname{#1}
  \def\Mprefix{#1}
  \def\Mdirname{#1}   % Used by the ascii help; check if this works properly
  \Mgfxpath{{PICTURES/#1/}}{{PICTURES/#1/}}

  % Some conditionals specific to the MuPAD-Combinat doc
  % Essentially, those conditional differ depending on whether the
  % text is in a paper, or in the documentation.
  \newif\ifcolloquial		% Do we allow ourselves some lousy style
  \colloquialtrue
  \newif\ifincludeExercises	% De we include the exercises in the doc
  \includeExercisestrue
  \newtheorem{exercise}{Exercise}[section]

  \begin{document}
  \Mlanguage{#3}\relax%
  \Mincpath{#2}\relax%
%  \pagenumbering{roman}%
  \ifhypermode\else\pagenumbering{roman}\fi%
  \Mnode{firstpage}%
  \Mnode{#1}%
  \Malias[firstpage]{#1}%
  \Malias[firstpage]{#1::toc}%

  % If the file title.tex exists, it's used as a title of the
  % document. To be consistent with MuPAD document files, the
  % right page should also be marked with the title, but I
  % don't know how to do it properly: \markright{\input{#2/title}}
  % does not work very well

  \ifhtml\else
    % Commented out in the html version to avoid a compilation error
  \IfFileExists{#2/title}{%
    \section*{\Mex{\Mpackname}~---~{\input{#2/title}}}%
    }{}
  \fi
  \markright{\Mex{\Mpackname}}%

  \eng{\section*{Table of contents}}%
  \de{\section*{Inhaltsverzeichnis}}%
  \fr{\section*{Table des matières}}%
  \thispagestyle{empty}%
  \Mnode{iM-toc}%
  \Mprintconts
  \par
  \newpage

  \Mnode{preface}%
  \InputIfFileExists{#2/preface}{%
    \eng{\addcontentsline{toc}{section}{Preface}}%
    \de{\addcontentsline{toc}{section}{Vorwort}}%
    \fr{\addcontentsline{toc}{section}{Préface}}%
    \Malias[preface]{\Mpackname::preface}%
    \Malias[preface]{\Mpackname::intro}}{}%
  \par\hyperpagebreak
  \ifhypermode\else\pagenumbering{arabic}\fi%
  \IfFileExists{#2/main}{%
    \Mwrite{mtoc}{%\string\par\string\medskip
      \string\eng{\string\Msection{Help Pages}}%
      \string\de{\string\Msection{Hilfeseiten}}%
      \string\fr{\string\Msection{Pages de documentation}}%
      \string\endgraf}%
    \input{#2/main}%
  }{}%
    
  \end{document}
}

\makeatother

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
