LaTeX Style File: epydoc-shaded.sty

% epydoc-shaded.sty
%
% Author: Edward Loper <edloper@seas.upenn.edu>
% URL: <http://epydoc.sf.net>
%
% This LaTeX stylesheet for epydoc's output uses shaded boxes to
% display the function, variable, and property lists.  Each
% object's name (or signature) is displayed in a lightly shaded
% box, and is immediately followed by a shaded and indented box 
% containing a description of that object:
%
%         +-------------------------------------------+
%         | object's name                             |
%         +-------------------------------------------+
%             | description of the object             |
%             | ...                                   |
%             +---------------------------------------+
%
% $Id:$
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{epydoc-shaded}[2008/02/26 v3.0.1 Epydoc Python Documentation]
% Pass options to the epydoc base package.
\RequirePackage{xkeyval}
\DeclareOptionX*{\PassOptionsToPackage{\CurrentOption}{epydoc-base}}
\ProcessOptionsX\relax
% Load the base epydoc package
\RequirePackage{epydoc-base}

% ======================================================================
% Customization hooks

% These colors 
\definecolor{EpydocNameColor}{gray}{0.95}
\definecolor{EpydocDetailsColor}{gray}{0.90}
\definecolor{EpydocValueColor}{gray}{0.85}
\definecolor{EpydocGroupColor}{gray}{0.8}
\definecolor{EpydocInheritanceListColor}{gray}{0.95}

% This length controls how tightly function, variable, and property
% entries are spaced.
\newlength{\EpydocListsep}
\setlength{\EpydocListsep}{\baselineskip}

% This length is used to dedent the section headings.
\newlength{\EpydocSectionHeaderDedent}
\setlength{\EpydocSectionHeaderDedent}{1cm}

% ======================================================================
% Colored minipage

% adapted from <http://www.texnik.de/color/color.phtml> for colored 
% paragraph boxes
\newcommand{\cmcolor}{}
\newenvironment{cminipage}[2][white]{%
    \renewcommand{\cmcolor}{#1}%
    \begin{lrbox}{\@tempboxa}%
      \begin{minipage}{#2}%
      \setlength{\parskip}{\EpydocParskip}%
  }{%
      \end{minipage}%
    \end{lrbox}%
    \colorbox{\cmcolor}{\usebox{\@tempboxa}}}

% ======================================================================
% Redefinitions

\renewenvironment{EpydocFunctionList}{%
  \setlength{\parskip}{\EpydocListsep}%
  \newcommand{\EpydocFunction}[1]{{
    \setkeys[Epydoc]{function}{##1}%
    % Decide whether to include a 'details' block
    \newif\ifEpydoc@details%
    \@ifundefined{cmdEpydoc@function@description}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@function@parameters}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@function@returndescr}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@function@returntype}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@function@raises}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@function@overrides}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@function@metadata}{}{\Epydoc@detailstrue}%
    % Add some vertical space.
    \par
    % Put a box around the whole thing, so the signature line and the
    % body don't get split across pages.
    \begin{minipage}{\textwidth}%
      \setlength{\parskip}{-1pt}\raggedleft%
      % Add the function signature in a gray95 box.
      \begin{cminipage}[EpydocNameColor]%
                       {\dimexpr \textwidth-2\fboxsep}
        \Large\raggedright\cmdEpydoc@function@signature
      \end{cminipage}\par
      % Add the details in a gray90 box.
      \ifEpydoc@details
        \begin{cminipage}[EpydocDetailsColor]%
                         {\dimexpr 0.95\linewidth-2\fboxsep}%
          \@ifundefined{cmdEpydoc@function@description}{}{%
              \par\cmdEpydoc@function@description}%
          \@ifundefined{cmdEpydoc@function@parameters}{}{%
              \par\cmdEpydoc@function@parameters}%
          \@ifundefined{cmdEpydoc@function@returntype}{
              \@ifundefined{cmdEpydoc@function@returndescr}{}{
                  \par\textbf{Return Value}%
                  \par\vspace{-\EpydocParskip}%
                  \begin{quote}\cmdEpydoc@function@returndescr%
                  \end{quote}}%
          }{
              \par\textbf{Return Value}%
              \par\vspace{-\EpydocParskip}%
              \begin{quote}%
                \@ifundefined{cmdEpydoc@function@returndescr}{
                    \textit{\cmdEpydoc@function@returntype}%
                }{%
                    \cmdEpydoc@function@returndescr%
                      \textit{(type=\cmdEpydoc@function@returntype)}}%
              \end{quote}}%
          \@ifundefined{cmdEpydoc@function@raises}{}{%
              \par\cmdEpydoc@function@raises}%
          \@ifundefined{cmdEpydoc@function@overrides}{}{%
              \par\cmdEpydoc@function@overrides}%
          \@ifundefined{cmdEpydoc@function@metadata}{}{%
              \par\cmdEpydoc@function@metadata}%
        \end{cminipage}\par
      \fi%
   \end{minipage}\par}}}
  {}

\newlength{\EpydocValueWidth}
\renewenvironment{EpydocVariableList}{%
  \setlength{\parskip}{\EpydocListsep}%
  \newcommand{\EpydocVariable}[1]{{
    \setkeys[Epydoc]{variable}{##1}%
    % Decide whether to include a 'details' block
    \newif\ifEpydoc@details%
    \@ifundefined{cmdEpydoc@variable@description}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@variable@value}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@variable@type}{}{\Epydoc@detailstrue}%
    % Put a box around the whole thing, so the variable's name line 
    % and the body don't get split across pages.
    \begin{minipage}{\linewidth}%
      \setlength{\parskip}{-1pt}\raggedleft%
      % Add the variable name in a gray95 box.
      \begin{cminipage}[EpydocNameColor]%
                       {\dimexpr \textwidth-2\fboxsep}
        \Large \bfseries \cmdEpydoc@variable@name%
      \end{cminipage}\par
      % Add the details in a gray90 box.
      \ifEpydoc@details
        \begin{cminipage}[EpydocDetailsColor]%
                         {\dimexpr 0.95\linewidth-2\fboxsep}%
          \setlength{\parskip}{\EpydocParskip}%
          \@ifundefined{cmdEpydoc@variable@description}{}{%
              \par\cmdEpydoc@variable@description}%
          \@ifundefined{cmdEpydoc@variable@type}{}{%
              \par\textbf{Type:} \texttt{\cmdEpydoc@variable@type}}%
          \@ifundefined{cmdEpydoc@variable@value}{}{%
            \settowidth{\EpydocValueWidth}{Value:w}%
            \par Value:
            \begin{cminipage}[EpydocValueColor]%
                             {\dimexpr \textwidth-2\fboxsep-\EpydocValueWidth}
              \texttt{\cmdEpydoc@variable@value}%
            \end{cminipage}}\par
        \end{cminipage}\par
      \fi%
    \end{minipage}\par}}}
  {}

\renewenvironment{EpydocPropertyList}{%
  \setlength{\parskip}{\EpydocListsep}%
  \newcommand{\EpydocProperty}[1]{{%
    \setkeys[Epydoc]{property}{##1}%
    % Decide whether to include a 'details' block
    \newif\ifEpydoc@details%
    \@ifundefined{cmdEpydoc@property@description}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@property@type}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@property@fget}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@property@fset}{}{\Epydoc@detailstrue}%
    \@ifundefined{cmdEpydoc@property@fdel}{}{\Epydoc@detailstrue}%
    % Put a box around the whole thing, so the property's name line 
    % and the body don't get split across pages.
    \begin{minipage}{\linewidth}%
      \setlength{\parskip}{-1pt}\raggedleft%
      % Add the variable name in a gray95 box.
      \begin{cminipage}[EpydocNameColor]
                       {\dimexpr \textwidth-2\fboxsep}
        \Large \bfseries \cmdEpydoc@property@name%
      \end{cminipage}\par
      % Add the details in a gray90 box.
      \ifEpydoc@details
        \begin{cminipage}[EpydocDetailsColor]
                         {\dimexpr 0.95\linewidth-2\fboxsep}
          \setlength{\parskip}{\EpydocParskip}
          \@ifundefined{cmdEpydoc@property@description}{}{%
              \par\cmdEpydoc@property@description}%
          \@ifundefined{cmdEpydoc@property@type}{}{%
              \par\textbf{Type:} \cmdEpydoc@property@type}%
          \@ifundefined{cmdEpydoc@property@fget}{}{%
              \par\textbf{Get:} \cmdEpydoc@property@fget}%
          \@ifundefined{cmdEpydoc@property@fset}{}{%
              \par\textbf{Set:} \cmdEpydoc@property@fset}%
          \@ifundefined{cmdEpydoc@property@fdel}{}{%
              \par\textbf{Delete:} \cmdEpydoc@property@fdel}%
        \end{cminipage}\par
      \fi%
    \end{minipage}\par}}}
  {}

\renewcommand{\EpydocGroup}[1]{\par
  \begin{cminipage}[EpydocGroupColor]
                   {\dimexpr \linewidth-2\fboxsep}
    {\Large\bf\center #1\\}
  \end{cminipage}\par}
\renewcommand{\EpydocInheritanceList}[2]{\par
  \begin{cminipage}[EpydocInheritanceListColor]
                   {\dimexpr \textwidth-2\fboxsep}
  \raggedright%
  Inherited from {#1}: #2%
  \end{cminipage}\par}

% This is just like the default definitions, except that we use
% \raggedright, and dedent by \EpydocSectionHeaderDedent
\renewcommand\section{\@startsection {section}{1}%
              {-\EpydocSectionHeaderDedent}%
              {-3.5ex \@plus -1ex \@minus -.2ex}%
              {2.3ex \@plus.2ex}%
              {\raggedright\normalfont\Large\bfseries}}
\renewcommand\subsection{\@startsection{subsection}{2}%
              {-\EpydocSectionHeaderDedent}%
              {-3.25ex\@plus -1ex \@minus -.2ex}%
              {1.5ex \@plus .2ex}%
              {\raggedright\normalfont\large\bfseries}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}%
              {-\EpydocSectionHeaderDedent}%
              {-3.25ex\@plus -1ex \@minus -.2ex}%
              {1.5ex \@plus .2ex}%
              {\raggedright\normalfont\normalsize\bfseries}}