% $Id: btxdockit.sty,v 1.2 2009/05/24 19:10:45 lehman stable $
%
% Copyright (c) 2008-2009 Philipp Lehman.
%
% Permission is granted to copy, distribute and/or modify this
% software under the terms of the LaTeX Project Public License
% (LPPL), version 1.3.
%
% The LPPL maintenance status of this software is
% 'author-maintained'.
%
% This software is provided 'as is', without warranty of any kind,
% either expressed or implied, including, but not limited to, the
% implied warranties of merchantability and fitness for a
% particular purpose.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{btxdockit}[2009/05/24 v1.2 bibtex documentation kit]
\RequirePackage{etoolbox}
\RequirePackage{ltxdockit}

% environments

\newenvironment*{fieldlist}
  {\ltd@pdfinit
   \list{}{%
     \setlength{\labelwidth}{\marglistwidth}%
     \setlength{\labelsep}{\marglistsep}%
     \setlength{\leftmargin}{0pt}%
     \renewcommand*{\makelabel}[1]{\hss\marglistfont##1}}%
   \def\fielditem##1##2{%
     \item[##1]%
     \ltd@pdfbookmark{##1}{##1}%
     field (##2)\par\nobreak
     \vspace{\itemsep}}%
   \def\listitem##1##2{%
     \item[##1]%
     \ltd@pdfbookmark{##1}{##1}%
     list (##2)\par\nobreak
     \vspace{\itemsep}}}
  {\endlist
   \ltd@pdfrestore}

\newenvironment*{typelist}
  {\ltd@pdfinit
   \list{}{%
     \setlength{\labelwidth}{\marglistwidth}%
     \setlength{\labelsep}{\marglistsep}%
     \setlength{\leftmargin}{0pt}%
     \renewcommand*{\makelabel}[1]{\hss\marglistfont##1}}%
   \def\typeitem##1{%
     \item[{##1}]%
     \ltd@pdfbookmark{##1}{##1}}%
   \def\reqitem{%
     \par\begingroup\itemsep0.5\itemsep\item
     Required fields: \btd@fieldloop}
   \def\optitem{%
     \par\begingroup\itemsep0.5\itemsep\item
     Optional fields: \btd@fieldloop}}
  {\endlist
   \ltd@pdfrestore}

\def\btd@fieldloop#1{%
  \interlinepenalty\@M\raggedright
  \def\@tempa{\def\@tempa{, }}
  \def\do##1{\@tempa\bibfield{##1}}%
  \docsvlist{#1}%
  \par\endgroup}

% verbatim

\lstdefinestyle{bibtex}{%
  moredelim=[is][\spotcolor]{<<}{>>}}

% markup

\newrobustcmd*{\bibfield}[1]{\mbox{\verbatimfont#1}}
\newrobustcmd*{\bibtype}[1]{\mbox{\verbatimfont @#1}}

\ifpdf
  \pdfstringdefDisableCommands{%
    \def\bibfield#1{'#1'}%
    \def\bibtype#1{@#1}}
\fi

\endinput
