% Copyright 2008 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.


% Make sure to use tex4ht (or htlatex, to be precise) to compile this.

\usepackage{tex4ht}
\def\pgfsysdriver{pgfsys-tex4ht.def}

\usepackage{xkeyval}
\usepackage{colortbl}

\makeatletter

\AtBeginDocument{
\CutAt{section,part}
\definecolor{graphicbackground}{rgb}{0.96,0.96,0.8}
\definecolor{codebackground}{rgb}{0.8,0.8,1}
\definecolor{declarebg}{rgb}{1,0.8,0.8}
\definecolor{gray}{gray}{.5}
\definecolor{darkgreen}{rgb}{0,.5,0}
\definecolor{orange}{rgb}{1,.5,0}
\definecolor{mintgreen}{rgb}{.5,.75,.5}
\definecolor{input}{rgb}{0,0,0.8}
\definecolor{output}{rgb}{0.7,0,0}
\definecolor{triangle}{rgb}{1,0.5,0}
\definecolor{border}{rgb}{0,0.8,0}

% Patches of macros...
\renewenvironment{pgfmanualentry}{\begin{description}}{\end{description}}
\renewcommand\pgfmanualentryheadline[1]{\item[\colorbox{declarebg}{\normalfont{#1}}]\par}
\renewcommand\pgfmanualbody{}

\def\endofcodeexample#1{%
  \endgroup%
  \ifcode@execute%
    \setbox\codeexamplebox=\hbox{%
      {%
        {%
          \returntospace%
          \commenthandler%
          \xdef\code@temp{#1}% removes returns and comments
        }%
        \color{black}\ignorespaces%
          \code@pre\expandafter\scantokens\expandafter{\code@temp\ignorespaces}\code@post\ignorespaces%
      }%
    }%
    \ifdim\wd\codeexamplebox>\codeexamplewidth%
      \box\codeexamplebox
      \begin{tabular}{>{\columncolor{codebackground}}l}
        \begin{minipage}{\textwidth}
      {%
        \let\do\@makeother
        \dospecials
        \frenchspacing\@vobeyspaces
        \normalfont\ttfamily\footnotesize
        \typesetcomment%
        \@tempswafalse
        \def\par{%
          \if@tempswa
          \leavevmode \null \@@par\penalty\interlinepenalty
          \else
          \@tempswatrue
          \ifhmode\@@par\penalty\interlinepenalty\fi
          \fi}%
        \obeylines
        \everypar \expandafter{\the\everypar \unpenalty}%
        #1}
        \end{minipage}
      \end{tabular}%
    \else
      \begin{tabular}{>{\columncolor{graphicbackground}}l>{\columncolor{codebackground}}l}
        \ \box\codeexamplebox\ \par &
        \begin{minipage}[t]{\textwidth}
        {\let\do\@makeother
        \dospecials
        \frenchspacing\@vobeyspaces
        \normalfont\ttfamily\footnotesize
        \typesetcomment%
        \@tempswafalse
        \def\par{%
          \if@tempswa
          \leavevmode \null \@@par\penalty\interlinepenalty
          \else
          \@tempswatrue
          \ifhmode\@@par\penalty\interlinepenalty\fi
          \fi}%
        \obeylines
        \everypar \expandafter{\the\everypar \unpenalty}%
        #1}
        \end{minipage}
      \end{tabular}
    \fi
  \else%
    \begin{tabular}{>{\columncolor{codebackground}}l}
      \begin{minipage}[t]{\textwidth}
      {%
        \let\do\@makeother
        \dospecials
        \frenchspacing\@vobeyspaces
        \normalfont\ttfamily\footnotesize
        \typesetcomment%
        \@tempswafalse
        \def\par{%
          \if@tempswa
          \leavevmode \null \@@par\penalty\interlinepenalty
          \else
          \@tempswatrue
          \ifhmode\@@par\penalty\interlinepenalty\fi
          \fi}%
        \obeylines
        \everypar \expandafter{\the\everypar \unpenalty}%
        #1}
       \end{minipage}
     \end{tabular}%
  \fi%
  \par%
  \end{codeexample}
}
}



\makeatother
