% $Id: chicago-notes-df.bbx,v 0.8.9.1 2009/07/02 11:04:08 dfussner Exp $
% This is a biblatex style file, adapted mainly from Lehman's standard.bbx
% It provides the bibliography formatting for the Chicago notes + 
% bibliography style.


\ProvidesFile{chicago-notes-df.bbx}[2009/07/02 v0.8 biblatex bibliography style]

%%%% Initialize and format bibliography and los %%%%

\DeclareFieldFormat{shorthandwidth}{#1}
\renewcommand*{\thebibitem}{\item}
\renewcommand*{\thelositem}{\item}
\newlength{\lositemsep}

\renewenvironment*{thebibliography}
  {\list
     {}
     {\setlength{\leftmargin}{\bibhang}%
      \setlength{\itemindent}{-\leftmargin}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}}
  {\endlist}

\renewenvironment*{theshorthands}
  {\list
     {\printfield[shorthandwidth]{shorthand}}
     {\setlength{\labelwidth}{\shorthandwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\lositemsep}%
      \setlength{\parsep}{\bibparsep}%
      \renewcommand*{\makelabel}[1]{##1\hss}}}
  {\endlist}

\AtBeginBibliography{%
  \togglefalse{cms@headlessnote}%
  \togglefalse{cms@shortnote}%
  \togglefalse{cms@fullnote}%
  \togglefalse{cms@allshort}%
  }

\AtEveryBibitem{%
  \iflistundef{language}%
  {\iffieldundef{usere}%
    {\togglefalse{cms@forlang}}%
    {\toggletrue{cms@forlang}}}%
  {\toggletrue{cms@forlang}}}%

\InitializeBibliographyStyle{%
  \let\bbx@lasthash\undefined}

%%%% Bibliography-specific bibstrings %%%%

%% Now in cms-american.lbx %%

%%%% Author, Editor, Translator, and Compiler  Macros %%%%

\newbibmacro*{author/editors/translators}{%
  \ifthenelse{\ifuseauthor\AND\NOT\ifnameundef{author}}%
    {\usebibmacro{author}}%
    {\ifthenelse{\ifuseeditor\AND\NOT\ifnameundef{namea}}%
       {\usebibmacro{parteditor}}%
       {\ifthenelse{\ifuseeditor\AND\NOT\ifnameundef{editor}}%
         {\usebibmacro{editor}}%
         {\ifthenelse{\ifusetranslator\AND\NOT\ifnameundef{nameb}}%
           {\usebibmacro{parttranslator}}%
           {\ifthenelse{\ifusetranslator\AND\NOT\ifnameundef{translator}}%
             {\usebibmacro{translator}}%
             {\ifnameundef{namec}%
               {\let\bbx@lasthash\undefined}%
               {\usebibmacro{compiler}}}}}}}}

\renewbibmacro*{author/editor}{%
  \ifuseauthor%
    {\usebibmacro{author}}%
    {\ifuseeditor%
      {\ifnameundef{namea}%
        {\usebibmacro{moreeditor}}%
        {\usebibmacro{parteditor}}}%
      {\ifusetranslator%
        {\ifnameundef{nameb}%
          {\usebibmacro{moretranslator}}%
          {\usebibmacro{parttranslator}}}%
        {\iftoggle{cms@usecompiler}%
          {\usebibmacro{compiler}}%
          {\let\bbx@lasthash\undefined%
            \settoggle{cms@usecompiler}{true}}}}}}

\renewbibmacro*{author}{%
  \iftoggle{cms@headlessnote}%
  {\usebibmacro{justauthor}}%
  {\usebibmacro{moreauthor}}}

\newbibmacro*{allauthor}{%
  \ifnameundef{author}%
  {\ifnameundef{editor}%
    {\ifnameundef{translator}%
      {\ifnameundef{namec}%
        {\let\bbx@lasthash\undefined}%
        {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
            \iffirstonpage}
               {\bibnamedash\addcomma\space}
               {\printnames[sortname]{namec}\addcomma\space
                 \savefield{namehash}{\bbx@lasthash}}%
               \usebibmacro{compilestrg}}}%
           {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
               \iffirstonpage}
             {\bibnamedash\addcomma\space}
             {\printnames[sortname]{translator}\addcomma\space
               \savefield{namehash}{\bbx@lasthash}}%
             \usebibmacro{transstrg}}}%
         {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
             \iffirstonpage}
           {\bibnamedash\addcomma\space}
           {\printnames{editor}\addcomma\space
             \savefield{namehash}{\bbx@lasthash}}%
           \usebibmacro{editstrg}}}%
       {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
           \iffirstonpage}
         {\iffieldundef{nameaddon}%
           {\bibnamedash\addperiod\addspace}
           {\bibnamedash\addspace}}%
         {\iffieldequalstr{authortype}{anon}%
           {\bibleftbracket\printnames{author}\bibrightbracket%
             \savefield{namehash}{\bbx@lasthash}}%
           {\iffieldequalstr{authortype}{anon?}%
             {\bibleftbracket\printnames{author}\addquestion\bibrightbracket%
               \savefield{namehash}{\bbx@lasthash}}%
             {\printnames{author}%
             \savefield{namehash}{\bbx@lasthash}}}}}}

\newbibmacro*{justauthor}{%
  \ifnameundef{author}
    {\let\bbx@lasthash\undefined}
    {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\bibnamedash\addperiod\addspace}
       {\iffieldequalstr{authortype}{anon}%
         {\bibleftbracket\printnames{author}\bibrightbracket%
           \savefield{namehash}{\bbx@lasthash}}%
         {\iffieldequalstr{authortype}{anon?}%
           {\bibleftbracket\printnames{author}\addquestion\bibrightbracket%
             \savefield{namehash}{\bbx@lasthash}}%
         {\printnames{author}%
        \savefield{namehash}{\bbx@lasthash}}}}}}

\newbibmacro*{moreauthor}{%
  \ifnameundef{author}
    {\usebibmacro{pickeditor}}
    {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\bibnamedash\addperiod\addspace}
       {\iffieldequalstr{authortype}{anon}%
         {\bibleftbracket\printnames{author}\bibrightbracket%
           \savefield{namehash}{\bbx@lasthash}}%
         {\iffieldequalstr{authortype}{anon?}%
           {\bibleftbracket\printnames{author}\addquestion\bibrightbracket%
             \savefield{namehash}{\bbx@lasthash}}%
         {\printnames{author}%
        \savefield{namehash}{\bbx@lasthash}}}}}}

\newbibmacro*{pickeditor}{%
  \ifnameundef{namea}
  {\usebibmacro{moreeditor}}%
  {\usebibmacro{moreparteditor}}}

\newbibmacro*{moreeditor}{%
  \ifnameundef{editor}
    {\usebibmacro{picktranslator}}
    {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\bibnamedash}
       {\printnames{editor}\addcomma\space
        \savefield{namehash}{\bbx@lasthash}}%
     \usebibmacro{editstrg}}}

\renewbibmacro*{editor}{%
  \ifnameundef{editor}
    {\let\bbx@lasthash\undefined}
    {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\bibnamedash}
       {\printnames{editor}\addcomma\space
        \savefield{namehash}{\bbx@lasthash}}%
     \usebibmacro{editstrg}}}

\newbibmacro*{parteditor}{%
  \ifnameundef{namea}
    {\let\bbx@lasthash\undefined}
    {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\bibnamedash}
       {\printnames[sortname]{namea}\addcomma\space
        \savefield{namehash}{\bbx@lasthash}}%
     \usebibmacro{parteditstrg}}}

\newbibmacro*{picktranslator}{%
  \ifnameundef{nameb}
  {\usebibmacro{moretranslator}}%
  {\usebibmacro{parttranslator}}}

\newbibmacro*{moretranslator}{%
  \ifnameundef{translator}
    {\usebibmacro{compiler}}
    {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\bibnamedash}
       {\printnames[sortname]{translator}\addcomma\space
        \savefield{namehash}{\bbx@lasthash}}%
     \usebibmacro{transstrg}}}

\newbibmacro*{parttranslator}{%
  \ifnameundef{nameb}
    {\let\bbx@lasthash\undefined}
    {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\bibnamedash}
       {\printnames[sortname]{nameb}\addcomma\space
        \savefield{namehash}{\bbx@lasthash}}%
     \usebibmacro{parttransstrg}}}

\newbibmacro*{compiler}{%
  \ifnameundef{namec}
    {\let\bbx@lasthash\undefined}
    {\ifthenelse{\iffieldequals{namehash}{\bbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\bibnamedash}
       {\printnames[sortname]{namec}\addcomma\space
        \savefield{namehash}{\bbx@lasthash}}%
     \usebibmacro{compilestrg}}}

%%%% Drivers for Bibliography entries and Shorthands %%%%

\DeclareBibliographyDriver{shorthands}{%
  \ifnameundef{labelname}
    {}
    {\ifnameundef{author}
       {\printnames[loseditor]{editor}%
        \addcomma\space
        \usebibmacro{editstrg}}
       {\printnames[losauthor]{author}}%
     \setunit{\addcomma\space}}%
  \printfield[lostitle]{title}%
  \finentry}

\DeclareBibliographyDriver{article}{%
  \iffieldequalstr{entrysubtype}{magazine}%
  {\usebibmacro{bibindex}%
  \usebibmacro{mag+news+author}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{mag+news+title}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit\newblock%
  \usebibmacro{issuetitle}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{note}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{mag+news+date}%
  \newcunit\newblock
  \usebibmacro{chap+pag}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{issn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}
  {\usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{mag+news+title}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{issuetitle}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{note}%
  \setunit*{\addcomma\addspace}\newblock% (changed for 0.7)??
%  \usebibmacro{in:}%
  \usebibmacro{journal+issue+year+pages}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{issn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{artwork}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newcunit\newblock
  \usebibmacro{letter+date}%
  \newcunit
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{howpublished}%
  \newunit\newblock
  \printfield{type}%
  \newcunit\newblock
  \printfield{version}%
  \newcunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{institution+organization}%
  \setunit*{\addcomma\addspace}\newblock
  \printlist{location}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \iffieldundef{maintitle}%
  {\ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
    {}%
    {\usebibmacro{edition}%
      \newunit
      \printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}%
      \newunit
      \printfield{volumes}%
      \clearfield{volumes}}%
    {}}%
  {}%
  \newcunit\newblock
  \usebibmacro{byauthor}
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \newunit\newblock
  \usebibmacro{mtitle+mstitle+vol+part+title+stitle}%
  \newcunit
  \ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
  {}%
  {\usebibmacro{edition}%
    \newcunit
    \iffieldundef{maintitle}
    {\printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}}%
    {}%
    \newcunit
    \printfield{volumes}%
    \clearfield{volumes}}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \usebibmacro{chap+pag}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{origyear}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newcunit
  \printlist[][-\value{listtotal}]{lista}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{booklet}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newcunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{howpubl+loc+year}%
  \newunit\newblock
  \usebibmacro{chap+pag}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{collection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \usebibmacro{mtitle+mstitle+vol+part+title+stitle}%
  \usebibmacro{editorpunct}%
  \ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
  {}%
  {\usebibmacro{edition}%
    \usebibmacro{editorpunct}%
    \iffieldundef{maintitle}
    {\printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}}%
    {}%
    \usebibmacro{editorpunct}%
    \printfield{volumes}%
    \clearfield{volumes}}%
  \usebibmacro{editorpunct}%
  \usebibmacro{bytranslator+others}%
%  \newunit\newblock
%  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{origyear}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{customa}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \printtext[title]{%
    \printfield[noformat]{title}}%
  \newcunit\newblock%
  \printfield{titleaddon}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{letter+date}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit\newblock%\bibsentence
  \usebibmacro{part+editor+translator}%
  \setunit*{\addperiod\addspace}%
  \iffieldundef{crossref}%
  {\iffieldundef{xref}%
  {\usebibmacro{chapincoll}%
  \usebibmacro{in:}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
  {}%
  {\usebibmacro{edition}%
    \newcunit
    \iffieldundef{maintitle}
    {\printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}}%
    {}%
    \newcunit
    \printfield{volumes}
    \clearfield{volumes}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \printfield{pages}%
%  \newunit\newblock
%  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publetter+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\bibxrefcite{\thefield{xref}}
  \usebibmacro{bibpostxref}%
  \usebibmacro{finentry}}}%
{\bibxrefcite{\thefield{crossref}}%
  \usebibmacro{bibpostxref}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{customb}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \ifthenelse{\iffieldundef{maintitle}\AND\iffieldundef{booktitle}}%
  {\ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
    {}%
    {\usebibmacro{edition}%
      \newunit
      \printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}%
      \newunit
      \printfield{volumes}%
      \clearfield{volumes}}%
    {}}%
  {}%
  \newcunit\newblock
  \newcunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \setunit*{\addperiod\addspace}%
  \usebibmacro{in:}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
  {}%
  {\usebibmacro{edition}%
    \newcunit
    \iffieldundef{maintitle}
    {\printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}}%
    {}%
    \newcunit
    \printfield{volumes}%
    \clearfield{volumes}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{editorpunct}
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \usebibmacro{chap+pag}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{origyear}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{customc}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{inforaft}%
  \setunit{\addspace}\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit
  \iffieldundef{maintitle}%
  {\ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
    {}%
    {\usebibmacro{edition}%
      \newunit
      \printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}%
      \newunit
      \printfield{volumes}%
      \clearfield{volumes}}%
    {}}%
  {}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \newunit\newblock
  \usebibmacro{mtitle+mstitle+vol+part+title+stitle}%
  \newcunit%
  \ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
  {}%
  {\usebibmacro{edition}%
    \newcunit
    \iffieldundef{maintitle}
    {\printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}}%
    {}%
    \newcunit
    \printfield{volumes}
    \clearfield{volumes}}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byeditor}%
  \newcunit\newblock
  \usebibmacro{chap+pag}%
%  \newunit\newblock
%  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{origyear}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{image}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{letter+date}%
  \newcunit
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{howpublished}%
  \newunit\newblock
  \printfield{type}%
  \newcunit\newblock
  \printfield{version}%
  \newcunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{institution+organization}%
  \setunit*{\addcomma\addspace}\newblock
  \printlist{location}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{inbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%\bibsentence
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addperiod\addspace}%
  \usebibmacro{part+editor+translator}%
  \setunit{\addperiod\addspace}%
  \usebibmacro{chapincoll}%
  \usebibmacro{in:}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
  {}%
  {\usebibmacro{edition}%
    \newcunit
    \iffieldundef{maintitle}
    {\printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}}%
    {}%
    \newcunit
    \printfield{volumes}
    \clearfield{volumes}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \printfield{pages}%
%  \newunit\newblock
%  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{origyear}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%

\DeclareBibliographyDriver{incollection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%\bibsentence
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addperiod\addspace}%
  \usebibmacro{part+editor+translator}%
  \setunit{\addperiod\addspace}%
  \iffieldundef{crossref}%
  {\iffieldundef{xref}%
  {\usebibmacro{chapincoll}%
  \usebibmacro{in:}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
  {}%
  {\usebibmacro{edition}%
    \newcunit
    \iffieldundef{maintitle}
    {\printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}}%
    {}%
    \newcunit
    \printfield{volumes}
    \clearfield{volumes}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \printfield{pages}%
%  \newunit\newblock
%  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{origyear}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\bibxrefcite{\thefield{xref}}
  \usebibmacro{bibpostxref}%
  \usebibmacro{finentry}}}%
{\bibxrefcite{\thefield{crossref}}%
  \usebibmacro{bibpostxref}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{inproceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addperiod\addspace}%
  \usebibmacro{part+editor+translator}%
  \setunit{\addperiod\addspace}%
  \iffieldundef{crossref}%
  {\iffieldundef{xref}%
  {\usebibmacro{chapincoll}%
    \usebibmacro{in:}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit\newblock
  \usebibmacro{chap+pag}%
  \newunit\newblock
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{org+publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\bibxrefcite{\thefield{xref}}
  \usebibmacro{bibpostxref}%
  \usebibmacro{finentry}}}%
{\bibxrefcite{\thefield{crossref}}%
  \usebibmacro{bibpostxref}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{inreference}{%
  \usebibmacro{bibindex}%
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \ifthenelse{\iffieldundef{maintitle}\AND\iffieldundef{booktitle}}%
  {\ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
    {}%
    {\usebibmacro{edition}%
      \newunit
      \printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}%
      \newunit
      \printfield{volumes}%
      \clearfield{volumes}}%
    {}}%
  {}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \setunit*{\addperiod\addspace}% need asterisk?
  \usebibmacro{alt-in:}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
  {}%
  {\usebibmacro{edition}%
    \newcunit
    \iffieldundef{maintitle}
    {\printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}}%
    {}%
    \newcunit
    \printfield{volumes}%
    \clearfield{volumes}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{editorpunct}
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \usebibmacro{chap+pag}%
%  \newunit\newblock
%  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{origyear}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newcunit\newblock
  \printlist[][-\value{listtotal}]{lista}%
  \setunit{\addspace}%
  \ifnameundef{author}%
  {}%
  {\printtext[parens]{%
      \bibstring{by}%
      \printnames[byauthor]{author}}}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyAlias{letter}{customa}

\DeclareBibliographyDriver{manual}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author+org}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \usebibmacro{edition}%
  \newcunit
  \usebibmacro{byauthor}%
%  \newunit\newblock
%  \printfield{edition}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{type}%
  \newunit
  \printfield{note}%
  \newunit\newblock%
  \usebibmacro{org+publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{misc}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \iffieldundef{entrysubtype}%
  {\usebibmacro{italtitle+stitle}}%
  {\printfield{title}%
    \setunit{\addcolon\addspace}%
    \printfield[noformat]{subtitle}%
    \newunit\newblock%
    \printfield{titleaddon}%
    \setunit{\addspace}%
    \usebibmacro{language+transtitle}}%
  % \newcunit\newblock}
  \iffieldequalstr{entrysubtype}{letter}%
  {\newcunit\newblock
    \usebibmacro{letter+date}}%
  {}%
  \newcunit
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{howpublished}%
  \newunit\newblock
  \printfield{type}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{institution+organization}%
  \setunit*{\addcomma\addspace}\newblock
  \printlist{location}%
  \iffieldequalstr{entrysubtype}{letter}%
  {}%
  {\newcunit\newblock
    \usebibmacro{date}}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{online}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newcunit%
  \usebibmacro{byauthor}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \printlist{organization}%
  \newunit\newblock
  \usebibmacro{date}%
  \newunit\newblock
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{patent}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author+holder}% + holder?
  \newunit\newblock
  \usebibmacro{title}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \setunit{\addperiod\addspace}%
  \printfield{note}%
  \setunit{\addperiod\addspace}%
  \printfield{type}%
  \setunit{\addspace}%
  \printfield{number}%
  \iflistundef{location}
    {}
    {\setunit*{\addspace}%
     \printtext[parens]{%
       \printlist[][-\value{listtotal}]{location}}}%
  \newcunit\newblock
  \printfield{version}%
  \setunit{\addcomma\addspace filed\addspace}\newblock%
  \usebibmacro{date}%
  \newcunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{periodical}{%
  \iffieldequalstr{entrysubtype}{magazine}%
  {\usebibmacro{bibindex}%
  \usebibmacro{editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{issuetitle}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit\newblock%
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{note}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{periodical+date+issue}%
  \newcunit\newblock
  \usebibmacro{chap+pag}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{issn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}
  {\usebibmacro{bibindex}%
  \usebibmacro{editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{issuetitle}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{note}%
  \setunit*{\addcomma\addspace}\newblock% (changed for 0.7)??
%  \usebibmacro{in:}%
  \usebibmacro{periodical+issue+year+pages}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{issn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{proceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \usebibmacro{mtitle+mstitle+vol+part+title+stitle}%
  \newunit\newblock
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{org+publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{reference}{%
  \usebibmacro{bibindex}%
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \ifthenelse{\iffieldundef{maintitle}\AND\iffieldundef{booktitle}}%
  {\ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
    {}%
    {\usebibmacro{edition}%
      \newunit
      \printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}%
      \newunit
      \printfield{volumes}%
      \clearfield{volumes}}%
    {}}%
  {}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \setunit*{\addperiod\addspace}% need asterisk?
  \usebibmacro{alt-in:}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \ifthenelse{\iffieldundef{edition}\AND\iffieldundef{userd}}%
  {}%
  {\usebibmacro{edition}%
    \newcunit
    \iffieldundef{maintitle}
    {\printfield{volume}%
      \printfield{part}%
      \clearfield{volume}%
      \clearfield{part}}%
    {}%
    \newcunit
    \printfield{volumes}%
    \clearfield{volumes}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{editorpunct}
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \usebibmacro{chap+pag}%
%  \newunit\newblock
%  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{origyear}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isbn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{report}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newcunit
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{type}%
  \newunit
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{inst+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{isrn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{review}{%
  \usebibmacro{bibindex}%
  \iffieldequalstr{entrysubtype}{magazine}%
  {\usebibmacro{mag+news+author}}%
  {\usebibmacro{author/editor}}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
%  \usebibmacro{mag+news+title}%
  \printfield{title}%
  \setunit{\addcolon\addspace}%
  \printfield[noformat]{subtitle}%
  \setunit{\addspace}%
  \printfield{titleaddon}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit\newblock%
  \usebibmacro{issuetitle}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{note}%
  \setunit*{\addcomma\addspace}\newblock%
  \iffieldequalstr{entrysubtype}{magazine}
  {\usebibmacro{mag+news+date}%
  \newcunit\newblock
  \usebibmacro{chap+pag}}%
  {\usebibmacro{journal+issue+year+pages}}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{issn}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyAlias{suppbook}{customc}

\DeclareBibliographyAlias{suppcollection}{customc}

\DeclareBibliographyAlias{suppperiodical}{review}

\DeclareBibliographyDriver{thesis}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}%\newblock%
  \usebibmacro{language+transtitle}%
  \newcunit%
  \usebibmacro{byauthor}%
  \setunit{\addperiod\addspace}%
  \printfield{note}%
  \setunit{\addperiod\addspace}\newblock%
  \usebibmacro{type+inst+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{doi}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{unpublished}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \newcunit%usebibmacro{byauthorpunct}% Why does this work?  No idea.
  \usebibmacro{byauthor}% Same in thesis type, as well.
  \setunit{\addperiod\addspace}%
  \printfield{howpublished}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{note}%
  \setunit*{\addcomma\addspace}\newblock%
  \printlist{location}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{date}% N.B. biblatex requires single integer in day field.
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{url+date}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

%%%% Other Formatting Macros %%%%

\newbibmacro*{bibpostxref}{%
  \iffieldundef{postnote}%
  {\iffieldundef{chapter}%
    {\iffieldundef{pages}%
      {}%
      {\postnotedelim%  Extra space?
        \printfield{pages}}}%
    {\postnotedelim%
      \printfield{chapter}}}%
  {\postnotedelim%
    \printfield{postnote}}}

\newbibmacro*{mtitle+mstitle+vol+part+title+stitle}{%
  \iffieldundef{maintitle}
  {}
  {\iffieldundef{volume}
    {\printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
      \setunit{\addcolon\addspace}%
      \printfield[noformat]{mainsubtitle}}%
    \newcunit
    \printfield{maintitleaddon}}
  {\printfield{volume}%
    \printfield{part}%
    \setunit{\addspace}
    \bibstring{ofseries}%
    \setunit{\addspace}
    \printtext[maintitle]{%
      \printfield[noformat]{maintitle}%
      \setunit{\addcolon\addspace}%
      \printfield[noformat]{mainsubtitle}}%
    \newcunit
    \printfield{maintitleaddon}}}}

\newbibmacro*{mtitle+mstitle+vol+part+btitle+bstitle}{%
  \usebibmacro{btitle+bstitle}%
  \iffieldundef{booktitle}
  {\setunit{\addperiod\addspace}}% Fix customc?
  {\setunit{\addcomma\addspace}}%
  \iffieldundef{maintitle}
  {}
  {\iffieldundef{volume}
    {\printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
      \setunit{\addcolon\addspace}%
      \printfield[noformat]{mainsubtitle}}%
    \newcunit
    \printfield{maintitleaddon}}
  {\printfield{volume}%
    \printfield{part}%
    \setunit{\addspace}
    \bibstring{ofseries}%
    \setunit{\addspace}
    \printtext[maintitle]{%
      \printfield[noformat]{maintitle}%
      \setunit{\addcolon\addspace}%
      \printfield[noformat]{mainsubtitle}}%
    \newcunit
    \printfield{maintitleaddon}}}}

\newbibmacro*{journal+issue+year+pages}{%
  \usebibmacro{cjournal+ser+vol+num}%
  \setunit{\addspace}%
  \printtext[parens]{%
    \iffieldundef{issue}
      {\iffieldundef{month}
         {\printfield{year}}
         {\iffieldundef{day}
           {\printfield{month}%
             \setunit{\addspace}%
             \printfield{year}}
            {\printtext{\bibdate}}}}
      {\printfield{issue}%
       \setunit{\addspace}%
       \printfield{year}}}%
  \setunit{\addcolon\addspace}
  \printfield{pages}}

\newbibmacro*{periodical+issue+year+pages}{%
  \usebibmacro{cperiodical+ser+vol+num}%
  \setunit{\addspace}%
  \printtext[parens]{%
    \iffieldundef{issue}
      {\iffieldundef{month}
         {\printfield{year}}
         {\iffieldundef{day}
           {\printfield{month}%
             \setunit{\addspace}%
             \printfield{year}}
            {\printtext{\bibdate}}}}
      {\printfield{issue}%
       \setunit{\addspace}%
       \printfield{year}}}%
  \setunit{\addcolon\addspace}
  \printfield{pages}}

\newbibmacro*{bycompiler}{%
  \ifnameundef{namec}
    {}
    {\bibstring{bycompiler}\addspace
     \printnames[bycompiler]{namec}}}

\renewbibmacro*{byeditor+others}{%
  \ifnameundef{editor}
    {}
    {\def\@tempa{byeditor}%
     \ifnamesequal{editor}{translator}
       {\edef\@tempa{\@tempa tr}%
        \clearname{translator}}
       {}%
       \ifnamesequal{editor}{namec}
       {\edef\@tempa{\@tempa cp}%
         \clearname{namec}}
       {}%
     \ifnamesequal{editor}{commentator}
       {\edef\@tempa{\@tempa co}%
        \clearname{commentator}}
       {\ifnamesequal{editor}{annotator}
          {\edef\@tempa{\@tempa an}%
           \clearname{annotator}}
          {}}%
     \ifnamesequal{editor}{introduction}
       {\edef\@tempa{\@tempa in}%
        \clearname{introduction}}
       {\ifnamesequal{editor}{foreword}
          {\edef\@tempa{\@tempa fo}%
           \clearname{foreword}}
          {\ifnamesequal{editor}{afterword}
             {\edef\@tempa{\@tempa af}%
              \clearname{afterword}}
             {}}}%
     \bibstring{\@tempa}\space
     \printnames[byeditor]{editor}%
     \clearname{editor}%
     \usebibmacro{editorpunct}}%
  \usebibmacro{bytranslator+others}}

\renewbibmacro*{bytranslator+others}{%
  \ifnameundef{translator}
    {}
    {\def\@tempa{bytranslator}%
      \ifnamesequal{translator}{namec}
      {\edef\@tempa{\@tempa cp}%
        \clearname{namec}}
      {}%
     \ifnamesequal{translator}{commentator}
       {\edef\@tempa{\@tempa co}%
        \clearname{commentator}}
       {\ifnamesequal{translator}{annotator}
          {\edef\@tempa{\@tempa an}%
           \clearname{annotator}}
          {}}%
     \ifnamesequal{translator}{introduction}
       {\edef\@tempa{\@tempa in}%
        \clearname{introduction}}
       {\ifnamesequal{translator}{foreword}
          {\edef\@tempa{\@tempa fo}%
           \clearname{foreword}}
          {\ifnamesequal{translator}{afterword}
             {\edef\@tempa{\@tempa af}%
              \clearname{afterword}}
             {}}}%
     \bibstring{\@tempa}\space
     \printnames[bytranslator]{translator}%
     \clearname{translator}%
     \usebibmacro{editorpunct}}%
  \usebibmacro{bycompiler+others}}

\newbibmacro*{bycompiler+others}{%
  \ifnameundef{namec}
    {}
    {\def\@tempa{bycompiler}%
     \ifnamesequal{namec}{commentator}
       {\edef\@tempa{\@tempa co}%
        \clearname{commentator}}
       {\ifnamesequal{namec}{annotator}
          {\edef\@tempa{\@tempa an}%
           \clearname{annotator}}
          {}}%
     \ifnamesequal{namec}{introduction}
       {\edef\@tempa{\@tempa in}%
        \clearname{introduction}}
       {\ifnamesequal{namec}{foreword}
          {\edef\@tempa{\@tempa fo}%
           \clearname{foreword}}
          {\ifnamesequal{namec}{afterword}
             {\edef\@tempa{\@tempa af}%
              \clearname{afterword}}
             {}}}%
     \bibstring{\@tempa}\space
     \printnames[bycompiler]{namec}%
     \clearname{namec}%
     \usebibmacro{editorpunct}}%
  \usebibmacro{byothers}}

\renewbibmacro*{byothers}{%
  \usebibmacro{bytranslator}%
  \usebibmacro{editorpunct}%
  \usebibmacro{bycompiler}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byredactor}%
  \usebibmacro{editorpunct}%
  \usebibmacro{withcommentator}%
  \usebibmacro{editorpunct}%
  \usebibmacro{withannotator}%
  \usebibmacro{editorpunct}%
  \usebibmacro{withintroduction}%
  \usebibmacro{editorpunct}%
  \usebibmacro{withforeword}%
  \usebibmacro{editorpunct}%
  \usebibmacro{withafterword}}

\endinput
