% 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-notes16.bbx}[2022/11/16 v 3.18b biblatex
bibliography style]

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

\providetoggle{cms@citejtabb}% Here for Sourcemap declaration
\providetoggle{cms@bibjtabb}%

\DeclareFieldFormat{shorthandwidth}{#1}

\DeclareFieldFormat{shortjournalwidth}{%
  \ifthenelse{\ifentrytype{jurisdiction}\OR%
    \ifentrytype{legal}\OR\ifentrytype{legislation}}%
  {\textbf{#1}\isdot}%
  {\mkbibemph{\textbf{#1}}\isdot}}%

\newlength{\lositemsep}

\defbibenvironment{bibliography}% New for 0.9a
  {\list
     {}
     {\setlength{\leftmargin}{\bibhang}%
      \setlength{\itemindent}{-\leftmargin}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}}
  {\endlist}
  {\item}

\defbibenvironment{shorthand}%
  {\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}
  {\item}

\defbibenvironment{losnotes}
  {\list
     {\printfield[shorthandwidth]{shorthand}}%
     {\footnotesize%
      \setlength{\labelwidth}{\shorthandwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{.3\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\lositemsep}%
      \setlength{\parsep}{\bibparsep}%
      \renewcommand*{\makelabel}[1]{##1\hss}}}
  {\endlist}
  {\item}

\defbibenvironment{losendnotes}
  {\list
     {\printfield[shorthandwidth]{shorthand}}%
     {\enotesize%
      \setlength{\labelwidth}{\shorthandwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{.3\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\lositemsep}%
      \setlength{\parsep}{\bibparsep}%
      \renewcommand*{\makelabel}[1]{##1\hss}}}
  {\endlist\nopunct\vspace{-\baselineskip}}% Kludges for endnotes
  {\item}

\defbibenvironment{shortjournal}%
  {\list
    {\printfield[shortjournalwidth]{shortjournal}}%
    {\setlength{\labelwidth}{\shortjournalwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{.7\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\lositemsep}%
      \setlength{\parsep}{\bibparsep}%
      \renewcommand*{\makelabel}[1]{##1\hss}}}
  {\endlist}
  {\item}

\defbibenvironment{sjnotes}%
  {\list
    {\printfield[shortjournalwidth]{shortjournal}}%
    {\footnotesize%
      \setlength{\labelwidth}{\shortjournalwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{.3\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\lositemsep}%
      \setlength{\parsep}{\bibparsep}%
      \renewcommand*{\makelabel}[1]{##1\hss}}}
  {\endlist}
  {\item}

\defbibenvironment{sjendnotes}%
  {\list
    {\printfield[shortjournalwidth]{shortjournal}}%
    {\enotesize%
      \setlength{\labelwidth}{\shortjournalwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{.3\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\lositemsep}%
      \setlength{\parsep}{\bibparsep}%
      \renewcommand*{\makelabel}[1]{##1\hss}}}
  {\endlist\nopunct\vspace{-\baselineskip}}
  {\item}

\defbibcheck{shortjournal}{% Only one list
  \ifthenelse{\iffieldundef{shortjournal}\OR%
    \iffieldsequal{journaltitle}{shortjournal}\OR%
    \(\iffieldundef{journaltitle}\AND\(\ifentrytype{legal}\OR%
    \ifentrytype{legislation}\OR\ifentrytype{jurisdiction}\)\)}%
  {\skipentry}%
  {\ifcsdef{\strfield{shortjournal}}%
    {\skipentry}%
    {\savefieldcs{shortjournal}%
      {\strfield{shortjournal}}}}}%

% \defbibcheck{shortjournal}{% Multiple lists
%   \ifcsdef{cms@shjour}%
%   {\iffieldequals{shortjournal}{\cms@shjour}%
%     {\skipentry}%
%     {\savefield{shortjournal}{\cms@shjour}}}%
%   {\savefield{shortjournal}{\cms@shjour}}}

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

\AtEveryBibitem{%
  \global\csundef{@cmsst}%
  \iffieldequalstr{pubstate}{reprint}%
  {\toggletrue{cms@reprint}}%
  {\togglefalse{cms@reprint}}%
  \ifboolexpr{%
    test {\iffieldundef{origyear}}%
    or
    test {\iffieldundef{year}}%
    or
    not test {\iffieldint{year}}%
    or
    not test {\iffieldint{origyear}}%
    or
    togl {cms@switchdates}%
  }%
  {}%
  {\ifboolexpr{% Needed for open-ended ranges
      test {\iffieldundef{endyear}}%
      or
      not test {\iffieldnum{endyear}}%
    }%
    {\ifthenelse{\thefield{origyear}>\thefield{year}}%
      {\toggletrue{cms@switchdates}}%
      {}}%
    {\ifthenelse{\thefield{origyear}>\thefield{endyear}}%
      {\toggletrue{cms@switchdates}}%
      {}}}}%

\AtEveryLositem{%
  \global\csundef{@cmsst}%
  \iffieldequalstr{pubstate}{reprint}%
  {\toggletrue{cms@reprint}}%
  {\togglefalse{cms@reprint}}%
  \ifboolexpr{%
    test {\iffieldundef{origyear}}%
    or
    test {\iffieldundef{year}}%
    or
    not test {\iffieldint{year}}%
    or
    not test {\iffieldint{origyear}}%
    or
    togl {cms@switchdates}%
  }%
  {}%
  {\ifboolexpr{% Needed for open-ended ranges
      test {\iffieldundef{endyear}}%
      or
      not test {\iffieldnum{endyear}}%
    }%
    {\ifthenelse{\thefield{origyear}>\thefield{year}}%
      {\toggletrue{cms@switchdates}}%
      {}}%
    {\ifthenelse{\thefield{origyear}>\thefield{endyear}}%
      {\toggletrue{cms@switchdates}}%
      {}}}}%

\AtEveryBiblistitem{shortjournal}{%
  \global\csundef{@cmsst}%
  \ifthenelse{\ifentrytype{jurisdiction}\OR%
    \ifentrytype{legal}\OR\ifentrytype{legislation}}%
  {\clearlist{location}}%
  {}}%

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

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

%% Now in *.lbx %%

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

\renewbibmacro*{name:last-first}[4]{%
  \ifuseprefix
  {\usebibmacro{name:delim}{#3#1}%
    \usebibmacro{name:hook}{#3#1}%
    \ifblank{#3}{}{%
      \ifcapital
      {\mkbibnameprefix{\MakeCapital{#3}}\isdot}%
      {\mkbibnameprefix{#3}\isdot}%
      \ifpunctmark{'}{}{\addhighpenspace}}%
    \mkbibnamelast{#1}\isdot
    \ifblank{#2}{}{\addcomma\addlowpenspace\mkbibnamefirst{#2}\isdot}%
    \ifblank{#4}{}{\addcomma\addlowpenspace\mkbibnameaffix{#4}\isdot}}%
  {\usebibmacro{name:delim}{#1}%
    \usebibmacro{name:hook}{#1}%
    \mkbibnamelast{#1}\isdot%
    \ifblank{#2#3#4}{}{\addcomma}%
    \ifblank{#2}{}{\addlowpenspace\mkbibnamefirst{#2}\isdot}%
    \ifblank{#3}{}{\addlowpenspace\mkbibnameprefix{#3}\isdot}%
    \ifblank{#4}{}{\addcomma\addlowpenspace\mkbibnameaffix{#4}\isdot}}}

\renewbibmacro*{name:first-last}[4]{%
  \usebibmacro{name:delim}{#2#3#1}%
  \usebibmacro{name:hook}{#2#3#1}%
  \ifblank{#2}{}{\mkbibnamefirst{#2}\isdot\addlowpenspace}%
  \ifblank{#3}{}{%
    \mkbibnameprefix{#3}\isdot
    \ifpunctmark{'}%
    {}%
    {\ifuseprefix{\addhighpenspace}{\addlowpenspace}}}%
  \mkbibnamelast{#1}\isdot
  \ifblank{#4}{}{%
    \iftoggle{cms@jrcomma}%
    {\ifnumeral{#4}%
      {\addlowpenspace\mkbibnameaffix{#4}\isdot}%
      {\addcomma\addlowpenspace\mkbibnameaffix{#4}\isdot%
        \ifboolexpr{%
          test{\ifnumless{\value{listcount}}{\value{listtotal}}}%
          and
          test{\ifnumless{\value{listcount}}{\value{maxnames}}}%
        }%
        {\addcomma}%
        {}}}%
    {\addlowpenspace\mkbibnameaffix{#4}\isdot}}}

\@ifpackagelater{biblatex}{2016/03/01}% For biblatex 3.3
{\renewbibmacro*{name:family-given}[4]{%
  \ifuseprefix
    {\usebibmacro{name:delim}{#3#1}%
     \usebibmacro{name:hook}{#3#1}%
     \ifdefvoid{#3}{}{%
       \ifcapital
         {\mkbibnameprefix{\MakeCapital{#3}}\isdot}%
         {\mkbibnameprefix{#3}\isdot}%
       \ifprefchar{}{\bibnamedelimc}}%
     \mkbibnamefamily{#1}\isdot
     \ifdefvoid{#2}{}{\revsdnamepunct\bibnamedelimd\mkbibnamegiven{#2}\isdot}%
     \ifdefvoid{#4}{}{\revsdnamepunct\bibnamedelimd\mkbibnamesuffix{#4}\isdot}}%
    {\usebibmacro{name:delim}{#1}%
      \usebibmacro{name:hook}{#1}%
      \mkbibnamefamily{#1}\isdot
      \ifboolexpr{%
        test {\ifdefvoid{#2}}%
        and
        test {\ifdefvoid{#3}}%
      }%
      {}{\revsdnamepunct}%
      \ifdefvoid{#2}{}{\bibnamedelimd\mkbibnamegiven{#2}\isdot}%
      \ifdefvoid{#3}{}{\bibnamedelimd\mkbibnameprefix{#3}\isdot}%
      \ifdefvoid{#4}{}{\revsdnamepunct\bibnamedelimd\mkbibnamesuffix{#4}\isdot}}}%

\renewbibmacro*{name:given-family}[4]{%
  \usebibmacro{name:delim}{#2#3#1}%
  \usebibmacro{name:hook}{#2#3#1}%
  \ifdefvoid{#2}{}{\mkbibnamegiven{#2}\isdot\bibnamedelimd}%
  \ifdefvoid{#3}{}{%
    \mkbibnameprefix{#3}\isdot
    \ifprefchar
      {}%
      {\ifuseprefix{\bibnamedelimc}{\bibnamedelimd}}}%
  \mkbibnamefamily{#1}\isdot
  \ifdefvoid{#4}{}{%
    \iftoggle{cms@jrcomma}%
    {\ifnumeral{#4}%
      {\bibnamedelimd\mkbibnamesuffix{#4}\isdot}%
      {\revsdnamepunct\bibnamedelimd\mkbibnamesuffix{#4}\isdot%
        \ifboolexpr{% Test needed in notes
          test{\ifnumless{\value{listcount}}{\value{listtotal}}}%
          and
          test{\ifnumless{\value{listcount}}{\value{maxnames}}}%
        }%
        {\revsdnamepunct}%
        {}}}%
    {\bibnamedelimd\mkbibnamesuffix{#4}\isdot}}}}{}%

\renewbibmacro*{author/editor}{%
  \ifboolexpr{%
    test {\ifuseauthor}%
    or
    togl {cms@headlessnote}
  }%
  {\usebibmacro{author}}%
  {\ifusenamea%
    {\usebibmacro{pickeditor}}%
    {\ifuseeditor%
      {\usebibmacro{moreeditor}}%
      {\ifusenameb%
        {\usebibmacro{picktranslator}}%
        {\ifusetranslator%
          {\usebibmacro{moretranslator}}%
          {\ifusenamec%
            {\usebibmacro{compiler}}%
            {\let\bbx@lasthash\undefined}}}}}}}%

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

\newbibmacro*{justauthor}{%
  \ifthenelse{\ifnameundef{author}\OR\NOT\ifuseauthor}%
  {\iftoggle{cms@origcite}{}{\let\bbx@lasthash\undefined}}%
  {\ifboolexpr{%
      test {\iffieldequals{fullhash}{\bbx@lasthash}}%
      and
      not test {\iffirstonpage}%
      and
      togl {cms@namedash}%
    }%
    {\iffieldundef{nameaddon}%
      {\printtext{\bibnamedash}}%\addperiod\addspace
      {\printtext{\bibnamedash}%
        \ifentrytype{customc}%
        {\newunit}%
        {\setunit{\addspace}}\printfield{nameaddon}}}%
    {\iffieldequalstr{authortype}{anon}%
      {\bibleftbracket\printnames{author}\bibrightbracket%
        \savefield{fullhash}{\bbx@lasthash}}%
      {\iffieldequalstr{authortype}{anon?}%
        {\bibleftbracket\printnames{author}\addquestion\bibrightbracket%
          \savefield{fullhash}{\bbx@lasthash}}%
        {\printnames{author}%
          \ifentrytype{customc}%
          {\ifbibliography{\newunit}{\newcunit}}%
          {\setunit{\addspace}}%
          \printfield{nameaddon}%
          \savefield{fullhash}{\bbx@lasthash}}}}}}

\newbibmacro*{moreauthor}{%
  \ifthenelse{\ifnameundef{author}\OR\NOT\ifuseauthor}%
  {\usebibmacro{pickeditor}}%
  {\ifboolexpr{%
      test {\iffieldequals{fullhash}{\bbx@lasthash}}%
      and
      not test {\iffirstonpage}%
      and
      togl {cms@namedash}%
    }%
    {\iffieldundef{nameaddon}%
      {\printtext{\bibnamedash}}%\addperiod\addspace
      {\printtext{\bibnamedash}\setunit{\addspace}\printfield{nameaddon}}}%
    {\iffieldequalstr{authortype}{anon}%
      {\bibleftbracket\printnames{author}\bibrightbracket%
        \savefield{fullhash}{\bbx@lasthash}}%
      {\iffieldequalstr{authortype}{anon?}%
        {\bibleftbracket\printnames{author}\addquestion\bibrightbracket%
          \savefield{fullhash}{\bbx@lasthash}}%
        {\printnames{author}%
          \setunit{\addspace}%
          \printfield{nameaddon}%
          \savefield{fullhash}{\bbx@lasthash}}}}}}

\newbibmacro*{pickeditor}{%
  \ifthenelse{\ifnameundef{namea}\OR\NOT\ifusenamea}%
  {\usebibmacro{moreeditor}}%
  {\usebibmacro{parteditor}}}

\newbibmacro*{moreeditor}{%
  \ifthenelse{\ifnameundef{editor}\OR\NOT\ifuseeditor}%
  {\usebibmacro{picktranslator}}%
  {\ifboolexpr{%
      test {\iffieldequals{fullhash}{\bbx@lasthash}}%
      and
      not test {\iffirstonpage}%
      and
      togl {cms@namedash}%
    }%
    {\iffieldundef{nameaddon}%
      {\printtext{\bibnamedash}\editordelim}%
      {\printtext{\bibnamedash}\setunit{\addspace}%
        \printfield{nameaddon}\editordelim}}%
    {\printnames{editor}%
      \setunit{\addspace}%
      \printfield{nameaddon}\editordelim%
      \savefield{fullhash}{\bbx@lasthash}}%
    \usebibmacro{editstrg}}}

\renewbibmacro*{editor}{%
  \iftoggle{cms@headlessnote}%
  {}%
  {\ifthenelse{\ifnameundef{namea}\OR\NOT\ifusenamea}%
    {\ifthenelse{\ifnameundef{editor}\OR\NOT\ifuseeditor}%
      {\usebibmacro{picktranslator}}%
      {\ifboolexpr{%
          test {\iffieldequals{fullhash}{\bbx@lasthash}}%
          and
          not test {\iffirstonpage}%
          and
          togl {cms@namedash}%
        }%
        {\iffieldundef{nameaddon}%
          {\printtext{\bibnamedash}\editordelim}%
          {\printtext{\bibnamedash}\setunit{\addspace}%
            \printfield{nameaddon}\editordelim}}%
        {\printnames{editor}%
          \setunit{\addspace}%
          \printfield{nameaddon}\editordelim%
          \savefield{fullhash}{\bbx@lasthash}}%
        \usebibmacro{editstrg}}}%
    {\ifboolexpr{%
        test {\iffieldequals{fullhash}{\bbx@lasthash}}%
        and
        not test {\iffirstonpage}%
        and
        togl {cms@namedash}%
      }%
      {\iffieldundef{nameaddon}%
        {\printtext{\bibnamedash}\nameadelim}%
        {\printtext{\bibnamedash}\setunit{\addspace}%
          \printfield{nameaddon}\nameadelim}}%
      {\printnames[sortname]{namea}%
        \setunit{\addspace}%
        \printfield{nameaddon}\nameadelim%
        \savefield{fullhash}{\bbx@lasthash}}%
      \usebibmacro{parteditstrg}}}}%

\newbibmacro*{parteditor}{%
  \ifthenelse{\ifnameundef{namea}\OR\NOT\ifusenamea}%
  {\usebibmacro{picktranslator}}%
  {\ifboolexpr{%
      test {\iffieldequals{fullhash}{\bbx@lasthash}}%
      and
      not test {\iffirstonpage}%
      and
      togl {cms@namedash}%
    }%
    {\iffieldundef{nameaddon}%
      {\printtext{\bibnamedash}\nameadelim}%
      {\printtext{\bibnamedash}\setunit{\addspace}%
        \printfield{nameaddon}\nameadelim}}%
    {\printnames[sortname]{namea}%
      \setunit{\addspace}%
      \printfield{nameaddon}\nameadelim%
      \savefield{fullhash}{\bbx@lasthash}}%
    \usebibmacro{parteditstrg}}}

\newbibmacro*{picktranslator}{%
  \ifthenelse{\ifnameundef{nameb}\OR\NOT\ifusenameb}%
  {\usebibmacro{moretranslator}}%
  {\usebibmacro{parttranslator}}}

\newbibmacro*{moretranslator}{%
  \ifthenelse{\ifnameundef{translator}\OR\NOT\ifusetranslator}%
  {\usebibmacro{compiler}}%
  {\ifboolexpr{%
      test {\iffieldequals{fullhash}{\bbx@lasthash}}%
      and
      not test {\iffirstonpage}%
      and
      togl {cms@namedash}%
    }%
    {\iffieldundef{nameaddon}%
      {\printtext{\bibnamedash}\newcunit}%
      {\printtext{\bibnamedash}\setunit{\addspace}%
        \printfield{nameaddon}\newcunit}}%
    {\printnames[sortname]{translator}%
      \setunit{\addspace}%
      \printfield{nameaddon}\newcunit%
      \savefield{fullhash}{\bbx@lasthash}}%
    \usebibmacro{transstrg}}}

\newbibmacro*{parttranslator}{%
  \ifthenelse{\ifnameundef{nameb}\OR\NOT\ifusenameb}%
  {\usebibmacro{compiler}}%
  {\ifboolexpr{%
      test {\iffieldequals{fullhash}{\bbx@lasthash}}%
      and
      not test {\iffirstonpage}%
      and
      togl {cms@namedash}%
    }%
    {\iffieldundef{nameaddon}%
      {\printtext{\bibnamedash}\newcunit}%
      {\printtext{\bibnamedash}\setunit{\addspace}%
        \printfield{nameaddon}\newcunit}}%
    {\printnames[sortname]{nameb}%
      \setunit{\addspace}%
      \printfield{nameaddon}\newcunit%
      \savefield{fullhash}{\bbx@lasthash}}%
    \usebibmacro{parttransstrg}}}

\newbibmacro*{compiler}{%
  \ifthenelse{\ifnameundef{namec}\OR\NOT\ifusenamec}%
  {\let\bbx@lasthash\undefined}%
  {\ifboolexpr{%
      test {\iffieldequals{fullhash}{\bbx@lasthash}}%
      and
      not test {\iffirstonpage}%
      and
      togl {cms@namedash}%
    }%
    {\iffieldundef{nameaddon}%
      {\printtext{\bibnamedash}\newcunit}%
      {\printtext{\bibnamedash}\setunit{\addspace}%
        \printfield{nameaddon}\newcunit}}%
    {\printnames[sortname]{namec}%
      \setunit{\addspace}%
      \printfield{nameaddon}\newcunit%
      \savefield{fullhash}{\bbx@lasthash}}%
    \usebibmacro{compilestrg}}}

\renewcommand*{\revsdnamedelim}{\addcomma}

\DeclareNameAlias{author}{sortname}% Needed in 0.9
\DeclareNameAlias{editor}{sortname}
\DeclareNameAlias{translator}{sortname}

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

\DeclareBibliographyDriver{shorthand}{%
  \iftoggle{cms@fullshhand}%
  {\usedriver{\frenchspacing}%
    {\thefield{entrytype}}%
    \finentry}%
  {\ifnameundef{labelname}%
    {\ifthenelse{\iffieldequalstr{entrysubtype}{magazine}\AND\NOT%
        \ifentrytype{periodical}}%
      {\printtext[bibhyperref]{\printfield[journaltitle]{journaltitle}%
          \newcunit}}%
      {\ifentrytype{manual}%
        {\printtext[bibhyperref]{\printlist{organization}\newcunit}}%
        {}}}%
    {\usebibmacro{author/editor}%
      \setunit{\addcomma\addspace}}%
    \printfield[lostitle]{title}%
    \finentry}}

\DeclareBibliographyDriver{shortjournal}{%
  \iffieldundef{journaltitle}%
  {\printtext[title]{%
      \printfield[tnoformat]{title}%
      \setunit{\subtitlepunct}%
      \printfield[stnoformat]{subtitle}}%
    \setunit*{\addspace}%
    \printlist[periodplace]{location}}%
  {\printtext[journaltitle]{%
      \printfield[jtnoformat]{journaltitle}%
      \setunit{\subtitlepunct}%
      \printfield[sjtnoformat]{journalsubtitle}}%
    \setunit*{\addspace}%
    \printlist[periodplace]{location}}%
  \finentry}%

\DeclareStyleSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pertype{periodical}
      \step[fieldsource=shorttitle, final]
      \step[fieldset=shortjournal, origfieldval]
    }
    \map{
      \pertype{jurisdiction}
      \pertype{legal}
      \pertype{legislation}
      \step[fieldsource=journaltitle, final]
      \step[fieldset=shortjournal, origfieldval]
    }
    \map[overwrite]{
      \pertype{jurisdiction}
      \step[fieldsource=shortjournal, match=\regexp{\\adddot},%
      replace=\regexp{\\ADDDOT}]
      \step[fieldsource=shortjournal, match=\regexp{[a-z]}, final]
      \step[fieldset=shortjournal, fieldvalue=\addnbspace, append]
    }
    \map[overwrite]{
      \pertype{jurisdiction}
      \step[fieldsource=shortjournal, match=\regexp{\\ADDDOT},%
      replace=\regexp{\\adddot}]
      }
    \map{
      \pertype{legislation}
      \step[fieldsource=title, match=\regexp{Const}, final]
      \step[fieldset=entrysubtype, fieldvalue=constitution]
    }
    \map{
      \pertype{legislation}
      \step[fieldsource=entrysubtype, match=\regexp{canada}, final]
      \step[fieldsource=bookpagination, match={section},
      replace={canadasection}]
      \step[fieldsource=pagination, match={section},
      replace={canadasection}]
    }
    \map{
      \step[fieldsource=pubstate, match={forthcoming}, final]
      \step[fieldset=year, origfieldval, final]
      \step[fieldsource=year, match=\regexp{(forthcoming)},
      replace=\regexp{\\bibstring\{$1\}}]%$
    }
    \map{
      \pertype{article}
      \pertype{periodical}
      \pertype{review}
      \pertype{suppperiodical}
      \step[fieldsource=entrysubtype, match={newspaper},
      replace={magazine}]
    }
    \map[overwrite]{
      \step[fieldsource=subtitle, final]
      \step[fieldsource=title,
      match=\regexp{\\(mkbib|en)quote\{.+((\?|\!)\})$},%$
      final]
      \step[fieldset=title, fieldvalue=\csgdef{@cmsst}{\@ne}, append]
    }
    \map[overwrite]{
      \step[fieldsource=booksubtitle, final]
      \step[fieldsource=booktitle,
      match=\regexp{\\(mkbib|en)quote\{.+((\?|\!)\})$},%$
      final]
      \step[fieldset=booktitle, fieldvalue=\csgdef{@cmsst}{\@ne}, append]
    }
    \map[overwrite]{
      \step[fieldsource=issuesubtitle, final]
      \step[fieldsource=issuetitle,
      match=\regexp{\\(mkbib|en)quote\{.+((\?|\!)\})$},%$
      final]
      \step[fieldset=issuetitle, fieldvalue=\csgdef{@cmsst}{\@ne}, append]
    }
    \map[overwrite]{
      \step[fieldsource=journalsubtitle, final]
      \step[fieldsource=journaltitle,
      match=\regexp{\\(mkbib|en)quote\{.+((\?|\!)\})$},%$
      final]
      \step[fieldset=journaltitle, fieldvalue=\csgdef{@cmsst}{\@ne}, append]
    }
    \map[overwrite]{
      \step[fieldsource=mainsubtitle, final]
      \step[fieldsource=maintitle,
      match=\regexp{\\(mkbib|en)quote\{.+((\?|\!)\})$},%$
      final]
      \step[fieldset=maintitle, fieldvalue=\csgdef{@cmsst}{\@ne}, append]
    }
  }
}%

\DeclareBibliographyDriver{article}{%
  \iffieldequalstr{entrysubtype}{magazine}%
  {\usebibmacro{bibindex}%
  \usebibmacro{mag+news+author}%
  \newunit\newblock
  \usebibmacro{mag+news+title}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit\newblock%
  \usebibmacro{part+editor+translator}%
  \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%
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldequalstr{relatedtype}{reviewof}}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}
  {\usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{mag+news+title}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit*{\addperiod\addspace}\newblock% 16th ed.
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \newunit\newblock%
  \usebibmacro{issuetitle}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{note}%
  \setunit*{\addcomma\addspace}\newblock% (changed for 0.7)??
  \usebibmacro{journal+issue+year+pages}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldequalstr{relatedtype}{reviewof}}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{artwork}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newcunit\newblock
  \usebibmacro{date}%
  \newunit% 16th ed.
  \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%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{audio}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock% 16th ed.
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \newcunit%\setunit{\addperiod\addspace}%
  \usebibmacro{chapinscore}%
  \usebibmacro{btitle+bstitle}%
  \iffieldundef{booktitle}%
  {\setunit{\addperiod\addspace}}% Fix customc?
  {\setunit{\addcomma\addspace}}%
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newunit% unit, not cunit?
  \usebibmacro{bybookauthor}%
  \usebibmacro{byeditor+others}%
  \newunit% ??? Editorpunct maybe not right here?
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\usebibmacro{cms-in:}%
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}
    {\printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}
      \bibstring{ofseries}%
      \setunit{\addspace}
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}}
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}%\printorigdate%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit
  \printfield{type}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isan}%
    \setunit*{\addcomma\addspace}\newblock%
    \printfield{ismn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \setunit{\addspace}%
  \usebibmacro{bib:xref+date}%
  \newunit\newblock
  \iffieldundef{maintitle}%
  {\iffieldundef{edition}%
    {}%
    {\usebibmacro{edition}}}%
  {}%
  \newunit\newblock% 16th ed.
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \newunit\newblock
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    togl {cms@bookbibxref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      togl {cms@bookbibxref}%
    }%
  {\usebibmacro{mtitle+mstitle+vol+part+title+stitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byeditor+others}%
  \usebibmacro{editorpunct}%\newcunit\newblock
  \iftoggle{cms@bookpages}%
  {}%
  {\clearfield{pages}}%
  \printfield{chapter}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%cmsorigdate%\printorigdate
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newcunit
  \printlist[][-\value{listtotal}]{lista}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newunit}%
    {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \bookbibxrefcite{\thefield{xref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \bookbibxrefcite{\thefield{crossref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{bookinbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \setunit{\addspace}%
  \usebibmacro{bib:xref+date}%
  \newunit\newblock
  \ifthenelse{\iffieldundef{maintitle}\AND\iffieldundef{booktitle}}%
  {\iffieldundef{edition}%
    {}%
    {\usebibmacro{edition}}}%
  {}%
  \newunit\newblock% 16th ed.
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \setunit*{\addperiod\addspace}%
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    togl {cms@bookbibxref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      togl {cms@bookbibxref}%
    }%
  {\usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \printfield{chapter}%
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}%\printorigdate%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \bookbibxrefcite{\thefield{xref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \bookbibxrefcite{\thefield{crossref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{booklet}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock% 16th ed.
  \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%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{collection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{editor}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \setunit{\addspace}%
  \usebibmacro{bib:xref+date}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \newunit\newblock
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    togl {cms@bookbibxref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      togl {cms@bookbibxref}%
    }%
  {\usebibmacro{mtitle+mstitle+vol+part+title+stitle}%
  \usebibmacro{editorpunct}%
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byeditor+others}%
  \newunit
  \usebibmacro{volume+or+volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}%\printorigdate%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \bookbibxrefcite{\thefield{xref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \bookbibxrefcite{\thefield{crossref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{customc}{%
  \usebibmacro{bibindex}%
  \usebibmacro{justauthor}%
  \iffieldundef{nameaddon}%
  {\newunit}%
  {\setunit{\addspace}}%
  \usebibmacro{italtitle+stitle}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{image}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newcunit%\setunit{\addcomma\addspace}%
  \usebibmacro{date}%
  \newunit% 16th ed.
  \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%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{inbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%\bibsentence
  \usebibmacro{language+transtitle}%
  \setunit{\addperiod\addspace}% 16th ed.
  \usebibmacro{byauthor}%
  \setunit{\addperiod\addspace}%
  \usebibmacro{part+editor+translator}%
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    togl {cms@bibcrossref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      togl {cms@bibcrossref}%
    }%
  {\setunit{\addperiod\addspace}%
  \usebibmacro{chapincoll}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}%\printorigdate%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \usebibmacro{chapincoll}%
  \bibxrefcite{\thefield{xref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\newunit}%
  \usebibmacro{xrefprenote}% Volume fix
  \usebibmacro{chapincoll}%
  \bibxrefcite{\thefield{crossref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{incollection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%\bibsentence
  \usebibmacro{language+transtitle}%
  \newunit\newblock% 16th ed.
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    togl {cms@bibcrossref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      togl {cms@bibcrossref}%
    }%
  {\newunit\newblock
  \usebibmacro{chapincoll}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}%\printorigdate%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \usebibmacro{chapincoll}%
  \bibxrefcite{\thefield{xref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \usebibmacro{chapincoll}%
  \bibxrefcite{\thefield{crossref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{inproceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \setunit{\addperiod\addspace}% 16th ed.
  \usebibmacro{byauthor}%
  \setunit{\addperiod\addspace}%
  \usebibmacro{part+editor+translator}%
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    togl {cms@bibcrossref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      togl {cms@bibcrossref}%
    }%
  {\setunit{\addperiod\addspace}%
  \usebibmacro{chapincoll}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit\newblock
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{org+publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \usebibmacro{chapincoll}%
  \bibxrefcite{\thefield{xref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \usebibmacro{chapincoll}%
  \bibxrefcite{\thefield{crossref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{inreference}{%
  \usebibmacro{bibindex}%
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \ifthenelse{\iffieldundef{maintitle}\AND\iffieldundef{booktitle}}%
  {\iffieldundef{edition}%
    {}%
    {\usebibmacro{edition}}}%
  {}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \setunit*{\addperiod\addspace}% need asterisk?
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \printfield{chapter}%
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}%\printorigdate%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newcunit\newblock
  \printlist[][-\value{listtotal}]{lista}%
  \newcunit\newblock%setunit{\addspace}% 16th ed
  \ifnameundef{author}%
  {}%
  {\printtext{% 16th ed
      \bibstring{by}%
      \addspace%
      \printnames[byauthor]{author}}}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyAlias{jurisdiction}{cite:jurisdiction}

\DeclareBibliographyAlias{legal}{cite:legal}

\DeclareBibliographyAlias{legislation}{cite:legislation}

\DeclareBibliographyDriver{letter}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \printtext[title]{%
    \printfield[noformat]{title}}%
  \setunit{\ctitleaddonpunct}%
  \printfield{titleaddon}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{letter+date}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit\newblock%\bibsentence
  \usebibmacro{part+editor+translator}%
  \setunit*{\addperiod\addspace}%
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    togl {cms@bibcrossref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      togl {cms@bibcrossref}%
    }%
  {\usebibmacro{chapincoll}%
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\newunit}%
  \usebibmacro{xrefprenote}% Volume fix
  \usebibmacro{chapincoll}%
  \bibxrefcite{\thefield{xref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\newunit}%
  \usebibmacro{xrefprenote}% Volume fix
  \usebibmacro{chapincoll}%
  \bibxrefcite{\thefield{crossref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{manual}{%
  \usebibmacro{bibindex}%
  \usebibmacro{bibauthor+org}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \usebibmacro{edition}%
  \newunit% 16th ed.
  \usebibmacro{byauthor}%
  \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%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{misc}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \iffieldundef{entrysubtype}%
  {\usebibmacro{italtitle+stitle}}%
  {\printfield{title}%
    \setunit{\subtitlepunct}%
    \printfield[noformat]{subtitle}%
    \setunit{\ctitleaddonpunct}%
    \printfield{titleaddon}%
    \setunit{\addspace}%
    \usebibmacro{language+transtitle}%
    \newcunit\newblock%
    \usebibmacro{unpubl+letter+date}}%
  \newunit% 16th ed.
  \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}%
  \iffieldundef{entrysubtype}%
  {\newcunit\newblock
    \usebibmacro{date}}%
  {}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{music}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit% 16th ed.
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \newunit\newblock
  \usebibmacro{music+eventdate}%
  \newunit\newblock
  \usebibmacro{chapinscore}%
  \usebibmacro{btitle+bstitle}%
  \iffieldundef{booktitle}%
  {\newunit}% Fix customc?
  {\newcunit}%
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newunit% unit, not cunit?
  \usebibmacro{bybookauthor}%
  \usebibmacro{byeditor+others}%
  \newunit% ??? Editorpunct maybe not right here?
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\usebibmacro{cms-in:}%
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}
    {\printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}
      \bibstring{ofseries}%
      \setunit{\addspace}
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}}
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock%
  \usebibmacro{music+origdate}%\printtext[eventdate]{\printeventdate}%
  \newunit\newblock
  \printlist{publisher}%
  \setunit*{\addcomma\addspace}\newblock
  \printfield{series}%
  \setunit{\addspace}%
  \printfield{number}%
  \newcunit\newblock
  \usebibmacro{date}%
  \newunit
  \usebibmacro{institution+organization}%
  \setunit*{\addcomma\addspace}\newblock
  \printlist{location}%
  \newcunit\newblock
  \printfield{type}%
  \newunit\newblock
  \usebibmacro{pubstate}% 16th ed.
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{iswc}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyAlias{mvbook}{book}

\DeclareBibliographyAlias{mvcollection}{collection}

\DeclareBibliographyAlias{mvproceedings}{proceedings}

\DeclareBibliographyAlias{mvreference}{reference}

\DeclareBibliographyDriver{online}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit% 16th ed.
  \usebibmacro{byauthor}%
  \newunit\newblock
  \printlist{organization}% Rearranged for 16th ed.
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{date}%
  \newunit\newblock
  \iffieldundef{urlyear}%
  {}%
  {\printurldate}% Date fix
  \newunit\newblock
  \iftoggle{cms@doionly}%
  {\iffieldundef{doi}%
    {}%
    {\printfield{doi}%
      \clearfield{url}}}%
  {\printfield{doi}}%
  \newunit\newblock
  \usebibmacro{eprint}%
  \newunit\newblock
  \printfield{url}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \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}%
  \iffieldundef{origyear}%
  {\iffieldundef{year}%
    {}%
    {\bibstring{patentfiled}\setunit{\addspace}% Issued -> filed
      \printdate}}%
  {\bibstring{patentfiled}\setunit{\addspace}%
    \usebibmacro{cmsorigdate}%
    \setunit{\finalandcomma\addspace\bibstring{and}%
      \addspace\bibstring{patentissued}\addspace}%
    \usebibmacro{date}}%
  \newcunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{periodical}{%
  \iffieldequalstr{entrysubtype}{magazine}%
  {\usebibmacro{bibindex}%
  \usebibmacro{editor}%
  \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%
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}
  {\usebibmacro{bibindex}%
  \usebibmacro{editor}%
  \newunit\newblock
  \usebibmacro{issuetitle}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit*{\addperiod\addspace}\newblock% 16th ed.
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{note}%
  \setunit*{\addcomma\addspace}\newblock% (changed for 0.7)??
  \usebibmacro{periodical+issue+year+pages}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{proceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{editor}%
  \newunit\newblock
  \usebibmacro{italtitle+stitle}%
  \setunit{\addspace}%
  \usebibmacro{bib:xref+date}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \newunit\newblock
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    togl {cms@bookbibxref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      togl {cms@bookbibxref}%
    }%
  {\usebibmacro{mtitle+mstitle+vol+part+title+stitle}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \usebibmacro{volume+or+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%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \bookbibxrefcite{\thefield{xref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}%
{\ifboolexpr{% Changed for 16th ed.
    test {\ifterm}%
    or
    test {\ifpunctmark{*}}%
  }%
  {\setunit{\addspace\bibsentence}}%
  {\setunit{\addperiod\addspace}}%
  \usebibmacro{xrefprenote}% Volume fix
  \bookbibxrefcite{\thefield{crossref}}%
  \usebibmacro{xrefpostnote}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{reference}{%
  \usebibmacro{bibindex}%
  \usebibmacro{italtitle+stitle}%
  \newunit\newblock
  \ifthenelse{\iffieldundef{maintitle}\AND\iffieldundef{booktitle}}%
  {\iffieldundef{edition}%
    {}%
    {\usebibmacro{edition}}}%
  {}%
  \newunit\newblock
  \usebibmacro{part+editor+translator}%
  \setunit*{\addperiod\addspace}% need asterisk?
  \usebibmacro{mtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byeditor+others}%
  \newcunit\newblock
  \printfield{chapter}%
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}%\printorigdate%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{report}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \iffieldequalstr{entrysubtype}{unpublished}%
  {\usebibmacro{title+stitle}}%
  {\usebibmacro{italtitle+stitle}}%
  \newunit% 16th ed.
  \usebibmacro{byauthor}%
  \newunit\newblock
  \printfield{type}%
  \newcunit
  \printfield{series}%
  \setunit{\addnbspace}%
  \printfield{number}%
  \newunit
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{inst+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isrn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{review}{%
  \usebibmacro{bibindex}%
  \iffieldequalstr{entrysubtype}{magazine}%
  {\usebibmacro{mag+news+author}}%
  {\usebibmacro{author/editor}}%
  \newunit\newblock
  \printeventdate% 16th ed.
  \setunit{\addspace}%
  \printfield{nameaddon}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    test {\iffieldequalstr{relatedtype}{reviewof}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}}%
  {\printfield{title}%
    \setunit{\subtitlepunct}%
    \printfield[noformat]{subtitle}}%
  \setunit{\ptitleaddonpunct}%
  \printfield{titleaddon}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit\newblock%
  \usebibmacro{part+editor+translator}%
  \newunit\newblock%
  \usebibmacro{issuetitle}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{byeditor+others}%
  \usebibmacro{editorpunct}%\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%
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldequalstr{relatedtype}{reviewof}}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{suppbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author}%
  \newunit\newblock
  \usebibmacro{inforaft}%
  \setunit{\addspace}\newblock
  \usebibmacro{italtitle+stitle}%
  \newunit
  \iffieldundef{maintitle}%
  {\iffieldundef{edition}%
    {}%
    {\usebibmacro{edition}}}%
  {}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \newcunit\newblock
  \usebibmacro{chap+pag}%
  \newunit\newblock
  \usebibmacro{mtitle+mstitle+vol+part+title+stitle}%
  \newcunit%
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \usebibmacro{editorpunct}%
  \usebibmacro{byeditor+others}%
  \newunit
  \usebibmacro{volume+or+volumes}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}%\printorigdate%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyAlias{suppcollection}{suppbook}

\DeclareBibliographyAlias{suppperiodical}{review}

\DeclareBibliographyDriver{thesis}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}%\newblock%
  \usebibmacro{language+transtitle}%
  \newunit% 16th ed.
  \usebibmacro{byauthor}%
  \setunit{\addperiod\addspace}%
  \printfield{note}%
  \setunit{\addperiod\addspace}\newblock%
  \usebibmacro{type+inst+year}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{unpublished}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \newunit%usebibmacro{byauthorpunct}% Why does this work?  No idea.
  \usebibmacro{byauthor}% Same in thesis type, as well. 16th ed.
  \setunit{\addperiod\addspace}%
  \usebibmacro{byeditor+others}%
  \newunit\newblock%
  \printfield{howpublished}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{note}%
  \setunit*{\addcomma\addspace}\newblock%
  \printfield{eventtitle}%
  \setunit*{\ctitleaddonpunct}\newblock%
  \printfield{eventtitleaddon}%
  \setunit*{\addcomma\addspace}%
  \printfield{venue}%
  \setunit*{\addcomma\addspace}%
  \printlist{location}%
  \setunit*{\addcomma\addspace}\newblock%
  \iffieldundef{eventyear}%
  {\usebibmacro{date}}%
  {\printeventdate}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{video}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author/editor}%
  \newunit\newblock
  \printtext[title]{%
    \printfield[noformat]{title}%
    \setunit{\subtitlepunct}%
    \printfield[noformat]{subtitle}}%
  \iffieldundef{booktitle}% Comma after italics, period after quotes
  {\setunit{\ctitleaddonpunct}}%
  {\setunit{\ptitleaddonpunct}}%\setunit{\addspace}\newblock%
  \printfield{titleaddon}%\usebibmacro{title+stitle}%
  \setunit{\addspace}\newblock%\bibsentence
  \usebibmacro{language+transtitle}%
  \setunit{\addperiod\addspace}% 16th ed.
  \usebibmacro{byauthor}%
  \setunit{\addperiod\addspace}%
  \usebibmacro{part+editor+translator}%
  \setunit{\addperiod\addspace}%
  \usebibmacro{chapinscore}%
  \usebibmacro{btitle+bstitle}%
  \iffieldundef{booktitle}%
  {\setunit{\addperiod\addspace}}% Fix customc?
  {\setunit{\addcomma\addspace}}%
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newunit% unit, not cunit?
  \usebibmacro{bybookauthor}%
  \usebibmacro{byeditor+others}%
  \newunit% ??? Editorpunct maybe not right here?
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\usebibmacro{cms-in:}%
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}%
    {\printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}
      \bibstring{ofseries}%
      \setunit{\addspace}
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}}%
  \newcunit\newblock
  \usebibmacro{volume+pages}%
  \newunit\newblock
  \usebibmacro{ser+num}%
  \newunit\newblock
  \usebibmacro{music+eventdate}%
  \newunit\newblock
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}%\printorigdate%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publ+loc+year}%
  \newunit\newblock
  \printfield{type}% 16th ed.
  \newunit\newblock
  \printfield{addendum}%
  \setunit*{\addcomma\addspace}\newblock%
  \iftoggle{cms@isbn}%
  {\printfield{isan}}%
  {}%
  \setunit*{\addcomma\addspace}\newblock%
  \usebibmacro{bib+doi+url}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \ifboolexpr{%
    togl {cms@related}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newunit}%
  {}%
  \usebibmacro{originally+published+as}%
  \usebibmacro{finentry}}%

%%%% Other Formatting Macros %%%%

\newbibmacro*{bib+doi+url}{% 16th ed.
  \ifboolexpr{%
    togl {cms@url}%
    and
    not test {\iffieldundef{urlyear}}%
    }%
  {\printurldate}% Date fix
  {}%
  \iffieldundef{addendum}% Punctuation fixes in 0.9.9c
  {\newunit\newblock}%
  {\newcunit\newblock}%
  \iftoggle{cms@doionly}%
  {\iffieldundef{doi}%
    {}%
    {\printfield{doi}%
      \setunit*{\addperiod\addspace}\newblock%
      \clearfield{url}}}%
  {\ifboolexpr{%
      togl {cms@doi}%
      and
      not test {\iffieldundef{doi}}%
    }%
    {\printfield{doi}%
      \setunit*{\addperiod\addspace}\newblock}%
    {}}%
  \ifboolexpr{%
    togl {cms@eprint}%
    and
    not test {\iffieldundef{eprint}}%
  }%
  {\usebibmacro{eprint}%
    \setunit*{\addperiod\addspace}\newblock}%
  {}%
  \ifboolexpr{%
    togl {cms@url}%
    and
    not test {\iffieldundef{url}}%
  }%
  {\printfield{url}}%
  {}}%

\newbibmacro{bib:xref+date}{% Experiment for xrefs
  \ifboolexpr{%
    togl {cms@omitxrefdate}%
    or
    togl {cms@bookbibxref}%
    or
    test {\iffieldundef{crossref}}%
    or
    test {\iffieldundef{maintitle}}%
    or
    ((
    test {\iffieldundef{year}}%
    or
    togl {cms@switchdates}%
    )
    and
    (test {\iffieldundef{origyear}}%
    or
    not togl {cms@switchdates}%
    ))
  }%
  {\ifboolexpr{%
      togl {cms@omitxrefdate}%
      or
      togl {cms@bookbibxref}%
      or
      test {\iffieldundef{xref}}%
      or
      test {\iffieldundef{maintitle}}%
      or
      ((
      test {\iffieldundef{year}}%
      or
      togl {cms@switchdates}%
      )
      and
      (test {\iffieldundef{origyear}}%
      or
      not togl {cms@switchdates}%
      ))
    }%
    {}%
    {\printtext[parens]{\usebibmacro{date}}}}%
  {\printtext[parens]{\usebibmacro{date}}}}

\newbibmacro*{volume+pages}{% Volume fix (modified)
  \ifboolexpr{%
    test {\iffieldundef{maintitle}}%
    or
    togl {cms@vol}%
  }%
  {\global\togglefalse{cms@vol}%
    \ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\printfield{pages}%
      \newunit%
      \printfield{volumes}}%
    {\iffieldundef{part}%
      {\iffieldundef{pages}%
        {\printfield{volume}}% Still print this w/o part or pages???
        {\ifthenelse{\iffieldnums{pages}\AND%
            \iffieldundef{bookpagination}\AND\iffieldnums{volume}}%
          {\printfield[default]{volume}%
            \postvolpunct%
            \printfield{pages}}%
          {\printfield{volume}%
            \addcomma\addspace%
            \printfield{pages}}}}%
      {\printfield{volume}%
        \printfield{part}%
        \newcunit%
        \printfield{pages}}}}%
  {\ifboolexpr{%
      togl {cms@hidevolumes}%
      and
      (
      not test {\iffieldundef{volume}}%
      or
      not test {\iffieldundef{part}}%
      )
    }%
    {\printfield{pages}}%
    {\printfield{pages}%
      \newunit%
      \printfield{volumes}}}}%

\newbibmacro*{mtitle+mstitle+vol+part+title+stitle}{%
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\usebibmacro{cms-in:}% 16th ed (Also 15th?)
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}
    {\printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}
      \bibstring{ofseries}%
      \setunit{\addspace}
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}}}

\newbibmacro*{mtitle+mstitle+vol+part+btitle+bstitle}{%
  \usebibmacro{btitle+bstitle}%
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\(\iffieldundef{volume}\AND\iffieldundef{part}\)\OR%
      \(\iffieldundef{booktitle}\AND\NOT\ifentrytype{bookinbook}\)}% ???
    {\usebibmacro{cms-in:}% 16th ed (also 15th?)
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}
      \printfield{maintitleaddon}%
      \toggletrue{cms@vol}}% InIn fix
    {\printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}
      \bibstring{ofseries}%
      \setunit{\addspace}
      \printtext[maintitle]{%
        \printfield[noformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[noformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}}}

\newbibmacro*{journal+issue+year+pages}{%
  \usebibmacro{cjournal+ser+vol+num}%
  \ifboolexpr{% 16th ed.
    test {\iffieldundef{issue}}%
    and
    test {\iffieldundef{year}}%
    and
    not togl {cms@switchdates}%
  }%
  {\iffieldundef{number}%
    {\iffieldundef{bookpagination}%
      {\setunit{\postvolpunct}}%
      {\setunit{\addcolon\addspace}}%
      \printfield{pages}}%
    {\newcunit\printfield{pages}}}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{number}}% 16th ed.
    {\newcunit%
      \iffieldundef{issue}%
      {\usebibmacro{number+or+month}}%
      {\printfield{issue}%
        \setunit{\addspace}%
        \usebibmacro{cmsyear}}%
      \newcunit\printfield{pages}}%
    {\setunit{\addspace}%
    \printtext[parens]{%
      \iffieldundef{issue}%
      {\usebibmacro{number+or+month}}%
      {\printfield{issue}%
        \setunit{\addspace}%
        \usebibmacro{cmsyear}}}%
    \setunit{\addcolon\addspace}%
    \printfield{pages}}}}

\newbibmacro*{periodical+issue+year+pages}{%
  \usebibmacro{cperiodical+ser+vol+num}%
  \ifboolexpr{% 16th ed.
    test {\iffieldundef{issue}}%
    and
    test {\iffieldundef{year}}%
    and
    not togl {cms@switchdates}%
  }%
  {\iffieldundef{number}%
    {\iffieldundef{bookpagination}%
      {\setunit{\postvolpunct}}%
      {\setunit{\addcolon\addspace}}%
      \printfield{pages}}%
    {\newcunit\printfield{pages}}}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{number}}% 16th ed.
    {\newcunit%
      \iffieldundef{issue}%
      {\usebibmacro{number+or+month}}%
      {\printfield{issue}%
        \setunit{\addspace}%
        \usebibmacro{cmsyear}}%
      \newcunit\printfield{pages}}%
    {\setunit{\addspace}%
    \printtext[parens]{%
      \iffieldundef{issue}%
      {\usebibmacro{number+or+month}}%
      {\printfield{issue}%
        \setunit{\addspace}%
        \usebibmacro{cmsyear}}}%
    \setunit{\addcolon\addspace}%
    \printfield{pages}}}}

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

\renewbibmacro*{byeditor}{%
  \ifnameundef{editor}%
    {}%
    {\usebibmacro{bytypestrg}{editor}{editor}%
     \setunit{\addspace}%
     \printnames[byeditor]{editor}%
     \usebibmacro{editorpunct}}%
  \usebibmacro{byeditorx}}

\renewbibmacro*{byeditorx}{%
  \ifnameundef{editora}%
    {}%
    {\usebibmacro{bytypestrg}{editora}{editor}%
     \setunit{\addspace}%
     \printnames[byeditora]{editora}%
     \usebibmacro{editorpunct}}%
  \ifnameundef{editorb}%
    {}%
    {\usebibmacro{bytypestrg}{editorb}{editor}%
     \setunit{\addspace}%
     \printnames[byeditorb]{editorb}%
     \usebibmacro{editorpunct}}%
  \ifnameundef{editorc}%
    {}%
    {\usebibmacro{bytypestrg}{editorc}{editor}%
     \setunit{\addspace}%
     \printnames[byeditorc]{editorc}%
     \usebibmacro{editorpunct}}}

\renewbibmacro*{byeditor+others}{%
  \ifthenelse{\NOT\ifnameundef{editor}\AND
    \(\iffieldundef{editortype}\OR
    \iffieldequalstr{editortype}{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}%
     \setunit{\addspace}%
     \printnames[byeditor]{editor}%
     \clearname{editor}%
     \usebibmacro{editorpunct}%
     \usebibmacro{byeditorx}}%
   {\usebibmacro{byeditor}}%
  \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}\addspace%
     \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}\addspace%
     \printnames[bycompiler]{namec}%
     \clearname{namec}%
     \usebibmacro{editorpunct}}%
  \usebibmacro{byothers}}%

\newbibmacro*{byothers}{% Changed for 0.9
  \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}}

%%%% New date macros enabling special handling of seasons, decades,
%%%% centuries, date eras, and uncertain dates (circa and ?), along
%%%% with CMS compression of year ranges.

\newcount\cms@tempcnta
\newcount\cms@tempcntb

\protected\def\cmsunspecified#1#2{%
  \ifboolexpr{%
    test {\iffieldundef{#2dateunspecified}}%
    or
    togl {cms@alwaysrange}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{#2endyear}}%
      or
      test {\iffieldequalstr{#2dateera}{bce}}%
      or
      not togl {cms@compyears}%
      or
      not test {\iffieldnum{#2year}}%
      or
      not test {\iffieldnum{#2endyear}}%
      or
      not test {\if@cms@onlyyears{#2}}%
    }%
    {\csuse{mkbibdate#1}{#2year}{#2month}{#2day}\cmsdateeraprint{#2year}}%
    {\cmscompcenturies{#2}%
      \ifboolexpr{%
        (
        test {\if@cms@bracket}%
        and
        not test {\if@cms@endbracket}
        )
        or
        (
        not test {\if@cms@bracket}%
        and
        test {\if@cms@endbracket}%
        )
        or
        (
        test {\if@cms@endcirca}%
        and
        not test {\if@cms@circa}%
        )
        or
        not test {\ifnumequal{\cms@tempcnta}{\cms@tempcntb}}%
      }%
      {\csuse{mkbibdate#1}{#2year}{}{}\cmsdateeraprint{#2year}}%
      {\cmsdateeraprintpre{#2year}\cmscompressyears{#2}%
        \cmsdateeraprint{#2endyear}\clearfield{#2endyear}}}}%
  {\ifboolexpr{%
      test {\iffieldequalstr{#2dateunspecified}{yearindecade}}%
      and
      test {\ifbibstring{decade}}%
      and
      not togl {cms@decaderange}%
    }%
    {\cmsmkdecade{#1}{#2}}%
    {\ifboolexpr{%
        test {\iffieldequalstr{#2dateunspecified}{yearincentury}}%
        and
        test {\ifbibstring{century}}%
        and
        not togl {cms@centuryrange}%
      }%
      {\cmsmkcentury{#2}}%
      {\iftoggle{cms@compyears}%
        {\cmsdateeraprintpre{#2year}\cmscompressyears{#2}%
          \cmsdateeraprint{#2endyear}\clearfield{#2endyear}}%
        {\csuse{mkbibdate#1}{#2year}{}{}\cmsdateeraprint{#2year}}}}}}%

\protected\def\cmscompressyears#1{%
  \def\cms@tempa{\thefield{#1year}--\thefield{#1endyear}}%
  \edef\cms@tempb{\mkcomprange{\csuse{cms@tempa}}}%
  \cms@tempb}%

\def\cmscompcenturies#1{%
  \cms@tempcnta=\thefield{#1year}%
  \divide\cms@tempcnta100
  \cms@tempcntb=\thefield{#1endyear}%
  \divide\cms@tempcntb100}

\protected\def\cmsformatextra{}% Author-date requires these

\protected\def\cmsformatendextra{}%

\newbibmacro*{cmsextradate}{}%

\newbibmacro*{cmsparensextradate}{}%

\protected\def\cmsdateeraprintpre#1{% AD/BC order depends on language
  \ifdefstring\blx@dateera{astronomical}%
  {\iffieldnum{#1}%
    {\begingroup%
      \let\blx@tempa\@empty%
      \blx@ifstrendswith{#1}{endyear}%
      {\blx@stripfromendinto{#1}{endyear}\blx@datetype%
        \def\blx@tempa{end}}%
      {\blx@stripfromendinto{#1}{year}\blx@datetype}%
      \csuse{if\blx@datetype\blx@tempa dateera}{bce}%
      {\ifnumless{0-\thefield{#1}}{0}%
        {\printtext{\csuse{bibdateera\blx@tempa prefix}}}%
        {}}%
      {}%
      \endgroup}%
    {}}%
  {\ifboolexpr{%
      test {\ifdefstring\blx@dateera{christian}}%
      and
      test {\if@cms@adfirst}%
    }%
    {\iffieldnum{#1}%
      {\begingroup%
        \let\blx@tempa\@empty%
        \blx@ifstrendswith{#1}{endyear}%
        {\blx@stripfromendinto{#1}{endyear}\blx@datetype%
          \def\blx@tempa{end}}%
        {\blx@stripfromendinto{#1}{year}\blx@datetype}%
        \csuse{if\blx@datetype\blx@tempa dateera}{bce}%
        {\ifdefstring\blx@tempa{end}{}{\global\toggletrue{cms@bc}}}%
        {\ifnumless{\thefield{#1}}\blx@dateeraauto%
          {\ifdefstring\blx@tempa{end}%
            {\iftoggle{cms@bc}%
              {\printtext{%
                  \bibsstring{\blx@dateera@ce}\printdelim{dateaddelim}}%
                \global\togglefalse{cms@bc}}%
              {}}%
            {\printtext{%
                \bibsstring{\blx@dateera@ce}\printdelim{dateaddelim}}%
              \global\togglefalse{cms@bc}}}%
          {}}%
        \endgroup}%
      {}}%
    {}}}

\protected\def\cmsdateeraprint#1{% AD/BC order depends on language
  \ifboolexpr{%
    test {\ifdefstring\blx@dateera{christian}}%
    and
    test {\if@cms@adfirst}%
  }%
  {\iffieldnum{#1}
    {\begingroup
      \let\blx@tempa\@empty
      \blx@ifstrendswith{#1}{endyear}
      {\blx@stripfromendinto{#1}{endyear}\blx@datetype
        \def\blx@tempa{end}}
      {\blx@stripfromendinto{#1}{year}\blx@datetype}%
      \csuse{if\blx@datetype\blx@tempa dateera}{bce}%
      {\ifdefstring\blx@tempa{end}%
        {\ifnum\numexpr0-\thefield{#1}\relax<\blx@dateeraauto%
          \printtext{\printdelim{dateeradelim}\midsentence%
            \bibsstring{\blx@dateera@bce}}\relax%
          \fi}%
        {\csuse{if\blx@datetype enddateera}{bce}%
          {}%
          {\ifnum\numexpr0-\thefield{#1}\relax<\blx@dateeraauto%
            \printtext{\printdelim{dateeradelim}\midsentence%
              \bibsstring{\blx@dateera@bce}}\relax%
            \fi}}}%
      {}%
      \endgroup}
    {}}%
  {\ifboolexpr{%
      test {\ifdefstring\blx@dateera{secular}}%
      or
      (
      test {\ifdefstring\blx@dateera{christian}}%
      and
      not test {\if@cms@adfirst}%
      )
    }%
    {\iffieldnum{#1}%
      {\begingroup%
        \let\blx@tempa\@empty%
        \blx@ifstrendswith{#1}{endyear}%
        {\blx@stripfromendinto{#1}{endyear}\blx@datetype%
          \def\blx@tempa{end}}%
        {\blx@stripfromendinto{#1}{year}\blx@datetype}%
        \csuse{if\blx@datetype\blx@tempa dateera}{bce}%
        {\ifdefstring\blx@tempa{end}%
          {\ifnum\numexpr0-\thefield{#1}\relax<\blx@dateeraauto%
            \printtext{\printdelim{dateeradelim}\midsentence%
              \bibsstring{\blx@dateera@bce}}\relax%
            \fi}%
          {\csuse{if\blx@datetype enddateera}{bce}%
            {}%
            {\ifnum\numexpr0-\thefield{#1}\relax<\blx@dateeraauto%
              \printtext{\printdelim{dateeradelim}\midsentence%
                \bibsstring{\blx@dateera@bce}}\relax%
              \fi}}}%
        {\ifdefstring\blx@tempa{end}%
          {\ifnumless{\thefield{#1}}\blx@dateeraauto%
            {\printtext{\printdelim{dateeradelim}\midsentence%
                \bibsstring{\blx@dateera@ce}}}%
            {}}%
          {\csuse{if\blx@datetype enddateera}{ce}%
            {}%
            {\ifnumless{\thefield{#1}}\blx@dateeraauto%
              {\printtext{\printdelim{dateeradelim}\midsentence%
                  \bibsstring{\blx@dateera@ce}}}%
              {}}}}%
        \endgroup}%
      {}}%
    {}}}

\newrobustcmd*{\cms@datebrackets}{%
  \iftoggle{cms@nodatebrackets}%
  {\global\boolfalse{cms:bracket}%
    \ifboolexpr{%
      test {\if@cms@bracket}%
      and
      togl {cms@nodates}%
      and
      not bool {cms:nd}%
    }%
    {\booltrue{cms:nd}\bibstring{nodate}\addcomma\addspace}%
    {\boolfalse{cms:nd}}}%
  {\global\booltrue{cms:bracket}%
    \bibopenbracket}}%

\newrobustcmd*{\cms@yearbrackets}{%
  \iftoggle{cms@noyearbrackets}%
  {\global\boolfalse{cms:bracket}%
    \ifboolexpr{%
      test {\if@cms@bracket}%
      and
      togl {cms@nodates}%
      and
      not bool {cms:nd}
    }%
    {\booltrue{cms:nd}\bibstring{nodate}\addcomma\addspace}%
    {\boolfalse{cms:nd}}}%
  {\global\booltrue{cms:bracket}%
    \bibopenbracket}}%

\newrobustcmd*{\cms@mkbibrangetrunc}[2]{% DATE FIX
  \begingroup
  \blx@metadateinfo{#2}%
  \clearfield{extradate}%
  \ifthenelse{\iffieldundef{#2year}\AND\iffieldundef{#2month}\AND%
    \iffieldundef{#2yeardivision}}%
  {}%
  {\printtext[#2date]{%
      \if@cms@bracket%
      {\cms@datebrackets%
        \if@cms@circa%
        {\bibsstring{circa}\printdelim{datecircadelim}}%
        {}}%
      {\global\boolfalse{cms:bracket}}%
      \iffieldundef{#2yeardivision}%
      {\ifdateyearsequal{#2}{#2end}%
        {\iffieldsequal{#2month}{#2endmonth}%
          {\csuse{mkbibdate#1}{}{}{#2day}}%
          {\ifthenelse{\iffieldundef{#2month}\AND\iffieldundef{#2day}}%
            {\csuse{mkbibdate#1}{#2year}{}{}\cmsdateeraprint{#2endyear}%
              \clearfield{#2endyear}}% Clear up inheritance problem ???
            {\csuse{mkbibdate#1}{}{#2month}{#2day}}}}%
        {\cmsunspecified{#1}{#2}}}%
      {\ifdateyearsequal{#2}{#2end}%
        {\ifthenelse{\iffieldundef{#2endyeardivision}\OR%
            \iffieldsequal{#2yeardivision}{#2endyeardivision}}%
          {\csuse{mkbibyeardivisiondate#1}{#2year}{#2yeardivision}%
            \cmsdateeraprint{#2endyear}\clearfield{#2endyear}}%
          {\csuse{mkbibyeardivisiondate#1}{}{#2yeardivision}}}%
        {\csuse{mkbibyeardivisiondate#1}{#2year}{#2yeardivision}%
          \cmsdateeraprint{#2year}}}%
      \if@cms@bracket%
      {\if@cms@uncertain%
        {\if@cms@enduncertain%
          {\iffieldundef{#2endyear}%
            {\bibdateuncertain}%
            {}}%
          {\bibdateuncertain}}%
        {\if@cms@enduncertain%
          {\iffieldundef{#2endyear}%
            {\bibdateuncertain}%
            {}}%
          {}}}%
      {}%
      \iffieldundef{#2endyear}%
      {\iffieldundef{#2endmonth}%
        {\ifthenelse{\iffieldundef{#2endyeardivision}\OR%
            \iffieldsequal{#2yeardivision}{#2endyeardivision}}%
          {\ifbool{cms:bracket}%
            {\bibclosebracket\global\boolfalse{cms:bracket}}%
            {}}%
          {\bibdaterangesep%
            \csuse{mkbibyeardivisiondate#1}{}{#2endyeardivision}}}%
        {\bibdaterangesep%
          \csuse{mkbibdate#1}{}{#2endmonth}{#2endday}}}%
      {\iffieldequalstr{#2endyear}{}%
        {\ifbool{cms:bracket}%
          {\bibclosebracket\global\boolfalse{cms:bracket}}%
          {}%
          \mbox{\bibdaterangesep}}%
        {\ifbool{cms:bracket}%
          {\if@cms@circa%
            {\if@cms@endbracket%
              {\bibdaterangesep}%
              {\bibclosebracket\global\boolfalse{cms:bracket}%
                \bibdaterangesep}}%
            {\if@cms@endcirca%
              {\bibdaterangesep\bibsstring{circa}\printdelim{datecircadelim}}%
              {\if@cms@enduncertain%
                {\bibdaterangesep}%
                {\bibclosebracket\global\boolfalse{cms:bracket}%
                  \bibdaterangesep}}}}%
          {\if@cms@endbracket%
            {\bibdaterangesep%
              \cms@datebrackets%
              \if@cms@endcirca%
              {\if@cms@circa%
                {}%
                {\bibsstring{circa}\printdelim{datecircadelim}}}%
              {}}%
            {\bibdaterangesep}}%\bibdatedash%
          \iffieldundef{#2endyeardivision}%
          {\ifdateyearsequal{#2}{#2end}%
            {\csuse{mkbibdate#1}{#2year}{#2endmonth}{#2endday}}%
            {\csuse{mkbibdate#1}{#2endyear}{#2endmonth}{#2endday}}}%
          {\ifdateyearsequal{#2}{#2end}%
            {\csuse{mkbibyeardivisiondate#1}{#2year}{#2endyeardivision}}%
            {\csuse{mkbibyeardivisiondate#1}{#2endyear}{#2endyeardivision}}}%
          \ifbool{cms:bracket}%
          {\if@cms@bracket%
            {\cmsdateeraprint{#2endyear}%
              \enddateuncertainprint%
              \bibclosebracket\global\boolfalse{cms:bracket}}%
            {\enddateuncertainprint%
              \bibclosebracket\global\boolfalse{cms:bracket}%
              \cmsdateeraprint{#2endyear}}}%
          {\enddateuncertainprint%
            \cmsdateeraprint{#2endyear}}}}}}%
  \endgroup}

\newrobustcmd*{\cms@mkbibrangefull}[2]{%
  \begingroup
  \blx@metadateinfo{#2}%
  \clearfield{extradate}%
  \ifthenelse{\iffieldundef{#2year}\AND\iffieldundef{#2month}\AND%
    \iffieldundef{#2yeardivision}}%
  {}%
  {\printtext[#2date]{%
      \if@cms@bracket%
      {\cms@datebrackets%
        \if@cms@circa%
        {\bibsstring{circa}\printdelim{datecircadelim}}
        {}}%
      {\global\boolfalse{cms:bracket}}%
      \iffieldundef{#2yeardivision}%
      {\csuse{mkbibdate#1}{#2year}{#2month}{#2day}%
        \ifboolexpr{%
          test {\ifdateyearsequal{#2}{#2end}}%
          and
          test {\iffieldundef{#2month}}%
          and
          test {\iffieldundef{#2day}}%
        }%
        {\cmsdateeraprint{#2endyear}\clearfield{#2endyear}}%
        {\cmsdateeraprint{#2year}}}%
      {\csuse{mkbibyeardivisiondate#1}{#2year}{#2yeardivision}%
        \cmsdateeraprint{#2year}}%
      \if@cms@bracket%
      {\if@cms@uncertain%
        {\if@cms@enduncertain%
          {\iffieldundef{#2endyear}%
            {\bibdateuncertain}%
            {}}%
          {\bibdateuncertain}}%
        {\if@cms@enduncertain%
          {\iffieldundef{#2endyear}%
            {\bibdateuncertain}%
            {}}%
          {}}}%
      {}%
      \ifthenelse{\iffieldundef{#2endyear}\AND\iffieldundef{#2endmonth}%
        \AND\iffieldundef{#2endyeardivision}}%
      {\ifbool{cms:bracket}%
        {\bibclosebracket\global\boolfalse{cms:bracket}}%
        {}}%
      {\iffieldequalstr{#2endyear}{}%
        {\ifbool{cms:bracket}%
          {\bibclosebracket\global\boolfalse{cms:bracket}}%
          {}%
          \mbox{\bibdaterangesep}}%
        {\ifbool{cms:bracket}%
          {\if@cms@circa%
            {\if@cms@endbracket%
              {\bibdaterangesep}%
              {\bibclosebracket\global\boolfalse{cms:bracket}%
                \bibdaterangesep}}%
            {\if@cms@endcirca%
              {\bibdaterangesep\bibsstring{circa}\printdelim{datecircadelim}}%
              {\if@cms@enduncertain%
                {\bibdaterangesep}%
                {\bibclosebracket\global\boolfalse{cms:bracket}%
                  \bibdaterangesep}}}}%
          {\if@cms@endbracket%
            {\bibdaterangesep%
              \cms@datebrackets%
              \if@cms@endcirca%
              {\if@cms@circa%
                {}%
                {\bibsstring{circa}\printdelim{datecircadelim}}}%
              {}}%
            {\bibdaterangesep}}%\bibdaterangesep%
          \iffieldundef{#2endyeardivision}%
          {\csuse{mkbibdate#1}{#2endyear}{#2endmonth}{#2endday}}%
          {\csuse{mkbibyeardivisiondate#1}{#2endyear}{#2endyeardivision}}%
          \ifbool{cms:bracket}%
          {\if@cms@bracket%
            {\cmsdateeraprint{#2endyear}%
              \enddateuncertainprint%
              \bibclosebracket\global\boolfalse{cms:bracket}}%
            {\enddateuncertainprint%
              \bibclosebracket\global\boolfalse{cms:bracket}%
              \cmsdateeraprint{#2endyear}}}%
          {\enddateuncertainprint%
            \cmsdateeraprint{#2endyear}}}}}}%
  \endgroup}

\newrobustcmd*{\cms@mkyearrangeextra}[3][]{%
  \begingroup
  \clearfield{#3month}\clearfield{#3day}\clearfield{#3endmonth}%
  \clearfield{#3endday}\clearfield{#3yeardivision}%
  \clearfield{#3endyeardivision}%
  \blx@metadateinfo{#3}%
  \iffieldundef{#3year}
  {\blx@nounit}%
  {\printtext{%
      \if@cms@bracket%
      {\cms@yearbrackets%
        \if@cms@circa%
        {\bibsstring{circa}\printdelim{datecircadelim}}
        {}}%
      {\global\boolfalse{cms:bracket}}%
      \ifdateyearsequal{#3}{#3end}%
      {\csuse{mkbibdate#2}{#3year}{}{}\cmsdateeraprint{#3endyear}%
        \clearfield{#3endyear}}%
      {\ifblank{#1}%
        {\cmsunspecified{#2}{#3}}%
        {\csuse{mkbibdate#2}{#3year}{}{}\cmsdateeraprint{#3year}}}%
      \if@cms@bracket%
      {\if@cms@uncertain%
        {\if@cms@enduncertain%
          {\iffieldundef{#3endyear}%
            {\bibdateuncertain}%
            {}}%
          {\bibdateuncertain}}%
        {\if@cms@enduncertain%
          {\iffieldundef{#3endyear}%
            {\bibdateuncertain}%
            {}}%
          {}}}%
      {}%
      \iffieldundef{#3endyear}
      {\ifbool{cms:bracket}%
        {\bibclosebracket\global\boolfalse{cms:bracket}}%
        {}}%
      {\iffieldequalstr{#3endyear}{}%
        {\ifbool{cms:bracket}%
          {\bibclosebracket\global\boolfalse{cms:bracket}}%
          {}%
          \mbox{\bibdaterangesep}}%
        {\ifbool{cms:bracket}%
          {\if@cms@circa%
            {\if@cms@endbracket%
              {\bibdaterangesep}%
              {\bibclosebracket\global\boolfalse{cms:bracket}%
                \bibdaterangesep}}%
            {\if@cms@endcirca%
              {\bibdaterangesep\bibsstring{circa}\printdelim{datecircadelim}}%
              {\if@cms@enduncertain%
                {\bibdaterangesep}%
                {\bibclosebracket\global\boolfalse{cms:bracket}%
                  \bibdaterangesep}}}}%
          {\if@cms@endbracket%
            {\bibdaterangesep%
              \cms@yearbrackets%
              \if@cms@endcirca%
              {\if@cms@circa%
                {}%
                {\bibsstring{circa}\printdelim{datecircadelim}}}%
              {}}%
            {\bibdaterangesep}}%
          \csuse{mkbibdate#2}{#3endyear}{}{}%
          \ifbool{cms:bracket}%
          {\if@cms@bracket%
            {\cmsdateeraprint{#3endyear}%
              \enddateuncertainprint%
              \bibclosebracket\global\boolfalse{cms:bracket}}%
            {\enddateuncertainprint%
              \bibclosebracket\global\boolfalse{cms:bracket}%
              \cmsdateeraprint{#3endyear}}}%
          {\if@cms@enduncertain%
            {\bibdateuncertain}%
            {}%
            \cmsdateeraprint{#3endyear}}}}}}%
  \endgroup}%

\def\if@cms@adfirst{%
  \ifboolexpr{%
    test {\ifdefstring\blx@languagename{american}}%
    or
    test {\ifdefstring\blx@languagename{british}}%
    or
    test {\ifdefstring\blx@languagename{canadian}}%
    or
    test {\ifdefstring\blx@languagename{english}}%
    or
    test {\ifdefstring\blx@languagename{UKenglish}}%
    or
    test {\ifdefstring\blx@languagename{USenglish}}%
    or
    test {\ifdefstring\blx@languagename{australian}}%
    or
    test {\ifdefstring\blx@languagename{newzealand}}%
  }%
  {\@firstoftwo}%
  {\@secondoftwo}}

\def\if@cms@bracket{%
  \ifboolexpr{%
    (
    test {\ifdatecirca}%
    and
    togl {blx@datecirca}%
    )
    or
    (
    test {\ifdateuncertain}%
    and
    togl {blx@dateuncertain}%
    )
  }%
  {\@firstoftwo}%
  {\@secondoftwo}}

\def\if@cms@endbracket{%
  \ifboolexpr{%
    (
    test {\ifenddatecirca}%
    and
    togl {blx@datecirca}%
    )
    or
    (
    test {\ifenddateuncertain}%
    and
    togl {blx@dateuncertain}%
    )
  }%
  {\@firstoftwo}%
  {\@secondoftwo}}

\def\if@cms@circa{%
  \ifboolexpr{%
    test {\ifdatecirca}%
    and
    togl {blx@datecirca}%
  }%
  {\@firstoftwo}%
  {\@secondoftwo}}

\def\if@cms@uncertain{%
  \ifboolexpr{%
    test {\ifdateuncertain}%
    and
    togl {blx@dateuncertain}%
  }%
  {\@firstoftwo}%
  {\@secondoftwo}}

\def\if@cms@endcirca{%
  \ifboolexpr{%
    test {\ifenddatecirca}%
    and
    togl {blx@datecirca}%
  }%
  {\@firstoftwo}%
  {\@secondoftwo}}

\def\if@cms@enduncertain{%
  \ifboolexpr{%
    test {\ifenddateuncertain}%
    and
    togl {blx@dateuncertain}%
  }%
  {\@firstoftwo}%
  {\@secondoftwo}}

\def\if@cms@onlyyears#1{%
  \ifboolexpr{%
    test {\iffieldundef{#1month}}%
    and
    test {\iffieldundef{#1endmonth}}%
    and
    test {\iffieldundef{#1day}}%
    and
    test {\iffieldundef{#1endday}}%
  }%
  {\@firstoftwo}%
  {\@secondoftwo}}

%%%% Related functionality from standard.bbx %%%%

\providecommand*{\mkrelatedstringtext}[1]{{{\mainlang #1}}}

\newcounter{bbx:relatedcount}
\newcounter{bbx:relatedtotal}

\newbibmacro*{related:init}{%
  \csundef{bbx:relatedloop}}

\newbibmacro*{begrelated}{\ifcsdef{bbx@lasthash}%
  {\let\cms@related@hash\bbx@lasthash}{}}%
\newbibmacro*{endrelated}{\ifcsdef{cms@related@hash}%
  {\global\let\bbx@lasthash\cms@related@hash%
    \let\cms@related@hash\undefined}{}}%
\newbibmacro*{begrelatedloop}{}
\newbibmacro*{endrelatedloop}{}

\def\ifrelatedloop{%
  \ifboolexpr{ test {\xifinlistcs{\strfield{entrykey}}{bbx:relatedloop}}%
    or test {\xifinlistcs{\strfield{clonesourcekey}}{bbx:relatedloop}} }}

\newbibmacro*{related}{%
  \ifboolexpr{ test {\iffieldundef{related}} or test {\ifrelatedloop} }%
    {}%
    {\ifcsundef{begrelateddelim\strfield{relatedtype}}%
       {\printunit{\begrelateddelim}}%
       {\printunit{\csuse{begrelateddelim\strfield{relatedtype}}}}%
     \usebibmacro{begrelated}%
     \def\bbx@tempa{}%
     \setcounter{bbx:relatedtotal}{0}%
     \def\do##1{%
       \entrydata{##1}{%
         \ifrelatedloop%
           {}%
           {\stepcounter{bbx:relatedtotal}%
            \gappto{\bbx@tempa}{##1,}}}}%
     \docsvfield{related}%
     \restorefield{related}{\bbx@tempa}%
     \ifnumgreater{\value{bbx:relatedtotal}}{0}%
       {\listcsxadd{bbx:relatedloop}{\strfield{entrykey}}%
        \iffieldundef{clonesourcekey}%
          {}%
          {\listcsxadd{bbx:relatedloop}{\strfield{clonesourcekey}}}%
        \setcounter{bbx:relatedcount}{0}%
        \def\do{%
          \stepcounter{bbx:relatedcount}%
          \ifnumgreater{\value{bbx:relatedcount}}{1}%
            {\ifcsundef{relateddelim\strfield{relatedtype}}%
              {\printunit{\relateddelim}}%
              {\expandafter\expandafter\expandafter\expandafter\expandafter
                \expandafter\expandafter\printunit
                \expandafter\expandafter\expandafter\expandafter\expandafter
                \expandafter\expandafter{%
                  \csuse{relateddelim\strfield{relatedtype}}}}}%
            {}}%
        \ifbibmacroundef{related:\strfield{relatedtype}}%
          {\appto{\do}{\usebibmacro{related:default}}}%
          {\appto{\do}{\usebibmacro*{related:\strfield{relatedtype}}}}%
        \iffieldformatundef{related:\strfield{relatedtype}}%
          {\def\bbx@tempa{related}}%
          {\def\bbx@tempa{related:\strfield{relatedtype}}}%
        \iffieldformatundef{relatedstring:\strfield{relatedtype}}%
          {\def\bbx@tempb{relatedstring:default}}%
          {\def\bbx@tempb{relatedstring:\strfield{relatedtype}}}%
        \printtext[\bbx@tempa]{%
          \usebibmacro{begrelatedloop}%
          \iffieldundef{relatedstring}%
            {\ifboolexpr{%
               test {\ifnumgreater{\value{bbx:relatedtotal}}{1}}%
               and
               test {\ifbibxstring{\thefield{relatedtype}s}}%
             }%
               {\printtext[\bbx@tempb]{%
                  \bibstring[\mkrelatedstringtext]{\thefield{relatedtype}s}}}%
               {\iffieldbibstring{relatedtype}%
                  {\printtext[\bbx@tempb]{%
                     \bibstring[\mkrelatedstringtext]{\thefield{relatedtype}}}}%
                  {}}}%
            {\iffieldbibstring{relatedstring}%
               {\printtext[\bbx@tempb]{%
                  \bibstring[\mkrelatedstringtext]{\thefield{relatedstring}}}}%
               {\printfield[\bbx@tempb]{relatedstring}}}%
          \docsvfield{related}%
          \usebibmacro{endrelatedloop}}}%
       {}%
     \usebibmacro{endrelated}}}%

%%% List of all CMS bibliography strings %%%

\NewBibliographyString{%
   afterwordto,%
   broadcast,%
   by,%
   bychoreographer,%
   bycompileraf,%
   bycompileran,%
   bycompileranaf,%
   bycompileranfo,%
   bycompileranin,%
   bycompilerco,%
   bycompilercoaf,%
   bycompilercofo,%
   bycompilercoin,%
   bycompilerfo,%
   bycompilerin,%
   byconductor,%
   bydirector,%
   byeditoralt,%
   byeditorcp,%
   byeditorcpaf,%
   byeditorcpan,%
   byeditorcpanaf,%
   byeditorcpanfo,%
   byeditorcpanin,%
   byeditorcpco,%
   byeditorcpcoaf,%
   byeditorcpcofo,%
   byeditorcpcoin,%
   byeditorcpfo,%
   byeditorcpin,%
   byeditortrcp,%
   byeditortrcpaf,%
   byeditortrcpan,%
   byeditortrcpanaf,%
   byeditortrcpanfo,%
   byeditortrcpanin,%
   byeditortrcpco,%
   byeditortrcpcoaf,%
   byeditortrcpcofo,%
   byeditortrcpcoin,%
   byeditortrcpfo,%
   byeditortrcpin,%
   bynone,%
   byproducer,%
   bytranslatorcp,%
   bytranslatorcpaf,%
   bytranslatorcpan,%
   bytranslatorcpanaf,%
   bytranslatorcpanfo,%
   bytranslatorcpanin,%
   bytranslatorcpco,%
   bytranslatorcpcoaf,%
   bytranslatorcpcofo,%
   bytranslatorcpcoin,%
   bytranslatorcpfo,%
   bytranslatorcpin,%
   canadasection,%
   canadasections,%
   cbyannotator,%
   cbyauthor,%
   cbychoreographer,%
   cbycollaborator,%
   cbycommentator,%
   cbycompiler,%
   cbycompileraf,%
   cbycompileran,%
   cbycompileranaf,%
   cbycompileranfo,%
   cbycompileranin,%
   cbycompilerco,%
   cbycompilercoaf,%
   cbycompilercofo,%
   cbycompilercoin,%
   cbycompilerfo,%
   cbycompilerin,%
   cbyconductor,%
   cbycontinuator,%
   cbydirector,%
   cbyeditor,%
   cbyeditoraf,%
   cbyeditoralt,%
   cbyeditoran,%
   cbyeditoranaf,%
   cbyeditoranfo,%
   cbyeditoranin,%
   cbyeditorco,%
   cbyeditorcoaf,%
   cbyeditorcofo,%
   cbyeditorcoin,%
   cbyeditorcp,%
   cbyeditorcpaf,%
   cbyeditorcpan,%
   cbyeditorcpanaf,%
   cbyeditorcpanfo,%
   cbyeditorcpanin,%
   cbyeditorcpco,%
   cbyeditorcpcoaf,%
   cbyeditorcpcofo,%
   cbyeditorcpcoin,%
   cbyeditorcpfo,%
   cbyeditorcpin,%
   cbyeditorfo,%
   cbyeditorin,%
   cbyeditortr,%
   cbyeditortraf,%
   cbyeditortran,%
   cbyeditortranaf,%
   cbyeditortranfo,%
   cbyeditortranin,%
   cbyeditortrco,%
   cbyeditortrcoaf,%
   cbyeditortrcofo,%
   cbyeditortrcoin,%
   cbyeditortrcp,%
   cbyeditortrcpaf,%
   cbyeditortrcpan,%
   cbyeditortrcpanaf,%
   cbyeditortrcpanfo,%
   cbyeditortrcpanin,%
   cbyeditortrcpco,%
   cbyeditortrcpcoaf,%
   cbyeditortrcpcofo,%
   cbyeditortrcpcoin,%
   cbyeditortrcpfo,%
   cbyeditortrcpin,%
   cbyeditortrfo,%
   cbyeditortrin,%
   cbyfounder,%
   cbynone,%
   cbyorganizer,%
   cbyproducer,%
   cbyredactor,%
   cbytranslator,%
   cbytranslatoraf,%
   cbytranslatoran,%
   cbytranslatoranaf,%
   cbytranslatoranfo,%
   cbytranslatoranin,%
   cbytranslatorco,%
   cbytranslatorcoaf,%
   cbytranslatorcofo,%
   cbytranslatorcoin,%
   cbytranslatorcp,%
   cbytranslatorcpaf,%
   cbytranslatorcpan,%
   cbytranslatorcpanaf,%
   cbytranslatorcpanfo,%
   cbytranslatorcpanin,%
   cbytranslatorcpco,%
   cbytranslatorcpcoaf,%
   cbytranslatorcpcofo,%
   cbytranslatorcpcoin,%
   cbytranslatorcpfo,%
   cbytranslatorcpin,%
   cbytranslatorfo,%
   cbytranslatorin,%
   century,%
   cfromamerican,%
   cfrombrazilian,%
   cfrombulgarian,%
   cfromcatalan,%
   cfromcroatian,%
   cfromczech,%
   cfromdanish,%
   cfromdutch,%
   cfromenglish,%
   cfromestonian,%
   cfromfinnish,%
   cfromfrench,%
   cfromgalician,%
   cfromgerman,%
   cfromgreek,%
   cfromitalian,%
   cfromjapanese,%
   cfromlatin,%
   cfromnorwegian,%
   cfrompolish,%
   cfromportuguese,%
   cfromrussian,%
   cfromslovak,%
   cfromslovene,%
   cfromspanish,%
   cfromswedish,%
   cfromukrainian,%
   choreographer,%
   choreographers,%
   commenton,%
   conductor,%
   conductors,%
   decade,%
   director,%
   directors,%
   discrecorded,%
   edamerican,%
   edbrazilian,%
   edbulgarian,%
   edcatalan,%
   edcroatian,%
   edczech,%
   eddanish,%
   eddutch,%
   edenglish,%
   edestonian,%
   edfinnish,%
   edfrench,%
   edgalician,%
   edgerman,%
   edgreek,%
   editalian,%
   editorcompiler,%
   editorcompilers,%
   editortranscompiler,%
   editortranscompilers,%
   editortranslator,%
   editortranslators,%
   edjapanese,%
   edlatin,%
   ednorwegian,%
   edpolish,%
   edportuguese,%
   edrussian,%
   edslovak,%
   edslovene,%
   edspanish,%
   edswedish,%
   edukrainian,%
   forewordto,%
   hereinafter,%
   inlang,%
   introductionto,%
   none,%
   nones,%
   note,%
   numbers,%
   of,%
   on,%
   origedition,%
   origpub,%
   origpublin,%
   origpubyear,%
   origpubyearalt,%
   origreleaseyear,%
   origshownyear,%
   partvolume,%
   patentfiled,%
   patentissued,%
   preface,%
   printed,%
   producer,%
   producers,%
   pseudonym,%
   review,%
   revisededition,%
   selfpublished,%
   songrecorded,%
   subsection,%
   subsections,%
   subverbis,%
   subverbo,%
   supranote,%
   tome,%
   track,%
   transcompiler,%
   transcompilers%
 }%

\endinput