%%% Rd.sty ... Style for printing the R manual
%%%
%%% Modified 1998/01/05 by Friedrich.Leisch@ci.tuwien.ac.at
%%% Last modified 1998/07/07 by Martin Maechler

\RequirePackage{amsbsy}          % AMS boldsymbol: defines `\boldsymbol'
\RequirePackage{alltt}           % {verbatim} allowing \..
\RequirePackage{verbatim}        % small example code

\addtolength{\textheight}{12mm}
\addtolength{\topmargin}{-9mm}   % still fits on US paper
\addtolength{\textwidth}{24mm}   % still fits on US paper
\setlength{\oddsidemargin}{10mm}
\setlength{\evensidemargin}{\oddsidemargin}

\newlength{\middle}
\setlength{\middle}{\textwidth}
\addtolength{\middle}{-2.25in}
\addtolength{\middle}{-4pt}

\newenvironment{display}[0]%
  {\begin{list}{}{\setlength{\leftmargin}{30pt}}\item}%
  {\end{list}}
\newcommand{\HTML}{{\normalfont\textsc{html}}}
\newcommand{\R}{{\normalfont\textsf{R}}}

\def\href#1#2{\special{html:<a href="#1">}{#2}\special{html:</a>}}

\newcommand{\vneed}[1]{%
  \penalty-1000\vskip#1 plus 10pt minus #1\penalty-1000\vspace{-#1}}

\newcommand{\Rdcontents}[1]{% modified \tableofcontents -- not \chapter
\section*{{#1}\@mkboth{\MakeUppercase#1}{\MakeUppercase#1}}
  \@starttoc{toc}}

\newcommand{\Header}[2]{%
  \vneed{1ex}
  \markboth{#1}{#1}
  \addcontentsline{toc}{subsection}{#1}
  \index{#1|textbf}
  \noindent
  \nopagebreak
  \begin{center}
    \begin{tabular}{c}
      \hline \rule[-0.275cm]{0cm}{0.8cm}
      \makebox[1in][l]{\texttt{#1}}
      \makebox[\middle]{
        \begin{minipage}{\middle}
          \begin{center}
            \emph{#2}
          \end{center}
        \end{minipage}}
      \makebox[1in][r]{\texttt{#1}} \\ \hline
    \end{tabular}
  \end{center}}
%
%
\newcommand{\Link}[1]{#1\index{#1|textit}}
%
% \alias{<alias>}{<header>}
\newcommand{\alias}[2]{\index{#1@#1\textit{(#2)}}}
% \keyword{<topic>}{<header>}
\newcommand{\keyword}[2]{\index{$*$Topic{\large\ \textbf{#1}}!#2@\textsf{#2}}}
%
\newcommand{\Itemize}[1]{\begin{itemize}{#1}\end{itemize}}
\newcommand{\Enumerate}[1]{\begin{enumerate}{#1}\end{enumerate}}
\newcommand{\describe}[1]{\begin{description}{#1}\end{description}}

\newcommand{\Tabular}[2]{%
  \begin{tabular}{#1}
    #2
  \end{tabular}}

\newlength{\ldescriptionwidth}
\newcommand{\ldescriptionlabel}[1]{%
  \settowidth{\ldescriptionwidth}{{#1}}%
  \ifdim\ldescriptionwidth>\labelwidth
    {\parbox[b]{\labelwidth}%
      {\makebox[0pt][l]{#1}\\[1pt]\makebox{}}}%
  \else
    \makebox[\labelwidth][l]{{#1}}%
  \fi
  \hfil\relax}
\newenvironment{ldescription}[1][1in]%
  {\begin{list}{}%
    {\setlength{\labelwidth}{#1}%
      \setlength{\leftmargin}{\labelwidth}%
      \addtolength{\leftmargin}{\labelsep}%
      \renewcommand{\makelabel}{\ldescriptionlabel}}}%
  {\end{list}}

\newenvironment{Rdsection}[1]{%
  \ifx\@empty#1\else\subsubsection*{#1}\fi
  \begin{list}{}{\setlength{\leftmargin}{0.25in}}\item}
  {\end{list}}

\newenvironment{Arguments}{%
  \begin{Rdsection}{Arguments}}{\end{Rdsection}}
\newenvironment{Author}{%
  \begin{Rdsection}{Author(s)}}{\end{Rdsection}}
\newenvironment{Description}{%
  \begin{Rdsection}{Description}}{\end{Rdsection}}
\newenvironment{Details}{%
  \begin{Rdsection}{Details}}{\end{Rdsection}}
\newenvironment{Examples}{%
  \begin{Rdsection}{Examples}}{\end{Rdsection}}
\newenvironment{Note}{%
  \begin{Rdsection}{Note}}{\end{Rdsection}}
\newenvironment{References}{%
  \begin{Rdsection}{References}}{\end{Rdsection}}
\newenvironment{SeeAlso}{%
  \begin{Rdsection}{See Also}\raggedright}{\end{Rdsection}}
\newenvironment{Format}{%
  \begin{Rdsection}{Format}\raggedright}{\end{Rdsection}}
\newenvironment{Source}{%
  \begin{Rdsection}{Source}\raggedright}{\end{Rdsection}}
\newenvironment{Section}[1]{%
  \begin{Rdsection}{#1}}{\end{Rdsection}}
\newenvironment{Usage}{%
  \begin{Rdsection}{}}{\end{Rdsection}}
\newenvironment{Value}{%
  \begin{Rdsection}{Value}}{\end{Rdsection}}

\newenvironment{ExampleCode}{\small\verbatim}{\endverbatim}

\ifx\textbackslash\undefined%-- e.g. for MM
\newcommand{\bsl}{\ifmmode\backslash\else$\backslash$\fi}
\else
\newcommand{\bsl}{\ifmmode\backslash\else\textbackslash\fi}
\fi
%fails for index (but is not used there...)
\newcommand{\SIs}{\relax\ifmmode\leftarrow\else$\leftarrow$\fi}
\newcommand{\SIIs}{\relax\ifmmode<\leftarrow\else$<\leftarrow$\fi}
\newcommand{\Sbecomes}{\relax\ifmmode\rightarrow\else$\rightarrow$\fi}
%
\newcommand{\deqn}[2]{\[#1\]}
\newcommand{\eqn}[2]{$#1$}
\newcommand{\bold}[1]{\ifmmode\boldsymbol{#1}\else\textbf{#1}\fi}
\newcommand{\code}[1]{\texttt{#1}}
\newcommand{\file}[1]{`\textsf{#1}'}
\newcommand{\url}[1]{\textsf{#1}}
\newcommand{\link}[1]{#1\index{#1}}
\newcommand{\email}[1]{$\langle${#1}$\rangle$}

\InputIfFileExists{Rd.cfg}{%
  \typeout{Reading personal defaults ...}}{}
