% This is a biblatex citation style file, originally adapted from
% Lehman's authortitle-cverb.cbx. It is heavily modified, with the
% intention of providing footnote citations and a bibliography
% formatted according to the specifications of the Chicago Manual of
% Style.

\ProvidesFile{chicago-notes.cbx}[2024/04/15 v 3.20 biblatex citation style]

%%%% Biblatex initialization + Chicago options + Toggles %%%%

\newbool{cms:bracket}% Date-handling booleans
\newbool{cms:extraparens}
\newbool{cms:comma}
\newbool{cms:nd}

% Here we provide a slightly improved \if@cms@capital replacement
% using expl3 facilities, and also backport a patch for a bug in
% (older versions of) expl3's case-changing code.

\ifdef{\ExplSyntaxOff}{}{\RequirePackage{xparse}\RequirePackage{expl3}}%

\ExplSyntaxOn%

\NewDocumentCommand \IfCMSFieldInitCS {m}
{
  \regex_match:nnTF
  {\A(?:\c{citeincite(?:f|s){0,2}}|\cM.)}
  {#1}
  {\use_i:nn}
  {\use_ii:nn}
}

\cs_if_exist:NTF \__text_change_case_switch_titleonly:nnNnnnn
{}
{\cs_new:Npn \__text_change_case_switch_titleonly:nnNnnnn #1#2#3#4#5#6#7
  {
    \__text_change_case_store:n {#7}
    \__text_change_case_break:w
  }
}

\ExplSyntaxOff

\providecommand*{\mkibid}[1]{#1}

\providetoggle{cms@oneyear}% Needed for author-date
\providetoggle{cms@switchdates}% ditto

\providetoggle{cms@jrcomma}% For comma before Jr./Sr.

\providetoggle{cms@url}% These are for the field-exclusion options
\providetoggle{cms@urltime}% 17th ed.
\providetoggle{cms@doi}
\providetoggle{cms@doionly}
\providetoggle{cms@doinodate}
\providetoggle{cms@eprint}
\providetoggle{cms@isbn}
\providetoggle{cms@numbermonth}
\providetoggle{cms@bookpages}
\providetoggle{cms@hidevolumes}% Modify volume fix
\providetoggle{cms@mtvolpunct}
\providetoggle{cms@bookseries}
\providetoggle{cms@citeshser}% For shortseries
\providetoggle{cms@bibshser}
\providetoggle{cms@notefield}
\providetoggle{cms@addendum}
\providetoggle{cms@notitle}% For classical short notes
\providetoggle{cms@comprange}
\providetoggle{cms@compyears}
\providetoggle{cms@modpostnote}
\providetoggle{cms@strippunct}
\providetoggle{cms@postspace}
\providetoggle{cms@url@innotes}
\providetoggle{cms@ukord}

\providetoggle{cms@bc}% Attempt to provide correct dateera handling
\providetoggle{cms@alwaysrange}% Turns off decade and century handling
\providetoggle{cms@decaderange}% Only turns off decade handling
\providetoggle{cms@centuryrange}% Only turns off century handling
\providetoggle{cms@nodatebrackets}% For brackets in uncertain & circa
\providetoggle{cms@noyearbrackets}%
\providetoggle{cms@nodates}%

\providetoggle{cms@strict}
\providetoggle{cms@headlessnote}
\providetoggle{cms@origcite}
\providetoggle{cms@fullnote}
\providetoggle{cms@shortnote}
\providetoggle{cms@allshort}
\providetoggle{cms@noibid}
\providetoggle{cms@noidem}
\providetoggle{cms@namedash}
\providetoggle{cms@bibnona}
\providetoggle{cms@citenona}
\providetoggle{cms@subseqnona}
\providetoggle{cms@useibid}
\providetoggle{cms@usecompiler}
\providetoggle{cms@shorthandibid}
\providetoggle{cms@printshhand}
\providetoggle{cms@fullshhand}
\providetoggle{cms@inheritshhand}
\providetoggle{cms@firstshort}
\providetoggle{cms@noshintro}
\providetoggle{cms@shandonly}
\providetoggle{cms@origpublished}
\providetoggle{cms@loccit}
\providetoggle{cms@annotation}
\providetoggle{cms@cbxannote}
\providetoggle{cms@postposit}
\providetoggle{cms@legalnotes}% For legal types
\providetoggle{cms@supranotes}% Ditto
\providetoggle{cms@noneshort}% Ditto
\providetoggle{cms@running@text}% For Jurisdiction entries
\providetoggle{cms@noterefs}% Backrefs inside notes
\providetoggle{cms@forcenoteref}% For shortrefcite command
\providetoggle{cms@nonoterefs}% To turn off noterefs by type or entry
\providetoggle{cms@zeropages}% For replacing zero sections
\providetoggle{cms@hidezeros}% Ditto, but differently
\providetoggle{cms@fullrefs}% Force printing of sec. no. w/in same sec.
\providetoggle{cms@ensplit}% Split endnotes w/o cmsendnotes
\providetoggle{cms@endnote}% Distinguish foot- and endnotes
\providetoggle{cms@relreview}%
\providetoggle{cms@vol}
\providetoggle{cms@postvol}
\providetoggle{cms@usedvol}
\providetoggle{cms@citecrossref}
\providetoggle{cms@bibcrossref}
\providetoggle{cms@bookcitexref}
\providetoggle{cms@bookbibxref}
\providetoggle{cms@xrefvol}
\providetoggle{cms@xrefpart}
\providetoggle{cms@omitxrefdate}
\providetoggle{cms@xrefurl}
\providetoggle{cms@blogurl}% For 17th ed. blogs w/ comments
\providetoggle{cms@related}
\providetoggle{cms@citerel}
\providetoggle{cms@reprintfrom}% maintitle type w/in relatedfrom type
\providetoggle{cms@gencite}
\providetoggle{cms@genallnames}

\AtEveryCitekey{%
  \iffieldundef{userc}%
  {}%
  {\nocite{\thefield{userc}}}%
  \ifboolexpr{%
    togl {cms@subseqnona}%
    and
    not togl {cms@citenona}%
    and
    test {\ifciteseen}%
    and
    not togl {cms@noneshort}%
  }%
  {\global\let\cms@lastna\undefined}{}%
  \global\togglefalse{cms@loccit}%
  \global\csundef{@cmsst}%
  \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}}%
      {}}}}%

\protected\def\cms@warning@noline#1{%
  \begingroup
  \blx@safe@actives
  \PackageWarningNoLine{biblatex-chicago}{#1}%
  \endgroup}

%% These are options for extended date attributes

\DeclareBiblatexOption{global,entry}[boolean]{alwaysrange}[true]{%
  \settoggle{cms@alwaysrange}{#1}}%

\DeclareBiblatexOption{global,entry}[boolean]{decaderange}[true]{%
  \settoggle{cms@decaderange}{#1}}%

\DeclareBiblatexOption{global,entry}[boolean]{centuryrange}[true]{%
  \settoggle{cms@centuryrange}{#1}}%

\DeclareBiblatexOption{global,type,entry}[boolean]{nodatebrackets}[true]{%
  \settoggle{cms@nodatebrackets}{#1}}%

\DeclareBiblatexOption{global,type,entry}[boolean]{noyearbrackets}[true]{%
  \settoggle{cms@noyearbrackets}{#1}}%

\DeclareBiblatexOption{global,type,entry}[boolean]{nodates}[true]{%
  \settoggle{cms@nodates}{#1}}%

\DeclareBiblatexOption{global,entry}[boolean]{genallnames}[true]{%
  \settoggle{cms@genallnames}{#1}}

\DeclareBiblatexOption{global,type,entry}[string]{annotation}[true]{%
  \ifcsdef{cms@opt@annot@#1}%
  {\csuse{cms@opt@annot@#1}}%
  {\blx@err@invopt{annotation=#1}{}}}%
\def\cms@opt@annot@true{%
  \toggletrue{cms@annotation}%
  \togglefalse{cms@cbxannote}}
\def\cms@opt@annot@false{%
  \togglefalse{cms@annotation}%
  \togglefalse{cms@cbxannote}}
\def\cms@opt@annot@notes{%
  \togglefalse{cms@annotation}%
  \toggletrue{cms@cbxannote}}
\def\cms@opt@annot@bib{%
  \toggletrue{cms@annotation}%
  \togglefalse{cms@cbxannote}}
\def\cms@opt@annot@all{%
  \toggletrue{cms@annotation}%
  \toggletrue{cms@cbxannote}}

\DeclareBiblatexOption{global,type,entry}[string]{bibannotesep}[vpar]{%
  \ifcsdef{cms@opt@bannsep@#1}%
  {\csuse{cms@opt@bannsep@#1}}%
  {\blx@err@invopt{bibannotesep=#1}{}}}
\def\cms@opt@bannsep@none{%
  \let\bibannotesep\@empty}%
\def\cms@opt@bannsep@comma{%
  \def\bibannotesep{\addcomma\addspace}}%
\def\cms@opt@bannsep@colon{%
  \def\bibannotesep{\addcolon\addspace}}%
\def\cms@opt@bannsep@space{%
  \def\bibannotesep{\addspace}}%
\def\cms@opt@bannsep@semicolon{%
  \def\bibannotesep{\addsemicolon\addspace}}%
\def\cms@opt@bannsep@period{%
  \def\bibannotesep{\addperiod\addspace}}%
\def\cms@opt@bannsep@par{%
  \def\bibannotesep{\addperiod\par\nobreak}}%
\def\cms@opt@bannsep@vpar{%
  \def\bibannotesep{\addperiod\par\nobreak \vskip \bibitemsep}}%
\def\cms@opt@bannsep@parbreak{%
  \def\bibannotesep{\addperiod\par}}%
\def\cms@opt@bannsep@vparbreak{%
  \def\bibannotesep{\addperiod\par \vskip \bibitemsep}}%

\DeclareBiblatexOption{global,type,entry}[string]{citeannotesep}[period]{%
  \ifcsdef{cms@opt@cannsep@#1}%
  {\csuse{cms@opt@cannsep@#1}}%
  {\blx@err@invopt{citeannotesep=#1}{}}}
\def\cms@opt@cannsep@none{%
  \let\citeannotesep\@empty}%
\def\cms@opt@cannsep@comma{%
  \def\citeannotesep{\addcomma\addspace}}%
\def\cms@opt@cannsep@colon{%
  \def\citeannotesep{\addcolon\addspace}}%
\def\cms@opt@cannsep@space{%
  \def\citeannotesep{\addspace}}%
\def\cms@opt@cannsep@semicolon{%
  \def\citeannotesep{\addsemicolon\addspace}}%
\def\cms@opt@cannsep@period{%
  \def\citeannotesep{\addperiod\addspace}}%
\def\cms@opt@cannsep@par{%
  \def\citeannotesep{\addperiod\par\nobreak}}%
\def\cms@opt@cannsep@vpar{%
  \def\citeannotesep{\addperiod\par\nobreak \vskip\p@}}%
\def\cms@opt@cannsep@parbreak{%
  \def\citeannotesep{\addperiod\par}}%
\def\cms@opt@cannsep@vparbreak{%
  \def\citeannotesep{\addperiod\par \vskip\p@}}%

\DeclareBiblatexOption{global}[string]{formatbib}[max]{%
  \ifcsdef{cms@opt@formatbib@#1}%
  {\csuse{cms@opt@formatbib@#1}}%
  {\blx@err@invopt{formatbib=#1}{}}}%
\def\cms@opt@formatbib@max{}%
\def\cms@opt@formatbib@min{%
  \renewcommand*{\bibsetup}{%
    \interlinepenalty=0\relax
    \widowpenalty=0\relax
    \@clubpenalty=0\relax
    \clubpenalty=0\relax
    \brokenpenalty=0\relax
    \raggedbottom
    \frenchspacing
    \biburlsetup}}%
\def\cms@opt@formatbib@minwo{%
  \patchcmd\bibsetup%
  {\interlinepenalty=5000\relax}%
  {\interlinepenalty=0\relax}{}{}}%
\def\cms@opt@formatbib@annote{%
  \patchcmd\bibsetup%
  {\interlinepenalty=5000\relax}%
  {\interlinepenalty=0\relax}{}{}%
  \AtEveryBibitem{%
    \interlinepenalty=5000\relax}}%
\def\cms@opt@formatbib@annotenp{%
  \AtEndPreamble{%
    \ifdefvoid{\cms@entrybreak}%
    {\patchcmd\bibsetup%
      {\interlinepenalty=5000\relax}%
      {\interlinepenalties\cmspens{3}\relax}{}{}}%
    {\patchcmd\bibsetup%
      {\interlinepenalty=5000\relax}%
      {\interlinepenalties\cmspens{\cms@entrybreak}\relax}{}{}}}}%

\DeclareBiblatexOption{global}[integer]{entrybreak}[3]{%
  \IfInteger{#1}%
  {\numdef\cms@entrybreak{#1}}%
  {\numdef\cms@entrybreak{3}\cms@warning@noline%
    {'entrybreak=#1' isn't a valid option.\MessageBreak
      This option only accepts integers.\MessageBreak
      It has been set to the default '3'.\MessageBreak
      Please see biblatex-chicago.pdf for\MessageBreak
      more information}}}

\def\cmspens@i#1{\space
  \ifnum#1>\@ne\number5000
  \expandafter\cmspens@i
  \expandafter{\number\numexpr#1-\@ne\expandafter}%
  \else
  \ifnum#1>\z@\number10
  \else\unspace
  \fi\fi}

\def\cmspens#1{\space #1\cmspens@i{#1}}

\DeclareBiblatexOption{global,type,entry}[boolean]{noibid}[true]{%
  \settoggle{cms@noibid}{#1}}

\DeclareBiblatexOption{global,type,entry}[boolean]{useibid}[true]{%
  \settoggle{cms@useibid}{#1}}

\DeclareBiblatexOption{global,type,entry}[boolean]{dashed}[true]{%
  \settoggle{cms@namedash}{#1}}

\DeclareBiblatexOption{global,type,entry}[boolean]{short}[true]{%
  \settoggle{cms@allshort}{#1}}

\DeclareBibliographyOption[boolean]{hidezeros}[true]{%
  \global\settoggle{cms@hidezeros}{#1}}

\DeclareEntryOption[boolean]{hidezeros}[true]{%
  \settoggle{cms@hidezeros}{#1}}

\DeclareBibliographyOption[boolean]{pagezeros}[true]{%
  \global\settoggle{cms@zeropages}{#1}}

\DeclareEntryOption[boolean]{pagezeros}[true]{%
  \settoggle{cms@zeropages}{#1}}

\DeclareBibliographyOption[boolean]{endnotesplit}[true]{%
  \global\settoggle{cms@ensplit}{#1}}

\DeclareBibliographyOption[integer]{noterefinterval}[0]{%
  \gdef\cms@note@distance{#1}}%

\DeclareBibliographyOption[string]{noterefintro}[preface]{%
  \def\cms@note@introname{#1}}%

\DeclareBiblatexOption{type,entry}[boolean]{suppressnoterefs}[true]{%
  \settoggle{cms@nonoterefs}{#1}}

\DeclareBiblatexOption{global}[boolean]{fullnoterefs}[true]{%
  \global\settoggle{cms@fullrefs}{#1}}%

\DeclareBibliographyOption[string]{noteref}[none]{%
  \global\toggletrue{cms@noterefs}%
  \ifcsdef{cms@opt@noterefs@#1}%
  {\letcs\cms@noteref@casenum{cms@opt@noterefs@#1}%
    \def\cms@noteref@interval{#1}%
    \def\cms@note@distance{0}}%
  {\blx@err@invopt{noteref=#1}{}}}%
\def\cms@opt@noterefs@none{0}%
\def\cms@opt@noterefs@part{1}%
\def\cms@opt@noterefs@chapter{2}%
\def\cms@opt@noterefs@section{3}%
\def\cms@opt@noterefs@subsection{4}%
\def\cms@opt@noterefs@page{5}%

\newbibmacro*{noteref+interval}{%
  \ifcase\cms@noteref@casenum% 0
  \cms@noteref{none}%
  \or % 1
  \cms@noteref{part}%
  \or % 2
  \cms@noteref{chapter}%
  \or % 3
  \cms@noteref{section}%
  \or % 4
  \cms@noteref{subsection}%
  \or % 5
  \cms@noteref{page}%
  \fi}

\newrobustcmd*{\cms@noteref}[1]{%
  \ifcsundef{cms@recent@\thefield{entrykey}}%
  {\cms@warning@noline%
    {I can't find a long citation of\MessageBreak
      the entry \thefield{entrykey}.\MessageBreak
      Most likely the initial citation\MessageBreak
      did not occur inside a note, or\MessageBreak
      perhaps you used a \citejournal\MessageBreak
      command for it. Biblatex-chicago\MessageBreak
      won't be able to generate a back\MessageBreak
      reference to it}}%
  {\ifboolexpr{%
      ((
      test {\iffieldequalstr{relatedtype}{reviewof}}%
      or
      test {\iffieldequalstr{relatedtype}{commenton}}% 17th ed.
      )
      and
      (
      test {\ifentrytype{review}}%
      or
      test {\ifentrytype{suppperiodical}}%
      or
      (
      test {\ifentrytype{online}}% 17th ed.
      and
      test {\IfBeginWith{\thefield{title}}{CCCCCC}}%
      )))
      or
      (
      test {\IfBeginWith{\thefield{relatedtype}}{maintitl}}%
      and
      test {\IfBeginWith{\thefield{entrytype}}{mv}}%
      )
    }%
    {\csdef{cms@tempcounta}{\value{cms@reviewcount}}}%
    {\csdef{cms@tempcounta}{\value{instcount}}}%
    \ifboolexpr{%
      test {\ifsamepage{\csuse{cms@tempcounta}}%{\the\value{instcount}}
        {\csuse{cms@recent@\thefield{entrykey}}}}% Replaces cbx@f@...
      and
      not togl {cms@forcenoteref}%
    }%
    {}%
    {\ifboolexpr{%
        test {\ifnumless{\csuse{cms@tempcounta} -
            \csuse{cms@recent@\thefield{entrykey}}}%
          {\csuse{cms@note@distance}}}%
        and
        not togl {cms@forcenoteref}%
      }%
      {}%
      {\ifnumequal{\csuse{cms@opt@noterefs@#1}}{0}%
        {\setunit{\addspace\bibopenparen}%
          \bibsstring{seenote}\addnbspace
          \printtext{\ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}%
          \bibcloseparen}%
        {\ifboolexpr{%
            (
            not test {\ifcsvoid{cms@end@split}}%
            and
            togl {cms@endnote}%
            )
            or
            togl {cms@ensplit}%
            or
            test {\ifnumequal{\csuse{cms@opt@noterefs@#1}}{5}}%
          }%
          {\ifnumequal{\csuse{cms@opt@noterefs@#1}}{5}%
            {\setunit{\addspace\bibopenparen}%
              \bibstring{see}\addnbspace\bibsstring{page}\addnbspace%
              \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
              \newcunit%
              \bibsstring{note}\addnbspace%
              \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
              \bibcloseparen}%
            {\iftoggle{cms@ensplit}%
              {\setunit{\addspace\bibopenparen}%
                \bibstring{see}\addnbspace%
                \getrefbykeydefault{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                    {name}{}%
                \newcunit%
                \bibsstring{note}\addnbspace%
                \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                \bibcloseparen}%
              {\setunit{\addspace\bibopenparen}%
                \bibstring{see}\addnbspace%
                \StrCut{%
                  \getrefbykeydefault{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                  {name}{}}{\ }{\cms@AA}{\cms@BB}%
                \ifcsvoid{cms@BB}%
                {}%
                {\StrLeft{\expandafter\string\cms@BB}{5}[\cms@CC]%
                  \StrGobbleLeft{\expandafter\string\cms@CC}{1}[\cms@CC]}%
                \ifboolexpr{%
                  test {\ifcsvoid{cms@BB}}%
                  or
                  test {\ifdefstring{\cms@CC}{zeri}}%
                }%
                {\ifcsvoid{cms@BB}%
                  {\ifbibxstring{\csuse{cms@note@introname}}%
                    {\bibsstring{\csuse{cms@note@introname}}}%
                    {\csuse{cms@note@introname}}}%
                  {\ifbibxstring{\csuse{cms@note@introname}}%
                    {\bibsstring{\csuse{cms@note@introname}}%
                      \addcomma\addspace\cms@BB}%
                    {\csuse{cms@note@introname}%
                      \addcomma\addspace\cms@BB}}}%
                {\ifcsvoid{cms@end@subheadername}%
                  {\ifbibxstring{\csuse{cms@end@split}}%
                    {\bibsstring{\csuse{cms@end@split}}\addnbspace\cms@BB}%
                    {\csuse{cms@end@split}\addnbspace\cms@BB}}%
                  {\ifbibxstring{\csuse{cms@end@subheadername}}%
                    {\bibsstring{\csuse{cms@end@subheadername}}%
                      \addnbspace\cms@BB}%
                    {\csuse{cms@end@subheadername}\addnbspace\cms@BB}}}%
                \newcunit%
                \bibsstring{note}\addnbspace%
                \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                \bibcloseparen}}}%
          {\ifnumless{\csuse{cms@opt@noterefs@#1}}{3}%
            {\ifboolexpr{%
                test {\ifnumcomp{\value{\csuse{cms@noteref@interval}}}{>}%
                  {\csuse{cms@invl@\thefield{entrykey}}}}%
                or
                togl {cms@fullrefs}%
              }%
              {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}{0}%
                {\ifcsundef{cms@note@introname}%
                  {\iftoggle{cms@zeropages}%
                    {\setunit{\addspace\bibopenparen}%
                      \bibstring{see}\addnbspace\bibsstring{page}%
                      \addnbspace%
                      \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                      \newcunit%
                      \bibsstring{note}\addnbspace%
                      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                      \bibcloseparen}%
                    {\setunit{\addspace\bibopenparen}%
                      \bibstring{see}\addnbspace%
                      \bibsstring{\csuse{cms@noteref@interval}}\addnbspace%
                      \printtext{\csuse{cms@invl@\thefield{entrykey}}}%
                      \newcunit%
                      \bibsstring{note}\addnbspace%
                      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                      \bibcloseparen}}%
                  {\setunit{\addspace\bibopenparen}%
                    \bibstring{see}\addnbspace%
                    \cms@ifcsstring{cms@note@introname}\newcunit%
                    \bibsstring{note}\addnbspace%
                    \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                    \bibcloseparen}}%
                {\setunit{\addspace\bibopenparen}%
                  \bibstring{see}\addnbspace%
                  \printtext[nr#1]{\csuse{cms@invl@\thefield{entrykey}}}%
                  \newcunit%
                  \bibsstring{note}\addnbspace%
                  \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                  \bibcloseparen}}%
              {\setunit{\addspace\bibopenparen}%
                \printtext{\bibsstring{seenote}\addnbspace%
                  \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}%
                \bibcloseparen}}%
            {\ifnumequal{\csuse{cms@opt@noterefs@#1}}{3}%
              {\ifundef{\chapter}%
                {\ifboolexpr{%
                    test {\ifnumcomp{\value{\csuse{cms@noteref@interval}}}{>}%
                      {\csuse{cms@invl@\thefield{entrykey}}}}%
                    or
                    togl {cms@fullrefs}%
                  }%
                  {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}{0}%
                    {\ifcsundef{cms@note@introname}%
                      {\iftoggle{cms@zeropages}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace\bibsstring{page}%
                          \addnbspace%
                          \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace%
                          \bibsstring{section}\addnbspace%
                          \printtext{\csuse{cms@invl@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}}%
                      {\setunit{\addspace\bibopenparen}%
                        \bibstring{see}\addnbspace%
                        \cms@ifcsstring{cms@note@introname}\newcunit%
                        \bibsstring{note}\addnbspace%
                        \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                        \bibcloseparen}}%
                    {\setunit{\addspace\bibopenparen}%
                      \bibstring{see}\addnbspace%
                      \bibsstring{section}\addnbspace%
                      \printtext{\csuse{cms@invl@\thefield{entrykey}}}%
                      \newcunit%
                      \bibsstring{note}\addnbspace%
                      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                      \bibcloseparen}}%
                  {\setunit{\addspace\bibopenparen}%
                    \printtext{\bibsstring{seenote}\addnbspace%
                      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}%
                    \bibcloseparen}}%
                {\ifboolexpr{%
                    test {\ifnumcomp{\value{\csuse{cms@noteref@interval}}}{>}%
                      {\csuse{cms@invl@\thefield{entrykey}}}}%
                    or
                    test {\ifnumcomp{\value{chapter}}{>}%
                      {\csuse{cms@chap@\thefield{entrykey}}}}%
                    or
                    togl {cms@fullrefs}%
                  }%
                  {\ifnumequal{\csuse{cms@chap@\thefield{entrykey}}}{0}%
                    {\ifcsundef{cms@note@introname}%
                      {\iftoggle{cms@zeropages}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace\bibsstring{page}%
                          \addnbspace%
                          \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace%
                          \bibsstring{section}\addnbspace%
                          \printtext{\csuse{cms@chap@\thefield{entrykey}}.%
                            \csuse{cms@invl@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}}%
                      {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}{0}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace%
                          \cms@ifcsstring{cms@note@introname}\newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace%
                          \cms@ifcsstring{cms@note@introname}\newcunit%
                          \bibsstring{section}\addnbspace%
                          \printtext{\csuse{cms@invl@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}}}%
                    {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}{0}%
                      {\iftoggle{cms@zeropages}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace\bibsstring{page}%
                          \addnbspace%
                          \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\iftoggle{cms@hidezeros}%
                          {\setunit{\addspace\bibopenparen}%
                            \bibstring{see}\addnbspace%
                            \bibsstring{section}\addnbspace%
                            \printtext{%
                              \csuse{cms@chap@\thefield{entrykey}}.%
                              1\addnbspace\mkbibparens{\cmspref}}%
                            \newcunit%
                            \bibsstring{note}\addnbspace%
                            \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                            \bibcloseparen}%
                          {\setunit{\addspace\bibopenparen}%
                            \bibstring{see}\addnbspace%
                            \bibsstring{section}\addnbspace%
                            \printtext{\csuse{cms@chap@\thefield{entrykey}}.%
                              \csuse{cms@invl@\thefield{entrykey}}}%
                            \newcunit%
                            \bibsstring{note}\addnbspace%
                            \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                            \bibcloseparen}}}%
                      {\setunit{\addspace\bibopenparen}%
                        \bibstring{see}\addnbspace%
                        \bibsstring{section}\addnbspace%
                        \printtext{\csuse{cms@chap@\thefield{entrykey}}.%
                          \csuse{cms@invl@\thefield{entrykey}}}%
                        \newcunit%
                        \bibsstring{note}\addnbspace%
                        \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                        \bibcloseparen}}}%
                  {\setunit{\addspace\bibopenparen}%
                    \printtext{\bibsstring{seenote}\addnbspace%
                      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}%
                    \bibcloseparen}}}%
              {\ifundef{\chapter}%
                {\ifboolexpr{%
                    test {\ifnumcomp{\value{\csuse{cms@noteref@interval}}}{>}%
                      {\csuse{cms@invl@\thefield{entrykey}}}}%
                    or
                    test {\ifnumcomp{\value{section}}{>}%
                      {\csuse{cms@sec@\thefield{entrykey}}}}%
                    or
                    togl {cms@fullrefs}%
                  }%
                  {\ifnumequal{\csuse{cms@sec@\thefield{entrykey}}}{0}%
                    {\ifcsundef{cms@note@introname}%
                      {\iftoggle{cms@zeropages}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace\bibsstring{page}%
                          \addnbspace%
                          \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace%
                          \bibsstring{section}\addnbspace%
                          \printtext{\csuse{cms@sec@\thefield{entrykey}}.%
                            \csuse{cms@invl@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}}%
                      {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}{0}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace%
                          \cms@ifcsstring{cms@note@introname}\newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace%
                          \cms@ifcsstring{cms@note@introname}\newcunit%
                          \bibsstring{section}\addnbspace%
                          \printtext{\csuse{cms@invl@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}}}%
                    {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}{0}%
                      {\iftoggle{cms@zeropages}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace\bibsstring{page}%
                          \addnbspace%
                          \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\iftoggle{cms@hidezeros}%
                          {\setunit{\addspace\bibopenparen}%
                            \bibstring{see}\addnbspace%
                            \bibsstring{section}\addnbspace%
                            \printtext{%
                              \csuse{cms@sec@\thefield{entrykey}}.%
                              1\addnbspace\mkbibparens{\cmspref}}%
                            \newcunit%
                            \bibsstring{note}\addnbspace%
                            \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                            \bibcloseparen}%
                          {\setunit{\addspace\bibopenparen}%
                            \bibstring{see}\addnbspace%
                            \bibsstring{section}\addnbspace%
                            \printtext{\csuse{cms@sec@\thefield{entrykey}}.%
                              \csuse{cms@invl@\thefield{entrykey}}}%
                            \newcunit%
                            \bibsstring{note}\addnbspace%
                            \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                            \bibcloseparen}}}%
                      {\setunit{\addspace\bibopenparen}%
                        \bibstring{see}\addnbspace%
                        \bibsstring{section}\addnbspace%
                        \printtext{\csuse{cms@sec@\thefield{entrykey}}.%
                          \csuse{cms@invl@\thefield{entrykey}}}%
                        \newcunit%
                        \bibsstring{note}\addnbspace%
                        \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                        \bibcloseparen}}}%
                  {\setunit{\addspace\bibopenparen}%
                    \printtext{\bibsstring{seenote}\addnbspace%
                      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}%
                    \bibcloseparen}}%
                {\ifboolexpr{%
                    test {\ifnumcomp{\value{\csuse{cms@noteref@interval}}}{>}%
                      {\csuse{cms@invl@\thefield{entrykey}}}}%
                    or
                    test {\ifnumcomp{\value{chapter}}{>}%
                      {\csuse{cms@chap@\thefield{entrykey}}}}%
                    or
                    test {\ifnumcomp{\value{section}}{>}%
                      {\csuse{cms@sec@\thefield{entrykey}}}}%
                    or
                    togl {cms@fullrefs}%
                  }%
                  {\ifnumequal{\csuse{cms@chap@\thefield{entrykey}}}{0}%
                    {\ifcsundef{cms@note@introname}%
                      {\iftoggle{cms@zeropages}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace\bibsstring{page}%
                          \addnbspace%
                          \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace%
                          \bibsstring{section}\addnbspace%
                          \printtext{\csuse{cms@chap@\thefield{entrykey}}.%
                            \csuse{cms@sec@\thefield{entrykey}}.%
                            \csuse{cms@invl@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}}%
                      {\ifboolexpr{%
                          test
                          {\ifnumequal{\csuse{cms@sec@\thefield{entrykey}}}%
                            {0}}%
                          and
                          test
                          {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}%
                            {0}}%
                        }%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace%
                          \cms@ifcsstring{cms@note@introname}\newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\ifboolexpr{%
                            togl {cms@zeropages}%
                            and
                            (
                            test
                            {\ifnumequal{\csuse{cms@sec@\thefield{entrykey}}}%
                              {0}}%
                            or
                            test
                            {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}%
                              {0}}%
                            )
                          }%
                          {\setunit{\addspace\bibopenparen}%
                            \bibstring{see}\addnbspace%
                            \cms@ifcsstring{cms@note@introname}\newcunit%
                            \bibsstring{page}%
                            \addnbspace%
                            \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                            \newcunit%
                            \bibsstring{note}\addnbspace%
                            \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                            \bibcloseparen}%
                          {\setunit{\addspace\bibopenparen}%
                            \bibstring{see}\addnbspace%
                            \cms@ifcsstring{cms@note@introname}\newcunit%
                            \bibsstring{section}\addnbspace%
                            \printtext{\csuse{cms@sec@\thefield{entrykey}}.%
                              \csuse{cms@invl@\thefield{entrykey}}}%
                            \newcunit%
                            \bibsstring{note}\addnbspace%
                            \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                            \bibcloseparen}}}}%
                    {\ifboolexpr{%
                        test
                        {\ifnumequal{\csuse{cms@sec@\thefield{entrykey}}}{0}}%
                        or
                        test
                        {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}{0}}%
                      }%
                      {\iftoggle{cms@zeropages}%
                        {\setunit{\addspace\bibopenparen}%
                          \bibstring{see}\addnbspace\bibsstring{page}%
                          \addnbspace%
                          \pageref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \newcunit%
                          \bibsstring{note}\addnbspace%
                          \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                          \bibcloseparen}%
                        {\iftoggle{cms@hidezeros}%
                          {\ifnumequal{\csuse{cms@sec@\thefield{entrykey}}}%
                            {0}%
                            {\ifnumequal{\csuse{cms@invl@\thefield{entrykey}}}%
                              {0}%
                              {\setunit{\addspace\bibopenparen}%
                                \bibstring{see}\addnbspace%
                                \bibsstring{section}\addnbspace%
                                \printtext{%
                                  \csuse{cms@chap@\thefield{entrykey}}.%
                                  1\addnbspace\mkbibparens{\cmspref}}%
                                \newcunit%
                                \bibsstring{note}\addnbspace%
                                \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                                \bibcloseparen}%
                              {\setunit{\addspace\bibopenparen}%
                                \bibstring{see}\addnbspace%
                                \bibsstring{section}\addnbspace%
                                \printtext{%
                                  \csuse{cms@chap@\thefield{entrykey}}.%
                                  \cmspref\adddot%
                                  \csuse{cms@invl@\thefield{entrykey}}}%
                                \newcunit%
                                \bibsstring{note}\addnbspace%
                                \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                                \bibcloseparen}}%
                            {\setunit{\addspace\bibopenparen}%
                              \bibstring{see}\addnbspace%
                              \bibsstring{section}\addnbspace%
                              \printtext{%
                                \csuse{cms@chap@\thefield{entrykey}}.%
                                \csuse{cms@sec@\thefield{entrykey}}.%
                                1\addnbspace\mkbibparens{\cmspref}}%
                              \newcunit%
                              \bibsstring{note}\addnbspace%
                              \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                              \bibcloseparen}}%
                          {\setunit{\addspace\bibopenparen}%
                            \bibstring{see}\addnbspace%
                            \bibsstring{section}\addnbspace%
                            \printtext{\csuse{cms@chap@\thefield{entrykey}}.%
                              \csuse{cms@sec@\thefield{entrykey}}.%
                              \csuse{cms@invl@\thefield{entrykey}}}%
                            \newcunit%
                            \bibsstring{note}\addnbspace%
                            \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                            \bibcloseparen}}}%
                      {\setunit{\addspace\bibopenparen}%
                        \bibstring{see}\addnbspace%
                        \bibsstring{section}\addnbspace%
                        \printtext{\csuse{cms@chap@\thefield{entrykey}}.%
                          \csuse{cms@sec@\thefield{entrykey}}.%
                          \csuse{cms@invl@\thefield{entrykey}}}%
                        \newcunit%
                        \bibsstring{note}\addnbspace%
                        \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
                        \bibcloseparen}}}%
                  {\setunit{\addspace\bibopenparen}%
                    \printtext{\bibsstring{seenote}\addnbspace%
                      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}%
                    \bibcloseparen}}}}}}%
        \ifnumequal{\csuse{cms@tempcounta}}{\value{cms@reviewcount}}%
        {\csxdef{cms@recent@\thefield{entrykey}}%
          {\the\value{cms@reviewcount}}}%
        {\csxdef{cms@recent@\thefield{entrykey}}{\the\value{instcount}}}}}}}%

\newrobustcmd*{\cmspref}{pref.\@}%
\newrobustcmd*{\cmsintrosection}{\S}%

\newrobustcmd*{\cms@ifcsstring}[1]{%
  \ifbibxstring{\csuse{#1}}%
  {\bibsstring{\csuse{#1}}}%
  {\csuse{#1}}}

\newrobustcmd*{\cms@save@locdata}[1]{%
  \iftoggle{cms@noterefs}%
  {\csxdef{cbx@f@\thefield{#1}}{\the\value{instcount}}%
    \csxdef{cms@recent@\thefield{#1}}{\the\value{instcount}}%
    \ifcase\cms@noteref@casenum%
    \or% 1
    \csxdef{cms@invl@\thefield{#1}}%
    {\the\value{\csuse{cms@noteref@interval}}}%
    \or% 2
    \csxdef{cms@invl@\thefield{#1}}%
    {\the\value{\csuse{cms@noteref@interval}}}%
    \or% 3
    \ifundef{\chapter}%
    {\csxdef{cms@invl@\thefield{#1}}%
      {\the\value{\csuse{cms@noteref@interval}}}}%
    {\csxdef{cms@invl@\thefield{#1}}%
      {\the\value{\csuse{cms@noteref@interval}}}%
      \csxdef{cms@chap@\thefield{#1}}{\the\value{chapter}}}%
    \or% 4
    \ifundef{\chapter}%
    {\csxdef{cms@invl@\thefield{#1}}%
      {\the\value{\csuse{cms@noteref@interval}}}%
      \csxdef{cms@sec@\thefield{#1}}{\the\value{section}}}%
    {\csxdef{cms@invl@\thefield{#1}}%
      {\the\value{\csuse{cms@noteref@interval}}}%
      \csxdef{cms@sec@\thefield{#1}}{\the\value{section}}%
      \csxdef{cms@chap@\thefield{#1}}{\the\value{chapter}}}%
    \or% 5
    \csxdef{cms@invl@\thefield{#1}}%
    {\the\value{\csuse{cms@noteref@interval}}}%
    \fi}%
  {}}

\DeclareBibliographyOption[boolean]{legalnotes}[true]{%
  \global\settoggle{cms@legalnotes}{#1}}

\DeclareBiblatexOption{global,entry}[boolean]{supranotes}[true]{%
  \settoggle{cms@supranotes}{#1}}

\DeclareBiblatexOption{global,type,entry}[boolean]{noneshort}[true]{%
  \settoggle{cms@noneshort}{#1}}

\DeclareBibliographyOption[boolean]{shorthandibid}[true]{%
  \global\toggletrue{cms@shorthandibid}}

\DeclareBibliographyOption[boolean]{shorthandfull}[true]{%
  \settoggle{cms@fullshhand}{#1}}

\DeclareBibliographyOption[boolean]{inheritshorthand}[true]{%
  \settoggle{cms@inheritshhand}{#1}}%

\DeclareBiblatexOption{global,entry}[boolean]{shorthandfirst}[true]{%
  \settoggle{cms@firstshort}{#1}}

\DeclareBiblatexOption{global,type,entry}[string]{shorthandintro}[full]{%
  \ifcsdef{cms@opt@shhintro@#1}%
  {\csuse{cms@opt@shhintro@#1}}%
  {\blx@err@invopt{shorthandintro=#1}{}}}
\def\cms@opt@shhintro@full{%
  \togglefalse{cms@noshintro}%
  \togglefalse{cms@shandonly}}%
\def\cms@opt@shhintro@short{%
  \toggletrue{cms@shandonly}}%
\def\cms@opt@shhintro@none{%
  \toggletrue{cms@noshintro}}%

\DeclareBibliographyOption[boolean]{compresspages}[true]{%
  \global\settoggle{cms@comprange}{#1}}%

\DeclareBibliographyOption[boolean]{compressyears}[true]{%
  \global\settoggle{cms@compyears}{#1}}%

\DeclareBibliographyOption[boolean]{postnotepunct}[true]{%
  \global\settoggle{cms@modpostnote}{#1}}%

\DeclareBiblatexOption{global,entry}[boolean]{usecompiler}[true]{%
  \settoggle{blx@usenamec}{#1}}

\DeclareBiblatexOption{global,entry}[boolean]{juniorcomma}[true]{%
  \settoggle{cms@jrcomma}{#1}}

\DeclareBiblatexOption{global,entry}[boolean]{delayvolume}[true]{%
  \settoggle{cms@postvol}{#1}}

\DeclareBiblatexOption{global,entry}[string]{longcrossref}[false]{%
  \ifcsdef{cms@opt@lxref@#1}%
  {\csuse{cms@opt@lxref@#1}}%
  {\blx@err@invopt{longcrossref=#1}{}}}%
\def\cms@opt@lxref@none{%
  \togglefalse{cms@citecrossref}%
  \togglefalse{cms@bibcrossref}%
  \togglefalse{cms@bookcitexref}%
  \togglefalse{cms@bookbibxref}}%
\def\cms@opt@lxref@true{%
  \toggletrue{cms@citecrossref}%
  \toggletrue{cms@bibcrossref}}%
\def\cms@opt@lxref@false{%
  \togglefalse{cms@citecrossref}%
  \togglefalse{cms@bibcrossref}}%
\def\cms@opt@lxref@notes{%
  \toggletrue{cms@citecrossref}%
  \togglefalse{cms@bibcrossref}}%
\def\cms@opt@lxref@bib{%
  \togglefalse{cms@citecrossref}%
  \toggletrue{cms@bibcrossref}}%

\DeclareBiblatexOption{global,entry}[string]{booklongxref}[true]{%
  \ifcsdef{cms@opt@bklxref@#1}%
  {\csuse{cms@opt@bklxref@#1}}%
  {\blx@err@invopt{booklongxref=#1}{}}}%
\def\cms@opt@bklxref@true{%
  \toggletrue{cms@bookcitexref}%
  \toggletrue{cms@bookbibxref}}%
\def\cms@opt@bklxref@false{%
  \togglefalse{cms@bookcitexref}%
  \togglefalse{cms@bookbibxref}}%
\def\cms@opt@bklxref@notes{%
  \toggletrue{cms@bookcitexref}%
  \togglefalse{cms@bookbibxref}}%
\def\cms@opt@bklxref@bib{%
  \togglefalse{cms@bookcitexref}%
  \toggletrue{cms@bookbibxref}}%

\DeclareBiblatexOption{global,entry}[boolean]{omitxrefdate}[true]{%
  \settoggle{cms@omitxrefdate}{#1}}%

\DeclareBiblatexOption{global,entry}[boolean]{xrefurl}[true]{%
  \settoggle{cms@xrefurl}{#1}}%

\DeclareBibliographyOption[boolean]{blogurl}[true]{%
  \settoggle{cms@blogurl}{#1}}%

\DeclareBiblatexOption{global,entry}[string]{journalabbrev}[false]{%
  \ifcsdef{cms@opt@jtabb@#1}%
  {\csuse{cms@opt@jtabb@#1}}%
  {\csuse{cms@opt@jtabb@false}\cms@warning@noline%
    {'journalabbrev=#1' isn't a valid option.\MessageBreak
      The default - 'false' - has been set.\MessageBreak
      Please see biblatex-chicago.pdf for valid\MessageBreak
      option keys}}}%
\def\cms@opt@jtabb@true{%
  \toggletrue{cms@citejtabb}%
  \toggletrue{cms@bibjtabb}}%
\def\cms@opt@jtabb@false{%
  \togglefalse{cms@citejtabb}%
  \togglefalse{cms@bibjtabb}}%
\def\cms@opt@jtabb@notes{%
  \toggletrue{cms@citejtabb}%
  \togglefalse{cms@bibjtabb}}%
\def\cms@opt@jtabb@bib{%
  \togglefalse{cms@citejtabb}%
  \toggletrue{cms@bibjtabb}}%

\DeclareBiblatexOption{global,type,entry}[string]{seriesabbrev}[false]{%
  \ifcsdef{cms@opt@shser@#1}%
  {\csuse{cms@opt@shser@#1}}%
  {\csuse{cms@opt@shser@false}\cms@warning@noline%
    {'seriesabbrev=#1' isn't a valid option.\MessageBreak
      The default - 'false' - has been set.\MessageBreak
      Please see biblatex-chicago.pdf for valid\MessageBreak
      option keys}}}%
\def\cms@opt@shser@true{%
  \toggletrue{cms@citeshser}%
  \toggletrue{cms@bibshser}}%
\def\cms@opt@shser@false{%
  \togglefalse{cms@citeshser}%
  \togglefalse{cms@bibshser}}%
\def\cms@opt@shser@notes{%
  \toggletrue{cms@citeshser}%
  \togglefalse{cms@bibshser}}%
\def\cms@opt@shser@bib{%
  \togglefalse{cms@citeshser}%
  \toggletrue{cms@bibshser}}%

\DeclareBibliographyOption[boolean]{ordinalgb}[true]{%
  \settoggle{cms@ukord}{#1}}%

% The field-exclusion options %

\DeclareBiblatexOption{global,type,entry}[boolean]{notitle}[true]{%
  \settoggle{cms@notitle}{#1}}%

\DeclareBiblatexOption{global,type,entry}[boolean]{urlnotes}[true]{%
  \settoggle{cms@url@innotes}{#1}}%

\DeclareBiblatexOption{global,type,entry}[boolean]{urlstamp}[true]{%
  \settoggle{cms@urltime}{#1}}%

\DeclareBiblatexOption{global,type,entry}[boolean]{isbn}[true]{%
  \settoggle{cms@isbn}{#1}}%
\DeclareBiblatexOption{global,type,entry}[boolean]{url}[true]{%
  \settoggle{cms@url}{#1}}%
\DeclareBiblatexOption{global,type,entry}[string]{doi}[true]{%
  \ifcsdef{cms@opt@doi@#1}%
  {\csuse{cms@opt@doi@#1}}%
  {\blx@err@invopt{doi=#1}{}}}%
\def\cms@opt@doi@true{%
  \toggletrue{cms@doi}}%
\def\cms@opt@doi@false{%
  \togglefalse{cms@doi}}%
\def\cms@opt@doi@only{%
  \toggletrue{cms@doionly}}%
\def\cms@opt@doi@onlynd{%
  \toggletrue{cms@doionly}%
  \toggletrue{cms@doinodate}}%
\DeclareBiblatexOption{global,type,entry}[boolean]{eprint}[true]{%
  \settoggle{cms@eprint}{#1}}%
\DeclareBiblatexOption{global,type,entry}[boolean]{numbermonth}[true]{%
  \settoggle{cms@numbermonth}{#1}}%
\DeclareBiblatexOption{global,type,entry}[boolean]{bookpages}[true]{%
  \settoggle{cms@bookpages}{#1}}%
\DeclareBiblatexOption{global,type,entry}[boolean]{includeall}[true]{%
  \settoggle{cms@isbn}{#1}%
  \settoggle{cms@url}{#1}%
  \settoggle{cms@urltime}{#1}% 17th ed.
  \settoggle{cms@doi}{#1}%
  \settoggle{cms@eprint}{#1}%
  \settoggle{cms@numbermonth}{#1}%
  \settoggle{cms@bookpages}{#1}}%
\DeclareBiblatexOption{global,type,entry}[boolean]{hidevolumes}[true]{%
  \settoggle{cms@hidevolumes}{#1}}%

\DeclareBiblatexOption{global,type,entry}[boolean]{addendum}[true]{%
  \settoggle{cms@addendum}{#1}}%
\DeclareBiblatexOption{global,type,entry}[boolean]{bookseries}[true]{%
  \settoggle{cms@bookseries}{#1}}%
\DeclareBiblatexOption{global,type,entry}[boolean]{notefield}[true]{%
  \settoggle{cms@notefield}{#1}}%
\DeclareBibliographyOption{completenotes}[true]{%
  \settoggle{cms@addendum}{#1}%
  \settoggle{cms@bookseries}{#1}%
  \settoggle{cms@notefield}{#1}}%

\DeclareBibliographyOption[string]{nameaddon}[all]{%
  \ifcsdef{cms@gopt@na@#1}%
  {\csuse{cms@gopt@na@#1}}%
  {\csuse{cms@gopt@na@all}\cms@warning@noline%
    {'nameaddon=#1' is not a valid global\MessageBreak
      option. The default - 'all' - has been set.\MessageBreak
      Please see biblatex-chicago.pdf for valid\MessageBreak
      option keys}}}%
\def\cms@gopt@na@all{}%
\def\cms@gopt@na@none{%
  \settoggle{cms@bibnona}{true}%
  \settoggle{cms@citenona}{true}}%
\def\cms@gopt@na@cite{\settoggle{cms@bibnona}{true}}%
\def\cms@gopt@na@bib{\settoggle{cms@citenona}{true}}%
\def\cms@gopt@na@first{\settoggle{cms@subseqnona}{true}}%
\def\cms@gopt@na@citefirst{%
  \settoggle{cms@bibnona}{true}%
  \settoggle{cms@subseqnona}{true}}%
\def\cms@gopt@na@bibfirst{%
  \settoggle{cms@citenona}{true}%
  \settoggle{cms@subseqnona}{true}}%

\DeclareTypeOption[string]{nameaddon}[all]{%
  \ifcsdef{cms@opt@na@#1}%
  {\csuse{cms@opt@na@#1}}%
  {\csuse{cms@opt@na@all}\cms@warning@noline%
    {'nameaddon=#1' is not a valid type\MessageBreak
      option. The default - 'all' - has been set.\MessageBreak
      Please see biblatex-chicago.pdf for valid\MessageBreak
      option keys}}}%
\def\cms@opt@na@all{}%
\def\cms@opt@na@none{%
  \settoggle{cms@bibnona}{true}%
  \settoggle{cms@citenona}{true}}%
\def\cms@opt@na@cite{\settoggle{cms@bibnona}{true}}%
\def\cms@opt@na@bib{\settoggle{cms@citenona}{true}}%

\DeclareEntryOption[string]{nameaddon}[all]{%
  \ifcsdef{cms@opt@na@#1}%
  {\csuse{cms@opt@na@#1}}%
  {\csuse{cms@opt@na@all}\cms@warning@noline%
    {'nameaddon=#1' is not a valid entry\MessageBreak
      option. The default - 'all' - has been set.\MessageBreak
      Please see biblatex-chicago.pdf for valid\MessageBreak
      option keys}}}%

\DeclareBiblatexOption{global,type,entry}[string]{related}[bib]{%
  \ifcsdef{cms@opt@rel@#1}%
  {\csuse{cms@opt@rel@#1}}%
  {\csuse{cms@opt@rel@bib}\cms@warning@noline%
    {'related=#1' is not a valid option.\MessageBreak
      The default - 'bib' - has been set.\MessageBreak
      Please see biblatex-chicago.pdf for valid\MessageBreak
      option keys}}}%
\def\cms@opt@rel@true{%
  \settoggle{cms@citerel}{true}%
  \settoggle{cms@related}{true}}%
\def\cms@opt@rel@false{%
  \settoggle{cms@citerel}{false}%
  \settoggle{cms@related}{false}}%
\def\cms@opt@rel@bib{%
  \settoggle{cms@citerel}{false}%
  \settoggle{cms@related}{true}}%
\def\cms@opt@rel@notes{%
  \settoggle{cms@citerel}{true}%
  \settoggle{cms@related}{false}}%

% Adding a disambiguating field to short notes otherwise identical %

\DeclareBiblatexOption{global,type,entry}[string]{shortextrafield}{%
  \def\cms@xfield{#1}}%

\DeclareBiblatexOption{global,type,entry}[string]{shortextraformat}{%
  \def\cms@xformat{#1}}%

\DeclareBiblatexOption{global,type,entry}[string]{shortextrapunct}[comma]{%
  \ifcsdef{cms@opt@shxp@#1}%
    {\csuse{cms@opt@shxp@#1}}%
    {\csuse{cms@opt@shxp@comma}\cms@warning@noline%
      {'shortextrapunct=#1' is not a valid option.\MessageBreak
        The default - 'comma' - has been set.\MessageBreak
        Please see biblatex-chicago.pdf for valid\MessageBreak
        option keys}}}%
\def\cms@opt@shxp@none{%
  \let\shortextrapunct\@empty}%
\def\cms@opt@shxp@comma{%
  \def\shortextrapunct{\addcomma\addspace}}%
\def\cms@opt@shxp@colon{%
  \def\shortextrapunct{\addcolon\addspace}}%
\def\cms@opt@shxp@space{%
  \def\shortextrapunct{\addspace}}%
\def\cms@opt@shxp@semicolon{%
  \def\shortextrapunct{\addsemicolon\addspace}}%
\def\cms@opt@shxp@period{%
  \def\shortextrapunct{\addperiod\addspace}}%

% Controlling formatting of, and punctuation before, nameaddon fields %

\DeclareBiblatexOption{global,type,entry}[string]{nameaddonformat}{%
  \def\cms@naformat{#1}}

\DeclareBiblatexOption{global,type,entry}[string]{nameaddonsep}[space]{%
  \ifcsdef{cms@opt@nasep@#1}%
    {\csuse{cms@opt@nasep@#1}}%
    {\csuse{cms@opt@nasep@space}\cms@warning@noline%
      {'nameaddonsep=#1' is not a valid option.\MessageBreak
        The default - 'space' - has been set.\MessageBreak
        Please see biblatex-chicago.pdf for valid\MessageBreak
        option keys}}}%
\def\cms@opt@nasep@none{%
  \let\nameaddonpunct\@empty}%
\def\cms@opt@nasep@comma{%
  \def\nameaddonpunct{\addcomma\addspace}}%
\def\cms@opt@nasep@colon{%
  \def\nameaddonpunct{\addcolon\addspace}}%
\def\cms@opt@nasep@space{%
  \def\nameaddonpunct{\addspace}}%
\def\cms@opt@nasep@semicolon{%
  \def\nameaddonpunct{\addsemicolon\addspace}}%
\def\cms@opt@nasep@period{%
  \def\nameaddonpunct{\addperiod\addspace}}%

% Controlling punctuation before titleaddon fields %

\DeclareBiblatexOption{global,type,entry}[string]{ptitleaddon}[period]{%
  \ifcsdef{cms@opt@ptao@#1}%
    {\csuse{cms@opt@ptao@#1}}%
    {\csuse{cms@opt@ptao@period}\cms@warning@noline%
      {'ptitleaddon=#1' is not a valid option.\MessageBreak
        The default - 'period' - has been set.\MessageBreak
        Please see biblatex-chicago.pdf for valid\MessageBreak
        option keys}}}%
\def\cms@opt@ptao@none{%
  \let\ptitleaddonpunct\@empty}%
\def\cms@opt@ptao@comma{%
  \def\ptitleaddonpunct{\addcomma\addspace}}%
\def\cms@opt@ptao@colon{%
  \def\ptitleaddonpunct{\addcolon\addspace}}%
\def\cms@opt@ptao@space{%
  \def\ptitleaddonpunct{\addspace}}%
\def\cms@opt@ptao@semicolon{%
  \def\ptitleaddonpunct{\addsemicolon\addspace}}%
\def\cms@opt@ptao@period{%
  \def\ptitleaddonpunct{\newunitpunct}}%

\DeclareBiblatexOption{global,type,entry}[string]{ctitleaddon}[comma]{%
  \ifcsdef{cms@opt@ctao@#1}%
    {\csuse{cms@opt@ctao@#1}}%
    {\csuse{cms@opt@ctao@comma}\cms@warning@noline%
      {'ctitleaddon=#1' is not a valid option.\MessageBreak
        The default - 'comma' - has been set.\MessageBreak
        Please see biblatex-chicago.pdf for valid\MessageBreak
        option keys}}}%
\def\cms@opt@ctao@none{%
  \let\ctitleaddonpunct\@empty}%
\def\cms@opt@ctao@comma{%
  \def\ctitleaddonpunct{\addcomma\addspace}}%
\def\cms@opt@ctao@colon{%
  \def\ctitleaddonpunct{\addcolon\addspace}}%
\def\cms@opt@ctao@space{%
  \def\ctitleaddonpunct{\addspace}}%
\def\cms@opt@ctao@semicolon{%
  \def\ctitleaddonpunct{\addsemicolon\addspace}}%
\def\cms@opt@ctao@period{%
  \def\ctitleaddonpunct{\newunitpunct}}%

\DeclareBiblatexOption{global,type,entry}[string]{jtitleaddon}[space]{%
  \ifcsdef{cms@opt@jtao@#1}%
    {\csuse{cms@opt@jtao@#1}}%
    {\csuse{cms@opt@jtao@space}\cms@warning@noline%
      {'jtitleaddon=#1' is not a valid option.\MessageBreak
        The default - 'space' - has been set.\MessageBreak
        Please see biblatex-chicago.pdf for valid\MessageBreak
        option keys}}}%
\def\cms@opt@jtao@none{%
  \let\jtitleaddonpunct\@empty}%
\def\cms@opt@jtao@comma{%
  \def\jtitleaddonpunct{\addcomma\addspace}}%
\def\cms@opt@jtao@colon{%
  \def\jtitleaddonpunct{\addcolon\addspace}}%
\def\cms@opt@jtao@space{%
  \def\jtitleaddonpunct{\addspace}}%
\def\cms@opt@jtao@semicolon{%
  \def\jtitleaddonpunct{\addsemicolon\addspace}}%
\def\cms@opt@jtao@period{%
  \def\jtitleaddonpunct{\newunitpunct}}%

% Controlling punctuation before shorthand in notes %

\DeclareBiblatexOption{global,type,entry}[string]{shorthandpunct}[space]{%
  \ifcsdef{cms@opt@shp@#1}%
    {\csuse{cms@opt@shp@#1}}%
    {\csuse{cms@opt@shp@space}\cms@warning@noline%
      {'shorthandpunct=#1' isn't a valid option.\MessageBreak
        The default - 'space' - has been set.\MessageBreak
        Please see biblatex-chicago.pdf for valid\MessageBreak
        option keys}}}%
\def\cms@opt@shp@none{%
  \let\shorthandpunct\@empty}%
\def\cms@opt@shp@comma{%
  \def\shorthandpunct{\addcomma\addspace}}%
\def\cms@opt@shp@colon{%
  \def\shorthandpunct{\addcolon\addspace}}%
\def\cms@opt@shp@space{%
  \def\shorthandpunct{\addspace}}%
\def\cms@opt@shp@semicolon{%
  \def\shorthandpunct{\addsemicolon\addspace}}%
\def\cms@opt@shp@period{%
  \def\shorthandpunct{\addperiod\addspace}}%
\def\cms@opt@shp@emdash{%
  \def\shorthandpunct{\addthinspace\textemdash\addthinspace}}%
\def\cms@opt@shp@endash{%
  \def\shorthandpunct{\addspace\textendash\addspace}}%

\ExecuteBibliographyOptions{includeall,completenotes,hidevolumes,%
  related,booklongxref,ptitleaddon,ctitleaddon,jtitleaddon,shorthandpunct,%
  urlnotes,legalnotes,supranotes,shortextrapunct,dashed,bibannotesep,%
  citeannotesep,nameaddonsep=space}

\ExecuteBibliographyOptions[standard]{useeditor=false,usenamec=false}%

\ExecuteBibliographyOptions[jurisdiction,legal,legislation]{%
  shorthandintro=full}%

\iftoggle{cms@legalnotes}%
{\ExecuteBibliographyOptions[jurisdiction,legal,legislation]{skipbib}}%
{}%

% For author-date compatibility %

\DeclareEntryOption[boolean]{switchdates}[true]{%
  \settoggle{cms@switchdates}{#1}}%

\DeclareEntryOption{cmsdate}{}%

\DeclareBibliographyOption{cmsdate}{}%

\DeclareBiblatexOption{global}[boolean]{strict}[true]{%
  \settoggle{cms@strict}{#1}}%

\protected\def\blx@newcunit{%
  \iftoggle{blx@keepunit}%
  {}%
  {\global\let\blx@unitpunct\newcunitpunct
    \global\toggletrue{blx@unit}}}%

\appto\blx@blxinit{%
  \let\newcunit\blx@newcunit}

\newcommand*{\newcunitpunct}{\addcomma\addspace}

\def\mkbibcurdinal#1{%
  \@tempcnta0#1 \the\@tempcnta}%

\@ifpackagelater{biblatex}{2010/08/28}
{}%
{\PackageError{biblatex}
  {Outdated 'biblatex' package}
  {The Chicago style requires biblatex v0.9 or later.\MessageBreak
    You are using: '\csuse{ver@biblatex.sty}'.\MessageBreak
    This is a fatal error. I'm aborting now.}%
  \endinput}

% American-specific punctuation change for 16th edition %

\DefineBibliographyExtras{american}{%
  \DeclarePunctuationPairs{comma}{*!?}}

%%%% Initialize and define bibstrings %%%%
%%%% This one needed for 16th edition. Others in cms-*.lbx %%%%

\DefineBibliographyStrings{english}{%
  citedas = {hereafter cited as},}

%%%% These are the macros and declarations needed to use non-default
%%%% name presentations, including new name parts and different
%%%% orderings of existing name parts. All of this becomes available
%%%% only when a user sets the "cmsnameparts" option. Nearly all of it
%%%% comes from the standard biblatex example file 93-nameparts.tex,
%%%% with changes to make it possible for users to add new name
%%%% treatments and also to set a new default name presentation style
%%%% for their documents.

\ifdefvoid{\cms@ldt@cmsnameparts}{}{%

  %% Wrapper for biblatex's Template declarations, allowing a chosen
  %% named template also to provide the default ("global") template.
  %% <template command><[template name]><definition of template>

  \def\cms@template@wrapper#1[#2]#3{%
    \def\cms@tpl{#2}
    \ifx\cms@ldt@cmsnameparts\cms@tpl
    #1{#3}%
    #1[#2]{#3}
    \else
    #1[#2]{#3}
    \fi}

  %% Name format declarations for bibliography and notes. The
  %% "default" format is for the head of long notes and for names in
  %% the body of long notes and bibliography entries. They should work
  %% for any name styles users might want to add themselves.

  \DeclareNameFormat{sortname}{%
    \ifdefstring{\blx@refcontext@sortingnamekeytemplatename}{global}%
    {\ifcsdef{cmssort:\cms@ldt@cmsnameparts-rev}%
      {\ifnumequal{\value{listcount}}{1}%
        {\csuse{cmssort:\cms@ldt@cmsnameparts-rev}}%
        {\ifcsdef{cmssort:\cms@ldt@cmsnameparts}%
          {\csuse{cmssort:\cms@ldt@cmsnameparts}}%
          {\csuse{cmssort:western}}}}%
      {\ifcsdef{cmssort:\cms@ldt@cmsnameparts}%
        {\csuse{cmssort:\cms@ldt@cmsnameparts}}%
        {\ifnumequal{\value{listcount}}{1}%
          {\csuse{cmssort:western-rev}}%
          {\csuse{cmssort:western}}}}}%
    {\ifcsdef{cmssort:\blx@refcontext@sortingnamekeytemplatename-rev}%
      {\ifnumequal{\value{listcount}}{1}%
        {\csuse{cmssort:\blx@refcontext@sortingnamekeytemplatename-rev}}%
        {\ifcsdef{cmssort:\blx@refcontext@sortingnamekeytemplatename}%
          {\csuse{cmssort:\blx@refcontext@sortingnamekeytemplatename}}%
          {\csuse{cmssort:western}}}}%
      {\ifcsdef{cmssort:\blx@refcontext@sortingnamekeytemplatename}%
        {\csuse{cmssort:\blx@refcontext@sortingnamekeytemplatename}}%
        {\ifnumequal{\value{listcount}}{1}%
          {\csuse{cmssort:western-rev}}%
          {\csuse{cmssort:western}}}}}%
    \usebibmacro{name:andothers}}%

  \DeclareNameFormat{default}{%
    \ifdefstring{\blx@refcontext@sortingnamekeytemplatename}{global}%
    {\ifcsdef{cmssort:\cms@ldt@cmsnameparts}%
      {\csuse{cmssort:\cms@ldt@cmsnameparts}}%
      {\csuse{cmssort:western}}}%
    {\ifcsdef{cmssort:\blx@refcontext@sortingnamekeytemplatename}%
      {\csuse{cmssort:\blx@refcontext@sortingnamekeytemplatename}}%
      {\csuse{cmssort:western}}}%
    \usebibmacro{name:andothers}}%

  \DeclareNameFormat{labelname}{%
    \ifdefstring{\blx@refcontext@sortingnamekeytemplatename}{global}%
    {\ifcsdef{cmslabel:\cms@ldt@cmsnameparts}%
      {\csuse{cmslabel:\cms@ldt@cmsnameparts}}%
      {\csuse{cmslabel:western}}}%
    {\ifcsdef{cmslabel:\blx@refcontext@sortingnamekeytemplatename}%
      {\csuse{cmslabel:\blx@refcontext@sortingnamekeytemplatename}}%
      {\csuse{cmslabel:western}}}%
    \usebibmacro{name:andothers}}%

  %% These are the template definitions for the four pre-defined
  %% styles, each with two templates, one for the sortname and one for
  %% the labelname. The "western" style, as in 93-nameparts.tex, is
  %% identical to biblatex's default style, but giving it a name
  %% allows other styles to become the default, if desired. You will
  %% need one template of each sort for any new style you wish to
  %% provide.

  \cms@template@wrapper{\DeclareSortingNamekeyTemplate}[cjk]{
    \keypart{
      \namepart{family}
    }
    \keypart{
      \namepart{given}
    }
    \keypart{
      \namepart{cjk}
    }
  }

  \cms@template@wrapper{\DeclareUniquenameTemplate}[cjk]{
    \namepart[base=true]{family}
    \namepart[disambiguation=full]{given}
    \namepart[disambiguation=full]{cjk}
  }

  \cms@template@wrapper{\DeclareSortingNamekeyTemplate}[ethiopian]{
    \keypart{
      \namepart{given}
    }
    \keypart{
      \namepart{patronymic}
    }
    \keypart{
      \namepart{papponymic}
    }
  }

  \cms@template@wrapper{\DeclareUniquenameTemplate}[ethiopian]{
    \namepart[base=true]{given}
    \namepart[disambiguation=full]{patronymic}
    \namepart[disambiguation=full]{papponymic}
  }

  \cms@template@wrapper{\DeclareSortingNamekeyTemplate}[russian]{
    \keypart{
      \namepart{family}
    }
    \keypart{
      \namepart{given}
    }
    \keypart{
      \namepart{patronymic}
    }
  }

  \cms@template@wrapper{\DeclareUniquenameTemplate}[russian]{
    \namepart[base=true]{family}
    \namepart{given}
    \namepart{patronymic}
  }

  \DeclareSortingNamekeyTemplate[western]{
    \keypart{
      \namepart[use=true]{prefix}
      \namepart{family}
    }
    \keypart{
      \namepart{given}
    }
    \keypart{
      \namepart{suffix}
    }
    \keypart{
      \namepart[use=false]{prefix}
    }
  }

  \DeclareUniquenameTemplate[western]{
    \namepart[use=true, base=true]{prefix}
    \namepart[base=true]{family}
    \namepart{given}
  }

  %% Biblatex version 3.20 added this declaration to its name-parts
  %% apparatus, and you need one for each new style you add when using
  %% that version, or else documents won't compile. I include them
  %% here inside the \ifdef test because earlier versions of biblatex
  %% don't define the command.

  \ifdef{\DeclareNamehashTemplate}{%
      \DeclareNamehashTemplate[western]{
        \namepart[hashscope=full]{family}
        \namepart[hashscope=full]{given}
        \namepart[hashscope=full]{prefix}
        \namepart[hashscope=full]{suffix}
      }%
      \cms@template@wrapper{\DeclareNamehashTemplate}[russian]{
        \namepart[hashscope=full]{prefix}
        \namepart[hashscope=full]{family}
        \namepart[hashscope=full]{suffix}
        \namepart[hashscope=full]{given}
        \namepart[hashscope=full]{patronymic}
      }%
      \cms@template@wrapper{\DeclareNamehashTemplate}[ethiopian]{
        \namepart[hashscope=full]{prefix}
        \namepart[hashscope=full]{family}
        \namepart[hashscope=full]{suffix}
        \namepart[hashscope=full]{given}
        \namepart[hashscope=full]{patronymic}
        \namepart[hashscope=full]{papponymic}
      }%
      \cms@template@wrapper{\DeclareNamehashTemplate}[cjk]{
        \namepart[hashscope=full]{prefix}
        \namepart[hashscope=full]{family}
        \namepart[hashscope=full]{suffix}
        \namepart[hashscope=full]{given}
        \namepart[hashscope=full]{cjk}
      }%
    }{}%

  %% These bibmacros print the names when the standard biblatex
  %% equivalents are insufficient. You only need to provide a new one
  %% for a new style if standard biblatex doesn't provide one that is
  %% suitable.

  \newbibmacro*{name:cjk}[3]{%
    \usebibmacro{name:delim}{#2#3#1}%
    \usebibmacro{name:hook}{#2#3#1}%
    \mkbibnamefamily{#1}%
    \ifdefvoid{#2}{}{\bibnamedelimd\mkbibnamegiven{#2}}%
    \ifdefvoid{#3}{}{\bibnamedelimd\mkbibnamecjk{#3}}}

  \newbibmacro*{name:ethiopian}[3]{%
    \usebibmacro{name:delim}{#1#2#3}%
    \usebibmacro{name:hook}{#1#2#3}%
    \mkbibethgiven{#1}%
    \ifdefvoid{#2}{}{\bibnamedelimd\mkbibethpat{#2}\isdot}%
    \ifdefvoid{#3}{}{\bibnamedelimd\mkbibethpap{#3}\isdot}}

  \let\mkbibethgiven\mkbibnamefamily
  \let\mkbibethpat\mkbibnamegiven
  \let\mkbibethpap\mkbibnamegiven

  \newbibmacro*{name:russian}[3]{%
    \usebibmacro{name:delim}{#1#2#3}%
    \usebibmacro{name:hook}{#1#2#3}%
    \ifdefvoid{#2}
    {}
    {\mkbibnamegiven{#2}\isdot\bibnamedelimd
      \ifdefvoid{#3}
      {}
      {\mkbibnamepatronymic{#3}\isdot\bibnamedelimd}}%
    \mkbibnamefamily{#1}}

  \newbibmacro*{name:russian-rev}[3]{%
    \usebibmacro{name:delim}{#1#2#3}%
    \usebibmacro{name:hook}{#1#2#3}%
    \mkbibnamefamily{#1}%
    \ifdefvoid{#2}
    {}
    {\revsdnamepunct\bibnamedelimd
      \mkbibnamegiven{#2}\isdot
      \ifdefvoid{#3}
      {}
      {\bibnamedelimd\mkbibnamepatronymic{#3}\isdot}}}

  %% These macros call the name-printing bibmacros with the
  %% appropriate arguments for the "sortname" and "default" name
  %% formats. Each style needs at least one for printing sortnames,
  %% and possibly a second if you wish to reverse the first name in a
  %% list.

  \csdef{cmssort:cjk}{%
    \usebibmacro{name:cjk}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartcjk}}%

  \csdef{cmssort:russian}{%
    \usebibmacro{name:russian}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartpatronymic}}%

  \csdef{cmssort:russian-rev}{%
    \usebibmacro{name:russian-rev}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartpatronymic}%
    \ifboolexpe{%
      test {\ifdefvoid\namepartgiven}
      and
      test {\ifdefvoid\namepartpatronymic}}
    {}%
    {\usebibmacro{name:revsdelim}}}%

  \csdef{cmssort:ethiopian}{%
    \usebibmacro{name:ethiopian}
    {\namepartgiven}
    {\namepartpatronymic}
    {\namepartpapponymic}}%

  \csdef{cmssort:western}{%
    \usebibmacro{name:given-family}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartprefix}
    {\namepartsuffix}}%

  \csdef{cmssort:western-rev}{%
    \usebibmacro{name:family-given}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartprefix}
    {\namepartsuffix}%
    \ifboolexpe{%
      test {\ifdefvoid\namepartgiven}
      and
      test {\ifdefvoid\namepartprefix}}
    {}%
    {\usebibmacro{name:revsdelim}}}%

  %% These macros call the name-printing macros for the labelname,
  %% i.e., in short notes. You'll need one for each new style you wish
  %% to provide for your documents.

  \csdef{cmslabel:cjk}{%
    \iffieldequalstr{uniquepart}{base}%
    {\usebibmacro{name:cjk}
      {\namepartfamily}
      {\empty}
      {\empty}}
    {\iffieldequalstr{uniquepart}{given}%
      {\usebibmacro{name:cjk}
        {\namepartfamily}
        {\namepartgiven}
        {\empty}}
      {\usebibmacro{name:cjk}
        {\namepartfamily}
        {\namepartgiven}
        {\namepartcjk}}}}

  \csdef{cmslabel:ethiopian}{%
    \iffieldequalstr{uniquepart}{base}%
    {\usebibmacro{name:ethiopian}
      {\namepartgiven}
      {\empty}
      {\empty}}
    {\iffieldequalstr{uniquepart}{patronymic}%
      {\usebibmacro{name:ethiopian}
        {\namepartgiven}
        {\namepartpatronymic}
        {\empty}}
      {\usebibmacro{name:ethiopian}
        {\namepartgiven}
        {\namepartpatronymic}
        {\namepartpapponymic}}}}

  \csdef{cmslabel:russian}{%
    \iffieldequalstr{uniquepart}{base}%
    {\usebibmacro{name:russian}
      {\namepartfamily}
      {\empty}
      {\empty}}
    {\ifnum\namepartgivenun=1\relax
      \usebibmacro{name:russian}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartpatronymici}%
      \else
      \usebibmacro{name:russian}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartpatronymic}%
      \fi}}

  \csdef{cmslabel:western}{%
    \ifcase\value{uniquename}%
    \usebibmacro{name:family}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartprefix}
    {\namepartsuffix}%
    \or
    \ifuseprefix
    {\usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartprefix}
      {\namepartsuffixi}}
    {\usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartprefixi}
      {\namepartsuffixi}}%
    \or
    \usebibmacro{name:given-family}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartprefix}
    {\namepartsuffix}%
    \fi}}

%%%% Cite macros for use by the citation commands %%%%

\newbibmacro*{cite:init}{%
  \global\let\cbx@lastkey\undefined}

\newbibmacro*{cite:save}{%
  \savefield{entrykey}{\cbx@lastkey}%
  \ifthenelse{\ifentrytype{inreference}\OR\ifentrytype{reference}\OR%
    \ifentrytype{mvreference}}%
  {\global\toggletrue{cms@noidem}}%
  {\global\togglefalse{cms@noidem}}}%

\newbibmacro*{cite}{%
  \ifboolexpr{%
    test {\ifciteseen}%
    and
    (
    not togl {cms@noneshort}% Intended for Bluebook citations
    or
    (
    test {\ifciteibid}%
    and
    not test {\iffirstonpage}%
    and
    not togl {cms@noibid}%
    )
    )
  }%
    {\ifboolexpr{%
        test {\iffieldundef{shorthand}}%
        or
        (
        togl {blx@skipbiblist}%
        and
        togl {cms@inheritshhand}%
        and
        not test {\iffieldundef{crossref}}%
        )
      }%
       {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}%
         {\usebibmacro{cite:ibid}%
           \usebibmacro{cite:save}}%
          {\global\toggletrue{cms@shortnote}%
            \global\togglefalse{cms@fullnote}%
            \usebibmacro{cite:short}{\thefield{entrytype}}%
           \usebibmacro{cite:save}}}%
       {\iftoggle{cms@shorthandibid}%
         {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}%
           {\usebibmacro{cite:ibid}%
             \usebibmacro{cite:save}}%
           {\usebibmacro{cite:shorthand}%
             \usebibmacro{cite:save}%
             \global\toggletrue{cms@noidem}}}%
         {\usebibmacro{cite:shorthand}%
           \usebibmacro{cite:save}%
           \global\toggletrue{cms@noidem}}}}%
     {\ifboolexpr{%
         togl{cms@firstshort}%
         and
         not test {\iffieldundef{shorthand}}%
       }%
       {\usebibmacro{cite:shorthand}%
         \usebibmacro{cite:save}%
         \global\toggletrue{cms@noidem}}%
       {\ifboolexpr{%
           togl {cms@allshort}%
           and
           not togl {cms@noneshort}%
         }%
         {\global\toggletrue{cms@shortnote}%
           \global\togglefalse{cms@fullnote}%
           \global\toggletrue{cms@printshhand}%
           \usebibmacro{cite:short}{\thefield{entrytype}}%
           \usebibmacro{cite:save}}%
         {\global\toggletrue{cms@fullnote}%
           \global\togglefalse{cms@shortnote}%
           \usebibmacro{footcite:save}% FIXME!!
           \usebibmacro{cite:full}%
           \usebibmacro{cite:save}}}}}%

\newbibmacro*{cite:full}{%
  \printtext[bibhypertarget]{%
    \usedriver
      {\DeclareNameAlias{sortname}{default}\frenchspacing}%
      {cite:\thefield{entrytype}}}}%

% {<entrytype>}
\newbibmacro*{cite:short}[1]{%
  \global\let\cms@pnsaved\undefined%
  \iftoggle{cms@notitle}%
  {\usebibmacro{cite:short:ibid}}%
  {\ifcsundef{cite:short:#1}%
    {\csuse{cite:short:book}}%
    {\csuse{cite:short:#1}}}}

\newbibmacro*{cite:short:ibid}{% For 17th edition
  \ifthenelse{\ifnameundef{labelname}\OR%
    \ifentrytype{inreference}\OR%
    \ifentrytype{reference}\OR%
    \ifentrytype{mvreference}}%
  {\ifthenelse{\iffieldequalstr{entrysubtype}{magazine}\AND\NOT%
      \ifentrytype{periodical}}% Simplify .bib creation
    {\ifuseauthor%
      {\ifboolexpr{%
          not test {\iffieldundef{shortjournal}}%
          and
          ((
          test {\ifcitation}%
          and
          togl {cms@citejtabb}%
          )
          or
          (
          test {\ifbibliography}%
          and
          togl {cms@bibjtabb}%
          )
          or
          (
          test {\iffieldundef{journaltitle}}%
          ))
        }%
        {\cmshyper{\printfield[shortjournal]{shortjournal}}\newcunit}%
        {\cmshyper{\printfield[journaltitle]{journaltitle}}\newcunit}}%
      {}}%
    {\ifentrytype{manual}%
      {\cmshyper{\printlist{organization}\isdot}\newcunit}%
      {\ifboolexpr{%
          test {\iffieldequalstr{entrysubtype}{tvepisode}}%
          and
          not test {\iffieldundef{title}}%
          and
          not test {\iffieldundef{booktitle}}%
          and
          test {\iffieldundef{shorttitle}}%
        }%
        {\cmshyper{\printtext[booktitle]{%
              \printfield[btnoformat]{booktitle}%
              \setunit{\subtitlepunct}%
              \printfield[sbtnoformat]{booksubtitle}}%
            \setunit{\ctitleaddonpunct}%
            \printfield{booktitleaddon}}}%
        {\cmshyper{\printfield[citetitle]{labeltitle}}}}}}%
  {\iffieldequalstr{authortype}{anon}%
    {\bibleftbracket\cmshyper{\printnames{labelname}}%
      \bibrightbracket\classicpunct}%
    {\iffieldequalstr{authortype}{anon?}%
      {\bibleftbracket\cmshyper{\printnames{labelname}?}%
        \bibrightbracket\classicpunct}%
      {\cmshyper{\printnames{labelname}}%\usebibmacro{choose+labelname}%
        \isdot\classicpunct}}}}%

\newbibmacro*{shortnote+extrafield}{% Disambiguate otherwise identical
  \iffieldundef{\csuse{cms@xfield}}% short notes
  {\iflistundef{\csuse{cms@xfield}}%
    {\ifnameundef{\csuse{cms@xfield}}%
      {\cms@xtime}% See below; stops spurious parentheses appearing
      {\printtext[\csuse{cms@xformat}]{%
          \printnames[default]{\csuse{cms@xfield}}}}}%
    {\printtext[\csuse{cms@xformat}]{%
        \printlist{\csuse{cms@xfield}}}}}%
  {\ifboolexpr{%
      test {\ifcsstring{cms@xfield}{month}}%
      or
      test {\ifcsstring{cms@xfield}{origmonth}}%
      or
      test {\ifcsstring{cms@xfield}{eventmonth}}%
      or
      test {\ifcsstring{cms@xfield}{urlmonth}}%
    }%
    {\printtext[\csuse{cms@xformat}]{%
        \mkbibmonth{\thefield{\csuse{cms@xfield}}}}}%
    {\ifboolexpr{%
        test {\ifcsstring{cms@xfield}{day}}%
        or
        test {\ifcsstring{cms@xfield}{origday}}%
        or
        test {\ifcsstring{cms@xfield}{eventday}}%
        or
        test {\ifcsstring{cms@xfield}{urlday}}%
      }%
      {\printtext[\csuse{cms@xformat}]{%
          \printfield[letterday]{\csuse{cms@xfield}}}}%
      {\ifboolexpr{%
          test {\ifcsstring{cms@xfield}{yeardivision}}%
          or
          test {\ifcsstring{cms@xfield}{origyeardivision}}%
          or
          test {\ifcsstring{cms@xfield}{eventyeardivision}}%
          or
          test {\ifcsstring{cms@xfield}{urlyeardivision}}%
        }%
        {\printtext[\csuse{cms@xformat}]{%
            \mkbibyeardivision{\thefield{\csuse{cms@xfield}}}}}%
        {\IfSubStr{\cms@xfield}{year}%
          {\StrCut{\cms@xfield}{year}\cms@yeartype\cms@tempnull%
            \iffieldundef{\csuse{cms@yeartype}year}%
            {}%
            {\printtext[\csuse{cms@xformat}]{%
                \csuse{print\cms@yeartype dateextra}}}}%
          {\printtext[\csuse{cms@xformat}]{%
              \printfield{\csuse{cms@xfield}}}}}}}}}%

\newrobustcmd*{\cms@xtime}{% Tests for presence of field before printing
  \IfSubStr{\cms@xfield}{time}%
  {\StrCut{\cms@xfield}{time}\cms@timetype\cms@tempnull%
    \iffieldundef{\csuse{cms@timetype}hour}%
    {}%
    {\printtext[\csuse{cms@xformat}]{%
        \csuse{print\cms@timetype date}%
        \newcunit\csuse{print\cms@timetype time}}}}%
  {\IfSubStr{\cms@xfield}{date}%
    {\StrCut{\cms@xfield}{date}\cms@datetype\cms@tempnull%
      \ifthenelse{\iffieldundef{\csuse{cms@datetype}year}\AND%
        \iffieldundef{\csuse{cms@datetype}month}\AND%
        \iffieldundef{\csuse{cms@datetype}yeardivision}}%
      {}%
      {\printtext[\csuse{cms@xformat}]{%
          \csuse{print\cms@datetype date}}}}%
    {}}}

\newbibmacro*{footcite:save}{%
  \iffootnote%
  {\ifthenelse{\ifentrytype{jurisdiction}\OR\ifentrytype{legal}\OR%
      \ifentrytype{legislation}}%
    {\ifboolexpr{%
        test {\ifentrytype{legal}}%
        or
        (
        test {\ifentrytype{legislation}}%
        and
        (
        test {\iffieldequalstr{entrysubtype}{un}}%
        or
        test {\iffieldequalstr{entrysubtype}{hearing}}%
        ))
      }%
      {\csxdef{cbx@f@\thefield{entrykey}}{\the\value{instcount}}%
        \label{cbx@\the\value{instcount}}}%
      {}}%
    {\cms@save@locdata{entrykey}%
      \label{cbx@\the\value{instcount}}}}%
  {}}

\newbibmacro*{print+noteref}{%
  \ifboolexpr{%
    togl {cms@noterefs}%
    and
    test {\ifbool{citetracker}}% For non-tracked citation commands
    and
    not togl {cms@allshort}%
    and
    not togl {cms@nonoterefs}% Type and entry option
    and
    test {\iffootnote}%
    and not
    (
    test {\ifentrytype{jurisdiction}}%
    or
    test {\ifentrytype{legal}}%
    or
    test {\ifentrytype{legislation}}%
    )
  }%
  {\usebibmacro{noteref+interval}}%
  {}}

%%% The cite:short per-type macros, with helper macros %%%

\csdef{cite:short:article}{%
  \usebibmacro{allshort+firstcite+xref}%
  \ifnameundef{labelname}%
  {\iffieldequalstr{entrysubtype}{magazine}%
    {\ifuseauthor%
      {\ifboolexpr{%
          not test {\iffieldundef{shortjournal}}%
          and
          ((
          test {\ifcitation}%
          and
          togl {cms@citejtabb}%
          )
          or
          (
          test {\ifbibliography}%
          and
          togl {cms@bibjtabb}%
          )
          or
          (
          test {\iffieldundef{journaltitle}}%
          ))
        }%
        {\printfield[shortjournal]{shortjournal}\newcunit}%
        {\printfield[journaltitle]{journaltitle}\newcunit}}%
      {}}%
    {}}%
  {\usebibmacro{cms+name+idem}}%
  \cmshyper{\printfield[citetitle]{labeltitle}}%
  \usebibmacro{cms+extra+test}}%

\csdef{cite:short:audio}{%
  \usebibmacro{allshort+firstcite+xref}%
  \ifnameundef{labelname}%
  {}%
  {\usebibmacro{cms+name+idem}}%
  \iffieldundef{labeltitle}%
  {\iffieldundef{booktitle}%
    {}%
    {\cmshyper{\printtext[booktitle]{%
          \printfield[btnoformat]{booktitle}}}}}%
  {\cmshyper{\printfield[citetitle]{labeltitle}}}%
  \usebibmacro{cms+extra+test}}%

\csdef{cite:short:book}{%
  \usebibmacro{allshort+firstcite+xref}%
  \ifnameundef{labelname}%
  {}%
  {\usebibmacro{cms+name+idem}}%
  \cmshyper{\printfield[citetitle]{labeltitle}}%
  \usebibmacro{cms+extra+test}}%

\csdef{cite:short:inreference}{%
  \usebibmacro{allshort+firstcite+xref}%
  \cmshyper{\printfield[citetitle]{labeltitle}}%
  \usebibmacro{cms+extra+test}}%

\csdef{cite:short:jurisdiction}{%
  \iffieldundef{labeltitle}%
  {}%
  {\cmshyper{\printfield[citetitle]{labeltitle}}}%
  \newcunit% Fixme: giving us a duplicate comma
  \printfield[jourvol]{volume}%
  \setunit*{\addnbspace}%
  \iffieldundef{shortjournal}% Test eliminates spurious comma
  {}%
  {\printtext[shortjournal]{%
      \printfield[jtsnoformat]{shortjournal}}}%
  \iffieldundef{issue}%
  {\printfield[jurisdictionser]{series}}%
  {\setunit{\addspace}%
    \printfield{issue}}% Better ideas?
  % \newcunit%
  \usebibmacro{juridpostnote}}%

\csdef{cite:short:legal}{%
  \iffieldundef{labeltitle}%
  {}%
  {\cmshyper{\printfield[citetitle]{labeltitle}}}%
  \newcunit% Fixme: giving us a duplicate comma
  \printfield[jourvol]{volume}%
  \setunit*{\addnbspace}%
  \iffieldundef{shortjournal}% Test eliminates spurious comma
  {}%
  {\printtext[shortjournal]{%
      \printfield[jtsnoformat]{shortjournal}}}%
  \printfield[legalser]{series}%
  \setunit{\addspace}%
  \printfield{issue}%
  % \newcunit%
  \ifboolexpr{%
    togl {cms@supranotes}%
    and
    test {\iffootnote}%
    and
    test {\ifciteseen}%
  }%
  {\newcunit%
    \printtext{\bibstring{supranote}\addnbspace%
      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}}% ??
  {}%
  \usebibmacro{juridpostnote}}%

\csdef{cite:short:legislation}{%
  \iffieldequalstr{entrysubtype}{constitution}%
  {\usebibmacro{clegis+news+title}%
    \setunit{\addspace}%
    \printfield[juridnum]{number}%
    \newcunit%
    \printfield{part}%
    \newcunit%
    \printfield{chapter}}%
  {\iffieldequalstr{labeltitlesource}{shorttitle}%
    {\cmshyper{\printfield[citetitle]{labeltitle}}}%
    {\ifboolexpr{%
        test {\iffieldundef{shortjournal}}%
        or
        (
        not test {\iffieldundef{volume}}%
        and
        not test {\iffieldint{volume}}%
        )
        or
        (
        test {\iffieldundef{volume}}% Bug fix; correct?
        and
        test {\iffieldundef{series}}%
        and
        not test {\iffieldundef{titleaddon}}%
        )
      }%
      {\ifboolexpr{%
          test {\iffieldundef{entrysubtype}}%
          and
          not test {\iflistundef{location}}
        }%
        {\printlist{location}%
          \setunit{\addspace}}%
        {}%
        \cmshyper{\printfield[citetitle]{labeltitle}}%
        \setunit{\addspace}%
        \printfield[juridnum]{number}%
        \newcunit%
        \printfield{part}%
        \newcunit%
        \printfield{chapter}}%
      {\printfield{note}%
        \newcunit%
        \printfield[jourvol]{volume}%
        \setunit*{\addnbspace}%
        \iffieldundef{shortjournal}% Test eliminates spurious comma
        {}%
        {\printtext[shortjournal]{%
            \printfield[jtsnoformat]{shortjournal}}}%
        \printfield[legislationser]{series}%
        \setunit{\addspace}%
        \printfield{issue}%
        \newcunit%
        \printfield{part}%
        \newcunit%
        \printfield{chapter}%
      }}}%
  \newcunit%
  \ifboolexpr{%
    togl {cms@supranotes}%
    and
    test {\iffootnote}%
    and
    test {\ifciteseen}%
    and
    (
    test {\iffieldequalstr{entrysubtype}{un}}%
    or
    test {\iffieldequalstr{entrysubtype}{hearing}}%
    )
  }%
  {\newcunit%
    \printtext{\bibstring{supranote}\addnbspace%
      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}}% ??
  {}%
  \usebibmacro{juridpostnote}}%

\csdef{cite:short:manual}{%
  \usebibmacro{allshort+firstcite+xref}%
  \ifnameundef{labelname}%
  {\ifboolexpr{%
      test {\iflistundef{organization}}%
      or
      togl {cms@headlessnote}%
    }%
    {}%
    {\printlist{organization}\isdot\newcunit}}%
  {\usebibmacro{cms+name+idem}}%
  \cmshyper{\printfield[citetitle]{labeltitle}}%
  \usebibmacro{cms+extra+test}}%

\csletcs{cite:short:music}{cite:short:audio}%

\csletcs{cite:short:mvreference}{cite:short:inreference}%

\csdef{cite:short:online}{%
  \usebibmacro{allshort+firstcite+xref}%
  \ifnameundef{labelname}%
  {}%
  {\usebibmacro{cms+name+idem}}%
  \ifboolexpr{%
    test {\IfBeginWith{\thefield{title}}{CCCCCC}}%
    and
    test {\iffieldequalstr{relatedtype}{commenton}}%
    and
    togl {cms@citerel}%
  }%
  {\setcounter{cms@reviewcount}{\value{instcount}}%
    \usebibmacro{related:init}%
    \usebibmacro{related}}%
  {\cmshyper{\printfield[citetitle]{labeltitle}}}%
  \usebibmacro{cms+extra+test}}%

\csdef{cite:short:periodical}{%
  \usebibmacro{allshort+firstcite+xref}%
  \ifnameundef{labelname}%
  {}%
  {\usebibmacro{cms+name+idem}}%
  \iffieldundef{issuetitle}%
  {\cmshyper{\printfield[citetitle]{labeltitle}}}%
  {\printfield{issuetitle}}
  \usebibmacro{cms+extra+test}}%

\csletcs{cite:short:reference}{cite:short:inreference}%

\csdef{cite:short:review}{%
  \usebibmacro{allshort+firstcite+xref}%
  \ifnameundef{labelname}%
  {\iffieldequalstr{entrysubtype}{magazine}%
    {\ifuseauthor%
      {\ifboolexpr{%
          not test {\iffieldundef{shortjournal}}%
          and
          ((
          test {\ifcitation}%
          and
          togl {cms@citejtabb}%
          )
          or
          (
          test {\ifbibliography}%
          and
          togl {cms@bibjtabb}%
          )
          or
          (
          test {\iffieldundef{journaltitle}}%
          ))
        }%
        {\printfield[shortjournal]{shortjournal}\newcunit}%
        {\printfield[journaltitle]{journaltitle}\newcunit}}%
      {}}%
    {}}%
  {\usebibmacro{cms+name+idem}}%
  \ifboolexpr{%
    (
    test {\iffieldequalstr{relatedtype}{reviewof}}%
    or
    test {\iffieldequalstr{relatedtype}{commenton}}%
    )
    and
    togl {cms@citerel}%
  }%
  {\setcounter{cms@reviewcount}{\value{instcount}}%
    \usebibmacro{related:init}%
    \usebibmacro{related}}%
  {\cmshyper{\printfield[citetitle]{labeltitle}}}%
  \usebibmacro{cms+extra+test}}%

\csdef{cite:short:standard}{%
  \usebibmacro{allshort+firstcite+xref}%
  \ifboolexpr{%
    (
    togl {cms@allshort}%
    and
    not test {\ifciteseen}%
    )
    or
    not test {\iffieldundef{entrysubtype}}%
  }%
  {\ifnameundef{labelname}%
    {\ifboolexpr{%
        test {\iflistundef{organization}}%
        or
        togl {cms@headlessnote}%
      }%
      {}%
      {\printlist{organization}\isdot\newcunit}}%
    {\iffieldequalstr{authortype}{anon}%
      {\bibleftbracket\printnames{labelname}%
        \bibrightbracket\classicpunct}%
      {\iffieldequalstr{authortype}{anon?}%
        {\bibleftbracket\printnames{labelname}?%
          \bibrightbracket\classicpunct}%
        {\printnames{labelname}%
          \isdot\classicpunct}}}}%
  {}%
  \cmshyper{\printfield[citetitle]{labeltitle}}%
  \usebibmacro{cms+extra+test}}

\csletcs{cite:short:suppperiodical}{cite:short:review}%

\csdef{cite:short:video}{%
  \usebibmacro{allshort+firstcite+xref}%
  \ifnameundef{labelname}%
  {}%
  {\usebibmacro{cms+name+idem}}%
  \ifboolexpr{%
    test {\iffieldequalstr{entrysubtype}{tvepisode}}%
    and
    not test {\iffieldundef{title}}%
    and
    not test {\iffieldundef{booktitle}}%
  }%
  {\iffieldundef{shorttitle}%
    {\cmshyper{\printtext[booktitle]{%
          \printfield[btnoformat]{booktitle}%
          \setunit{\subtitlepunct}%
          \printfield[sbtnoformat]{booksubtitle}}% (?)
        \setunit{\ctitleaddonpunct}%
        \printfield{booktitleaddon}}}%
    {\cmshyper{\printfield[citetitle]{labeltitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{booktitleaddon}}}%
  {\iffieldundef{labeltitle}%
    {\iffieldundef{booktitle}%
      {}%
      {\cmshyper{\printtext[booktitle]{%
            \printfield[btnoformat]{booktitle}}}}}%
    {\cmshyper{\printfield[citetitle]{labeltitle}}}}%
  \usebibmacro{cms+extra+test}}%

\newbibmacro*{cms+extra+test}{% Used in previous defs
  \ifboolexpr{%
    test {\iffieldundef{extratitle}}% Most reliable test
    or
    test {\ifcsundef{cms@xfield}}%
  }%
  {}%
  {\setunit{\shortextrapunct}%
    \usebibmacro{shortnote+extrafield}}}

\newbibmacro*{cms+name+idem}{% Used in previous defs
  \ifboolexpr{%
    test {\ifciteidem}%
    and
    not test {\ifbibliography}%
    and
    not test {\iffirstonpage}%
    and
    not togl {cms@noidem}%
    and
    not togl {cms@headlessnote}%
  }%
  {\bibstring[\mkibid]{idem\thefield{gender}}%
    \classicpunct}%
  {\iffieldequalstr{authortype}{anon}%
    {\bibleftbracket\printnames{labelname}%
      \bibrightbracket\classicpunct}%
    {\iffieldequalstr{authortype}{anon?}%
      {\bibleftbracket\printnames{labelname}?%
        \bibrightbracket\classicpunct}%
      {\printnames{labelname}%
        \isdot\classicpunct}}}}

\newbibmacro*{cite:shorthand}{%
  \global\let\cms@pnsaved\undefined%
  \ifthenelse{\ifentrytype{jurisdiction}\OR\ifentrytype{legal}\OR%
    \ifentrytype{legislation}}%
  {\usebibmacro{cite:shorthand:legal}}%
  {\usebibmacro{cite:shorthand:cms}}}

\newbibmacro*{cite:shorthand:cms}{%
  \usebibmacro{allshort+firstcite+xref}%
  \cmshyper{\printfield{shorthand}}}

\newbibmacro*{cite:shorthand:legal}{%
  \usebibmacro{allshort+firstcite+xref}%
  \cmshyper{\printfield{shorthand}}%
  \ifboolexpr{%
    test {\iffootnote}%
    and
    togl {cms@supranotes}%
    and
    test {\ifciteseen}%
    and
    (
    test {\ifentrytype{legal}}%
    or
    (
    test {\ifentrytype{legislation}}%
    and
    (
    test {\iffieldequalstr{entrysubtype}{un}}%
    or
    test {\iffieldequalstr{entrysubtype}{hearing}}%
    )))
  }%
  {\newcunit%
    \printtext{\bibstring{supranote}\addnbspace%
      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}%
      \iffieldundef{postnote}{}{\printunit{\addcomma\addspace}}}}% ??
  {}}% The printunit is for when a shorthand is also an ibidem.

\newbibmacro*{cms:shorthandintro}{% For changing the citedas phrase
  \ifboolexpr{%
    test {\iffieldundef{shorthand}}%
    or
    togl {cms@noshintro}% option shorthandintro=none
    or
    togl {cms@noneshort}% mainly for Bluebook
  }%
  {}%
  {\iftoggle{cms@shandonly}% option shorthandintro=short
    {\ifthenelse{\ifentrytype{jurisdiction}\OR\ifentrytype{legal}\OR%
        \ifentrytype{legislation}}%
      {\printtext[brackets]{\printfield{shorthand}}}%
      {\printtext[parens]{\printfield{shorthand}}}}%
    {\iffieldundef{shorthandintro}%
      {\ifthenelse{\ifentrytype{jurisdiction}\OR\ifentrytype{legal}\OR%
          \ifentrytype{legislation}}%
        {\printtext[brackets]{%
            \bibstring{hereinafter}\addspace%
            \printfield{shorthand}}}%
        {\printtext[parens]{%
            \bibstring{citedas}\addspace%
            \printfield{shorthand}}}}%
      {\printfield{shorthandintro}}}}}

\newbibmacro*{cite:ibid}{%
  \ifthenelse{\ifentrytype{jurisdiction}\OR\ifentrytype{legal}\OR%
    \ifentrytype{legislation}}%
  {\usebibmacro{cite:ibid:legal}}%
  {\usebibmacro{cite:ibid:cms}}}

\newbibmacro*{cite:ibid:legal}{%
  \ifboolexpr{%
    togl {cms@noibid}%
    or
    test {\ifbibliography}% Needed for inheritshorthand option
  }%
  {\global\toggletrue{cms@shortnote}%
    \global\togglefalse{cms@fullnote}%
    \usebibmacro{cite:short}{\thefield{entrytype}}%
    \usebibmacro{cite:save}}%
  {\cmshyper{\bibsstring[\mkbibemph]{ibidem}}%
    \ifboolexpr{%
      test {\ifloccit}%
      or
      (
      test {\ifciteibid}%
      and
      test {\iffieldequalcs{postnote}{cms@pnsaved}}%
      and
      not test {\ifdefvoid{\blx@loccittracker}}% Package option=false
      )
    }%
    {\global\toggletrue{cms@loccit}}%
    {}}}%

\newbibmacro*{cite:ibid:cms}{%
  \iftoggle{cms@useibid}%
  {\ifboolexpr{%
      test {\ifbibliography}%
      or
      togl {cms@noibid}%
    }%
    {\global\toggletrue{cms@shortnote}%
      \global\togglefalse{cms@fullnote}%
      \usebibmacro{cite:short}{\thefield{entrytype}}%
      \usebibmacro{cite:save}}%
    {\cmshyper{\bibstring[\mkibid]{ibidem}}%
      \ifboolexpr{%
        test {\ifloccit}%
        or
        (
        test {\ifciteibid}%
        and
        test {\iffieldequalcs{postnote}{cms@pnsaved}}%
        and
        not test {\ifdefvoid{\blx@loccittracker}}% Package option=false
        )
      }%
      {\global\toggletrue{cms@loccit}%
        \global\let\cms@pnsaved\undefined}%
      {\global\let\cms@pnsaved\undefined}}}%
  {\ifboolexpr{%
      test {\iffieldequalstr{entrysubtype}{classical}}%
      or
      togl {cms@noibid}%
    }%
    {\global\toggletrue{cms@shortnote}%
      \global\togglefalse{cms@fullnote}%
      \usebibmacro{cite:short}{\thefield{entrytype}}%
      \usebibmacro{cite:save}}%
    {\global\toggletrue{cms@shortnote}%
      \global\togglefalse{cms@fullnote}%
      \usebibmacro{cite:short:ibid}%
      \usebibmacro{cite:save}}}}%

\newbibmacro*{cite:journal}{%
  \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}%
  {\iffieldundef{prenote}%
    {\bibsentence\usebibmacro{cite:ibid}}%
    {\usebibmacro{cite:ibid}}%
    \usebibmacro{cite:save}}%
  {\ifthenelse{\iffieldundef{journaltitle}\AND\iffieldundef{shortjournal}\AND%
      \iffieldundef{journaltitleaddon}}%
    {\usebibmacro{cite:short}{\thefield{entrytype}}%
      \usebibmacro{cite:save}}%
    {\ifboolexpr{%
      test {\ifciteidem}%
      and
      not test {\ifbibliography}%
      and
      not test {\iffirstonpage}%
      and
      not togl {cms@noidem}%
    }%
    {\iffieldundef{prenote}%
      {\bibsentence\bibstring[\mkibid]{idem\thefield{gender}}%
        \newcunit}%
      {\bibstring[\mkibid]{idem\thefield{gender}}%
        \newcunit}}%
    {\iffieldequalstr{authortype}{anon}%
      {\bibleftbracket\printnames{labelname}%
        \bibrightbracket\newcunit}%
      {\iffieldequalstr{authortype}{anon?}%
        {\bibleftbracket\printnames{labelname}?%
          \bibrightbracket\newcunit}%
        {\printnames{labelname}%
          \isdot\newcunit}}}%
    \iftoggle{cms@allshort}%
    {\ifboolexpr{%
        not test {\iffieldundef{shortjournal}}%
        and
        ((
        test {\ifcitation}%
        and
        togl {cms@citejtabb}%
        )
        or
        (
        test {\ifbibliography}%
        and
        togl {cms@bibjtabb}%
        )
        or
        (
        test {\iffieldundef{journaltitle}}%
        and
        test {\iffieldundef{journaltitleaddon}}%
        ))
      }%
      {\printtext[bibhyperref]{%
          \printfield[shortjournal]{shortjournal}}}%
      {\iffieldundef{journaltitle}%
        {\printtext[bibhyperref]{\printfield{journaltitleaddon}}}%
        {\printtext[bibhyperref]{%
            \printfield[journaltitle]{journaltitle}}}}}%
    {\ifboolexpr{%
        not test {\iffieldundef{shortjournal}}%
        and
        ((
        test {\ifcitation}%
        and
        togl {cms@citejtabb}%
        )
        or
        (
        test {\ifbibliography}%
        and
        togl {cms@bibjtabb}%
        )
        or
        (
        test {\iffieldundef{journaltitle}}%
        and
        test {\iffieldundef{journaltitleaddon}}%
        ))
      }%
      {\printtext[bibhyperlink]{%
          \printfield[shortjournal]{shortjournal}}}%
      {\iffieldundef{journaltitle}%
        {\printtext[bibhyperlink]{\printfield{journaltitleaddon}}}%
        {\printtext[bibhyperlink]{%
            \printfield[journaltitle]{journaltitle}}}}}%
    \iffieldundef{volume}%
    {\iffieldundef{number}%
      {\iffieldundef{issue}%
        {\newcunit%
          \usebibmacro{number+or+month}}%
        {\newcunit%
          \printfield{issue}%
          \setunit{\addspace}%
          \usebibmacro{cmsyear}}}%
      {\newcunit%
        \printfield[journum]{number}}}%
    {\toggletrue{cms@fullnote}%
      \togglefalse{cms@shortnote}%
      \setunit{\addspace}%
      \printfield[jourvol]{volume}%
      \ifthenelse{\iffieldundef{pagination}\AND%
        \iffieldundef{bookpagination}}%
      {\setunit{\postvolpunct}}%
      {\setunit{\journalpagespunct}}}}}}%

%% Macros from verbose.cbx %%

\newbibmacro*{textcite}{%
  \ifnameundef{labelname}%
  {\printfield[citetitle]{labeltitle}}%
  {\printnames{labelname}}%
  \ifboolexpr{%
    togl {cms@gencite}%
    and
    (
    test {\iflastcitekey}%
    or
    togl {cms@genallnames}%
    )
  }%
  {\thegen}%
  {}}%

\newbibmacro*{textcite:init}{%
  \citetrackerfalse%
  \pagetrackerfalse%
  \iffirstcitekey
    {\global\undef\cbx@lasthash}%
    {}}%

\newbibmacro*{textcite:count}{%
  \stepcounter{textcitetotal}%
  \ifnumgreater{\value{uniquelist}}{\value{maxnames}}%
    {\ifnumgreater{\value{uniquelist}}{\value{textcitemaxnames}}%
       {\setcounter{textcitemaxnames}{\value{uniquelist}}}%
       {}}%
    {\ifnumless{\value{labelname}}{\value{maxnames}}%
       {\ifnumgreater{\value{labelname}}{\value{textcitemaxnames}}%
          {\setcounter{textcitemaxnames}{\value{labelname}}}%
          {}}%
       {\ifnumgreater{\value{maxnames}}{\value{textcitemaxnames}}%
          {\setcounter{textcitemaxnames}{\value{maxnames}}}%
          {}}}}%

%%%% Citation Commands, internal and external %%%%

\DeclareCiteCommand{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\cmsnoopcite}%
{}{}{}{}%

\DeclareCiteCommand{\bibxrefcite}
  {\usebibmacro{backref+check}}% So cites in biblio don't turn up
  {\usebibmacro{cms-in:}%        in backref list
    \ifthenelse{\iffieldequals{fullhash}{\bbx@lasthash}\AND\NOT%
      \(\ifentrytype{collection}\OR\ifentrytype{proceedings}\OR%
      \ifentrytype{mvcollection}\OR\ifentrytype{mvproceedings}\)}%
    {\clearname{author}%
      \clearname{shortauthor}%
      \clearname{labelname}}%
    {}%
    \toggletrue{cms@shortnote}%
    \togglefalse{cms@fullnote}%
    \ifboolexpr{%
      togl {cms@inheritshhand}%
      and
      not test {\iffieldundef{shorthand}}%
    }%
    {\usebibmacro{cite}}%
    {\usebibmacro{cite:short}{\thefield{entrytype}}}}% Would {cite} be better?
  {}%
  {\usebibmacro{crossref:volume+postnote}}% Volume fix

\DeclareCiteCommand{\bookbibxrefcite}
  {\usebibmacro{backref+check}}% So cites in biblio don't turn up
  {\iffieldequals{fullhash}{\bbx@lasthash}% in backref list
    {\ifthenelse{\ifentrytype{collection}\OR%
        \ifentrytype{proceedings}\OR\ifentrytype{mvcollection}\OR%
        \ifentrytype{mvproceedings}}%
      {\clearname{editor}%
        \clearname{shorteditor}%
        \clearname{labelname}}%
      {\clearname{author}%
        \clearname{shortauthor}%
        \clearname{labelname}}}%
    {}%
    \toggletrue{cms@shortnote}%
    \togglefalse{cms@fullnote}%
    \usebibmacro{bibxref-in:}%
    \ifboolexpr{%
      togl {cms@inheritshhand}%
      and
      not test {\iffieldundef{shorthand}}%
    }%
    {\usebibmacro{cite}}%
    {\usebibmacro{cite:short}{\thefield{entrytype}}}}%
  {}%
  {\usebibmacro{crossref:volume+postnote}}% Volume fix

\DeclareCiteCommand*{\cite}
  {\usebibmacro{cite:init}%
    \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \blx@ibidreset
    \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\footcite}[\mkbibfootnote]
  {\usebibmacro{prenote}}%\bibsentence
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\smartcite}
  [\iffootnote{}{\mkbibfootnote}]
  {\usebibmacro{prenote}}%\bibsentence
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareMultiCiteCommand{\smartcites}[\iffootnote{}{\mkbibfootnote}]%
{\smartcite}{\multicitedelim}

\DeclareCiteCommand{\footfullcite}[\mkbibfootnote]
  {\usebibmacro{prenote}}%\bibsentence
  {\usebibmacro{citeindex}%
    \toggletrue{cms@fullnote}%
    \togglefalse{cms@shortnote}%
    \usebibmacro{footcite:save}%
    \usebibmacro{cite:full}%
    \usebibmacro{cite:save}}
  {\multicitedelim}
  {}

\DeclareCiteCommand{\fullcite}
  {\usebibmacro{prenote}}%\bibsentence
  {\usebibmacro{citeindex}%
    \toggletrue{cms@fullnote}%
    \togglefalse{cms@shortnote}%
    \usebibmacro{footcite:save}%
    \usebibmacro{cite:full}%
    \usebibmacro{cite:save}}
  {\multicitedelim}
  {}

\DeclareCiteCommand{\origfullcite}
  {\usebibmacro{backref+check}%
    \ifhyperref%
    {\hypertarget{cite.\the\c@refsection @\abx@field@entrykey}{}}%
    {}%
    \nopunct}% Remove \unspace for v. 2.0
  {\usedriver
    {\DeclareNameAlias{sortname}{default}\clearfield{postnote}%
      \usebibmacro{clearorigin}\clearfield{userf}\clearfield{shorthand}%
      \toggletrue{cms@fullnote}\toggletrue{cms@headlessnote}%
      \frenchspacing}%
    {cite:\thefield{entrytype}}%
    \iflistundef{pageref}{}{\newunit\usebibmacro{pageref}}}%
  {\multicitedelim}%
  {}%\finentry% (No longer) Helps with annotated bibliographies (?)

\DeclareCiteCommand{\origpublcite}% Similar to above, w/o title.
  {\usebibmacro{backref+check}%
    \ifhyperref%
    {\hypertarget{cite.\the\c@refsection @\abx@field@entrykey}{}}%
    {}%
    \nopunct% Remove otherlang test for 3.16
  }%\unspace Put \nopunct and \unspace here for 0.8e.
  {\usedriver
    {\DeclareNameAlias{sortname}{default}\clearfield{postnote}%
      \usebibmacro{clearpublin}\clearfield{shorthand}%
      \usebibmacro{cms:titlehook}%
      \global\toggletrue{cms@reprintfrom}%
      \toggletrue{cms@fullnote}\toggletrue{cms@headlessnote}%
      \toggletrue{cms@origpublished}\frenchspacing}%
    {cite:\thefield{entrytype}}%
    \iflistundef{pageref}{}{\newunit\usebibmacro{pageref}}%
    \global\togglefalse{cms@reprintfrom}}%
  {\multicitedelim}%
  {}%\finentry

\DeclareCiteCommand{\headlessfullcite}
  {\usebibmacro{prenote}}%
  {\printtext[bibhypertarget]{%
      \usedriver
      {\DeclareNameAlias{sortname}{default}\toggletrue{cms@fullnote}%
        \toggletrue{cms@headlessnote}\usebibmacro{footcite:save}%
        \usebibmacro{cite:save}\usebibmacro{clear+labelname}%
        \global\toggletrue{cms@noidem}}%
      {cite:\thefield{entrytype}}}}%
  {\multicitedelim}%
  {}%\usebibmacro{finentry}}

\DeclareCiteCommand{\headlesscite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \toggletrue{cms@headlessnote}%
    \usebibmacro{clear+labelname}%
    \clearname{labelname}%
    \usebibmacro{cite}%
    \global\toggletrue{cms@noidem}}%
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\headlessparencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \toggletrue{cms@headlessnote}%
    \usebibmacro{clear+labelname}%
    \clearname{labelname}%
    \usebibmacro{cite}%
    \global\toggletrue{cms@noidem}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\headlessparenshortcite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \ifboolexpr{%
      togl{cms@firstshort}%
      and
      not test {\iffieldundef{shorthand}}%
    }%
    {\usebibmacro{cite:shorthand}}%
    {\toggletrue{cms@headlessnote}%
      \toggletrue{cms@shortnote}%
      \togglefalse{cms@fullnote}%
      \clearname{labelname}%
      \usebibmacro{cite:short}{\thefield{entrytype}}}%
    \global\toggletrue{cms@noidem}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\surnamecite}
  {\usebibmacro{prenote}}%\usebibmacro{hlcprenote}}
  {\usebibmacro{citeindex}%
    \ifboolexpr{%
      (
      test {\ifciteseen}%
      or
      togl {cms@allshort}%
      )
      and
      not togl {cms@noneshort}%
    }%
    {\usebibmacro{cite:short}{\thefield{entrytype}}}%
    {\renewbibmacro*{author/editor}{\usebibmacro{choose+surname}}%
      \renewbibmacro*{editor}{\usebibmacro{choose+surname}}%
      \renewbibmacro*{author}{\usebibmacro{choose+surname}}%
      \usebibmacro{cite}}}%
  {\multicitedelim}%
  {\usebibmacro{cite:postnote}}

\DeclareMultiCiteCommand{\surnamecites}{surnamecite}{\multicitedelim}

\DeclareCitePunctuationPosition{\citeincitef}{d}

\DeclareCitePunctuationPosition{\citeincitefs}{d}

\DeclareMultiCiteCommand{\citeincites}[\cmswrap]%
{citeincite}{\multicitedelim}

\DeclareMultiCiteCommand{\citeincitefs}[\cmswrapf]%
{citeincitef}{\multicitedelim}

\DeclareMultiCiteCommand{\fullciteincites}[\cmsfwrap]%
{fullciteincite}{\multicitedelim}

\DeclareCiteCommand{\citeincite}[\cmswrap]
{\usebibmacro{backref+check}%
  \usebibmacro{prenote}}%
{\toggletrue{cms@shortnote}%
  \togglefalse{cms@fullnote}%
  \toggletrue{cms@noidem}%
  \usebibmacro{citeindex}%
  \usebibmacro{cite:short}{\thefield{entrytype}}%
  \usebibmacro{cite:save}}
{\multicitedelim}
{\usebibmacro{postnote}}%

\DeclareCiteCommand{\citeincitef}[\cmswrapf]
{\usebibmacro{backref+check}%
  \usebibmacro{prenote}}%
{\toggletrue{cms@shortnote}%
  \togglefalse{cms@fullnote}%
  \toggletrue{cms@noidem}%
  \usebibmacro{citeindex}%
  \usebibmacro{cite:short}{\thefield{entrytype}}%
  \usebibmacro{cite:save}}
{\multicitedelim}
{\usebibmacro{postnote}}%

\DeclareCiteCommand{\fullciteincite}[\cmsfwrap]
{\usebibmacro{backref+check}%
  \usebibmacro{prenote}}%
{\usebibmacro{citeindex}%
  \toggletrue{cms@fullnote}%
  \togglefalse{cms@shortnote}%
  \usebibmacro{footcite:save}%
  \usebibmacro{cite:full}%
  \usebibmacro{cite:save}}
{\multicitedelim}
{}

\def\cmsfwrap#1{\clearfield{prenote}#1}%

\def\cmswrap#1{%
  \gundef{\cms@pncic}%
  \savefield{postnote}{\cms@pncic}%
  \clearfield{postnote}\clearfield{prenote}%
  \begingroup#1\endgroup%
  \ifdef{\blx@thepostpunct}%
  {\ifdefvoid{\abx@field@postpunct}%
    {\blx@dopostpunct}{}}%
  {}%
  \global\let\abx@field@postnote\cms@pncic%
  \global\let\abx@field@postpunct\@empty}%

\def\cmswrapf#1{%
  \gundef{\cms@pncic}%
  \savefield{postnote}{\cms@pncic}%
  \clearfield{postnote}\clearfield{prenote}%
  \begingroup#1\ifdef{\blx@thepostpunct}{\cms@cicpunct}{}\endgroup
  \global\let\abx@field@postnote\cms@pncic}%

\def\cms@cicpunct{}% Only needed in US; redefine in lbx

\DeclareCiteCommand{\shortcite}
  {\usebibmacro{prenote}}%
  {\toggletrue{cms@shortnote}%
    \togglefalse{cms@fullnote}%
    \usebibmacro{citeindex}%
    \usebibmacro{cite:short}{\thefield{entrytype}}%
    \usebibmacro{cite:save}}
  {\multicitedelim}
  {\usebibmacro{postnote}}%

\DeclareCiteCommand*{\shortcite}
  {\boolfalse{citetracker}%
    \boolfalse{pagetracker}%
    \usebibmacro{prenote}}%
  {\toggletrue{cms@shortnote}%
    \togglefalse{cms@fullnote}%
    \usebibmacro{citeindex}%
    \usebibmacro{cite:short}{\thefield{entrytype}}%
    \usebibmacro{cite:save}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\shortrefcite}
  {\usebibmacro{prenote}}
  {\toggletrue{cms@shortnote}%
    \togglefalse{cms@fullnote}%
    \usebibmacro{citeindex}%
    \usebibmacro{cite:short}{\thefield{entrytype}}%
    \usebibmacro{cite:save}}%
  {\multicitedelim}
  {\toggletrue{cms@forcenoteref}%
    \usebibmacro{postnote}%
    \togglefalse{cms@forcenoteref}}%

\DeclareCiteCommand{\shorthandcite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \iftoggle{cms@shorthandibid}%
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}%
      {\usebibmacro{cite:ibid}%
        \usebibmacro{cite:save}}%
      {\usebibmacro{cite:shorthand}%
        \usebibmacro{cite:save}%
        \global\toggletrue{cms@noidem}}}%
    {\usebibmacro{cite:shorthand}%
      \usebibmacro{cite:save}%
      \global\toggletrue{cms@noidem}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\shorthandcite}
  {\boolfalse{citetracker}%
    \boolfalse{pagetracker}%
    \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \iftoggle{cms@shorthandibid}%
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}%
      {\usebibmacro{cite:ibid}%
        \usebibmacro{cite:save}}%
      {\usebibmacro{cite:shorthand}%
        \usebibmacro{cite:save}%
        \global\toggletrue{cms@noidem}}}%
    {\usebibmacro{cite:shorthand}%
      \usebibmacro{cite:save}%
      \global\toggletrue{cms@noidem}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\shorthandrefcite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \iftoggle{cms@shorthandibid}%
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}%
      {\usebibmacro{cite:ibid}%
        \usebibmacro{cite:save}}%
      {\usebibmacro{cite:shorthand}%
        \usebibmacro{cite:save}%
        \global\toggletrue{cms@noidem}}}%
    {\usebibmacro{cite:shorthand}%
      \usebibmacro{cite:save}%
      \global\toggletrue{cms@noidem}}}
  {\multicitedelim}
  {\toggletrue{cms@forcenoteref}%
    \usebibmacro{postnote}%
    \togglefalse{cms@forcenoteref}}

\DeclareCiteCommand{\citejournal}% Name?
  {\usebibmacro{prenote}}
  {\toggletrue{cms@shortnote}%
    \togglefalse{cms@fullnote}%
    \clearfield{pages}%
    \usebibmacro{citeindex}%
    \usebibmacro{cite:journal}%
    \usebibmacro{cite:save}}
  {\multicitedelim}
  {\iftoggle{cms@loccit}%
    {}%
    {\usebibmacro{fullpostnote}}}

\DeclareCiteCommand{\runcite}% 17th ed.
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \toggletrue{cms@running@text}%
    \usebibmacro{cite}%
    \togglefalse{cms@running@text}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\toggletrue{cms@shortnote}%
    \togglefalse{cms@fullnote}%
    \ifciteindex
     {\indexnames{labelname}}
     {}%
   \printnames{labelname}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\newrobustcmd*{\Shortcite}{%
  \@ifstar{\bibsentence\shortcite*}{\bibsentence\shortcite}}%

\newrobustcmd*{\Shortrefcite}{\bibsentence\shortrefcite}%

\newrobustcmd*{\Headlesscite}{\bibsentence\headlesscite}

\newrobustcmd*{\Headlesscites}{\bibsentence\headlesscites}

\DeclareMultiCiteCommand{\citetitles}{citetitle}{\multicitedelim}

\DeclareMultiCiteCommand{\headlesscites}{headlesscite}{\multicitedelim}

\DeclareMultiCiteCommand{\headlessfullcites}{headlessfullcite}{\multicitedelim}

\DeclareMultiCiteCommand{\headlessparencites}[\mkbibparens]%
{headlessparencite}{\multicitedelim}

\DeclareMultiCiteCommand{\headlessparenshortcites}[\mkbibparens]%
{headlessparenshortcite}{\multicitedelim}

%% Textcite commands adapted from verbose.cbx %%

\DeclareCiteCommand{\cbx@textcite}
  {\usebibmacro{textcite:init}}
  {\iffieldequals{namehash}{\cbx@lasthash}
     {}%
     {\iffirstcitekey
        {}%
        {\textcitedelim}%
      \stepcounter{textcitecount}%
      \usebibmacro{textcite}%
      \savefield{namehash}{\cbx@lasthash}}}
  {}
  {}

\DeclareCiteCommand{\textcite}[\cbx@textcite@init\cbx@textcite\cms@textcite@i]
  {\usebibmacro{textcite:init}%
   \gdef\cbx@savedkeys{}%
   \DeferNextCitekeyHook}
  {\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}%
     {\protected@xappto\cbx@footcite@args{%
        (\thefield{multiprenote})(\thefield{multipostnote})}}%
     {}%
   \xappto\cbx@savedkeys{\thefield{entrykey},}%
   \iffieldequals{namehash}{\cbx@lasthash}%
     {}%
     {\usebibmacro{textcite:count}%
      \savefield{namehash}{\cbx@lasthash}}%
   \ifnumequal{\value{citecount}}{\value{citetotal}}%
     {\protected@xappto\cbx@textcite@args{{\cbx@savedkeys}}%
      \protected@xappto\cbx@footcite@args{%
        [\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}%
      \iflastcitekey
        {\iffootnote
          {\protected@xappto\cbx@textcite@args{\nopunct}%
            \protected@xappto\cbx@footcite@args{\thefield{postpunct}}}%
          {\protected@xappto\cbx@textcite@args{\thefield{postpunct}}% Switch
            \protected@xappto\cbx@footcite@args{\nopunct}}}% these two?
        {}}
     {}}
  {}
  {}

\newrobustcmd{\cbx@textcite@init}[3]{%
  \setcounter{textcitetotal}{0}%
  \setcounter{textcitecount}{0}%
  \setcounter{textcitemaxnames}{0}%
  \def\cbx@textcite@args{#1}\def\cbx@footcite@args{#2}#3%
  \cbx@textcite@args\empty\cbx@footcite@args\empty}

\DeclareMultiCiteCommand{\cbx@textcites}{\cbx@textcite}{}
\DeclareMultiCiteCommand{\textcites}
  [\cbx@textcites@init\cbx@textcites\cms@textcites@i]{\textcite}{}

\let\cbx@textcites@init\cbx@textcite@init
\pretocmd{\cbx@textcites@init}{%
  \UseNextMultiCiteHook%
  \AtNextMultiCite{%
    \renewbibmacro{multiprenote}{}%
    \renewbibmacro{multipostnote}{}}}{}{}

\renewcommand*{\textcitedelim}{%
  \iffinalcitedelim%
  {\ifnumgreater{\value{textcitetotal}}{2}%
    {\addcomma}%
    {}%
    \addspace\bibstring{and}}%
  {\addcomma}%
  \addspace}%

\newrobustcmd{\cms@textcite@i}{%
  \iffootnote{\foottextcite}{\footcite}}

\newrobustcmd{\cms@textcites@i}{%
  \iffootnote{\foottextcites}{\footcites}}

\newcommand{\foottextcite}{\addspace\headlessparenshortcite}

\newcommand{\foottextcites}{\addspace\headlessparenshortcites}

%%% The \gentextcite commands - \textcite in the genitive case %%%

\DeclareCiteCommand{\cms@gentextcite@i}
  {\usebibmacro{textcite:init}%
    \toggletrue{cms@gencite}}%
  {\iffieldequals{namehash}{\cbx@lasthash}%
     {}%
     {\iffirstcitekey
        {}%
        {\textcitedelim}%
      \stepcounter{textcitecount}%
      \usebibmacro{textcite}%
      \savefield{namehash}{\cbx@lasthash}}}
  {}
  {\togglefalse{cms@gencite}}%

\DeclareCiteCommand{\cms@gentextcite}[\cbx@textcite@init\cms@gentextcite@i\cms@textcite@i]
  {\usebibmacro{textcite:init}%
   \gdef\cbx@savedkeys{}%
   \DeferNextCitekeyHook}
  {\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}%
     {\protected@xappto\cbx@footcite@args{%
        (\thefield{multiprenote})(\thefield{multipostnote})}}%
     {}%
   \xappto\cbx@savedkeys{\thefield{entrykey},}%
   \iffieldequals{namehash}{\cbx@lasthash}%
     {}%
     {\usebibmacro{textcite:count}%
      \savefield{namehash}{\cbx@lasthash}}%
   \ifnumequal{\value{citecount}}{\value{citetotal}}%
     {\protected@xappto\cbx@textcite@args{{\cbx@savedkeys}}%
      \protected@xappto\cbx@footcite@args{%
        [\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}%
      \iflastcitekey
        {\iffootnote
          {\protected@xappto\cbx@textcite@args{\nopunct}%
            \protected@xappto\cbx@footcite@args{\thefield{postpunct}}}%
          {\protected@xappto\cbx@textcite@args{\thefield{postpunct}}% Switch
            \protected@xappto\cbx@footcite@args{\nopunct}}}% these two?
        {}}
     {}}
  {}
  {}

\DeclareMultiCiteCommand{\cms@gentextcite@is}{\cms@gentextcite@i}{}
\DeclareMultiCiteCommand{\cms@gentextcites}
  [\cbx@textcites@init\cms@gentextcite@is\cms@textcites@i]{\cms@gentextcite}{}

\newrobustcmd*{\gentextcite}[1][]{%
  \@ifnextchar[%]
  {\gencite@i[#1]}%
  {\gencite@i[][#1]}}%

\def\gencite@i[#1][#2]{%
  \@ifnextchar[%]
  {\gencite@ii[#1][#2]}%
  {\gencite@ii[][#1][#2]}}%

\def\gencite@ii[#1][#2][#3]#4{%
  \ifblank{#1}{\def\thegen{'s}}{\def\thegen{#1}}%
  \gencite@iii[#2][#3]{#4}}%

\def\gencite@iii#1{\cms@gentextcite#1}

\newrobustcmd*{\gentextcites}[1][]{%
  \@ifnextchar(%)
  {\gencites@iv[#1]}%
  {\@ifnextchar[%]
    {\gencites@i[#1]}%
    {\gencites@i[][#1]}}}%

\def\gencites@i[#1][#2]{%
  \@ifnextchar[%]
  {\gencites@ii[#1][#2]}%
  {\gencites@ii[][#1][#2]}}%

\def\gencites@ii[#1][#2][#3]#4{%
  \ifblank{#1}{\def\thegen{'s}}{\def\thegen{#1}}%
  \gencites@iii[#2][#3]{#4}}%

\def\gencites@iii#1{\cms@gentextcites#1}%

\def\gencites@iv[#1]#2{%
  \ifblank{#1}{\def\thegen{'s}}{\def\thegen{#1}}%
  \cms@gentextcites#2}%

\newrobustcmd*{\Gentextcite}{\bibsentence\gentextcite}
\newrobustcmd*{\Gentextcites}{\bibsentence\gentextcites}

%%% End code for \gentextcite %%%

%%%% Drivers for the Long Note Format %%%%

\DeclareBibliographyDriver{cite:article}{%
  \iffieldequalstr{entrysubtype}{magazine}%
  {\usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{cmag+news+author}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{cmag+news+title}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%\newblock%
  \usebibmacro{cpart+editor+translator}%
  \newcunit%
  \usebibmacro{issuetitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cbyeditor+others}%
  \setunit{\addcomma\addspace}%
  \printfield{note}%
  \setunit{\addcomma\addspace}\newblock
  \usebibmacro{mag+news+date}%
  \newcunit\newblock
  \printfield{type}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldequalstr{relatedtype}{reviewof}}%
    and
    not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related:noterefhelper}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
  \usebibmacro{finentry}}%
  {\usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{cmag+news+title}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cpart+editor+translator}%
  \newcunit%
  \usebibmacro{issuetitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cbyeditor+others}%
  \setunit{\addcomma\addspace}%
  \printfield{note}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cjournal+issue+year+pages}%
  \usebibmacro{eid+fullpostnote}%
  \newcunit\newblock
  \printfield{eid}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldequalstr{relatedtype}{reviewof}}%
    and
    not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related:noterefhelper}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{cite:artwork}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \usebibmacro{citaltitle+stitle}%
  \newcunit\newblock
  \iffieldundef{origyear}% 17th ed.
  {\printdate}%
  {\usebibmacro{cmsorigdate}}%
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit\newblock
  \usebibmacro{cbyeditor+others}%
  \newcunit\newblock
  \ifthenelse{\iffieldundef{origyear}\OR\iffieldundef{year}}% 17th ed.
  {}%
  {\usebibmacro{date}}%
  \newcunit\newblock
  \printfield{type}%
  \newcunit\newblock
  \printfield[type]{version}%
  \newcunit\newblock
  \usebibmacro{cnotefield}%
  \newcunit\newblock
  \usebibmacro{institution+organization}%
  \newcunit\newblock
  \printlist{location}%
  \newcunit\newblock
  \printfield{howpublished}%
  \setunit*{\addspace}%
  \usebibmacro{music+eventdate}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:audio}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{ctitle+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \newcunit
  \usebibmacro{music+eventdate}%
  \newcunit
  \usebibmacro{chapinscore}%
  \usebibmacro{btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{cbyeditor+others}%
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\ifthenelse{\iffieldundef{title}\AND\iffieldundef{booktitle}}%
      {\usebibmacro{cms-in:}}%
      {\bibstring{in}\setunit{\addspace}}%
      \printtext[maintitle]{%
        \printfield[mtnoformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[smtnoformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}
    {\toggletrue{cms@usedvol}%
      \printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}
      \bibstring[\cms@ofwrap]{ofseries}%
      \iftoggle{smartof}{}{\setunit{\addspace}}%
      \printtext[default]{%
        \printfield[title:hook:alt]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[title]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}
      \printfield{maintitleaddon}}}
  \newcunit
  \usebibmacro{volume+or+volumes}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \newcunit\newblock
  \usebibmacro{cnotefield}%
  \newcunit\newblock
  \usebibmacro{cpubl+loc+year}%
  \newcunit
  \printfield{type}%
  \usebibmacro{volfullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{isan}%
    \newcunit\newblock
    \printfield{ismn}}%
  {}%
  \newcunit\newblock%
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{citaltitle+stitle}%
  \setunit{\addspace}%
  \usebibmacro{cite:xref+date}%
  \newcunit
  \iffieldundef{maintitle}%
  {\iffieldundef{edition}%
    {}%
    {\usebibmacro{edition}}%
    \newcunit
    \usebibmacro{version}}% 17th ed.
  {}%
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \newcunit%
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@bookcitexref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@bookcitexref}%
    }%
    {\usebibmacro{cmtitle+mstitle+vol+part+title+stitle}%
      \newcunit\newblock
      \iffieldundef{edition}%
      {}%
      {\usebibmacro{edition}}%
      \newcunit
      \iffieldundef{version}% 17th ed.
      {}%
      {\usebibmacro{version}}%
      \newcunit
      \usebibmacro{cbyeditor+others}%
      \newcunit
      \usebibmacro{volume+or+volumes}%
      \newcunit\newblock
      \usebibmacro{cser+num}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \usebibmacro{cpubl+loc+year}%
      \iftoggle{cms@bookpages}%
      {}%
      {\clearfield{pages}}%
      \usebibmacro{volfullpostnote}%
      \newcunit\newblock
      \printlist[][-\value{listtotal}]{lista}%
      \newcunit\newblock
      \printfield{type}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{book:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
        \newcunit}%
      {\usebibmacro{book:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}% This seems to work.
      {\ifbibliography%
        {\setunit{\bibsentence}}{\addspace\bibsentence}}%
      {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
      \usebibmacro{xrefprenote}% Volume fix
      \bookbibxrefcite{\thefield{xref}}% Removed \addspace from each.
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}% This seems to work.
    {\ifbibliography%
      {\setunit{\bibsentence}}{\addspace\bibsentence}}%
    {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
    \usebibmacro{xrefprenote}% Volume fix
    \bookbibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}

\DeclareBibliographyDriver{cite:bookinbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{citaltitle+stitle}%
  \setunit{\addspace}%
  \usebibmacro{cite:xref+date}%
  \newcunit\newblock
  \usebibmacro{byauthor}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \setunit*{\addcomma\addspace}%
  \ifboolexpr{%
    not togl {cms@citerel}%
    or
    (
    not test {\iffieldequalstr{relatedtype}{maintitle}}%
    and
    not test {\iffieldequalstr{relatedtype}{maintitlenc}}%
    )
    or
    test {\iffieldundef{related}}%
  }%
  {\ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@bookcitexref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@bookcitexref}%
    }%
    {\usebibmacro{cmtitle+mstitle+vol+part+btitle+bstitle}%
      \newcunit
      \iffieldundef{edition}%
      {}%
      {\usebibmacro{edition}}%
      \newcunit
      \usebibmacro{bybookauthor}%
      \usebibmacro{cbyeditor+others}%
      \newcunit
      \usebibmacro{volume+or+volumes}%
      \newcunit\newblock
      \usebibmacro{cser+num}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \usebibmacro{cpubl+loc+year}%
      \usebibmacro{volfullpostnote}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{book:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
        \newcunit}%
      {\usebibmacro{book:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}% This seems to work.
      {\ifbibliography%
        {\setunit{\bibsentence}}{\addspace\bibsentence}}%
      {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
      \usebibmacro{xrefprenote}% Volume fix
      \bookbibxrefcite{\thefield{xref}}% Removed \addspace from each.
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}% This seems to work.
    {\ifbibliography%
      {\setunit{\bibsentence}}{\addspace\bibsentence}}%
    {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
    \usebibmacro{xrefprenote}% Volume fix
    \bookbibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}%
{\entrydata{\thefield{related}}{%
    \ifboolexpr{%
      test {\ifentryseen{\thefield{clonesourcekey}}}%
      and
      not togl {cms@bookcitexref}%
    }%
    {\savefield{clonesourcekey}{\cms@shortmtkey}}%
    {}}%
  \iftoggle{cms@noterefs}{\addtocounter{instcount}{-1}}{}% Alternatives?
  \ifcsundef{cms@shortmtkey}%
  {\unspace% Needed for entries with langid (?)
    \usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related:mtsave}%
    \usebibmacro{related}%
    \newcunit%
    \usebibmacro{finentry}}%
  {\ifpunctmark{.}% This seems to work.
    {\ifbibliography%
      {\setunit{\bibsentence}}{\addspace\bibsentence}}%
    {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
    \usebibmacro{xrefprenote}% Volume fix
    \bookbibxrefcite{\csuse{cms@shortmtkey}}%
    \usebibmacro{xrefpostnote}%
    \csgundef{cms@shortmtkey}%
    \usebibmacro{finentry}}}}

\DeclareBibliographyDriver{cite:booklet}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \usebibmacro{citaltitle+stitle}%
  \newcunit\newblock
  \usebibmacro{byauthor}%
  \newcunit
  \usebibmacro{cnotefield}%
  \setunit{\addspace}\newblock%
  \printtext[parens]{%
  \usebibmacro{howpubl+loc+year}}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:collection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock%
  \usebibmacro{citaltitle+stitle}%
  \setunit{\addspace}
  \usebibmacro{cite:xref+date}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \newcunit
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@bookcitexref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@bookcitexref}%
    }%
    {\usebibmacro{cmtitle+mstitle+vol+part+title+stitle}%
      \newcunit\newblock
      \iffieldundef{edition}%
      {}%
      {\usebibmacro{edition}}%
      \newcunit
      \usebibmacro{cbyeditor+others}%
      \newcunit\newblock
      \usebibmacro{volume+or+volumes}%
      \newcunit\newblock
      \usebibmacro{cser+num}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \usebibmacro{cpubl+loc+year}%
      \usebibmacro{volfullpostnote}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{book:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
        \newcunit}%
      {\usebibmacro{book:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}% This seems to work.
      {\ifbibliography%
        {\setunit{\bibsentence}}{\addspace\bibsentence}}%
      {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
      \usebibmacro{xrefprenote}% Volume fix
      \bookbibxrefcite{\thefield{xref}}% Removed \addspace from each.
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}% This seems to work. Only with Vol?
    {\ifbibliography%
      {\setunit{\bibsentence}}{\addspace\bibsentence}}%
    {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
    \usebibmacro{xrefprenote}% Volume fix
    \bookbibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}

\DeclareBibliographyDriver{cite:customc}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{justauthor}%
  \ifboolexpr{%
    test {\iffieldundef{nameaddon}}%
    or
    togl {cms@citenona}%
  }%
  {\newcunit}%
  {\setunit{\addspace}}%
  \usebibmacro{italtitle+stitle}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:dataset}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \iftoggle{cms@headlessnote}{}{\setunit{\addspace}\newblock}%
  \printtext[parens]{%
    \printfield{title}%
    \setunit{\subtitlepunct}%
    \printfield[noformat]{subtitle}%
    \setunit{\ctitleaddonpunct}%
    \printfield{titleaddon}%
    \setunit{\addspace}%
    \usebibmacro{language+transtitle}%
    \newcunit
    \usebibmacro{byauthor}%
    \newcunit\newblock
    \usebibmacro{cbyeditor+others}%
    \setunit{\addspace}\newblock%
    \ifthenelse{\iffieldundef{howpublished}\AND%
      \iffieldundef{number}\AND\iffieldundef{type}}%
    {}%
    {\printtext[parens]{%
        \printfield{howpublished}%
        \newcunit
        \printfield{type}%
        \setunit{\addspace}%
        \printfield{number}}}%
    \newcunit\newblock
    \printfield{version}%
    \newcunit\newblock
    \printfield{note}%
    \newcunit\newblock
    \usebibmacro{institution+organization}%
    \newcunit\newblock
    \printlist{location}%
    \setunit{\addsemicolon\addspace}%
    \printurldate%
    \ifboolexpr{%
      togl {cms@urltime}%
      and
      not test {\iffieldundef{urlhour}}%
    }%
    {\newcunit\printurltime}%
    {}}%
  \usebibmacro{fullpostnote}%
  \newcunit\newblock
  \iffieldundef{pubstate}%
  {}%
  {\iffieldbibstring{pubstate}%
    {\bibsstring{\thefield{pubstate}}}%
    {\printfield[prenote]{pubstate}}%
    \setunit{\addspace}}%
  \usebibmacro{date}%
  \clearfield{urlyear}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:image}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \usebibmacro{citaltitle+stitle}%
  \newcunit%\setunit{\addcomma\addspace}%
  \iffieldundef{origyear}% 17th ed.
  {\printdate}%
  {\usebibmacro{cmsorigdate}}%
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit\newblock
  \usebibmacro{cbyeditor+others}%
  \newcunit\newblock
  \ifthenelse{\iffieldundef{origyear}\OR\iffieldundef{year}}% 17th ed.
  {}%
  {\usebibmacro{date}}%
  \newcunit\newblock
  \printfield{type}%
  \newcunit\newblock
  \printfield[type]{version}%
  \newcunit\newblock
  \usebibmacro{cnotefield}%
  \newcunit\newblock
  \usebibmacro{institution+organization}%
  \newcunit\newblock
  \printlist{location}%
  \newcunit\newblock
  \printfield{howpublished}% 17th ed.
  \setunit*{\addspace}%
  \usebibmacro{music+eventdate}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:inbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{ctitle+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cpart+editor+translator}%
  \setunit{\addcomma\addspace}%
  \ifboolexpr{%
    not togl {cms@citerel}%
    or
    (
    not test {\iffieldequalstr{relatedtype}{maintitle}}%
    and
    not test {\iffieldequalstr{relatedtype}{maintitlenc}}%
    )
    or
    test {\iffieldundef{related}}%
  }%
  {\ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@citecrossref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@citecrossref}%
    }%
    {\usebibmacro{chapincoll}%
      \usebibmacro{cmtitle+mstitle+vol+part+btitle+bstitle}%
      \newcunit
      \iffieldundef{edition}%
      {}%
      {\usebibmacro{edition}}%
      \newcunit
      \usebibmacro{bybookauthor}%
      \usebibmacro{cbyeditor+others}%
      \newcunit
      \usebibmacro{volume+or+volumes}%
      \newcunit\newblock
      \usebibmacro{cser+num}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \usebibmacro{cpubl+loc+year}%
      \usebibmacro{volfullpostnote}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{cite:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
        \newcunit}%
      {\usebibmacro{cite:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
      \usebibmacro{xrefprenote}% Volume fix
      \usebibmacro{xrefchapincoll}%
      \bibxrefcite{\thefield{xref}}% Removed \addspace from each.
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
    \usebibmacro{xrefprenote}% Volume fix
    \usebibmacro{xrefchapincoll}%
    \bibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}%
{\usebibmacro{extract+clonekey+note}%
  \ifcsundef{cms@shortmtkey}%
  {\unspace% Needed for entries with langid (?)
    \usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related:mtsave}%
    \usebibmacro{related}%
    \newcunit%
    \usebibmacro{finentry}}%
  {\ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
    \usebibmacro{xrefprenote}% Volume fix
    \usebibmacro{xrefchapincoll}%
    \bibxrefcite{\csuse{cms@shortmtkey}}%
    \usebibmacro{xrefpostnote}%
    \csgundef{cms@shortmtkey}%
    \usebibmacro{finentry}}}}

\DeclareBibliographyDriver{cite:incollection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock%
  \usebibmacro{ctitle+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cpart+editor+translator}%
  \setunit{\addcomma\addspace}%
  \ifboolexpr{%
    not togl {cms@citerel}%
    or
    (
    not test {\iffieldequalstr{relatedtype}{maintitle}}%
    and
    not test {\iffieldequalstr{relatedtype}{maintitlenc}}%
    )
    or
    test {\iffieldundef{related}}%
  }%
  {\ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@citecrossref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@citecrossref}%
    }%
    {\usebibmacro{chapincoll}%
      \usebibmacro{cmtitle+mstitle+vol+part+btitle+bstitle}%
      \newcunit
      \iffieldundef{edition}%
      {}%
      {\usebibmacro{edition}}%
      \newcunit
      \usebibmacro{bybookauthor}%
      \usebibmacro{cbyeditor+others}%
      \newcunit
      \usebibmacro{volume+or+volumes}%
      \newcunit\newblock
      \usebibmacro{cser+num}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \usebibmacro{cpubl+loc+year}%
      \usebibmacro{volfullpostnote}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{cite:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
        \newcunit}%
      {\usebibmacro{cite:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
      \usebibmacro{xrefprenote}% Volume fix
      \usebibmacro{xrefchapincoll}%
      \bibxrefcite{\thefield{xref}}% Removed \addspace from each.
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
    \usebibmacro{xrefprenote}% Volume fix
    \usebibmacro{xrefchapincoll}%
    \bibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}%
{\usebibmacro{extract+clonekey+note}%
  \ifcsundef{cms@shortmtkey}%
  {\unspace% Needed for entries with langid (?)
    \usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related:mtsave}%
    \usebibmacro{related}%
    \newcunit%
    \usebibmacro{finentry}}%
  {\ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
    \usebibmacro{xrefprenote}% Volume fix
    \usebibmacro{xrefchapincoll}%
    \bibxrefcite{\csuse{cms@shortmtkey}}%
    \usebibmacro{xrefpostnote}%
    \csgundef{cms@shortmtkey}%
    \usebibmacro{finentry}}}}

\DeclareBibliographyDriver{cite:inproceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{ctitle+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cpart+editor+translator}%
  \setunit{\addcomma\addspace}%
  \ifboolexpr{%
    not togl {cms@citerel}%
    or
    (
    not test {\iffieldequalstr{relatedtype}{maintitle}}%
    and
    not test {\iffieldequalstr{relatedtype}{maintitlenc}}%
    )
    or
    test {\iffieldundef{related}}%
  }%
  {\ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@citecrossref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@citecrossref}%
    }%
    {\usebibmacro{chapincoll}%
      \usebibmacro{cmtitle+mstitle+vol+part+btitle+bstitle}%
      \newcunit\newblock
      \usebibmacro{cbyeditor+others}%
      \newcunit\newblock
      \usebibmacro{volume+or+volumes}%
      \newcunit\newblock
      \usebibmacro{cser+num}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \printfield{eventtitle}%
      \setunit{\ctitleaddonpunct}%
      \printfield{eventtitleaddon}%
      \newcunit%
      \printfield{venue}%
      \newcunit\newblock
      \printeventdate%
      \setunit{\addspace}\newblock%
      \printtext[parens]{%
        \usebibmacro{org+publ+loc+year}}%
      \usebibmacro{volfullpostnote}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{cite:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
        \newcunit}%
      {\usebibmacro{cite:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
      \usebibmacro{xrefprenote}% Volume fix
      \usebibmacro{xrefchapincoll}%
      \bibxrefcite{\thefield{xref}}%
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
    \usebibmacro{xrefprenote}% Volume fix
    \usebibmacro{xrefchapincoll}%
    \bibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}%
{\usebibmacro{extract+clonekey+note}%
  \ifcsundef{cms@shortmtkey}%
  {\unspace% Needed for entries with langid (?)
    \usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related:mtsave}%
    \usebibmacro{related}%
    \newcunit%
    \usebibmacro{finentry}}%
  {\ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
    \usebibmacro{xrefprenote}% Volume fix
    \usebibmacro{xrefchapincoll}%
    \bibxrefcite{\csuse{cms@shortmtkey}}%
    \usebibmacro{xrefpostnote}%
    \csgundef{cms@shortmtkey}%
    \usebibmacro{finentry}}}}

\DeclareBibliographyDriver{cite:inreference}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \iffieldundef{clonesourcekey}{}{\newcunit}%
  \usebibmacro{citaltitle+stitle}%
  \newcunit\newblock
  \ifthenelse{\iffieldundef{maintitle}\AND\iffieldundef{booktitle}}%
  {\iffieldundef{edition}%
    {}%
    {\usebibmacro{edition}}}%
  {}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cmtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{cbyeditor+others}%
  \newcunit
  \usebibmacro{volume+or+volumes}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \newcunit\newblock
  \usebibmacro{crefpubl+loc+year}% 17th ed.
  \usebibmacro{inreffullpostnote}%
  \newcunit\newblock%setunit{\addspace}% 16th ed
  \ifnameundef{author}%
  {}%
  {\printtext{% 16th ed
      \bibstring{by}%
      \addspace%
      \printnames{author}}}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:jurisdiction}{%
  \iffieldequalstr{entrysubtype}{square}% FIXME?
  {\usebibmacro{bibindex}%
    \usebibmacro{begentry}%
    \usebibmacro{clegis+news+title}%
    \setunit{\addspace}%
    \usebibmacro{language+transtitle}%
    \setunit{\addcomma\addspace}%
    \usebibmacro{byauthor}%
    \setunit{\addcomma\addspace}%
    \usebibmacro{cpart+editor+translator}%
    \newcunit%
    \usebibmacro{issuetitle}%
    \setunit{\addcomma\addspace}%
    \usebibmacro{cbyeditor+others}%
    \setunit{\addcomma\addspace}%
    \printfield[juridnum]{number}%
    \newcunit%
    \iffieldundef{year}%
    {}%
    {\printtext[brackets]{%
      \begingroup% Better ideas?
      \let\abx@bibmonth\blx@imc@bibsstring%
      \usebibmacro{date}\endgroup}}%
    \setunit*{\addspace}%
    \printfield[jourvol]{volume}%
    \setunit{\addnbspace}%
    \iffieldundef{shortjournal}%
    {}%
    {\printtext[shortjournal]{%
      \printfield[jtsnoformat]{shortjournal}}}%
    \iffieldundef{issue}%
    {\printfield[jurisdictionser]{series}}%
    {\setunit{\addspace}%
      \printfield{issue}}% Better ideas?
    \usebibmacro{juridpostnote}%
    \setunit{\addcomma\addspace}%
    \printfield{note}%
    \setunit{\addspace}%
    \printlist{location}%
    \setunit{\shorthandpunct}%
    \usebibmacro{cms:shorthandintro}% Moved before addendum
    \setunit{\addspace}\newblock
    \printfield{addendum}%
    \newcunit\newblock
    \iftoggle{cms@isbn}%
    {\printfield{issn}}%
    {}%
    \newcunit\newblock
    \usebibmacro{cite+doi+url}%
    \newcunit\newblock
    \usebibmacro{pageref}%
    \newcunit\newblock
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}
  {\iffieldequalstr{entrysubtype}{round}% FIXME?
    {\usebibmacro{bibindex}%
      \usebibmacro{begentry}%
      \usebibmacro{clegis+news+title}%
      \setunit{\addspace}%
      \usebibmacro{language+transtitle}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{byauthor}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{cpart+editor+translator}%
      \newcunit%
      \usebibmacro{issuetitle}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{cbyeditor+others}%
      \setunit{\addcomma\addspace}%
      \printfield[juridnum]{number}%
      \newcunit%
      \iffieldundef{year}%
      {}%
      {\printtext[parens]{%
        \begingroup% Better ideas?
        \let\abx@bibmonth\blx@imc@bibsstring%
        \usebibmacro{date}\endgroup}}%
      \setunit*{\addspace}%
      \printfield[jourvol]{volume}%
      \setunit{\addnbspace}%
      \iffieldundef{shortjournal}%
      {}%
      {\printtext[shortjournal]{%
        \printfield[jtsnoformat]{shortjournal}}}%
      \iffieldundef{issue}%
      {\printfield[jurisdictionser]{series}}%
      {\setunit{\addspace}%
        \printfield{issue}}% Better ideas?
      \usebibmacro{juridpostnote}%
      \setunit{\addcomma\addspace}%
      \printfield{note}%
      \setunit{\addspace}%
      \printlist{location}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}% Moved before addendum
      \setunit{\addspace}\newblock
      \printfield{addendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{issn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}
    {\usebibmacro{bibindex}%
      \usebibmacro{begentry}%
      \usebibmacro{clegis+news+title}%
      \setunit{\addspace}%
      \usebibmacro{language+transtitle}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{byauthor}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{cpart+editor+translator}%
      \newcunit%
      \usebibmacro{issuetitle}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{cbyeditor+others}%
      \setunit{\addcomma\addspace}%
      \printfield[juridnum]{number}%
      \newcunit%
      \printfield[jourvol]{volume}%
      \setunit*{\addnbspace}%
      \iffieldundef{shortjournal}%
      {}%
      {\printtext[shortjournal]{%
        \printfield[jtsnoformat]{shortjournal}}}%
      \iffieldundef{issue}%
      {\printfield[jurisdictionser]{series}}%
      {\setunit{\addspace}%
        \printfield{issue}}% Better ideas?
      \setunit{\addspace}%
      \printlist{origpublisher}% Extra reporters, same pagination
      \usebibmacro{juridpostnote}%
      \setunit{\addcomma\addspace}%
      \printlist{origlocation}% Extra reporters, different pagination
      \setunit{\addcomma\addspace}%
      \printfield{note}%
      \setunit{\addspace}%
      \ifboolexpr{%
        test {\iffieldundef{year}}%
        and
        test {\iflistundef{location}}%
      }%
      {}%
      {\printtext[parens]{%
        \printlist{location}%
        \setunit*{\addspace}%
        \begingroup% Better ideas?
        \let\abx@bibmonth\blx@imc@bibsstring%
        \usebibmacro{date}\endgroup}}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}% Moved before addendum
      \setunit{\addspace}\newblock
      \printfield{addendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{issn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}}

\DeclareBibliographyDriver{cite:legal}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{clegis+news+title}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cpart+editor+translator}%
  \newcunit%
  \usebibmacro{issuetitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cbyeditor+others}%
  \setunit{\addcomma\addspace}%
  \printfield[juridnum]{number}%
  \newcunit%
  \iffieldundef{year}%
  {}%
  {\printtext{%
    \begingroup% Better ideas?
    \let\abx@bibmonth\blx@imc@bibsstring%
    \usebibmacro{date}\endgroup}}%
  \newcunit%\setunit*{\addspace}%
  \printfield[jourvol]{volume}%
  \setunit*{\addnbspace}%
  \iffieldundef{shortjournal}%
  {}%
  {\printtext[shortjournal]{%
    \printfield[jtsnoformat]{shortjournal}}}%
  \setunit{\addspace}%
  \printfield{series}%
  \setunit{\addspace}%
  \printfield{issue}%
  \newcunit%
  \printfield{part}%
  \newcunit%
  \printfield{chapter}%
  \usebibmacro{juridpostnote}%
  \setunit{\addcomma\addspace}%
  \printfield{note}%
  \setunit{\addspace}%
  \printlist{location}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}% Moved before addendum
  \setunit{\addspace}\newblock%
  \printfield{addendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:legislation}{%
  \iffieldequalstr{entrysubtype}{uk}% FIXME?
  {\usebibmacro{bibindex}%
    \usebibmacro{begentry}%
    \usebibmacro{author/editor}%
    \usebibmacro{hlpunct}%\newcunit\newblock
    \usebibmacro{clegis+news+title}%
    \setunit{\addspace}%
    \usebibmacro{language+transtitle}%
    \setunit{\addcomma\addspace}%
    \usebibmacro{byauthor}%
    \setunit{\addcomma\addspace}%
    \usebibmacro{cpart+editor+translator}%
    \newcunit%
    \usebibmacro{issuetitle}%
    \setunit{\addcomma\addspace}%
    \usebibmacro{cbyeditor+others}%
    \setunit{\addcomma\addspace}%
    \printfield[juridnum]{number}%
    \setunit{\addcomma\addspace}%
    \printfield{note}% Needed here?
    \newcunit%
    \iffieldundef{year}%
    {}%
    {\printtext{%
      \begingroup% Better ideas?
      \let\abx@bibmonth\blx@imc@bibsstring%
      \usebibmacro{date}\endgroup}}%
    \newcunit%\setunit*{\addspace}%
    \printfield[jourvol]{volume}%
    \setunit*{\addnbspace}%
    \iffieldundef{shortjournal}%
    {}%
    {\printtext[shortjournal]{%
      \printfield[jtsnoformat]{shortjournal}}}%
    \setunit{\addspace}%
    \printfield{series}%
    \setunit{\addspace}%
    \printfield{issue}%
    \newcunit%
    \printfield{part}%
    \newcunit%
    \printfield{chapter}%
    \usebibmacro{juridpostnote}%
    \setunit{\addspace}%
    \printlist{location}%
    \setunit{\shorthandpunct}%
    \usebibmacro{cms:shorthandintro}% Moved before addendum
    \setunit{\addspace}\newblock%
    \printfield{addendum}%
    \newcunit\newblock
    \iftoggle{cms@isbn}%
    {\printfield{issn}}%
    {}%
    \newcunit\newblock
    \usebibmacro{cite+doi+url}%
    \newcunit\newblock
    \usebibmacro{pageref}%
    \newcunit\newblock
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}
  {\iffieldequalstr{entrysubtype}{hansard}% FIXME?
    {\usebibmacro{bibindex}%
      \usebibmacro{begentry}%
      \usebibmacro{author/editor}%
      \usebibmacro{hlpunct}%\newcunit\newblock
      \usebibmacro{clegis+news+title}%
      \setunit{\addspace}%
      \usebibmacro{language+transtitle}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{byauthor}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{cpart+editor+translator}%
      \newcunit%
      \usebibmacro{issuetitle}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{cbyeditor+others}%
      \setunit{\addcomma\addspace}%
      \printfield[juridnum]{number}%
      \setunit{\addcomma\addspace}%
      \printfield{note}% Needed here?
      \newcunit%
      \printfield[jourvol]{volume}%
      \setunit*{\addnbspace}%
      \iffieldundef{shortjournal}%
      {}%
      {\printtext[shortjournal]{%
        \printfield[jtsnoformat]{shortjournal}}}%
      \setunit{\addspace}%
      \printfield[hansardser]{series}%
      \setunit{\addspace}%
      \iffieldundef{year}%
      {}%
      {\printtext[parens]{%
        \begingroup% Better ideas?
        \let\abx@bibmonth\blx@imc@bibsstring%
        \usebibmacro{date}\endgroup}}%
      \usebibmacro{juridpostnote}%
      \setunit{\addspace}%
      \printlist{location}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}% Moved before addendum
      \setunit{\addspace}\newblock%
      \printfield{addendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{issn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}
    {\usebibmacro{bibindex}%
      \usebibmacro{begentry}%
      \usebibmacro{author/editor}%
      \usebibmacro{hlpunct}%\newcunit\newblock
      \usebibmacro{clegis+news+title}%
      \setunit{\addspace}%
      \usebibmacro{language+transtitle}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{byauthor}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{cpart+editor+translator}%
      \newcunit%
      \usebibmacro{issuetitle}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{cbyeditor+others}%
      \setunit{\addspace}% FIXME?
      \printfield[juridnum]{number}%
      \setunit{\addcomma\addspace}%
      \printfield{note}% Needed here?
      \newcunit%
      \printfield[jourvol]{volume}%
      \setunit*{\addnbspace}%
      \iffieldundef{shortjournal}%
      {}%
      {\printtext[shortjournal]{%
        \printfield[jtsnoformat]{shortjournal}}}%
      \newcunit%
      \printfield{series}%
      \setunit{\addspace}%
      \printfield{issue}%
      \newcunit%
      \printfield{part}%
      \newcunit%
      \printfield{chapter}%
      \usebibmacro{juridpostnote}%
      \setunit{\addspace}%
      \ifboolexpr{%
        test {\iffieldundef{year}}%
        and
        test {\iffieldundef{usera}}%
        and
        test {\iflistundef{location}}%
      }%
      {}%
      {\printtext[parens]{%
          \printlist{location}%
          \setunit*{\addspace}%
          \printfield{usera}%
          \setunit*{\addspace}%
          \begingroup% Better ideas?
          \let\abx@bibmonth\blx@imc@bibsstring%
          \usebibmacro{date}\endgroup}}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \setunit{\addspace}\newblock%
      \printfield{addendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{issn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}}

\DeclareBibliographyDriver{cite:letter}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \savefield{fullhash}{\bbx@lasthash}%
  \printtext[title]{%
    \printfield[noformat]{title}}%
  \setunit{\ctitleaddonpunct}%
  \printfield{titleaddon}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{letter+date}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newcunit\newblock%
  \usebibmacro{cpart+editor+translator}%
  \setunit*{\addcomma\addspace}%
  \ifboolexpr{%
    not togl {cms@citerel}%
    or
    (
    not test {\iffieldequalstr{relatedtype}{maintitle}}%
    and
    not test {\iffieldequalstr{relatedtype}{maintitlenc}}%
    )
    or
    test {\iffieldundef{related}}%
  }%
  {\ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@citecrossref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@citecrossref}%
    }%
    {\usebibmacro{chapincoll}%
      \usebibmacro{cmtitle+mstitle+vol+part+btitle+bstitle}%
      \newcunit
      \iffieldundef{edition}%
      {}%
      {\usebibmacro{edition}}%
      \newcunit
      \usebibmacro{bybookauthor}%
      \usebibmacro{cbyeditor+others}%
      \newcunit
      \usebibmacro{volume+or+volumes}%
      \newcunit\newblock
      \usebibmacro{cser+num}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \usebibmacro{cpubletter+loc+year}%
      \usebibmacro{volfullpostnote}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{cite:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
      \newcunit}%
      {\usebibmacro{cite:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
      \usebibmacro{xrefprenote}% Volume fix
      \usebibmacro{xrefchapincoll}%
      \bibxrefcite{\thefield{xref}}%
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
    \usebibmacro{xrefprenote}% Volume fix
    \usebibmacro{xrefchapincoll}%
    \bibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}%
{\usebibmacro{extract+clonekey+note}%
  \ifcsundef{cms@shortmtkey}%
  {\unspace% Needed for entries with langid (?)
    \usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related:mtsave}%
    \usebibmacro{related}%
    \newcunit%
    \usebibmacro{finentry}}%
  {\ifpunctmark{.}{\setunit{\addspace\bibsentence}}{\newcunit}% 16th ed.
    \usebibmacro{xrefprenote}% Volume fix
    \usebibmacro{xrefchapincoll}%
    \bibxrefcite{\csuse{cms@shortmtkey}}%
    \usebibmacro{xrefpostnote}%
    \csgundef{cms@shortmtkey}%
    \usebibmacro{finentry}}}}

\DeclareBibliographyDriver{cite:manual}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author+org}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock%
  \usebibmacro{citaltitle+stitle}%
  \newcunit
  \usebibmacro{edition}%
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \newcunit\newblock
  \printfield{type}%
  \newcunit
  \usebibmacro{cnotefield}%
  \setunit{\addspace}\newblock%
  \printtext[parens]{%
  \usebibmacro{org+publ+loc+year}}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:misc}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \iffieldundef{entrysubtype}%
  {\usebibmacro{citaltitle+stitle}}%
  {\printfield{title}%
    \setunit{\subtitlepunct}%
    \printfield[noformat]{subtitle}%
    \setunit{\ctitleaddonpunct}%
    \printfield{titleaddon}%
    \setunit{\addspace}%
    \usebibmacro{language+transtitle}%
    \newcunit%
    \usebibmacro{unpubl+letter+date}%
    \newcunit
    \printlist{origlocation}}% 17th ed.
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit\newblock
  \usebibmacro{cbyeditor+others}%
  \newcunit\newblock
  \printfield{howpublished}%
  \newcunit\newblock
  \printfield{type}%
  \newcunit\newblock
  \printfield{version}%
  \newcunit\newblock
  \printfield{note}%
  \newcunit\newblock
  \iffieldundef{entrysubtype}%
  {\printfield{venue}\newcunit}%
  {}%
  \usebibmacro{misc+institution+organization}%
  \newcunit\newblock
  \printlist{location}%
  \iffieldundef{entrysubtype}%
  {\newcunit\newblock
    \usebibmacro{date}}%
  {}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:music}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \usebibmacro{citaltitle+stitle}%
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit\newblock
  \usebibmacro{cpart+editor+translator}%
  \newcunit\newblock
  \ifthenelse{\iffieldundef{booktitle}\AND\iffieldundef{entrysubtype}}%
  {\usebibmacro{cbyeditor+others}\newcunit\newblock}{}%
  \usebibmacro{music+eventdate}%
  \newcunit\newblock
  \usebibmacro{cnotefield}%
  \newcunit\newblock
  \printfield{howpublished}%
  \newcunit\newblock
  \usebibmacro{chap+as+track}%inscore% 17th ed.
  \usebibmacro{music+bookauthor}% Ditto
  \usebibmacro{btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \ifthenelse{\iffieldundef{booktitle}\AND\iffieldundef{entrysubtype}}%
  {}{\usebibmacro{cbyeditor+others}}%
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\ifthenelse{\iffieldundef{title}\AND\iffieldundef{booktitle}}%
      {\usebibmacro{cms-in:}}%
      {\bibstring{in}\setunit{addspace}}%
      \printtext[maintitle]{%
        \printfield[mtnoformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[smtnoformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}
    {\toggletrue{cms@usedvol}%
      \printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}
      \bibstring[\cms@ofwrap]{ofseries}%
      \iftoggle{smartof}{}{\setunit{\addspace}}%
      \printtext[default]{%
        \printfield[title:hook:alt]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[title]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}}
  \newcunit
  \usebibmacro{volume+or+volumes}%
  \newcunit\newblock
  \printfield{version}%
  \newcunit\newblock
  \usebibmacro{music+origdate}% Altered for 17th ed.
  \newcunit\newblock
  \printlist{publisher}%
  \newcunit\newblock
  \usebibmacro{series+or+shortser}%
  \ifboolexpr{test {\iflistundef{publisher}} and test {\iffieldundef{series}}}%
  {\newcunit}%
  {\setunit{\addspace}}%
  \printfield{number}%
  \newcunit\newblock
  \usebibmacro{date}%
  \newcunit
  \usebibmacro{institution+organization}%
  \newcunit\newblock
  \printlist{location}%
  \newcunit\newblock
  \printfield{type}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \usebibmacro{music+pubstate}% 17th ed.
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{iswc}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:mvbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{citaltitle+stitle}%
  \setunit{\addspace}%
  \usebibmacro{cite:xref+date}%
  \usebibmacro{mt+mvnames+save}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit
  \usebibmacro{cbyeditor+others}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \ifthenelse{\iffieldequalstr{relatedtype}{maintitle}\OR%
    \iffieldequalstr{relatedtype}{maintitlenc}}{}%
  {\newcunit
    \usebibmacro{volume+or+volumes}}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \ifboolexpr{%
    not togl {cms@citerel}%
    or
    (
    not test {\iffieldequalstr{relatedtype}{maintitle}}%
    and
    not test {\iffieldequalstr{relatedtype}{maintitlenc}}%
    )
    or
    test {\iffieldundef{related}}%
  }%
  {\ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@bookcitexref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@bookcitexref}%
    }%
    {\usebibmacro{cmtitle+mstitle+vol+part+title+stitle}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \usebibmacro{cpubl+loc+year}%
      \iftoggle{cms@bookpages}%
      {}%
      {\clearfield{pages}}%
      \usebibmacro{volfullpostnote}%
      \newcunit\newblock
      \printlist[][-\value{listtotal}]{lista}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{book:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
        \newcunit}%
      {\usebibmacro{book:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}% This seems to work.
      {\ifbibliography%
        {\setunit{\bibsentence}}{\addspace\bibsentence}}%
      {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
      \usebibmacro{xrefprenote}% Volume fix
      \bookbibxrefcite{\thefield{xref}}% Removed \addspace from each.
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}% This seems to work.
    {\ifbibliography%
      {\setunit{\bibsentence}}{\addspace\bibsentence}}%
    {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
    \usebibmacro{xrefprenote}% Volume fix
    \bookbibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}%
{\unspace% Needed for entries with langid (?)
  \usebibmacro{related:init}%
  \usebibmacro{related:noterefhelper}%
  \usebibmacro{related:mtsave}%
  \usebibmacro{related}%
  \newcunit%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{cite:mvcollection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock%
  \usebibmacro{citaltitle+stitle}%
  \setunit{\addspace}
  \usebibmacro{cite:xref+date}%
  \usebibmacro{mt+mvnames+save}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \newcunit
  \usebibmacro{cbyeditor+others}%
  \newcunit\newblock
  \ifthenelse{\iffieldequalstr{relatedtype}{maintitle}\OR%
    \iffieldequalstr{relatedtype}{maintitlenc}}{}%
  {\newcunit\newblock
    \usebibmacro{volume+or+volumes}}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \ifboolexpr{%
    not togl {cms@citerel}%
    or
    (
    not test {\iffieldequalstr{relatedtype}{maintitle}}%
    and
    not test {\iffieldequalstr{relatedtype}{maintitlenc}}%
    )
    or
    test {\iffieldundef{related}}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{crossref}}%
      or
      not test {\ifentryseen{\thefield{crossref}}}%
      or
      togl {cms@bookcitexref}%
    }%
    {\ifboolexpr{%
        test {\iffieldundef{xref}}%
        or
        not test {\ifentryseen{\thefield{xref}}}%
        or
        togl {cms@bookcitexref}%
      }%
      {\usebibmacro{cmtitle+mstitle+vol+part+title+stitle}%
        \newcunit\newblock
        \usebibmacro{cnotefield}%
        \newcunit\newblock
        \usebibmacro{cpubl+loc+year}%
        \usebibmacro{volfullpostnote}%
        \usebibmacro{caddendum}%
        \newcunit\newblock
        \iftoggle{cms@isbn}%
        {\printfield{isbn}}%
        {}%
        \newcunit\newblock
        \usebibmacro{cite+doi+url}%
        \setunit{\shorthandpunct}%
        \usebibmacro{cms:shorthandintro}%
        \newcunit\newblock
        \usebibmacro{pageref}%
        \newcunit\newblock
        \ifboolexpr{%
          togl {cms@citerel}%
          and
          not test {\iffieldundef{related}}%
        }%
        {\usebibmacro{book:xref+finentry}%
          \usebibmacro{related:init}%
          \usebibmacro{related:noterefhelper}%
          \usebibmacro{related}%
          \newcunit}%
        {\usebibmacro{book:xref+finentry}}%
        \usebibmacro{finentry}}%
      {\ifboolexpr{%
          togl {cms@citerel}%
          and
          not test {\iffieldundef{related}}%
        }%
        {\usebibmacro{related:noterefhelper}}%
        {}%
        \ifpunctmark{.}% This seems to work.
        {\ifbibliography%
          {\setunit{\bibsentence}}{\addspace\bibsentence}}%
        {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
        \usebibmacro{xrefprenote}% Volume fix
        \bookbibxrefcite{\thefield{xref}}% Removed \addspace from each.
        \usebibmacro{xrefpostnote}%
        \ifboolexpr{%
          togl {cms@citerel}%
          and
          not test {\iffieldundef{related}}%
        }%
        {\usebibmacro{related:init}%
          \usebibmacro{related}%
          \newcunit}%
        {}%
        \usebibmacro{finentry}}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}% This seems to work. Only with Vol?
      {\ifbibliography%
        {\setunit{\bibsentence}}{\addspace\bibsentence}}%
      {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
      \usebibmacro{xrefprenote}% Volume fix
      \bookbibxrefcite{\thefield{crossref}}%
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\unspace% Needed for entries with langid (?)
    \usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related:mtsave}%
    \usebibmacro{related}%
    \newcunit%
    \usebibmacro{finentry}}}%

\DeclareBibliographyDriver{cite:mvproceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock%
  \usebibmacro{citaltitle+stitle}%
  \setunit{\addspace}
  \usebibmacro{cite:xref+date}%
  \usebibmacro{mt+mvnames+save}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \newcunit
  \usebibmacro{cbyeditor+others}%
  \newcunit\newblock
  \ifthenelse{\iffieldequalstr{relatedtype}{maintitle}\OR%
    \iffieldequalstr{relatedtype}{maintitlenc}}{}%
  {\newcunit\newblock
    \usebibmacro{volume+or+volumes}}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \ifboolexpr{%
    not togl {cms@citerel}%
    or
    (
    not test {\iffieldequalstr{relatedtype}{maintitle}}%
    and
    not test {\iffieldequalstr{relatedtype}{maintitlenc}}%
    )
    or
    test {\iffieldundef{related}}%
  }%
  {\ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@bookcitexref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@bookcitexref}%
    }%
    {\usebibmacro{cmtitle+mstitle+vol+part+title+stitle}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \printfield{eventtitle}%
      \setunit{\ctitleaddonpunct}%
      \printfield{eventtitleaddon}%
      \newcunit%
      \printfield{venue}%
      \newcunit\newblock
      \printeventdate%
      \setunit{\addspace}\newblock%
      \printtext[parens]{%
        \usebibmacro{org+publ+loc+year}}%
      \usebibmacro{volfullpostnote}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{book:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
        \newcunit}%
      {\usebibmacro{book:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}% This seems to work.
      {\ifbibliography%
        {\setunit{\bibsentence}}{\addspace\bibsentence}}%
      {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
      \usebibmacro{xrefprenote}% Volume fix
      \bookbibxrefcite{\thefield{xref}}% Removed \addspace from each.
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}% This seems to work.
    {\ifbibliography%
      {\setunit{\bibsentence}}{\addspace\bibsentence}}%
    {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
    \usebibmacro{xrefprenote}% Volume fix
    \bookbibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}%
{\unspace% Needed for entries with langid (?)
  \usebibmacro{related:init}%
  \usebibmacro{related:noterefhelper}%
  \usebibmacro{related:mtsave}%
  \usebibmacro{related}%
  \newcunit%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{cite:mvreference}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{citaltitle+stitle}%
  \newcunit\newblock
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \newcunit
  \usebibmacro{cbyeditor+others}%
  \ifthenelse{\iffieldequalstr{relatedtype}{maintitle}\OR%
    \iffieldequalstr{relatedtype}{maintitlenc}}{}%
  {\newcunit
    \usebibmacro{volume+or+volumes}}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \setunit*{\addcomma\addspace}%
  \ifboolexpr{%
    not togl {cms@citerel}%
    or
    (
    not test {\iffieldequalstr{relatedtype}{maintitle}}%
    and
    not test {\iffieldequalstr{relatedtype}{maintitlenc}}%
    )
    or
    test {\iffieldundef{related}}%
  }%
  {\usebibmacro{cmtitle+mstitle+vol+part+btitle+bstitle}%
    \newcunit\newblock
    \usebibmacro{crefpubl+loc+year}%
    \usebibmacro{volfullpostnote}%
    \usebibmacro{caddendum}%
    \newcunit\newblock
    \iftoggle{cms@isbn}%
    {\printfield{isbn}}%
    {}%
    \newcunit\newblock
    \usebibmacro{cite+doi+url}%
    \setunit{\shorthandpunct}%
    \usebibmacro{cms:shorthandintro}%
    \newcunit\newblock
    \usebibmacro{pageref}%
    \newcunit\newblock
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related:noterefhelper}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}%
  {\unspace% Needed for entries with langid (?)
    \usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related:mtsave}%
    \usebibmacro{related}%
    \newcunit%
    \usebibmacro{finentry}}}

\DeclareBibliographyDriver{cite:online}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \IfBeginWith{\thefield{title}}{CCCCCC}%
  {}%
  {\usebibmacro{ctitle+stitle}%
    \setunit{\addspace}%
    \usebibmacro{language+transtitle}%
    \setunit{\addcomma\addspace}%
    \usebibmacro{byauthor}%
    \setunit{\addcomma\addspace}%
    \usebibmacro{cbyeditor+others}%
    \newcunit\newblock
    \printlist{organization}% Rearranged for 16th ed.
    \setunit{\addcomma\addspace}%
    \usebibmacro{cnotefield}%
    \setunit{\addcomma\addspace}}%
  \usebibmacro{date}%
  \usebibmacro{time+stamp}%
  \newcunit\newblock
  \printfield{type}% 17th ed.
  \ifboolexpr{%
    test {\iffieldequalstr{relatedtype}{commenton}}%
    and
    togl {cms@citerel}%
  }%
  {\toggletrue{cms@relreview}%
    \usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \togglefalse{cms@relreview}}%
  {}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \ifboolexpr{%
    test {\iffieldundef{urlyear}}%
    or
    togl {cms@doinodate}%
  }%
  {}%
  {\printurldate%
    \ifboolexpr{%
      togl {cms@urltime}%
      and
      not test {\iffieldundef{urlhour}}%
    }%
    {\newcunit\printurltime}%
    {}}% Date fix
  \newcunit\newblock
  \iftoggle{cms@doionly}%
  {\iffieldundef{doi}%
    {}%
    {\printfield{doi}%
      \clearfield{url}}}%
  {\printfield{doi}}%
  \newcunit\newblock
  \usebibmacro{eprint}%
  \newcunit\newblock
  \printfield{url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldequalstr{relatedtype}{commenton}}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:patent}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author+holder}% +holder?
  \usebibmacro{hlpunct}%\newcunit\newblock
  \iffieldundef{title}%
  {}%
  {\printtext{%
      \printfield{title}%
      \setunit{\subtitlepunct}%
      \printfield[subtitle]{subtitle}}%
    \setunit{\ctitleaddonpunct}%
    \printfield{titleaddon}}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}\newblock%
  \usebibmacro{cnotefield}%
  \setunit{\addspace}%
  \printtext[parens]{%
  \printfield{type}%
  \setunit*{\addspace}%
  \printfield{number}%
  \iflistundef{location}%
    {}%
    {\setunit*{\addspace}%
     \printtext[parens]{%
       \printlist[][-\value{listtotal}]{location}}}%
  \newcunit\newblock
  \printfield{version}%
  \newcunit
  \iffieldundef{origyear}%
  {\iffieldundef{year}%
    {}%
    {\bibstring{patentfiled}\setunit{\addspace}% Changed to filed
      \printdate}}%
  {\bibstring{patentfiled}\setunit{\addspace}%
    \usebibmacro{cmsorigdate}%
    \setunit{\finalandcomma\addspace\bibstring{and}%
      \addspace\bibstring{patentissued}\addspace}%
  \usebibmacro{date}}%
  \usebibmacro{caddendum}}%
  \usebibmacro{fullpostnote}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:performance}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \usebibmacro{citaltitle+stitle}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
    \newcunit
  \usebibmacro{byauthor}%
  \newcunit\newblock
  \usebibmacro{cbyeditor+others}%
  \newcunit\newblock
  \printfield{howpublished}%
  \newcunit\newblock
  \printfield{type}%
  \newcunit\newblock
  \printfield{version}%
  \newcunit\newblock
  \printfield{note}%
  \newcunit\newblock
  \printfield{venue}%
  \newcunit\newblock%
  \usebibmacro{institution+organization}%
  \newcunit\newblock
  \printlist{location}%
  \newcunit\newblock
  \usebibmacro{date}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:periodical}{%
  \iffieldequalstr{entrysubtype}{magazine}%
  {\usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{issuetitle}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%\newblock%
  \usebibmacro{cbyeditor+others}%
  \setunit{\addcomma\addspace}%
  \printfield{note}%
  \setunit{\addcomma\addspace}\newblock
  \usebibmacro{periodical+date+issue}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}%
  {\usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{editor}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{issuetitle}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cbyeditor+others}%
  \setunit{\addcomma\addspace}%
  \printfield{note}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cjournal+issue+year+pages}%
  \usebibmacro{eid+fullpostnote}%
  \newcunit\newblock
  \printfield{eid}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{issn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}}

\DeclareBibliographyDriver{cite:proceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock%
  \usebibmacro{citaltitle+stitle}%
  \setunit{\addspace}
  \usebibmacro{cite:xref+date}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \newcunit
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@bookcitexref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@bookcitexref}%
    }%
    {\usebibmacro{cmtitle+mstitle+vol+part+title+stitle}%
      \newcunit
      \usebibmacro{cbyeditor+others}%
      \newcunit\newblock
      \usebibmacro{volume+or+volumes}%
      \newcunit\newblock
      \usebibmacro{cser+num}%
      \newcunit\newblock
      \usebibmacro{cnotefield}%
      \newcunit\newblock
      \printfield{eventtitle}%
      \setunit{\ctitleaddonpunct}%
      \printfield{eventtitleaddon}%
      \newcunit%
      \printfield{venue}%
      \newcunit\newblock
      \printeventdate%
      \setunit{\addspace}\newblock%
      \printtext[parens]{%
        \usebibmacro{org+publ+loc+year}}%
      \usebibmacro{volfullpostnote}%
      \usebibmacro{caddendum}%
      \newcunit\newblock
      \iftoggle{cms@isbn}%
      {\printfield{isbn}}%
      {}%
      \newcunit\newblock
      \usebibmacro{cite+doi+url}%
      \setunit{\shorthandpunct}%
      \usebibmacro{cms:shorthandintro}%
      \newcunit\newblock
      \usebibmacro{pageref}%
      \newcunit\newblock
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{book:xref+finentry}%
        \usebibmacro{related:init}%
        \usebibmacro{related:noterefhelper}%
        \usebibmacro{related}%
        \newcunit}%
      {\usebibmacro{book:xref+finentry}}%
      \usebibmacro{finentry}}%
    {\ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:noterefhelper}}%
      {}%
      \ifpunctmark{.}% This seems to work.
      {\ifbibliography%
        {\setunit{\bibsentence}}{\addspace\bibsentence}}%
      {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
      \usebibmacro{xrefprenote}% Volume fix
      \bookbibxrefcite{\thefield{xref}}% Removed \addspace from each.
      \usebibmacro{xrefpostnote}%
      \ifboolexpr{%
        togl {cms@citerel}%
        and
        not test {\iffieldundef{related}}%
      }%
      {\usebibmacro{related:init}%
        \usebibmacro{related}%
        \newcunit}%
      {}%
      \usebibmacro{finentry}}}%
  {\ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:noterefhelper}}%
    {}%
    \ifpunctmark{.}% This seems to work.
    {\ifbibliography%
      {\setunit{\bibsentence}}{\addspace\bibsentence}}%
    {\ifbibliography{\unspace}{\addcomma\addspace}}% ?!?
    \usebibmacro{xrefprenote}% Volume fix
    \bookbibxrefcite{\thefield{crossref}}%
    \usebibmacro{xrefpostnote}%
    \ifboolexpr{%
      togl {cms@citerel}%
      and
      not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}}

\DeclareBibliographyDriver{cite:reference}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \iffieldundef{clonesourcekey}{}{\newcunit}%
  \usebibmacro{citaltitle+stitle}%
  \newcunit\newblock
  \ifthenelse{\iffieldundef{maintitle}\AND\iffieldundef{booktitle}}%
  {\iffieldundef{edition}%
    {}%
    {\usebibmacro{edition}}}%
  {}%
  \newcunit
  \usebibmacro{cpart+editor+translator}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cmtitle+mstitle+vol+part+btitle+bstitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{cbyeditor+others}%
  \newcunit
  \usebibmacro{volume+or+volumes}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \newcunit\newblock
  \usebibmacro{crefpubl+loc+year}%
  \usebibmacro{volfullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:report}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \iffieldequalstr{entrysubtype}{unpublished}%
  {\usebibmacro{ctitle+stitle}}%
  {\usebibmacro{citaltitle+stitle}}%
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit%
  \printfield{type}%
  \newcunit
  \usebibmacro{series+or+shortser}%
  \ifthenelse{\iffieldundef{type}\AND\iffieldundef{series}}%
  {\newcunit}%
  {\setunit{\addnbspace}}%
  \printfield{number}%
  \newcunit%
  \usebibmacro{cnotefield}%
  \setunit{\addspace}\newblock%
  \printtext[parens]{%
  \usebibmacro{inst+loc+year}}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{isrn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:review}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \iffieldequalstr{entrysubtype}{magazine}%
  {\usebibmacro{cmag+news+author}}%
  {\usebibmacro{author/editor}}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{music+eventdate}% 17th ed.
  \newcunit\newblock
  \printeventtime%
  \newcunit\newblock
  \ifboolexpr{%
    (
    test {\iffieldequalstr{relatedtype}{reviewof}}%
    or
    test {\iffieldequalstr{relatedtype}{commenton}}%
    )
    and
    togl {cms@citerel}%
    }%
    {\toggletrue{cms@relreview}%
      \usebibmacro{related:init}%
      \usebibmacro{related:noterefhelper}%
      \usebibmacro{related}%
      \togglefalse{cms@relreview}}%
    {\printfield{title}%
      \setunit{\subtitlepunct}%
      \printfield[noformat]{subtitle}}%
  \setunit{\ctitleaddonpunct}%
  \printfield{titleaddon}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%\newblock%
  \usebibmacro{cpart+editor+translator}%
  \ifboolexpr{%
    test {\iffieldundef{crossref}}%
    or
    not test {\ifentryseen{\thefield{crossref}}}%
    or
    togl {cms@citecrossref}%
  }%
  {\ifboolexpr{%
      test {\iffieldundef{xref}}%
      or
      not test {\ifentryseen{\thefield{xref}}}%
      or
      togl {cms@citecrossref}%
    }%
    {\iffieldequalstr{relatedtype}{commenton}%
      {\usebibmacro{eid+fullpostnote}%
        \newcunit\newblock
        \printfield{eid}%
        \newcunit\newblock
        \usebibmacro{caddendum}}%
      {\newcunit%
        \usebibmacro{issuetitle}%
        \setunit{\addcomma\addspace}%
        \usebibmacro{cbyeditor+others}%
        \setunit{\addcomma\addspace}%
        \printfield{note}%
        \setunit{\addcomma\addspace}%
        \iffieldequalstr{entrysubtype}{magazine}%
        {\usebibmacro{mag+news+date}%
          \newcunit\newblock
          \printfield{type}}%
        {\usebibmacro{cjournal+issue+year+pages}}%
        \usebibmacro{eid+fullpostnote}%
        \newcunit\newblock
        \printfield{eid}%
        \usebibmacro{caddendum}%
        \newcunit\newblock
        \iftoggle{cms@isbn}%
        {\printfield{issn}}%
        {}%
        \usebibmacro{cite:xref+finentry}}}%
    {\usebibmacro{eid+fullpostnote}%
      \newcunit\newblock
      \printfield{eid}%
      \newcunit\newblock
      \usebibmacro{caddendum}}}%
  {\usebibmacro{eid+fullpostnote}%
    \newcunit\newblock
    \printfield{eid}%
    \newcunit\newblock
    \usebibmacro{caddendum}}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldequalstr{relatedtype}{reviewof}}%
    and
    not test {\iffieldequalstr{relatedtype}{commenton}}%
    and
    not test {\iffieldundef{related}}%
    }%
    {\usebibmacro{related:init}%
      \usebibmacro{related:noterefhelper}%
      \usebibmacro{related}%
      \newcunit}%
    {}%
    \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:standard}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \iffieldundef{entrysubtype}%
  {}%
  {\ifnameundef{author}%
    {\iflistundef{organization}%
      {}%
      {\printlist{organization}%
        \usebibmacro{print+nameaddon}}}%
    {\usebibmacro{justauthor}}%
    \usebibmacro{hlpunct}}%\setunit{\addcomma\addspace}\newblock%
  \usebibmacro{citaltitle+stitle}%
  \newcunit
  \usebibmacro{edition}%
  \newcunit
  \usebibmacro{byauthor}%
  \newcunit\newblock
  \usebibmacro{cbyeditor+others}%
  \newcunit\newblock
  \usebibmacro{series+or+shortser}%
  \setunit*{\addnbspace}%
  \printfield{number}%
  \newcunit\newblock
  \printfield{type}%
  \newcunit
  \usebibmacro{cnotefield}%
  \setunit{\addspace}\newblock%
  \printtext[parens]{%
    \usebibmacro{origpubl+loc+year}%{cmsorigdate}% 16th ed.
    \reprintpunct%
    \iffieldundef{pubstate}%
    {}%
    {\iffieldbibstring{pubstate}%
      {\bibsstring{\thefield{pubstate}}}%
      {\printfield[prenote]{pubstate}}%
      \newcunit}%
    \printlist{location}%
    \iflistundef{organization}%
    {\iflistundef{publisher}%
      {\setunit*{\addcomma\addspace}}%
      {\setunit*{\addcolon\addspace}%
        \printlist{publisher}%
        \setunit*{\addcomma\addspace}}}%
    {\setunit*{\addcolon\addspace}%
      \printlist{organization}%
      \setunit*{\addcomma\addspace}}%
    \usebibmacro{date}%
    \setunit{\addsemicolon\addspace}%
    \printfield{howpublished}%
    \setunit*{\addspace}%
    \usebibmacro{music+eventdate}}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:suppbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author}%
  \usebibmacro{hlpunct}%\newcunit\newblock
  \usebibmacro{inforaft}%
  \setunit{\addspace}\newblock
  \usebibmacro{citaltitle+stitle}%
  \newcunit
  \iffieldundef{maintitle}%
  {\iffieldundef{edition}%
    {}%
    {\usebibmacro{edition}}}%
  {}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \newcunit\newblock
  \usebibmacro{cpart+editor+translator}%
  \newcunit\newblock
  \usebibmacro{cmtitle+mstitle+vol+part+title+stitle}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{cbyeditor+others}%
  \newcunit
  \usebibmacro{volume+or+volumes}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \newcunit\newblock
  \usebibmacro{cnotefield}%
  \newcunit\newblock
  \usebibmacro{cpubl+loc+year}%
  \clearfield{pages}% ?? For 16th ed.
  \usebibmacro{volfullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{isbn}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyAlias{cite:suppcollection}{cite:suppbook}

\DeclareBibliographyAlias{cite:suppperiodical}{cite:review}

\DeclareBibliographyDriver{cite:thesis}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \usebibmacro{ctitle+stitle}%
  \setunit{\addspace}\newblock%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{cnotefield}%
  \setunit{\addspace}%
  \printtext[parens]{%
  \usebibmacro{type+inst+year}}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:unpublished}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \usebibmacro{hlpunct}%\setunit{\addcomma\addspace}\newblock
  \usebibmacro{ctitle+stitle}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \setunit{\addcomma\addspace}%
  \usebibmacro{byauthor}%
  \newcunit\newblock%
  \usebibmacro{cbyeditor+others}%
  \setunit{\addspace}\newblock%
  \printtext[parens]{%
    \printfield{howpublished}%
    \newcunit\newblock
    \usebibmacro{cnotefield}%
    \newcunit\newblock
    \printfield{eventtitle}%
    \setunit{\ctitleaddonpunct}%
    \printfield{eventtitleaddon}%
    \newcunit%
    \printfield{venue}%
    \newcunit%
    \printlist{location}%
    \newcunit\newblock
    \iffieldundef{eventyear}%
    {\usebibmacro{date}}%
    {\printeventdate}}%
  \usebibmacro{fullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{cite:video}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \ifboolexpr{%
    test {\iffieldequalstr{entrysubtype}{tvepisode}}%
    and
    (
    not test {\iffieldundef{title}}%
    and
    not test {\iffieldundef{booktitle}}%
    )
  }%
  {\usebibmacro{author/editor}%
    \usebibmacro{hlpunct}%\newcunit\newblock
    \usebibmacro{btitle+bstitle}%
    \newcunit\newblock
    \usebibmacro{ctitle+stitle}%
    \setunit{\addspace}\newblock%
    \usebibmacro{language+transtitle}%
    \newcunit
    \usebibmacro{byauthor}%
    \newcunit
    \usebibmacro{cpart+editor+translator}}%
  {\usebibmacro{author/editor}%
    \usebibmacro{hlpunct}%\newcunit\newblock
    \usebibmacro{ctitle+stitle}%
    \setunit{\addspace}\newblock%
    \usebibmacro{language+transtitle}%
    \newcunit
    \usebibmacro{byauthor}%
    \newcunit
    \usebibmacro{cpart+editor+translator}%
    \newcunit
    \usebibmacro{chapinscore}%
    \usebibmacro{btitle+bstitle}}%
  \newcunit
  \iffieldundef{edition}%
  {}%
  {\usebibmacro{edition}}%
  \newcunit
  \usebibmacro{bybookauthor}%
  \usebibmacro{cbyeditor+others}%
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\ifthenelse{\iffieldundef{title}\AND\iffieldundef{booktitle}}%
      {\usebibmacro{cms-in:}}%
      {\bibstring{in}\setunit{\addspace}}%
      \printtext[maintitle]{%
        \printfield[mtnoformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[smtnoformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}
    {\toggletrue{cms@usedvol}%
      \printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}
      \bibstring[\cms@ofwrap]{ofseries}%
      \iftoggle{smartof}{}{\setunit{\addspace}}%
      \printtext[default]{%
        \printfield[title:hook:alt]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[title]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}}
  \newcunit
  \usebibmacro{volume+or+volumes}%
  \newcunit\newblock
  \usebibmacro{cser+num}%
  \newcunit\newblock
  \usebibmacro{cnotefield}%
  \newcunit\newblock
  \usebibmacro{music+eventdate}%
  \newcunit\newblock
  \printfield{usera}%
  \newcunit\newblock
  \usebibmacro{cpubl+loc+year}%
  \newcunit\newblock
  \printfield{type}% Order of this and next?
  \usebibmacro{volfullpostnote}%
  \usebibmacro{caddendum}%
  \newcunit\newblock
  \iftoggle{cms@isbn}%
  {\printfield{isan}}%
  {}%
  \newcunit\newblock
  \usebibmacro{cite+doi+url}%
  \setunit{\shorthandpunct}%
  \usebibmacro{cms:shorthandintro}%
  \newcunit\newblock
  \usebibmacro{pageref}%
  \newcunit\newblock
  \ifboolexpr{%
    togl {cms@citerel}%
    and
    not test {\iffieldundef{related}}%
  }%
  {\usebibmacro{related:init}%
    \usebibmacro{related:noterefhelper}%
    \usebibmacro{related}%
    \newcunit}%
  {}%
  \usebibmacro{finentry}}

%%%% List Formats %%%%

\DeclareListFormat{language}{%
  \ifthenelse{\value{listcount}=1}%
  {\bibleftbracket\bibstring{inlang}%\addspace - for inflected langs.
    \ifbibstring{#1}%
    {\bibstring{#1}}%
    {\ifbibstring{lang#1}%
      {\bibstring{lang#1}}%
      {#1}}%
    \ifthenelse{\value{listtotal}=1}%
    {\bibrightbracket}%
    {}}%
  {\ifthenelse{\value{listcount}=\value{listtotal}}%
    {\multilangdelim%
      \ifbibstring{#1}%
      {\bibstring{#1}}%
      {\ifbibstring{lang#1}%
        {\bibstring{lang#1}}%
        {#1}}%
      \bibrightbracket}%
    {\multilangdelim%
      \ifbibstring{#1}%
      {\bibstring{#1}}%
      {\ifbibstring{lang#1}%
        {\bibstring{lang#1}}%
        {#1}}}}%
  \usebibmacro{langlist:andothers}}

\DeclareListFormat{publisher}{%
  \ifthenelse{\value{listtotal}<2}%
  {#1\isdot}%
  {\ifthenelse{\value{listcount}=1}%
    {#1}%
    {\multipubsdelim #1\isdot}}}

\DeclareListFormat[jurisdiction]{location}{%
  \iffieldundef{entrysubtype}%
  {\usebibmacro{list:delim}{#1}%
    #1\isdot%
    \usebibmacro{list:andothers}}%
  {\ifthenelse{\value{listcount}<\value{listtotal}}%
    {\mkbibparens{#1}\addspace}%
    {\mkbibparens{#1\isdot}}}}%

\DeclareListFormat[jurisdiction]{origlocation}{%
  \ifthenelse{\value{listcount}<\value{listtotal}}%
  {#1\isdot\addcomma\addspace}%
  {#1\isdot}}

\DeclareListFormat[jurisdiction]{origpublisher}{%
  \ifthenelse{\value{listcount}<\value{listtotal}}%
  {\mkbibparens{#1}\addspace}%
  {\mkbibparens{#1\isdot}}}

\DeclareListFormat{periodplace}{\mkbibparens{#1}}

\DeclareListFormat{lista}{%
  \ifthenelse{\value{listtotal}<2}%
  {\bibsstring{subverbo}\addspace\mkbibquote{#1\isdot}}%
  {\ifthenelse{\value{listcount}=1}%
    {\bibsstring{subverbis}\addspace\mkbibquote{#1\isdot}\addcomma}%
    {\ifthenelse{\value{listcount}<\value{listtotal}}%
      {\addspace\mkbibquote{#1\isdot}\addcomma}%
      {\addspace\mkbibquote{#1\isdot}}}}}

%%%% Field Formats -- Title, Citetitle, Lostitle %%%%

\DeclareFieldFormat{title}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat{citetitle}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat{lostitle}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat
[article,inbook,incollection,inproceedings,online,thesis,unpublished]
{title}{%
  \iffieldundef{title}%
  {}%
  {\mkbibquote{#1\isdot}}}

\DeclareFieldFormat
[article,inbook,incollection,inproceedings,online,thesis,unpublished]
{citetitle}{%
  \iffieldundef{title}%
  {#1\isdot}%
  {\mkbibquote{#1\isdot}}}

\DeclareFieldFormat
[article,inbook,incollection,inproceedings,online,thesis,unpublished]
{lostitle}{%
  \iffieldundef{title}%
  {#1\isdot}%
  {\mkbibquote{#1\isdot}}}

\DeclareFieldFormat[artwork,image,inreference]{title}{%
  \iffieldundef{entrysubtype}%
  {\mkbibemph{#1}\isdot}%
  {#1\isdot}}

\DeclareFieldFormat[artwork,image,inreference]{citetitle}{%
  \iffieldundef{entrysubtype}%
  {\mkbibemph{#1}\isdot}%
  {#1\isdot}}

\DeclareFieldFormat[artwork,image,inreference]{lostitle}{%
  \iffieldundef{entrysubtype}%
  {\mkbibemph{#1}\isdot}%
  {#1\isdot}}

\DeclareFieldFormat[letter]{title}{#1\isdot}

\DeclareFieldFormat[patent]{title}{\MakeSentenceCase*{#1}\isdot}

\DeclareFieldFormat[letter]{citetitle}{#1\isdot}

\DeclareFieldFormat[patent]{citetitle}{\MakeSentenceCase*{#1}\isdot}

\DeclareFieldFormat[letter]{lostitle}{#1\isdot}

\DeclareFieldFormat[patent]{lostitle}{\MakeSentenceCase*{#1}\isdot}

\DeclareFieldFormat{prenote}{%
  \ifcapital{\MakeCapital{#1}}{#1}\isdot}

%% comprange code moved to .sty

\DeclareFieldFormat{postnote}{% Changed for page compression option
  \ifpages{#1}% xetex and luatex revealed a bug in original logic
  {\iftoggle{cms@comprange}%
    {{\iffieldundef{pagination}%
        {\mkcomprange{#1}}%
        {\mkcomprange[{\mkpageprefix[pagination]}]{#1}}}}%
    {{\iffieldundef{pagination}%
        {\mknormrange{#1}}%
        {\mknormrange[{\mkpageprefix[pagination]}]{#1}}}}}%
  {\iffieldundef{pagination}%
    {#1}%
    {\mkpageprefix[pagination]{#1}}}}%

\DeclareFieldFormat[inreference]{postnote}{%
  \ifpages{#1}%
  {\iftoggle{cms@comprange}%
    {\iffieldundef{pagination}%
      {\bibsstring{subverbo}\addnbspace\mkbibquote{#1}}%
      {\mkcomprange[{\mkpageprefix[pagination]}]{#1}}}%
    {\iffieldundef{pagination}%
      {\bibsstring{subverbo}\addnbspace\mkbibquote{#1}}%
      {\mknormrange[{\mkpageprefix[pagination]}]{#1}}}}%
  {\iffieldundef{pagination}%
    {\bibsstring{subverbo}\addnbspace\mkbibquote{#1}}%
    {\mkpageprefix[pagination]{#1}}}}%

\newrobustcmd*{\mkjuridprefix}[1]{%
  \ifboolexpr{% FIXME: Is this always right?
    test {\iftoggle{cms@fullnote}}%
    and
    test {\ifentrytype{jurisdiction}}%
    }%
  {\iffieldundef{issue}%
    {#1}%
    {\printtext{at}\addspace *#1}}%
  {\iffieldundef{issue}%
    {\printtext{at}\addspace #1}% FIXME: Make it a bibstring?
    {\ifentrytype{jurisdiction}%
      {\printtext{at}\addspace *#1}%
      {\printtext{at}\addspace #1}}}}%

\DeclareFieldFormat[jurisdiction,legal,legislation]{postnote}{%
  \ifboolexpr{%
    togl {cms@comprange}%
    and
    test {\ifpages{#1}}%
  }%
  {\iffieldundef{pagination}%
    {\mkcomprange[\mkjuridprefix]{#1}}%
    {\mkcomprange[{\mkpageprefix[pagination]}]{#1}}}%
  {\iffieldundef{pagination}%
    {\mkjuridprefix{#1}}%
    {\mkpageprefix[pagination]{#1}}}}%

\DeclareFieldFormat{pages}{%
  \ifboolexpr{%
    togl {cms@comprange}%
    and
    test {\ifpages{#1}}%
  }%
  {\iffieldundef{bookpagination}%
    {\mkcomprange{#1}\isdot}%
    {\mkcomprange[{\mkpageprefix[bookpagination]}]{#1}}}%
  {\iffieldundef{bookpagination}%
    {#1\isdot}%
    {\mkpageprefix[bookpagination]{#1}}}}%

\DeclareListFormat{edlang}{% Required for feminine forms in some
  \usebibmacro{list:delim}{% languages
    \ifbibstring{#1}%
    {\bibxstring{#1}}%
    {\ifbibstring{ed#1}%
      {\bibxstring{ed#1}}%
      {\ifcapital{\MakeCapital{#1}}{#1}}}}%
  \ifbibstring{#1}%
  {\bibstring{#1}}%
  {\ifbibstring{ed#1}%
    {\bibstring{ed#1}}%
    {\ifcapital{\MakeCapital{#1}}{#1}}}%
  \usebibmacro{list:andothers}}

\DeclareFieldFormat[suppbook,suppcollection]{title}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat[suppbook,suppcollection]{citetitle}{%
  \usebibmacro{inforaft}%
  \addspace%
  \mkbibemph{#1}\isdot}

\DeclareFieldFormat[suppbook,suppcollection]{lostitle}{%
  \usebibmacro{inforaft}%
  \addspace%
  \mkbibemph{#1}\isdot}

\DeclareFieldFormat[customc]{title}{%
  \ifboolexpr{%
    test {\iffieldundef{nameaddon}}%
    or
    (
    test {\ifbibliography}%
    and
    togl {cms@bibnona}%
    )
    or
    (
    test {\ifcitation}%
    and
    togl {cms@citenona}%
    )
  }%
  {\mkbibemph{\bibstring{see}}%
    \addspace%
    #1}%
  {#1}}

\DeclareFieldFormat[customc]{citetitle}{%
  \ifboolexpr{%
    test {\iffieldundef{nameaddon}}%
    or
    togl {cms@citenona}%
  }%
  {\mkbibemph{\bibstring{see}}%
    \addspace%
    #1}%
  {\printfield{nameaddon}\addspace #1}}

\DeclareFieldFormat[customc]{lostitle}{%
  \ifboolexpr{%
    test {\iffieldundef{nameaddon}}%
    or
    togl {cms@bibnona}%
  }%
  {\mkbibemph{\bibstring{see}}%
    \addspace%
    #1}%
  {\addspace #1}}

\DeclareFieldFormat[misc]{title}{%
  \iffieldundef{entrysubtype}%
  {\mkbibemph{#1}\isdot}%
  {\ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}}

\DeclareFieldFormat[misc]{citetitle}{%
  \iffieldundef{entrysubtype}%
  {\mkbibemph{#1}\isdot}%
  {\ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}}

\DeclareFieldFormat[misc]{lostitle}{%
  \iffieldundef{entrysubtype}%
  {\mkbibemph{#1}\isdot}%
  {\ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}}

\DeclareFieldFormat[dataset]{title}{%
  \ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}

\DeclareFieldFormat[dataset]{citetitle}{%
  \mkbibparens{\ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}}

\DeclareFieldFormat[dataset]{lostitle}{%
  \addspace% Instead of in shorthand driver (2.1)
  \mkbibparens{\ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}}

\DeclareFieldFormat[review,suppperiodical]{title}{%
  \ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}

\DeclareFieldFormat[review,suppperiodical]{citetitle}{%
  \ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}

\DeclareFieldFormat[review,suppperiodical]{lostitle}{%
  \ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}

\DeclareFieldFormat[report]{title}{%
  \iffieldequalstr{entrysubtype}{unpublished}%
  {\mkbibquote{#1\isdot}}%
  {\mkbibemph{#1}\isdot}}%

\DeclareFieldFormat[report]{citetitle}{%
  \iffieldequalstr{entrysubtype}{unpublished}%
  {\mkbibquote{#1\isdot}}%
  {\mkbibemph{#1}\isdot}}

\DeclareFieldFormat[report]{lostitle}{%
  \iffieldequalstr{entrysubtype}{unpublished}%
  {\mkbibquote{#1\isdot}}%
  {\mkbibemph{#1}\isdot}}

\DeclareFieldFormat[audio,music]{title}{%
  \ifthenelse{\iffieldundef{booktitle}\AND\iffieldundef{entrysubtype}}%
  {\mkbibemph{#1}\isdot}%
  {\mkbibquote{#1\isdot}}}

\DeclareFieldFormat[audio,music]{citetitle}{%
  \ifthenelse{\iffieldundef{booktitle}\AND\iffieldundef{entrysubtype}}%
  {\mkbibemph{#1}\isdot}%
  {\mkbibquote{#1\isdot}}}

\DeclareFieldFormat[audio,music]{lostitle}{%
  \ifthenelse{\iffieldundef{booktitle}\AND\iffieldundef{entrysubtype}}%
  {\mkbibemph{#1}\isdot}%
  {\mkbibquote{#1\isdot}}}

\DeclareFieldFormat[video]{title}{%
  \ifthenelse{\iffieldundef{booktitle}\AND\iffieldundef{entrysubtype}}%
  {\mkbibemph{#1}\isdot}%
  {\mkbibquote{#1\isdot}}}

\DeclareFieldFormat[video]{citetitle}{%
  \ifthenelse{\iffieldundef{booktitle}\AND\iffieldundef{entrysubtype}}%
  {\mkbibemph{#1}\isdot}%
  {\ifboolexpr{%
      test {\iffieldequalstr{entrysubtype}{tvepisode}}%
      and
      not test {\iffieldundef{title}}%
      and
      not test {\iffieldundef{booktitle}}%
      and
      not test {\iffieldundef{shorttitle}}%
    }%
    {\mkbibemph{#1}\isdot}%
    {\mkbibquote{#1\isdot}}}}

\DeclareFieldFormat[video]{lostitle}{%
  \ifthenelse{\iffieldundef{booktitle}\AND\iffieldundef{entrysubtype}}%
  {\mkbibemph{#1}\isdot}%
  {\mkbibquote{#1\isdot}}}

\DeclareFieldFormat[jurisdiction]{title}{%
  \iftoggle{cms@running@text}%
  {\mkbibemph{#1}\isdot}%
  {#1\isdot}}

\DeclareFieldFormat[legal]{title}{#1\isdot}

\DeclareFieldFormat[legislation]{title}{%
  \iffieldequalstr{entrysubtype}{hearing}%
  {\mkbibemph{#1}\isdot}%
  {#1\isdot}}

\DeclareFieldFormat[jurisdiction]{citetitle}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat[jurisdiction,legal]{lostitle}{#1\isdot}

\DeclareFieldFormat[legislation]{lostitle}{%
  \iffieldequalstr{entrysubtype}{hearing}%
  {\mkbibemph{#1}\isdot}%
  {#1\isdot}}

\DeclareFieldFormat[legal]{citetitle}{#1\isdot}

\DeclareFieldFormat[legislation]{citetitle}{%
  \iffieldequalstr{entrysubtype}{hearing}%
  {\mkbibemph{#1}\isdot}%
  {#1\isdot}}

%%%% Other Field Formats %%%%

\DeclareFieldFormat{letterday}{\mkbibcurdinal{#1}}

\DeclareFieldFormat{note}{%
  \ifcapital{\IfCMSFieldInitCS{#1}{#1}{\MakeCapital{#1}}}{#1}}%

\DeclareFieldFormat{capital}{%
  \ifcapital{\MakeCapital{#1}}{#1}}

\DeclareFieldFormat
[audio,manual,music,patent,report,suppbook,suppcollection,thesis,video]
{type}{%
  \ifbibstring{#1}%
  {\bibstring{#1}}%
  {\ifcapital%
    {\MakeCapital{#1\isdot}}%
    {#1\isdot}}}

\DeclareFieldFormat[artwork,image,online,article,review,suppperiodical,book]
{type}{%
  \ifcapital%
  {\MakeCapital{#1}}%
  {#1}}

\DeclareFieldFormat[artwork,image,music]{howpublished}{%
  \ifcapital%
  {\MakeCapital{#1}}%
  {#1}}

\DeclareFieldFormat[video]{usera}{%
  \bibstring{on}\addspace #1}

\DeclareFieldFormat{version}{\bibsstring{version}\addspace #1}%

\DeclareFieldFormat{url}{\url{#1}}

\DeclareFieldFormat{doi}{%
  \url{https://doi.org/#1}}

\DeclareFieldFormat[music]{date}{% Generalize userd ???
  \ifthenelse{\iffieldundef{userd}\OR\NOT\iffieldundef{urlyear}%
  \OR\NOT\iffieldundef{eventyear}\OR\NOT\iffieldundef{origyear}}%
  {#1}%
  {\printfield{userd}\addspace #1}}

\DeclareFieldFormat[video]{date}{% Generalize userd ???
  \ifthenelse{\iffieldundef{userd}\OR\NOT\iffieldundef{urlyear}%
  \OR\NOT\iffieldundef{eventyear}}%
  {#1}%
  {\printfield{userd}\addspace #1}}

\DeclareFieldFormat[artwork,image]{date}{%
  \iffieldundef{origyear}%
  {#1}%
  {\iftoggle{cms@switchdates}%
    {#1}%
    {\iffieldundef{userd}%
      {\bibstring{printed}\addspace #1}%
      {\printfield{userd}\addspace #1}}}}

\DeclareFieldFormat[artwork,image]{origdate}{%
  \iffieldundef{year}%
  {#1}%
  {\iftoggle{cms@switchdates}%
    {\iffieldundef{userd}%
      {\bibstring{printed}\addspace #1}%
      {\printfield{userd}\addspace #1}}%
    {#1}}}

\DeclareFieldFormat[artwork,image]{urldate}{%
  \ifboolexpr{%
    test {\iffieldundef{userd}}%
    or
    (
    not test {\iffieldundef{year}}%
    and
    not test {\iffieldundef{origyear}}%
    )
  }%
  {\bibstring{urlseen}\addspace #1}%
  {\printfield{userd}\addspace #1}}

\DeclareFieldFormat{date}{% Generalize userd ???
  \ifthenelse{\iffieldundef{userd}\OR\NOT\iffieldundef{urlyear}}%
  {#1}%
  {\printfield{userd}\addspace #1}}

\DeclareFieldFormat{urldate}{% 16th ed.
  \iffieldundef{userd}%
  {\bibstring{urlseen}\addspace #1}%
  {\printfield{userd}\addspace #1}}

\DeclareFieldFormat[video]{urldate}{% 16th ed.
  \ifthenelse{\iffieldundef{userd}\OR\NOT\iffieldundef{eventyear}}%
  {\bibstring{urlseen}\addspace #1}%
  {\printfield{userd}\addspace #1}}

\DeclareFieldFormat[music]{urldate}{% 16th ed.
  \ifthenelse{\iffieldundef{userd}\OR\NOT\iffieldundef{eventyear}%
    \OR\NOT\iffieldundef{origyear}}%
  {\bibstring{urlseen}\addspace #1}%
  {\printfield{userd}\addspace #1}}

\DeclareFieldFormat[music]{origdate}{% 16th ed.
  \iffieldequalstr{pubstate}{reprint}% Date fix
  {#1}%
  {\ifthenelse{\iffieldundef{userd}\OR\NOT\iffieldundef{eventyear}}%
    {\bibstring{discrecorded}\addspace #1}% Can now match gender
    {\printfield{userd}\addspace #1}}}

\DeclareFieldFormat[music]{eventdate}{% 16th ed.
  \iffieldundef{userd}%
  {\bibstring{songrecorded}\addspace #1}% Can now match gender
  {\printfield{userd}\addspace #1}}

\DeclareFieldFormat[video]{eventdate}{% 16th ed.
  \iffieldundef{userd}%
  {\bibstring{broadcast}\addspace #1}%
  {\printfield{userd}\addspace #1}}

\DeclareFieldAlias{userd}{titleaddon}% 16th ed.

\DeclareFieldFormat{nameaddon}{%
  \ifdefvoid{\cms@naformat}%
  {\mkbibbrackets{#1\bibsentence}}%
  {\printtext[\cms@naformat]{#1\isdot}}}%

\DeclareFieldFormat[online,review,suppperiodical]{nameaddon}{%
  \ifdefvoid{\cms@naformat}%
  {#1\ifboolexpr{%(
      test {\IfEndWith{\thefield{nameaddon}}{)}}%[
      or
      test {\IfEndWith{\thefield{nameaddon}}{]}}%
    }%
    {\bibsentence}{\isdot}}%
  {\printtext[\cms@naformat]{#1\isdot}}}

\DeclareFieldFormat[misc]{nameaddon}{%
  \iffieldundef{entrysubtype}%
  {\ifdefvoid{\cms@naformat}%
    {\mkbibbrackets{#1\bibsentence}}%
    {\printtext[\cms@naformat]{#1\isdot}}}%
  {\ifdefvoid{\cms@naformat}%
    {#1\ifboolexpr{%(
        test {\IfEndWith{\thefield{nameaddon}}{)}}%[
        or
        test {\IfEndWith{\thefield{nameaddon}}{]}}%
      }%
      {\bibsentence}{\isdot}}%
    {\printtext[\cms@naformat]{#1\isdot}}}}

\DeclareFieldFormat[customc]{nameaddon}{% For cross-refs
  \ifbibstring{#1}%
  {\mkbibemph{\bibstring{#1}}}%
  {#1}}

\DeclareFieldFormat{edition}{% New in 0.8
  \ifinteger{#1}
  {\mkbibordedition{#1}~\bibstring{edition}}%
  {\ifcapital%
    {\MakeCapital{#1\isdot}}%
    {#1\isdot}}}

\DeclareFieldFormat{year}{% To cope with abbreviation n.d.
  \iftoggle{cms@fullnote}%
  {#1\bibsentence}%
  {#1\isdot}}% (?)

\DeclareFieldFormat[misc]{year}{#1\isdot}

\DeclareFieldFormat[article]{year}{% To cope with abbreviation n.d.
  \iffieldequalstr{entrysubtype}{magazine}%
  {#1\isdot}
  {#1\bibsentence}}

\DeclareFieldAlias[review]{year}[article]{year}

\DeclareFieldAlias[periodical]{year}[article]{year}

\DeclareFieldAlias[suppperiodical]{year}[article]{year}

\DeclareFieldFormat{usere}{[#1]} % Better than mkbibbrackets?

\DeclareFieldFormat{titleaddon}{%
  \ifcapital{\IfCMSFieldInitCS{#1}{#1\isdot}%
      {\MakeCapital{#1\isdot}}}{#1\isdot}}%

\DeclareFieldFormat[periodical]{titleaddon}{%
  \ifcapital{\IfCMSFieldInitCS{#1}{#1\isdot}%
      {\MakeCapital{#1\isdot}}}{#1\isdot}}

\DeclareFieldAlias{booktitleaddon}{titleaddon}

\DeclareFieldAlias{maintitleaddon}{titleaddon}

\DeclareFieldAlias[article,periodical,review,suppperiodical]{maintitleaddon}%
{journaltitleaddon}

\DeclareFieldFormat{journaltitleaddon}{%
  \ifcapital{\MakeCapital{#1\isdot}}{#1\isdot}}

\DeclareFieldFormat[jurisdiction,legal,legislation]{journaltitle}{%
  \iffieldundef{shortjournal}%
  {#1\isdot}%
  {\mkbibemph{#1}\isdot}}

\DeclareFieldFormat[jurisdiction,legal,legislation]{shortjournal}{#1\isdot}

\DeclareFieldFormat{journaltitle}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat{injournaltitle}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat{issuetitle}{\mkbibquote{#1\isdot}}

\DeclareFieldFormat{shortjournal}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat{inshortjournal}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat[periodical]{shorttitle}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat{jourser}{%
  \ifinteger{#1}%
  {\mkbibordseries{#1}%
    \addnbspace%
    \bibstring{jourser}}%
  {\ifbibstring{#1}{\bibstring{#1}}{#1}}}%

\DeclareFieldFormat{jurisdictionser}{%
  \ifinteger{#1}%
  {\mkjuridordinal{#1}}%
  {\ifbibstring{#1}{\bibstring{#1}}{#1}}}%

\DeclareFieldFormat{legislationser}{%
  \iffieldequalstr{entrysubtype}{hansard}%
  {\ifinteger{#1}%
    {\addspace\mkbibparens{\mkjuridordinal{#1}\addspace\bibsstring{jourser}}}%
    {\ifbibstring{#1}%
      {\addspace\mkbibparens{\bibstring{#1}}}%
      {\addspace\mkbibparens{#1}}}}%
  {\iffieldequalstr{entrysubtype}{uk}%
    {\addspace #1\isdot}%
    {\addcomma\addspace #1\isdot}}}%

\DeclareFieldFormat{legalser}{\addspace #1\isdot}%

\DeclareFieldFormat{hansardser}{%
  \ifinteger{#1}%
  {\mkbibparens{\mkjuridordinal{#1}\addspace\bibsstring{jourser}}}%
  {\ifbibstring{#1}{\mkbibparens{\bibstring{#1}}}{\mkbibparens{#1}}}}%

\DeclareFieldFormat{journum}{% Revised for 0.9.5
  \ifboolexpr{%
    test {\ifnumerals{#1}}%
    and
    not test {\ifnumeral{#1}}%
  }%
  {\bibstring{numbers}\addspace #1}%
  {\bibstring{number}\addspace #1}}%

\DeclareFieldFormat{juridnum}{\bibcpstring{number}\addspace #1}%

\DeclareFieldFormat{jourvol}{#1}

\DeclareFieldFormat{shortvol}{#1}

\DeclareFieldFormat{sernum}{%
  \ifnumeral{#1}%
  {\addnbspace #1}%
  {\addcomma\addspace #1}}

\DeclareFieldFormat{series}{#1\isdot}

\DeclareFieldFormat{shortseries}{#1\isdot}

\DeclareFieldFormat{addendum}{%
  \ifcapital{\IfCMSFieldInitCS{#1}{#1\isdot}%
      {\MakeCapital{#1\isdot}}}{#1\isdot}}

\DeclareFieldFormat[jurisdiction,legal,legislation]{addendum}{%
  \ifcapital%
    {\mkbibparens{\IfCMSFieldInitCS{#1}{#1\isdot}%
        {\MakeCapital{#1\isdot}}}}{\mkbibparens{#1\isdot}}}

% For annotation fixes move all code for separators to the entrytail
% macro, below.

\DeclareFieldFormat{annotation}{#1}%

\DeclareFieldFormat{part}{% xref revision ???
  \ifnumerals{#1}%
  {\addcomma\addspace\bibstring{partvolume}~#1}%
  {\addcomma\addspace\ifcapital{\MakeCapital{#1}}{#1}}}

\global\let\cmsnrpart\RN
\DeclareFieldFormat{nrpart}{\bibsstring{part}~\cmsnrpart{#1}}% Noterefs
\DeclareFieldFormat{nrchapter}{\bibsstring{chapter}~#1}%

\DeclareFieldFormat{xrefpart}{% xref revision ???
  \ifnumerals{#1}%
  {\bibstring{partvolume}~#1}%
  {\ifcapital{\MakeCapital{#1}}{#1}}}

\DeclareFieldFormat[legal,legislation]{part}{%
  \ifnumerals{#1}%
  {\bibsstring{part}~#1}%
  {#1\isdot}}%

\DeclareFieldFormat[legal,legislation]{chapter}{c\adddotspace #1}%

\DeclareFieldFormat[music]{chapter}{\bibstring{track}~#1}

%% This tries to get hyperlinks from shortened cross-ref'd notes to %%
%% long notes working properly.  Used in short and shorthand cites. %%

\DeclareFieldFormat{cmshyperlink}{% Obsolete?
  \iffieldundef{crossref}%
  {\iffieldundef{xref}%
    {\bibhyperlink{\thefield{entrykey}}{#1}}%
    {\ifboolexpr{((
        test {\ifentrytype{book}}%
        or
        test {\ifentrytype{bookinbook}}%
        or
        test {\ifentrytype{collection}}%
        or
        test {\ifentrytype{proceedings}}%
        )
        and
        not togl {cms@bookcitexref}%
        )
        or
        ((
        test {\ifentrytype{inbook}}%
        or
        test {\ifentrytype{letter}}%
        or
        test {\ifentrytype{incollection}}%
        or
        test {\ifentrytype{inproceedings}}%
        )
        and
        not togl {cms@citecrossref}%
        )
      }%
      {\bibhyperlink{\thefield{xref}}{#1}}%
      {\bibhyperlink{\thefield{entrykey}}{#1}}}}%
  {\ifboolexpr{((
        test {\ifentrytype{book}}%
        or
        test {\ifentrytype{bookinbook}}%
        or
        test {\ifentrytype{collection}}%
        or
        test {\ifentrytype{proceedings}}%
        )
        and
        not togl {cms@bookcitexref}%
        )
        or
        ((
        test {\ifentrytype{inbook}}%
        or
        test {\ifentrytype{letter}}%
        or
        test {\ifentrytype{incollection}}%
        or
        test {\ifentrytype{inproceedings}}%
        )
        and
        not togl {cms@citecrossref}%
        )
      }%
      {\bibhyperlink{\thefield{crossref}}{#1}}%
      {\bibhyperlink{\thefield{entrykey}}{#1}}}}

\newrobustcmd*{\cmshyper}[1]{%
  \ifbibliography%
  {\ifboolexpr{%
      test {\ifentryinbib{\thefield{entrykey}}}%
      and
      not togl {blx@skipbib}%
    }%
    {\printtext[bibhyperref]{#1}}%
    {\ifentryinbib{\thefield{clonesourcekey}}%
      {\printtext{\bibhyperref[\abx@field@clonesourcekey]{#1}}}%
      {#1}}}%
  {\iftoggle{cms@allshort}%
    {\iftoggle{blx@skipbib}{#1}{\printtext[bibhyperref]{#1}}}%
    {\iffieldundef{clonesourcekey}%
      {\printtext[bibhyperlink]{#1}}%
      {\printtext{\bibhyperlink{\abx@field@clonesourcekey}{#1}}}}}}%

\newrobustcmd*{\cmsshhyper}[1]{%
  \iffootnote%
  {\iftoggle{cms@allshort}%
    {\iftoggle{blx@skipbib}{#1}{\printtext[bibhyperref]{#1}}}%
    {\printtext[bibhyperlink]{#1}}}%
  {\ifboolexpr{%
      test {\ifentryinbib{\thefield{entrykey}}}%
      and
      not togl {blx@skipbib}%
    }%
    {\printtext[bibhyperref]{#1}}%
    {\iftoggle{cms@allshort}%
      {#1}%
      {\printtext[bibhyperlink]{#1}}}}}%

\DeclareFieldAlias[review]{volume}[article]{volume}

\DeclareFieldAlias[suppperiodical]{volume}[article]{volume}

%%%% Related field formats from biblatex.def %%%%

\DeclareFieldFormat{related:origpubas}{#1}% This and next remove parens

\DeclareFieldFormat{related:origpubin}{#1}

\DeclareFieldFormat{relatedstring:default}{% For notes + bib
  \ifboolexpr{%
    test {\iffieldundef{relatedstring}}%
    or
    test {\iffieldbibstring{relatedstring}}%
  }%
  {#1}%
  {\ifcapital%
    {\MakeCapital{#1}}%
    {#1}}%
  \ifentrytype{jurisdiction}%
  {\newcunit}%
  {\iftoggle{smartof}{}{\printunit{\relatedpunct}}}}% Issue w/ printunit.

\DeclareFieldFormat{relatedstring:reprintfrom}{% For notes + bib
  \ifboolexpr{%
    test {\iffieldundef{relatedstring}}%
    or
    test {\iffieldbibstring{relatedstring}}%
  }%
  {#1}%
  {\ifcapital%
    {\MakeCapital{#1}}%
    {#1}}}%

%%%% Commands, for users and internal %%%%

\renewcommand*{\multicitedelim}{\addsemicolon\addspace}

\renewcommand*{\iffinalcitedelim}{%
  \ifnumequal{\value{textcitecount}}{\value{textcitetotal}-1}}

\renewcommand*{\subtitlepunct}{% Follows CMS16 spec.
  \ifboolexpr{%
    test {\ifterm}%
    and
    not test {\ifcsdef{@cmsst}}%
  }%
  {\addspace}%
  {\addcolon\addspace%
    \global\csundef{@cmsst}}%
}

\newcommand*{\classicpunct}{% 17th ed.
  \ifboolexpr{%
    (
    test {\iffieldequalstr{entrysubtype}{classical}}%
    and
    test {\iffieldundef{labeltitle}}%
    )
    or
    test {\ifentrytype{letter}}%
    or
    test {\ifentrytype{dataset}}%
  }%
  {\setunit*{\addspace}}%
  {\setunit*{\addcomma\addspace}}}

\newcommand*{\reprintpunct}{%
  \iftoggle{cms@fullnote}%
  {\setunit*{\addsemicolon\addspace}}%
  {\setunit*{\newunitpunct}}}

\newcommand*{\encypunct}{% for named entries in an encyclopedia
  \iftoggle{cms@fullnote}%
  {\ifentrytype{book}%
    {\ifthenelse{\iffieldundef{addendum}\AND\iffieldundef{doi}\AND
        \iffieldundef{isbn}\AND\iffieldundef{url}}%
      {\ifthenelse{\value{multicitecount} < \value{multicitetotal}}%
        {}%
        {\addperiod}}%
      {\addcomma}}%
    {\ifnameundef{author}%
      {\ifthenelse{\iffieldundef{addendum}\AND\iffieldundef{doi}\AND
          \iffieldundef{isbn}\AND\iffieldundef{url}}%
        {\ifthenelse{\value{multicitecount} < \value{multicitetotal}}%
          {}%
          {\addperiod}}%
        {\addcomma}}%
      {}}}%
  {\ifentrytype{book}%
    {\addperiod}%
    {\ifnameundef{author}%
      {\addperiod}%
      {}}}}%

\newcommand*{\postvolpunct}{\addcolon}% For vol:page customization

\newcommand*{\parttrans}{%
  \iftoggle{cms@fullnote}%
  {\bibstring{cbytranslator}\addspace}%
  {\bibstring{bytranslator}\addspace}}%

\protected\def\partedit#1{%
  \ifcat\noexpand~\noexpand#1%
  \ifundef{\cms@tempb}{}{\appto{\cms@tempb}{#1}}%
  \def\cms@tempa{\futurelet\cms@tempa\partedit}%
  \else%
  \ifx\addnbspace#1%
  \ifundef{\cms@tempb}{}{\appto{\cms@tempb}{#1}}%
  \def\cms@tempa{\futurelet\cms@tempa\partedit}%
  \else%
  \ifx\addspace#1%
  \ifundef{\cms@tempb}{}{\appto{\cms@tempb}{#1}}%
  \def\cms@tempa{\futurelet\cms@tempa\partedit}%
  \else%
  \if#1H%
  \appto{\cms@tempb}{#1}%
  \def\cms@tempa{\futurelet\cms@tempa\partedit}%
  \else%
  \if#1h%
  \appto{\cms@tempb}{#1}%
  \def\cms@tempa{\futurelet\cms@tempa\partedit}%
  \else%
  \def\cms@tempa{\part@edit@i\lbx@initnamehook{#1}%
    \csuse{cms@tempb}#1\csundef{cms@tempb}}%
  \fi%
  \fi%
  \fi%
  \fi%
  \fi%
  \cms@tempa%
}%

\newcommand*{\part@edit@i}{%
  \iftoggle{cms@fullnote}%
  {\bibstring{cbyeditor}\addspace}%
  {\bibstring{byeditor}\addspace}}%

\newcommand*{\partcomp}{%
  \iftoggle{cms@fullnote}%
  {\bibstring{cbycompiler}\addspace}%
  {\bibstring{bycompiler}\addspace}}%

\newcommand*{\parteditandcomp}{%
  \iftoggle{cms@fullnote}%
  {\bibstring{cbyeditorcp}\addspace}%
  {\bibstring{byeditorcp}\addspace}}%

\newcommand*{\parttransandcomp}{%
  \iftoggle{cms@fullnote}%
  {\bibstring{cbytranslatorcp}\addspace}%
  {\bibstring{bytranslatorcp}\addspace}}%

\newcommand*{\partedittransandcomp}{%
  \iftoggle{cms@fullnote}%
  {\bibstring{cbyeditortrcp}\addspace}%
  {\bibstring{byeditortrcp}\addspace}}%

\newcommand*{\parteditandtrans}{%
  \iftoggle{cms@fullnote}%
  {\bibstring{cbyeditortr}\addspace}%
  {\bibstring{byeditortr}\addspace}}%

\newcommand*{\reprint}{%
  \iftoggle{cms@fullnote}%
  {\bibsstring{reprint}}%
  {\bibstring{reprint}}}%

\newcommand*{\multipubsdelim}{\addnbspace/\addspace}

\newcommand*{\multilocsdelim}{%
  \ifthenelse{\value{listcount}<\value{liststop}}%
    {\ifthenelse{\numexpr\value{listcount}+1<\value{liststop}}%
       {\addcomma\addspace}%
       {\ifthenelse{\value{liststop}>2}%
         {\addcomma\addspace\bibstring{and}\addspace}%
         {\addspace\bibstring{and}\addspace}}}%
       {}}%

\newcommand*{\multilangdelim}{%
  \ifthenelse{\value{listtotal}<3}%
  {\addspace\bibstring{and}\addspace}%
  {\ifthenelse{\value{listcount}<\value{listtotal}}%
    {\addcomma\addspace}%
    {\addcomma\addspace\bibstring{and}\addspace}}}%

\newcommand*{\journalpagespunct}{\addcolon\space}% Make it configurable

\renewcommand*{\postnotedelim}{% v 2.1: Made all punct use units
  \ifboolexpr{%
    test {\ifciteibid}%
    and
    (
    test {\ifentrytype{jurisdiction}}%
    or
    test {\ifentrytype{legal}}%
    or
    test {\ifentrytype{legislation}}%
    )
  }%
  {\setunit{\addspace}}%
  {\iftoggle{cms@shortnote}%
    {\iffieldequalstr{entrysubtype}{classical}%
      {\DeclareNumChars*{abcdeABCDE:}% Makes classical
        \iffieldpages{postnote}% test more accurate. See 17.253.
        {\setunit{\addspace}}%
        {\newcunit}\DeclareNumChars{.}}%
      {\newcunit}}% 16th ed -- no more volumes test.
    {\iftoggle{cms@fullnote}%
      {\ifthenelse{\(\ifentrytype{article}\OR
          \ifentrytype{review}\OR
          \ifentrytype{periodical}\OR
          \ifentrytype{suppperiodical}\)\AND\NOT
          \iffieldequalstr{entrysubtype}{magazine}}%
        {\setunit{\journalpagespunct}}%
        {\newcunit}}%
      {\newcunit}}}}%

\DeclareListParser{\docmslist}{|}
\DeclareListParser*{\forcmslist}{|}
\newcounter{cms@punct}

\def\cms@strip@spaces#1{%
  \def\do@i##1{%
    \iffieldstart{postnote}{##1}%
    {\toggletrue{cms@postspace}%
      \expandarg
      \StrGobbleLeft{#1}{1}[#1]\listbreak}%
    {}}%
  \forcmslist{\do@i}{\space|\,|\addspace|\;|\:|\!}}

\newcommand*{\postnotewrapper}{% To fix bugs in v 2.0 & ff.
  \setcounter{cms@punct}{0}%
  \iftoggle{cms@modpostnote}%
  {\def\do##1{%
      \iffieldstart{postnote}{##1}%
      {\togglefalse{blx@unit}%
        \toggletrue{cms@strippunct}%
        \ifcase\c@cms@punct% Allows US-style punctuation to work
        \def\cms@userpunct{\addcolon}%
        \or
        \def\cms@userpunct{\addsemicolon}%
        \or
        \def\cms@userpunct{\addperiod}%
        \or
        \def\cms@userpunct{\addcomma}%
        \or
        \def\cms@userpunct{\addcomma}%
        \else
        \def\cms@userpunct{##1}%
        \fi
        \expandarg
        \StrGobbleLeft{\abx@field@postnote}{1}[\abx@field@postnote]%
        \cms@strip@spaces{\abx@field@postnote}%
        \ifboolexpr{%
          not test {\iffieldpages{postnote}}%
          and
          test {\iffieldstart{postnote}{ }}%
        }%
        {\StrSubstitute[1]{\abx@field@postnote}{ }{\ }[\abx@field@postnote]}%
        {}%
        \iffieldstart{postnote}{\ }%
        {\setunit{\cms@userpunct}}%
        {\ifboolexpr{%
            test {\iffieldstart{postnote}{ }}%
            or
            togl {cms@postspace}%
          }%
          {\togglefalse{cms@postspace}%
            \setunit{\cms@userpunct\addspace}}%
          {\setunit{\cms@userpunct}}}%
        \listbreak}%
      {\stepcounter{cms@punct}}}%
    \docmslist{:|;|.|,|\bibrangessep|\addcolon|\addsemicolon|
      \addcomma|\addperiod}%
    \iftoggle{cms@strippunct}%
    {\togglefalse{cms@strippunct}}%
    {\postnotedelim}}%
  {\postnotedelim}}

\newrobustcmd*{\iffieldstart}[2]{% Philipp Lehman's code, from
  \begingroup%                     comp.text.tex
  \edef\@tempa{%
    \long\def\noexpand\iffieldstart@i####1\detokenize{#2}####2}%
  \@tempa\@nil{\endgroup\ifblank{##1}}%
  \savefield*{#1}{\@tempa}%
  \expandafter\iffieldstart@i\detokenize
  \expandafter\expandafter\expandafter{%
    \expandafter\@tempa\detokenize{#2}}\@nil}

\newcommand*{\editordelim}{%
  \ifboolexpr{%
    test {\iffieldequalstr{editortype}{none}}%
    and
    not togl {cms@fullnote}%
  }%
  {\newunit}%\addperiod\addspace
  {\newcunit}}%\addcomma\addspace

\newcommand*{\nameadelim}{%
  \ifboolexpr{%
    test {\iffieldequalstr{nameatype}{none}}%
    and
    not togl {cms@fullnote}%
  }%
  {\newunit}%\addperiod\addspace
  {\newcunit}}%\addcomma\addspace

\DeclareDelimFormat{dateeradelim}{\addnbspace}%
\DeclareDelimFormat{dateaddelim}{\addnbspace}%

\DeclareListFormat{cfromoriglanguage}{% Needed for notes, to provide
  \begingroup% final {by}.
  \blx@bibstringnormal%
  \usebibmacro{list:delim}{%
    \ifbibstring{from#1}%
      {\bibxlstring{cfrom#1}}%
      {\ifbibstring{clang#1}%
         {\bibxlstring{lang#1}}%
         {#1}}}%
  \ifbibstring{cfrom#1}%
  {\ifboolexpr{%
      test {\ifnumless{\value{listcount}}{\value{liststop}}}%
      or
      test {\ifmoreitems}%
     }%
     {\bibstring{from#1}}%
     {\bibstring{cfrom#1}}}%
    {\ifbibstring{lang#1}%
       {\biblstring{lang#1}}%
       {#1}}%
 \usebibmacro{list:andotherlangs}%
 \endgroup}

\newbibmacro*{list:andotherlangs}{% Final {by} after {andmore}
  \ifboolexpr{%
    test {\ifnumequal{\value{listcount}}{\value{liststop}}}%
    and
    test {\ifmoreitems}%
  }%
    {\ifnumgreater{\value{liststop}}{1}%
       {\finalandcomma}%
       {}%
     \printdelim{andmoredelim}\bibstring{andmore}\addspace\bibstring{by}}%
    {}}

\newcommand*{\lbx@cfromlang}{% Because the cbytranslator string can't
  \iffieldundef{userf}% have {by} in it unless there's an origlanguage.
  {\iflistundef{origlanguage}%
    {\unspace}%
    {\printlist[cfromoriglanguage]{origlanguage}}}%
  {\unspace}}%

\renewcommand*{\lbx@fromlang}{%
  \iffieldundef{userf}%
  {\iflistundef{origlanguage}%
    {\unspace}%
    {\printlist[lfromoriglanguage]{origlanguage}}}%
  {\unspace}}%

\renewcommand*{\lbx@lfromlang}{%
  \iffieldundef{userf}%
  {\iflistundef{origlanguage}%
    {\unspace}%
    {\printlist[lfromoriglanguage]{origlanguage}}}%
  {\unspace}}%

\renewcommand*{\lbx@sfromlang}{%
  \iffieldundef{userf}%
  {\iflistundef{origlanguage}%
    {\unspace}%
    {\printlist[sfromoriglanguage]{origlanguage}}}%
  {\unspace}}%

%%%% Formatting macros, called both by cbx and bbx %%%%

\newbibmacro*{finentry}{%{\finentry} To make annotated bibliography
  \togglefalse{cms@switchdates}%
  \ifboolexpr{%
    togl {cms@annotation}%
    or
    togl {cms@cbxannote}%
  }%
    {\usebibmacro{entrytail}}%
    {}%
  \finentry}

\newbibmacro*{book:xref+finentry}{% FIXME
  \ifthenelse{\iffieldundef{crossref}\OR\ifbibliography}%
  {\ifthenelse{\iffieldundef{xref}\OR\ifbibliography}%
    {}%
    {\iftoggle{cms@bookcitexref}%
      {\cms@citetracker@xref}%
      {\bibhypertarget{\thefield{xref}}%
        {\cms@citetracker@xref}}}}%
  {\iftoggle{cms@bookcitexref}%
    {\cms@citetracker@crossref}%
    {\bibhypertarget{\thefield{crossref}}%
      {\cms@citetracker@crossref}}}}%

\newbibmacro*{cite:xref+finentry}{% FIXME
  \ifthenelse{\iffieldundef{crossref}\OR\ifbibliography}%
  {\ifthenelse{\iffieldundef{xref}\OR\ifbibliography}%
    {}%
    {\iftoggle{cms@citecrossref}%
      {\cms@citetracker@xref}%
      {\bibhypertarget{\thefield{xref}}%
        {\cms@citetracker@xref}}}}%
  {\iftoggle{cms@citecrossref}%
    {\cms@citetracker@crossref}%
    {\bibhypertarget{\thefield{crossref}}%
      {\cms@citetracker@crossref}}}}%

\newbibmacro*{allshort+firstcite+xref}{%
  \ifboolexpr{%
    (
    togl {cms@citecrossref}%
    and
    togl {cms@bookcitexref}%
    )
    or
    not togl {cms@allshort}%
  }%
  {}%
  {\ifciteseen%
    {}%
    {\iffieldundef{crossref}%
      {\iffieldundef{xref}%
        {}%
        {\cms@citetracker@xref}}%
      {\cms@citetracker@crossref}}}}%

\def\cms@citetracker@crossref{% cf. \blx@citetracker@global
  \ifbool{citetracker}%
    {\xifinlistcs\abx@field@crossref{blx@bsee@\the\c@refsection}%
       {}%
       {\listcsxadd{blx@bsee@\the\c@refsection}\abx@field@crossref%
         \iffieldundef{clonesourcekey}%
         {\cms@save@locdata{crossref}}{}}}%
    {}}%

\def\cms@citetracker@xref{% cf. \blx@citetracker@global
  \ifbool{citetracker}%
    {\xifinlistcs\abx@field@xref{blx@bsee@\the\c@refsection}%
       {}%
       {\listcsxadd{blx@bsee@\the\c@refsection}\abx@field@xref%
         \iffieldundef{clonesourcekey}%
         {\cms@save@locdata{xref}}{}}}%
    {}}%

\def\cms@citetracker@clonesourcekey{%
  \ifbool{citetracker}%
  {\xifinlistcs\abx@field@clonesourcekey{blx@bsee@\the\c@refsection}%
    {}%
    {\listcsxadd{blx@bsee@\the\c@refsection}\abx@field@clonesourcekey%
      \cms@save@locdata{clonesourcekey}}}%
  {}}%

\newbibmacro*{entrytail}{% From reading.bbx, for annotated bibliography
  \ifbibliography%
  {\iftoggle{cms@annotation}%
    {\togglefalse{blx@unit}%
      \togglefalse{blx@keepunit}%
      \setunit{\bibannotesep}%
      \usebibmacro{annotation}%
      \newunit\newblock}%
    {\newunit}}%
  {\iftoggle{cms@cbxannote}%
    {\togglefalse{blx@unit}%
      \togglefalse{blx@keepunit}%
      \setunit{\citeannotesep}%
      \usebibmacro{annotation}%
      \newunit\newblock}%
    {\newunit}}}%

% From biblatex.def; biblatex 3.15 toggled blx@bibliography off here,
% but we still need to be able to test it in Chicago, at least with
% the current code, so redefine the macro.

\renewbibmacro*{annotation}{%
  \iffieldundef{annotation}%
    {\printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}}%
    {\printfield{annotation}}}

\newbibmacro*{author+holder}{%
  \ifnameundef{author}%
    {}%
    {\printnames{author}%
     \ifthenelse{\ifnameundef{holder}\OR%
                 \ifnamesequal{author}{holder}}%
       {}%
       {\setunit{\addspace}%
        \printtext[parens]{\printnames{holder}}}}}

\renewbibmacro*{byauthor}{% MT fix
  \ifnameundef{author}%
  {}%
  {\ifboolexpr{%
      test {\ifuseauthor}%
      and not
      test {\ifcsempty{abx@macro@author/editor}}%
    }%
    {}%
    {\bibstring{byauthor}\addspace%
     \printnames[byauthor]{author}}}}

\newbibmacro*{byauthorpunct}{% Obsolete?
  \ifthenelse{\ifuseauthor\OR\ifnameundef{author}}%
  {\addperiod\addspace}%
  {\newcunit}}

\renewbibmacro*{bybookauthor}{%
  \ifnameundef{bookauthor}%
    {}%
    {\ifnamesequal{author}{bookauthor}%
      {}%
      {\bibstring{byauthor}\addspace\printnames[default]{bookauthor}%
     \newcunit\newblock}}}

\newbibmacro*{music+bookauthor}{%
  \ifnameundef{bookauthor}%
    {}%
    {\ifnamesequal{author}{bookauthor}%
      {}%
      {\printnames[default]{bookauthor}%
     \newcunit\newblock}}}

\newbibmacro*{editorpunct}{%
  \ifthenelse{\(\iffieldundef{booktitle}\AND%
    \iffieldundef{maintitle}\AND\iffieldundef{issuetitle}\)%
    \OR\iffieldsequal{booktitle}{title}%  Changed these for crossrefed
    \OR\iffieldsequal{maintitle}{title}}% entries.  Create problems?
  {\ifboolexpr{%
      test {\ifentrytype{video}}% Change for Video type?  Appears
      or
      togl {cms@mtvolpunct}%
    }%
    {\newcunit\newblock}% to treat italicized title as booktitle in
    {\newunit\newblock}}% available examples.  Added issuetitle 0.9.9c.
  {\newcunit\newblock}}

\newbibmacro*{edition}{%
  \printfield{edition}%
  \clearfield{edition}}%

\newbibmacro*{version}{%
  \printfield{version}%
  \clearfield{version}}%

\newbibmacro*{inforaft}{%
  \ifnameundef{introduction}%
  {\ifnameundef{afterword}%
    {\ifnameundef{foreword}%
      {\printfield{type}}%
      {\bibstring{forewordto}%
        \clearname{foreword}}}% 16th ed.
    {\bibstring{afterwordto}%
      \clearname{afterword}}}%
  {\bibstring{introductionto}%
    \clearname{introduction}}}

\newbibmacro*{langlist:andothers}{%
  \ifthenelse{\value{listcount}=\value{liststop}\AND%
              \ifmoreitems}%
    {\ifnum\value{liststop}>1 \finalandcomma\fi%
     \andmoredelim\bibstring{andmore}\bibrightbracket}%
    {}}%

\newbibmacro*{mag+news+author}{%
  \ifnameundef{author}%
  {\ifboolexpr{%
      test {\iffieldequals{journaltitle}{\bbx@lasthash}}%
      and
      not test {\iffirstonpage}%
      and
      togl {cms@namedash}%
    }%
    {\printtext{\bibnamedash}}%
    {\usebibmacro{journal+sub}{}%
      \setunit{\addspace}%
      \printlist[periodplace]{location}%
      \savefield{journaltitle}{\bbx@lasthash}}}%
  {\ifuseauthor%
    {\usebibmacro{author}}%
    {}}}%

\newbibmacro*{cmag+news+author}{%
  \ifnameundef{author}%
  {}% 16th ed.
  {\ifuseauthor%
    {\usebibmacro{author}}%
    {}}}%

\newbibmacro*{type+inst+year}{%
  \printfield{type}%
  \newcunit
  \printlist{institution}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{date}}%  Instead of cmsyear

\newbibmacro*{institution+organization}{%
  \iflistundef{organization}%
  {\iflistundef{institution}%
    {}%
    {\printlist{institution}}}%
  {\printlist{organization}%
    \newcunit%
    \printlist{institution}}}

\newbibmacro*{misc+institution+organization}{% 17th ed.
  \iffieldundef{number}%
  {\iflistundef{organization}%
    {\iflistundef{institution}%
      {}%
      {\printlist{institution}}}%
    {\printlist{organization}%
      \newcunit%
      \printlist{institution}}}%
  {\iflistundef{organization}%
    {\iflistundef{institution}%
      {\newcunit\printfield{number}}%
      {\newcunit\printfield{number}%
        \iftoggle{cms@fullnote}%
        {\newcunit}%
        {\newunit}%
        \printlist{institution}}}%
    {\iflistundef{institution}%
      {\newcunit\printfield{number}%
        \iftoggle{cms@fullnote}%
        {\newcunit}%
        {\newunit}%
        \printlist{organization}}%
      {\printlist{organization}%
        \newcunit%
        \printfield{number}%
        \newcunit%
        \printlist{institution}}}}}

\newbibmacro*{bibauthor+org}{%
  \ifnameundef{author}%
  {\ifnameundef{editor}%
    {\iflistundef{organization}%
      {}%
      {\ifboolexpr{%
          test {\iflistequals{organization}{\bbx@lasthash}}%
          and
          not test {\iffirstonpage}%
          and
          togl {cms@namedash}%
        }%
        {\printtext{\bibnamedash}}%
        {\printlist{organization}%
          \savelist{organization}{\bbx@lasthash}}}}%
    {\usebibmacro{editor}}}%
  {\usebibmacro{author/editor}}}

\newbibmacro*{author+org}{%
  \ifnameundef{author}%
  {\ifnameundef{editor}%
    {\iflistundef{organization}%
      {}%
      {\printlist{organization}}}%
    {\usebibmacro{editor}}}%
  {\usebibmacro{author/editor}}}

\renewbibmacro*{bytypestrg}[2]{% From biblatex.def
  \iffieldundef{#1type}%
    {\bibstring{by#2}}%
    {\ifbibxstring{by\thefield{#1type}}%
      {\bibstring{by\thefield{#1type}}}%
      {\printtext[capital]{\thefield{#1type}}}}}%

\newbibmacro*{cbytypestrg}[2]{%
  \iffieldundef{#1type}%
    {\bibstring{cby#2}}%
    {\ifbibxstring{cby\thefield{#1type}}%
      {\bibstring{cby\thefield{#1type}}}%
      {\printtext[capital]{\thefield{#1type}}}}}%

\newbibmacro*{cbyeditor}{%
  \ifnameundef{editor}%
    {}%
    {\usebibmacro{cbytypestrg}{editor}{editor}%
     \setunit{\addspace}%
     \printnames[byeditor]{editor}%
     \newcunit}%
  \usebibmacro{cbyeditorx}}

\newbibmacro*{cbyeditorx}{%
  \ifnameundef{editora}%
    {}%
    {\usebibmacro{cbytypestrg}{editora}{editor}%
     \setunit{\addspace}%
     \printnames[byeditora]{editora}%
     \newcunit}%
  \ifnameundef{editorb}%
    {}%
    {\usebibmacro{cbytypestrg}{editorb}{editor}%
     \setunit{\addspace}%
     \printnames[byeditorb]{editorb}%
     \newcunit}%
  \ifnameundef{editorc}%
    {}%
    {\usebibmacro{cbytypestrg}{editorc}{editor}%
     \setunit{\addspace}%
     \printnames[byeditorc]{editorc}%
     \newcunit}}

\newbibmacro*{cbytranslator}{%
  \ifnameundef{translator}%
  {}%
  {\bibstring{cbytranslator}%
    \addspace%
    \printnames[bytranslator]{translator}}}

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

\newbibmacro*{cbyredactor}{%
  \ifnameundef{redactor}%
    {}%
    {\bibstring{cbyredactor}\addspace%
     \printnames[byredactor]{redactor}}}

\newbibmacro*{cwithcommentator}{%
  \ifnameundef{commentator}%
    {}%
    {\bibsstring{withcommentator}\addspace%
     \printnames[withcommentator]{commentator}}}

\newbibmacro*{cwithannotator}{%
  \ifnameundef{annotator}%
    {}%
    {\bibsstring{withannotator}\addspace%
     \printnames[withannotator]{annotator}}}

\newbibmacro*{cwithintroduction}{%
  \ifnameundef{introduction}%
    {}%
    {\bibstring{withintroduction}\addspace%
     \printnames[withintroduction]{introduction}}}

\newbibmacro*{cwithforeword}{%
  \ifnameundef{foreword}%
    {}%
    {\bibstring{withforeword}\addspace%
     \printnames[withforeword]{foreword}}}

\newbibmacro*{cwithafterword}{%
  \ifnameundef{afterword}%
    {}%
    {\bibstring{withafterword}\addspace%
     \printnames[withafterword]{afterword}}}

\newbibmacro*{cbyeditor+others}{%
  \ifthenelse{\NOT\ifnameundef{editor}\AND%
    \(\iffieldundef{editortype}\OR%
    \iffieldequalstr{editortype}{editor}\)}%
  {\def\@tempa{cbyeditor}%
    \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}\addspace% \setunit here?
    \printnames[byeditor]{editor}%
    \clearname{editor}%
    \newcunit%
    \usebibmacro{cbyeditorx}}%
  {\usebibmacro{cbyeditor}}%
  \usebibmacro{cbytranslator+others}}

\newbibmacro*{cbytranslator+others}{%
  \ifnameundef{translator}%
    {}%
    {\def\@tempa{cbytranslator}%
      \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}%
     \newcunit}%
  \usebibmacro{cbycompiler+others}}

\newbibmacro*{cbycompiler+others}{%
  \ifnameundef{namec}%
    {}%
    {\def\@tempa{cbycompiler}%
     \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}%
     \newcunit}%
  \usebibmacro{cbyothers}}

\newbibmacro*{cbyothers}{%
  \usebibmacro{cbytranslator}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cbycompiler}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cbyredactor}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cwithcommentator}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cwithannotator}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cwithintroduction}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cwithforeword}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cwithafterword}}

\newbibmacro*{part+editor+translator}{%
  \ifnameundef{namea}%
  {\ifnameundef{nameb}%
    {}%
    {\bibstring{bytranslator}\addspace%
      \printnames[bytranslator]{nameb}}}%
  {\ifthenelse{\iffieldundef{nameatype}\OR%
      \iffieldequalstr{nameatype}{editor}}%
    {\ifnamesequal{namea}{nameb}%
      {\bibstring{byeditortr}\addspace%
        \printnames[byeditor]{namea}}%
      {\bibstring{byeditor}\addspace%
        \printnames[byeditor]{namea}%
        \ifnameundef{nameb}%
        {}%
        {\usebibmacro{related:mtpunct}%\newunit% MT fix
          \bibstring{bytranslator}\addspace%
          \printnames[bytranslator]{nameb}}}}%
    {\usebibmacro{bytypestrg}{namea}{editor}%
      \setunit{\addspace}%
      \printnames[byeditor]{namea}%
      \ifnameundef{nameb}%
      {}%
      {\usebibmacro{related:mtpunct}%\newunit% MT fix
        \bibstring{bytranslator}\addspace%
        \printnames[bytranslator]{nameb}}}}}

\newbibmacro*{cpart+editor+translator}{%
  \ifnameundef{namea}%
  {\ifnameundef{nameb}%
    {}%
    {\bibstring{cbytranslator}\addspace%
      \printnames[bytranslator]{nameb}}}%
  {\ifthenelse{\iffieldundef{nameatype}\OR%
      \iffieldequalstr{nameatype}{editor}}%
    {\ifnamesequal{namea}{nameb}%
      {\bibstring{cbyeditortr}\addspace%
        \printnames[byeditor]{namea}}%
      {\bibstring{cbyeditor}\addspace% Need this \space here?
        \printnames[byeditor]{namea}%
        \ifnameundef{nameb}%
        {}%
        {\newcunit%
          \bibstring{cbytranslator}\addspace%
          \printnames[bytranslator]{nameb}}}}%
    {\usebibmacro{cbytypestrg}{namea}{editor}%
      \setunit{\addspace}%
      \printnames[byeditor]{namea}%
      \ifnameundef{nameb}%
      {}%
      {\newcunit%
        \bibstring{cbytranslator}\addspace%
        \printnames[bytranslator]{nameb}}}}}

\newbibmacro*{cms-in:}{% Fix for 0.9a compat.
  \iftoggle{cms@origpublished}%
  {}% Removed the cms@crspace test -- fixed a bug I had introduced
  {\bibstring{in}%
    \setunit{\addspace}}}

\newbibmacro*{bibxref-in:}{%
  \iffieldundef{volume}%
  {\ifcsdef{cbx@incollvol}%
    {\restorefield{volume}{\cbx@incollvol}\toggletrue{cms@xrefvol}%
      \ifcsdef{cbx@incollpart}%
      {\restorefield{part}{\cbx@incollpart}}%
      {}%
      \ifboolexpr{%
        test {\IfBeginWith{\thefield{entrytype}}{mv}}%
        and
        not test {\IfBeginWith{\thefield{relatedtype}}{maintitl}}%
      }%
      {\DeclareFieldAlias{citetitle}{title:hook:alt}%
        \DeclareFieldAlias{shorthand}{shorthand:hook}%
        \printfield{volume}%
        \clearfield{volume}%
        \global\let\cbx@incollvol\undefined% Volume fix
        \printfield{part}%
        \clearfield{part}%
        \global\let\cbx@incollpart\undefined% Volume fix
        \setunit{\addspace}%
        \bibstring{ofseries}%
        \iftoggle{smartof}{}{\setunit{\addspace}}}%
      {\bibstring{in}\setunit{\addspace}}}%
    {\iffieldundef{part}%
      {\ifcsdef{cbx@incollpart}%
        {\restorefield{part}{\cbx@incollpart}\toggletrue{cms@xrefpart}}%
        {}}%
      {}%
      \ifboolexpr{%
        test {\IfBeginWith{\thefield{entrytype}}{mv}}%
        and
        not test {\IfBeginWith{\thefield{relatedtype}}{maintitl}}%
        and
        togl {cms@xrefpart}%
      }%
      {\DeclareFieldAlias{citetitle}{title:hook:alt}%
        \DeclareFieldAlias{shorthand}{shorthand:hook}%
        \printfield[xrefpart]{part}%
        \clearfield{part}%
        \global\let\cbx@incollpart\undefined% Volume fix
        \setunit{\addspace}%
        \bibstring{ofseries}%
        \iftoggle{smartof}{}{\setunit{\addspace}}}%
      {\bibstring{in}\setunit{\addspace}}}}%
  {\iffieldundef{part}%
    {\ifcsdef{cbx@incollpart}%
      {\restorefield{part}{\cbx@incollpart}\toggletrue{cms@xrefpart}}%
      {}}%
    {}%
    \ifthenelse{\ifentrytype{mvbook}\OR\ifentrytype{mvcollection}\OR%
      \ifentrytype{mvproceedings}\OR\ifentrytype{mvreference}}%
    {\DeclareFieldAlias{citetitle}{title:hook:alt}%
      \DeclareFieldAlias{shorthand}{shorthand:hook}%
      \printfield{volume}%
      \clearfield{volume}%
      \global\let\cbx@incollvol\undefined% Volume fix
      \printfield{part}%
      \clearfield{part}%
      \global\let\cbx@incollpart\undefined% Volume fix
      \setunit{\addspace}%
      \bibstring{ofseries}%
      \iftoggle{smartof}{}{\setunit{\addspace}}}%
    {\bibstring{in}\setunit{\addspace}}}}%

\newbibmacro*{chapincoll}{%
  \iffieldundef{chapter}%
  {}%
  {\printfield{chapter}\addspace%
    \clearfield{chapter}}}%

\newbibmacro*{xrefchapincoll}{%
  \iffieldundef{chapter}%
  {\printtext{\relax}}%
  {\printfield{chapter}\addspace%
    \clearfield{chapter}}}%

\newbibmacro*{chapinscore}{%
  \iffieldundef{chapter}%
  {\ifboolexpr{%
      not test {\iffieldundef{eventyear}}%
      and
      not test {\iffieldundef{booktitle}}%
      and
      test {\ifentrytype{audio}}%
      and
      not togl {cms@origpublished}%
      and
      (
      not test {\iffieldundef{title}}%
      or
      not test {\iffieldundef{titleaddon}}%
      )
    }%
    {\bibstring{in}\setunit{\addspace}}%
    {}}%
  {\printfield{chapter}\clearfield{chapter}%
    \iffieldundef{booktitle}%
    {}%
    {\iftoggle{cms@reprintfrom}%
      {\DeclareFieldAlias{btnoformat}{title:hook}}%
      {\DeclareFieldAlias{btnoformat}{title:hook:alt}}%
      \DeclareFieldAlias{sbtnoformat}{title}%
      \DeclareFieldAlias{booktitle}{default}%
      \addspace\bibstring[\cms@ofwrap]{ofseries}%
      \iftoggle{smartof}{}{\setunit{\addspace}}}}}%

\newbibmacro*{chap+as+track}{%
  \iffieldundef{chapter}%
  {\ifboolexpr{%
      not test {\iffieldundef{booktitle}}%
      and
      not togl {cms@origpublished}%
      and
      (
      not test {\iffieldundef{title}}%
      or
      not test {\iffieldundef{titleaddon}}%
      )
    }%
    {\bibstring{on}\setunit{\addspace}}%
    {}}%
  {\printfield{chapter}\clearfield{chapter}%
    \iffieldundef{booktitle}%
    {}%
    {\addspace\bibstring[\cms@ofwrap]{on}\setunit{\addspace}}}}%

\newbibmacro*{caddendum}{% New macros for 16th ed. field exclusion
  \ifboolexpr{%
    togl {cms@addendum}%
    and
    not test {\iffieldundef{addendum}}%
  }%
  {\newcunit\printfield{addendum}}%
  {}}%

\newbibmacro*{cnotefield}{%
  \iftoggle{cms@notefield}%
  {\printfield{note}}%
  {}}%

\newbibmacro*{cser+num}{%
  \iftoggle{cms@bookseries}%
  {\usebibmacro{series+or+shortser}%
    \printfield[sernum]{number}}%
  {}}%

\newbibmacro*{ser+num}{%
  \usebibmacro{series+or+shortser}%
  \printfield[sernum]{number}}

\newbibmacro*{series+or+shortser}{%
  \iffieldundef{shortseries}%
  {\printfield{series}}%
  {\ifboolexpr{%
      (
      test {\ifcitation}%
      and
      togl {cms@citeshser}%
      )
      or
      (
      test {\ifbibliography}%
      and
      togl {cms@bibshser}%
      )
    }%
    {\printfield{shortseries}}%
    {\printfield{series}}}}

\newbibmacro*{music+origdate}{%
  \iffieldequalstr{pubstate}{reprint}% 17th ed.
  {}%
  {\iffieldundef{origyear}%
    {}%
    {\usebibmacro{cmsorigdate}}%
    \iffieldundef{pubstate}%
    {}%
    {\iffieldbibstring{pubstate}%
      {\iftoggle{cms@fullnote}%
        {\newcunit
          \bibsstring{\thefield{pubstate}}}%
        {\newunit
          \biblstring{\thefield{pubstate}}}}%
      {\iftoggle{cms@fullnote}%
        {\newcunit}%
        {\newunit}%
        \printfield[prenote]{pubstate}}}}}% Date fix

\newbibmacro*{music+eventdate}{%
  \iffieldundef{eventyear}%
  {}%
  {\printeventdate}}% Date fix

\newbibmacro*{ctitle+stitle}{% New test here for related entries.
  \iffieldundef{title}%
  {}%
  {\printtext[title]{%
      \printfield[tnoformat]{title}%
      \setunit{\subtitlepunct}%
      \printfield[stnoformat]{subtitle}}}%
  \setunit{\ctitleaddonpunct}%
  \printfield{titleaddon}}%

\newbibmacro*{citaltitle+stitle}{% New test, as above.
  \iffieldundef{title}%
  {}%
  {\printtext[title]{%
      \printfield[tnoformat]{title}%
      \setunit{\subtitlepunct}%
      \printfield[stnoformat]{subtitle}}}%
  \setunit{\ctitleaddonpunct}%
  \printfield{titleaddon}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newcunit\newblock}

\newbibmacro*{title+stitle}{%
  \iffieldundef{title}%
  {}%
  {\printtext[title]{%
      \printfield[noformat]{title}%
      \setunit{\subtitlepunct}%
      \printfield[noformat]{subtitle}}}%
  \setunit{\ptitleaddonpunct}%
  \printfield{titleaddon}}%

\newbibmacro*{italtitle+stitle}{%
  \iffieldundef{title}%
  {}%
  {\printtext[title]{%
      \printfield[noformat]{title}%
      \setunit{\subtitlepunct}%
      \printfield[noformat]{subtitle}}}%
  \setunit{\ptitleaddonpunct}%
  \printfield{titleaddon}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit\newblock}

\newbibmacro*{mag+news+title}{%
  \printtext[title]{%
       \printfield[noformat]{title}%
       \setunit{\subtitlepunct}%
       \printfield[noformat]{subtitle}}%
     \setunit{\ptitleaddonpunct}%
     \ifboolexpr{%
       test {\iffieldequalstr{relatedtype}{reviewof}}%
       and
       togl {cms@related}%
     }%
     {\usebibmacro{related:init}%
       \usebibmacro{related}}%
     {\printfield{titleaddon}}%
     }%

\newbibmacro*{cmag+news+title}{%
  \printtext[title]{%
       \printfield[noformat]{title}%
       \setunit{\subtitlepunct}%
       \printfield[noformat]{subtitle}}%
     \setunit{\ctitleaddonpunct}%
     \ifboolexpr{%
       test {\iffieldequalstr{relatedtype}{reviewof}}%
       and
       togl {cms@citerel}%
     }%
     {\toggletrue{cms@relreview}%
       \usebibmacro{related:init}%
       \usebibmacro{related:noterefhelper}%
       \usebibmacro{related}%
       \togglefalse{cms@relreview}}%
     {\printfield{titleaddon}}%
     }%

\newbibmacro*{clegis+news+title}{%
  \ifthenelse{\iffieldundef{title}\AND\iffieldundef{subtitle}\AND%
    \iffieldundef{titleaddon}}%
  {}%
  {\printtext[title]{%
      \printfield[noformat]{title}%
      \setunit{\subtitlepunct}%
      \printfield[noformat]{subtitle}}%
    \setunit{\ctitleaddonpunct}%
    \printfield{titleaddon}%
  }}%

\newbibmacro*{language+transtitle}{%
  \iffieldundef{usere}%
  {\printlist[][-\value{listtotal}]{language}}%
  {\printfield{usere}}}

\newbibmacro*{issuetitle}{%
  \iffieldundef{issuetitle}%
  {}%
  {\ifthenelse{\ifentrytype{article}\OR%
      \ifentrytype{review}\OR%
      \ifentrytype{suppperiodical}}% This test is for
    {\usebibmacro{cms-in:}}% periodical entries
    {}%
    \printtext[issuetitle]{%
      \printfield[itnoformat]{issuetitle}%
      \iftoggle{cms@reprintfrom}% Complications due to \smartof
      {}%
      {\setunit{\subtitlepunct}%
        \printfield[sitnoformat]{issuesubtitle}}}}}

\newbibmacro*{btitle+bstitle}{%
  \iffieldundef{booktitle}%
  {}%
  {\ifthenelse{\ifentrytype{audio}\OR\ifentrytype{music}\OR%
      \ifentrytype{video}}%
    {}%
    {\usebibmacro{cms-in:}}%
    \printtext[booktitle]{%
      \printfield[btnoformat]{booktitle}%
      \setunit{\subtitlepunct}%
      \printfield[sbtnoformat]{booksubtitle}}%
    \setunit{\ctitleaddonpunct}%
    \printfield{booktitleaddon}}}%

\newbibmacro*{publ+loc+year}{% Revised for reprint (17th ed.)
  \iffieldundef{pubstate}%
  {}%
  {\iffieldequalstr{pubstate}{reprint}%
    {\ifentrytype{video}%
      {}%
      {\bibstring{reprint}%
        \newcunit}}%
    {\iffieldbibstring{pubstate}%
      {\bibstring{\thefield{pubstate}}%
        \newcunit}%
      {\printfield[prenote]{pubstate}%
        \newcunit}}}%
  \printlist{location}%
  \iflistundef{publisher}%
  {\setunit*{\addcomma\addspace}}%
  {\setunit*{\addcolon\addspace}}%
  \printlist{publisher}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{date}%
}

\newbibmacro*{origpubl+loc+year}{% 16th ed.
  \printlist{origlocation}%
  \iflistundef{origpublisher}%
  {\setunit*{\addcomma\addspace}}%
  {\setunit*{\addcolon\addspace}}%
  \printlist{origpublisher}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{cmsorigdate}%
}

\newbibmacro*{howpubl+loc+year}{% Revised for reprint (17th ed)
  \usebibmacro{cmsorigdate}%
  \reprintpunct%
  \iffieldundef{pubstate}%
  {}%
  {\iffieldbibstring{pubstate}%
    {\iftoggle{cms@fullnote}%
      {\bibsstring{\thefield{pubstate}}}%
      {\biblstring{\thefield{pubstate}}}}%
    {\printfield[prenote]{pubstate}}%
    \newcunit}%
  \printlist{location}%
  \iffieldundef{howpublished}%
  {\setunit*{\addcomma\addspace}}%
  {\setunit*{\addcolon\addspace}}%
  \printfield{howpublished}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{date}%
}

\newbibmacro*{inst+loc+year}{% Revised for reprint (17th ed)
  \usebibmacro{origpubl+loc+year}% 16th ed.
  \reprintpunct%
  \iffieldundef{pubstate}%
  {}%
  {\iffieldbibstring{pubstate}%
    {\iftoggle{cms@fullnote}%
      {\bibsstring{\thefield{pubstate}}}%
      {\biblstring{\thefield{pubstate}}}}%
    {\printfield[prenote]{pubstate}}%
    \newcunit}%
  \printlist{location}%
  \iflistundef{institution}%
  {\setunit*{\addcomma\addspace}}%
  {\setunit*{\addcolon\addspace}}%
  \printlist{institution}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{date}%
}%

\newbibmacro*{cpubl+loc+year}{% Revised for reprint
  \ifboolexpr{%
    test {\iflistundef{location}}%
    and
    test {\iflistundef{publisher}}%
    and
    test {\iffieldundef{year}}%
    and
    test {\iffieldundef{pubstate}}% 17th ed
  }%
  {}%
  {\setunit{\addspace}%
    \printtext[parens]{%
      \usebibmacro{origpubl+loc+year}%
      \setunit*{\addsemicolon\addspace}%
      \iffieldundef{pubstate}% 17th ed
      {}%
      {\iffieldequalstr{pubstate}{reprint}%
        {\ifentrytype{video}%
          {}%
          {\bibsstring{reprint}%
            \newcunit}}%
        {\iffieldbibstring{pubstate}%
          {\bibsstring{\thefield{pubstate}}%
            \newcunit}%
          {\printfield[prenote]{pubstate}%
            \newcunit}}}%
      \printlist{location}%
      \iflistundef{publisher}%
      {\setunit*{\addspace}}%
      {\setunit*{\addcolon\addspace}}%
      \printlist{publisher}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{date}}}}%

\newbibmacro*{crefpubl+loc+year}{% 17th ed.
  \ifboolexpr{%
    test {\iflistundef{location}}%
    and
    test {\iflistundef{publisher}}%
    and
    test {\iffieldundef{year}}%
    and
    test {\iffieldundef{pubstate}}%
    and
    test {\iffieldundef{note}}%
  }%
  {}%
  {\setunit{\addspace}%
    \printtext[parens]{%
      \usebibmacro{origpubl+loc+year}%
      \setunit*{\addsemicolon\addspace}%
      \iffieldundef{pubstate}%
      {}%
      {\iffieldequalstr{pubstate}{reprint}%
        {\ifentrytype{video}%
          {}%
          {\bibsstring{reprint}%
            \newcunit}}%
        {\iffieldbibstring{pubstate}%
          {\bibsstring{\thefield{pubstate}}%
            \newcunit}%
          {\printfield[prenote]{pubstate}%
            \newcunit}}}%
      \usebibmacro{cnotefield}%
      \setunit*{\addcomma\addspace}%
      \printlist{location}%
      \iflistundef{publisher}%
      {\setunit*{\addspace}}%
      {\setunit*{\addcolon\addspace}}%
      \printlist{publisher}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{date}}}}%

\newbibmacro*{cpubletter+loc+year}{%
  \ifboolexpr{%
    test {\iflistundef{location}}%
    and
    test {\iflistundef{publisher}}%
    and
    test {\iffieldundef{year}}%
  }%
  {}%
  {\setunit{\addspace}%
    \printtext[parens]{%
      \printlist{location}%
      \iflistundef{publisher}%
      {\setunit*{\addspace}}%
      {\setunit*{\addcolon\addspace}}%
      \printlist{publisher}%
      \setunit{\addcomma\addspace}%
      \usebibmacro{date}}}}% Changed for 0.9

\newbibmacro*{originally+published+as}{% Punctuation fix now in
  \iffieldundef{userf}%                  \origfullcite for 0.8e.
  {\iffieldundef{reprinttitle}%
    {}%
    {\usebibmacro{begrelated}%
      \bibstring{reprintfrom}% ?
      \origpublcite{\thefield{reprinttitle}}%
      \usebibmacro{endrelated}%
      \newunit}}%
  {\usebibmacro{begrelated}%
    \iflistundef{origlanguage}%
    {\bibstring{origpub}%
      \origfullcite{\thefield{userf}}%
      \usebibmacro{endrelated}%
      \newunit}%
    {\iftoggle{cms@postposit}%
      {\bibstring{origedition}%
        \setunit{\addspace}%
        \printlist[edlang]{origlanguage}%
        \addcolon\addspace%
        \origfullcite{\thefield{userf}}%
        \usebibmacro{endrelated}%
        \newunit}%
      {\printlist[edlang]{origlanguage}%
        \setunit{\addspace}%
        \bibstring{origedition}%
        \origfullcite{\thefield{userf}}%
        \usebibmacro{endrelated}%
        \newunit}}}}

\newbibmacro*{org+publ+loc+year}{% What was wrong with \ifthenelse here?
  \usebibmacro{origpubl+loc+year}%{cmsorigdate}% 16th ed.
  \reprintpunct%
  \iffieldundef{pubstate}%
  {}%
  {\iffieldbibstring{pubstate}%
    {\iftoggle{cms@fullnote}%
      {\bibsstring{\thefield{pubstate}}}%
      {\biblstring{\thefield{pubstate}}}}%
    {\printfield[prenote]{pubstate}}%
    \newcunit}%
  \printlist{location}%
  \iflistundef{organization}%
  {\iflistundef{publisher}%
    {\setunit*{\addcomma\addspace}}%
    {\setunit*{\addcolon\addspace}}}%
  {\setunit*{\addcolon\addspace}}%
  \printlist{organization}%
  \setunit*{\addcomma\addspace}%
  \printlist{publisher}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{date}}

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

\newbibmacro*{letter+date}{% New for 0.9
  \iflistundef{origlocation}%
  {}%
  {\printlist{origlocation}%
    \newcunit\newblock}%
  \iftoggle{cms@switchdates}%
  {\ifthenelse{\iffieldundef{year}\AND\iffieldundef{month}\AND%
      \iffieldundef{yeardivision}}%
    {}%
    {\cms@datelong{}}}%
  {\ifthenelse{\iffieldundef{origyear}\AND\iffieldundef{origmonth}\AND%
      \iffieldundef{origyeardivision}}%
    {}%
    {\cms@datelong{orig}}}}

\newbibmacro*{unpubl+letter+date}{% For Misc entries
  \iffieldundef{venue}%
  {}%
  {\printfield{venue}%
    \newcunit\newblock}%
  \iftoggle{cms@switchdates}%
  {\ifthenelse{\iffieldundef{year}\AND\iffieldundef{month}\AND%
      \iffieldundef{yeardivision}}%
    {}%
    {\cms@datelong{}}}%
  {\ifthenelse{\iffieldundef{origyear}\AND\iffieldundef{origmonth}\AND%
      \iffieldundef{origyeardivision}}%
    {\printdate}% For interviews and other dated non-letters.
    {\cms@datelong{orig}}}}

\newbibmacro*{music+pubstate}{%
  \iffieldequalstr{pubstate}{reprint}%
  {\iftoggle{cms@switchdates}%
    {\iffieldundef{year}%
      {}%
      {\printtext{% 16th ed.
          \usebibmacro{choosepubstring}%
          \printdate}}}%
    {\iffieldundef{origyear}%
      {}%
      {\printtext{% 16th ed.
          \usebibmacro{choosepubstring}%
          \printorigdate}}}}%
  {}}%

\newbibmacro*{choosepubstring}{%
  \ifthenelse{\ifentrytype{video}\OR%
    \ifentrytype{music}}%
  {\bibstring{origreleaseyear}}%
  {\bibstring{origpubyearalt}}}%

\renewbibmacro*{date}{% New for 0.9
  \iftoggle{cms@switchdates}%
  {\printorigdate}%
  {\printdate}}

\newbibmacro*{time+stamp}{% 17th ed.
  \iftoggle{cms@switchdates}%
  {\iffieldundef{orighour}%
    {}%
    {\newcunit\printorigtime}}%
  {\iffieldundef{hour}%
    {}%
    {\newcunit\printtime}}}

\newbibmacro{cite:xref+date}{%
  \ifboolexpr{%
    togl {cms@omitxrefdate}%
    or
    togl {cms@bookcitexref}%
    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}%
    ))
    or
    not test {\ifentryseen{\thefield{crossref}}}%
  }%
  {\ifboolexpr{%
      togl {cms@omitxrefdate}%
      or
      togl {cms@bookcitexref}%
      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}%
      ))
      or
      not test {\ifentryseen{\thefield{xref}}}%
    }%
    {}%
    {\printtext[parens]{\usebibmacro{date}}}}%
  {\printtext[parens]{\usebibmacro{date}}}}

\newbibmacro*{cmsorigdate}{% New for 0.9
  \iftoggle{cms@switchdates}%
  {\printdate}%
  {\printorigdate}}

\newbibmacro*{cmsyear}{%
  \iftoggle{cms@switchdates}%
  {\printorigdateextra}% \printfield{origyear}
  {\printdateextra}}% \printfield{year}

\newbibmacro*{number+or+month}{%
  \iffieldundef{number}%
  {\usebibmacro{date}}%
  {\iftoggle{cms@numbermonth}%
    {\usebibmacro{date}}%
    {\usebibmacro{cmsyear}}}}

\newcommand*{\cms@datelong}[1]{% Modified for 17th ed.
  \begingroup
  \protected\def\mkbibdatelong##1##2##3{%
    \iffieldundef{##3}%
    {}%
    {\iftoggle{cms@ukord}%
      {\mkbibordinal{\thefield{##3}}}%
      {\stripzeros{\thefield{##3}}}%
      \iffieldundef{##2}{}{\nobreakspace}}%
    \iffieldundef{##2}%
    {}%
    {\mkbibmonth{\thefield{##2}}%
      \iffieldundef{##1}{}{\space}}%
    \iffieldbibstring{##1}%
    {\bibstring{\thefield{##1}}}%
    {\cmsdateeraprintpre{##1}\stripzeros{\thefield{##1}}}}%
  \cms@mkbibrangetrunc{long}{#1}%
  \endgroup}%

\newrobustcmd*{\letterdatelong}{% For users: 17th ed.
  \ifboolexpr{%
    test {\ifdefstring{\blx@languagename}{american}}%
    or
    test {\ifdefstring{\blx@languagename}{english}}% i.e., no babel
  }%
  {\iftoggle{cms@switchdates}%
    {\cms@datelong{}}%
    {\cms@datelong{orig}}}%
  {\iftoggle{cms@switchdates}%
    {\printdate}%
    {\printorigdate}}}%

\newbibmacro*{cjournal+ser+vol+num}{%
  \usebibmacro{journal+sub}{in}%
  \setunit{\addspace}%
  \printlist[periodplace]{location}%
  \setunit{\addspace}%
  \iffieldundef{series}%
    {}%
    {\newcunit%
      \printfield[jourser]{series}%
      \newcunit}%\setunit*{\addspace}?
  \printfield[jourvol]{volume}%
  \setunit{\addcomma\addspace}% need * here?
  \printfield[journum]{number}}% Moved eid for 17th ed.

\newbibmacro*{cperiodical+ser+vol+num}{% For periodical entries,
  \ifboolexpr{% article subtype
    not test {\iffieldundef{shorttitle}}%
    and
    ((
    test {\ifcitation}%
    and
    togl {cms@citejtabb}%
    )
    or
    (
    test {\ifbibliography}%
    and
    togl {cms@bibjtabb}%
    )
    or
    (
    test {\iffieldundef{title}}%
    and
    test {\iffieldundef{titleaddon}}%
    ))
  }%
  {\clearlist{location}\printtext[shorttitle]{%
      \printfield[tnoformat]{shorttitle}}}%
  {\iffieldundef{title}%
    {\printfield{titleaddon}}%
    {\printtext[title]{%
        \printfield[tnoformat]{title}%
        \setunit{\subtitlepunct}%
        \printfield[stnoformat]{subtitle}}%
      \setunit{\jtitleaddonpunct}%
      \printfield{titleaddon}}}%
  \setunit{\addspace}%
  \printlist[periodplace]{location}%
  \setunit*{\addspace}%
  \iffieldundef{series}%
    {}%
    {\newcunit%
      \printfield[jourser]{series}%
      \newcunit}%\setunit*{\addspace}?
  \printfield[jourvol]{volume}%
  \setunit{\addcomma\addspace}% need * here?
  \printfield[journum]{number}}% Move eid field for 17th ed.

\newbibmacro*{journal+sub}[1]{%
  \ifboolexpr{%
    not test {\iffieldundef{shortjournal}}%
    and
    ((
    test {\ifcitation}%
    and
    togl {cms@citejtabb}%
    )
    or
    (
    test {\ifbibliography}%
    and
    togl {cms@bibjtabb}%
    )
    or
    (
    test {\iffieldundef{journaltitle}}%
    and
    test {\iffieldundef{journaltitleaddon}}%
    ))
  }%
  {\clearlist{location}\printtext[#1shortjournal]{%
      \printfield[jtsnoformat]{shortjournal}}}%
  {\iffieldundef{journaltitle}%
    {\iffieldundef{journaltitleaddon}%
      {}%
      {\printfield{journaltitleaddon}}}%
    {\printtext[#1journaltitle]{%
        \printfield[jtnoformat]{journaltitle}%
        \setunit{\subtitlepunct}%
        \printfield[sjtnoformat]{journalsubtitle}}%
      \setunit{\jtitleaddonpunct}%
      \printfield{journaltitleaddon}}}}%

\newbibmacro*{cite+doi+url}{% 16th ed.
  \iftoggle{cms@url@innotes}%
  {\ifboolexpr{% Fix printing of urldate when url=false
      togl {cms@url}%
      and
      not test {\iffieldundef{urlyear}}%
      and
      not togl {cms@doinodate}%
    }%
    {\printurldate%
      \ifboolexpr{% 17th ed.
        togl {cms@urltime}%
        and
        not test {\iffieldundef{urlhour}}%
      }%
      {\newcunit\printurltime}%
      {}}% Date fix
    {}%
    \newcunit\newblock
    \iftoggle{cms@doionly}%
    {\iffieldundef{doi}%
      {}%
      {\printfield{doi}%
        \clearfield{url}}}%
    {\ifboolexpr{%
        togl {cms@doi}%
        and
        not test {\iffieldundef{doi}}%
      }%
      {\printfield{doi}}%
      {}}%
    \newcunit\newblock
    \ifboolexpr{%
      togl {cms@eprint}%
      and
      not test {\iffieldundef{eprint}}%
    }%
    {\usebibmacro{eprint}}%
    {}%
    \newcunit\newblock
    \ifboolexpr{%
      togl {cms@url}%
      and
      not test {\iffieldundef{url}}%
    }%
    {\printfield{url}}%
    {}}%
  {}}%

\newbibmacro*{chap+pag}{%
  \printfield{chapter}%
  \setunit*{\addcomma\addspace}%
  \printfield{pages}}

\newbibmacro*{mag+news+date}{% 17th ed.
  \iftoggle{cms@fullnote}%
  {\usebibmacro{cmag+date+issue}}%
  {\ifnameundef{author}%
    {\iffieldundef{maintitle}%
      {\newunit\newblock}% Punctuation differs after title and jtitle
      {\printtext[maintitle]{%
          \printfield[mtnoformat]{maintitle}%
          \setunit{\subtitlepunct}%
          \printfield[smtnoformat]{mainsubtitle}}%
        \setunit{\jtitleaddonpunct}%
        \printfield{maintitleaddon}%
        \newcunit\newblock}%
      \printfield{usera}%
      \setunit*{\addcomma\addspace}\newblock%
      \usebibmacro{date+issue}}%
    {\usebibmacro{mag+date+issue}}}}

\newbibmacro*{date+issue}{%
  \iffieldundef{issue}%
  {\iffieldundef{number}%
    {\usebibmacro{date}%
      \usebibmacro{time+stamp}}% 17th ed.
    {\iftoggle{cms@numbermonth}% For exclusion of month
      {\usebibmacro{date}}%
      {\usebibmacro{cmsyear}}%
      \setunit{\addcomma\addspace}%
      \printfield[journum]{number}}}%
  {\printfield{issue}%
    \setunit{\addspace}%
    \usebibmacro{cmsyear}}}

\newbibmacro*{cmag+date+issue}{%
  \usebibmacro{journal+sub}{in}%
  \setunit{\addspace}%
  \printlist[periodplace]{location}%
  \newcunit\newblock
  \iffieldundef{maintitle}%
  {}%
  {\printtext[maintitle]{%
      \printfield[mtnoformat]{maintitle}%
      \setunit{\subtitlepunct}%
      \printfield[smtnoformat]{mainsubtitle}}%
    \setunit{\jtitleaddonpunct}%
    \printfield{maintitleaddon}}
  \newcunit\newblock
  \printfield{usera}% For network ID and possible section of newspaper.
  \newcunit\newblock
  \usebibmacro{date+issue}}

\newbibmacro*{mag+date+issue}{%
  \usebibmacro{journal+sub}{in}%
  \setunit{\addspace}%
  \printlist[periodplace]{location}%
  \newunit\newblock
  \iffieldundef{maintitle}%
  {}%
  {\printtext[maintitle]{%
      \printfield[mtnoformat]{maintitle}%
      \setunit{\subtitlepunct}%
      \printfield[smtnoformat]{mainsubtitle}}%
    \setunit{\jtitleaddonpunct}%
    \printfield{maintitleaddon}}
  \newcunit\newblock
  \printfield{usera}% For network ID and possible section of newspaper.
  \newcunit\newblock
  \usebibmacro{date+issue}}

\newbibmacro*{periodical+date+issue}{% For periodical type &
  \ifboolexpr{% magazine subtype
    not test {\iffieldundef{shorttitle}}%
    and
    ((
    test {\ifcitation}%
    and
    togl {cms@citejtabb}%
    )
    or
    (
    test {\ifbibliography}%
    and
    togl {cms@bibjtabb}%
    )
    or
    (
    test {\iffieldundef{title}}%
    and
    test {\iffieldundef{titleaddon}}%
    ))
  }%
  {\clearlist{location}\printtext[shorttitle]{%
      \printfield[tnoformat]{shorttitle}}}%
  {\iffieldundef{title}%
    {\printfield{titleaddon}}%
    {\printtext[title]{%
        \printfield[tnoformat]{title}%
        \setunit{\subtitlepunct}%
        \printfield[stnoformat]{subtitle}}%
      \setunit{\jtitleaddonpunct}%
      \printfield{titleaddon}}}%
  \setunit{\addspace}%
  \printlist[periodplace]{location}%
  \iftoggle{cms@fullnote}{\newcunit}{\newunit}%
  \iffieldundef{maintitle}%
  {}%
  {\printtext[maintitle]{%
      \printfield[mtnoformat]{maintitle}%
      \setunit{\subtitlepunct}%
      \printfield[smtnoformat]{mainsubtitle}}%
    \setunit{\jtitleaddonpunct}%
    \printfield{maintitleaddon}}
  \newcunit\newblock
  \printfield{usera}% For network ID and possible section of newspaper.
  \newcunit\newblock
  \usebibmacro{date+issue}}

\def\cms@ofwrap#1{#1}

\newbibmacro*{cmtitle+mstitle+vol+part+title+stitle}{%
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\iffieldundef{title}%
      {\usebibmacro{cms-in:}}%
      {\bibstring{in}\setunit{\addspace}}%
      \printtext[maintitle]{%
        \printfield[mtnoformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[smtnoformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}%
    {\toggletrue{cms@usedvol}%
      \printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}%
      \bibstring[\cms@ofwrap]{ofseries}%
      \iftoggle{smartof}{}{\setunit{\addspace}}%
      \printtext[default]{%
        \printfield[title:hook:alt]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[title]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}}}

\newbibmacro*{cmtitle+mstitle+vol+part+btitle+bstitle}{%
  \usebibmacro{btitle+bstitle}%
  \newcunit% MT Fix
  \iffieldundef{maintitle}%
  {}%
  {\ifthenelse{\(\iffieldundef{volume}\AND\iffieldundef{part}\)\OR%
      \(\iffieldundef{booktitle}\AND\NOT\ifentrytype{bookinbook}\)}%
    {\iffieldundef{booktitle}% Fix for origpublin ???
      {\usebibmacro{cms-in:}}%
      {\bibstring{in}\setunit{\addspace}}%
      \printtext[maintitle]{%
        \printfield[mtnoformat]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[smtnoformat]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}%
      \toggletrue{cms@vol}}% InIn fix
    {\toggletrue{cms@usedvol}%
      \printfield{volume}%
      \printfield{part}%
      \setunit{\addspace}%
      \bibstring[\cms@ofwrap]{ofseries}%
      \iftoggle{smartof}{}{\setunit{\addspace}}%
      \printtext[default]{%
        \printfield[title:hook:alt]{maintitle}%
        \setunit{\subtitlepunct}%
        \printfield[title]{mainsubtitle}}%
      \setunit{\ctitleaddonpunct}%
      \printfield{maintitleaddon}}}}

\newbibmacro*{backref+check}{%
  \ifbibliography%
  {\backtrackerfalse}%
  {}}%

\newbibmacro*{cite:postnote}{%
  \iftoggle{cms@loccit}%
  {}%
  {\usebibmacro{postnote}}}

\newbibmacro*{semel:postnote}{% Fix to print postnote only once
  \printfield{postnote}% Old form broke \ifloccit
  \global\let\cms@pnsaved\abx@field@postnote%
  \global\let\abx@field@postnote\undefined%
  \AtNextCitekey{\ifciteibid{}{\global\let\cms@pnsaved\undefined}}}%

\renewbibmacro*{postnote}{%
  \iftoggle{cms@fullnote}%
  {\global\togglefalse{cms@shortnote}%
    \global\togglefalse{cms@fullnote}}%
  {\IfBeginWith{\thefield{entrytype}}{mv}%
    {\usebibmacro{crossref:volume+postnote}}%
    {\iftoggle{cms@printshhand}%
      {\iffieldundef{postnote}%
        {\iffieldundef{shorthand}%
          {\global\togglefalse{cms@printshhand}%
            \global\togglefalse{cms@shortnote}%
            \global\togglefalse{cms@fullnote}}%
          {\setunit{\shorthandpunct}%
            \usebibmacro{cms:shorthandintro}%
            \global\togglefalse{cms@printshhand}%
            \global\togglefalse{cms@shortnote}%
            \global\togglefalse{cms@fullnote}}}%
        {\iffieldundef{shorthand}%
          {\postnotewrapper%delim%
            \usebibmacro{semel:postnote}%
            \global\togglefalse{cms@printshhand}%
            \global\togglefalse{cms@shortnote}%
            \global\togglefalse{cms@fullnote}}%
          {\postnotewrapper%delim%
            \usebibmacro{semel:postnote}%
            \setunit{\shorthandpunct}%
            \usebibmacro{cms:shorthandintro}%
            \global\togglefalse{cms@printshhand}%
            \global\togglefalse{cms@shortnote}%
            \global\togglefalse{cms@fullnote}}}}%
      {\iffieldundef{postnote}%
        {\usebibmacro{print+noteref}%
          \global\togglefalse{cms@shortnote}%
          \global\togglefalse{cms@fullnote}}%
        {\postnotewrapper%delim%
          \usebibmacro{semel:postnote}%
          \usebibmacro{print+noteref}%
          \global\togglefalse{cms@shortnote}%
          \global\togglefalse{cms@fullnote}}}}}}%

\newbibmacro*{fullpostnote}{%
  \iffieldundef{postnote}%
  {\iffieldundef{chapter}%
    {\iffieldundef{pages}%
      {}%
      {\postnotedelim%
        \printfield{pages}}}%
    {\postnotedelim%
      \printfield{chapter}}}%
  {\postnotewrapper%delim% Don't need \ifbibliography test w/ following
    \usebibmacro{semel:postnote}}}

\newbibmacro*{eid+fullpostnote}{%
  \iffieldundef{postnote}%
  {\iffieldundef{chapter}%
    {\iffieldundef{pages}%
      {\iffieldundef{eid}%
        {}%
        {\postnotedelim%
          \printfield{eid}%
          \clearfield{eid}}}%
      {\postnotedelim%
        \printfield{pages}}}%
    {\postnotedelim%
      \printfield{chapter}}}%
  {\postnotewrapper%
    \usebibmacro{semel:postnote}}}

\newbibmacro*{juridpostnote}{%
  \iftoggle{cms@fullnote}%
  {\iffieldundef{issue}%
    {\iffieldundef{shortjournal}%
      {\setunit{\addcomma\addspace}}%
      {\ifthenelse{\iffieldundef{part}\AND\iffieldundef{chapter}}%
        {\setunit{\addspace}}%
        {\ifpunctmark{*}{\setunit{\addspace}}{\newcunit}}}%
      \printfield{pages}%
      \iffieldundef{postnote}%
      {}%
      {\ifthenelse{\ifentrytype{legislation}\OR\ifentrytype{legal}}%
        {\newcunit}%
        {\setunit*{\addcomma\addspace}}%
        \usebibmacro{semel:postnote}}}%
    {\iffieldundef{postnote}%
      {\iffieldundef{pages}%
        {}%
        {\newcunit%
          \printfield{pages}}}%
      {\newcunit%
        \usebibmacro{semel:postnote}}}}%
  {\iffieldundef{issue}%
    {\iffieldundef{postnote}%
      {\iffieldundef{pages}%
        {}%
        {\iffieldundef{shortjournal}%
          {\setunit{\addcomma\addspace}}%
          {\ifthenelse{\iffieldundef{part}\AND\iffieldundef{chapter}}%
            {\setunit{\addspace}}%
            {\ifpunctmark{*}{\setunit{\addspace}}{\newcunit}}}%
          \printfield{pages}}}%
      {\iffieldundef{shortjournal}%
        {\setunit{\addcomma\addspace}}%
        {\ifthenelse{\iffieldundef{part}\AND\iffieldundef{chapter}}%
          {\setunit{\addspace}}%
          {\ifpunctmark{*}{\setunit{\addspace}}{\newcunit}}}%
        \usebibmacro{semel:postnote}}}% See below for alternate test here
    {\iffieldundef{postnote}%
      {\iffieldundef{pages}%
        {}%
        {\newcunit%
          \printfield{pages}}}%
      {\newcunit%
        \usebibmacro{semel:postnote}}}%
    \global\togglefalse{cms@fullnote}%
    \global\togglefalse{cms@shortnote}}}%

\newbibmacro*{volfullpostnote}{%
  \iftoggle{cms@postvol}%
  {\ifboolexpr{(
      test {\iffieldundef{volume}}%
      and
      test {\iffieldundef{part}}%
      )
      or
      togl {cms@usedvol}%
    }%
    {\usebibmacro{fullpostnote}}%
    {\iffieldundef{postnote}%
      {\iffieldundef{chapter}%
        {\iffieldundef{pages}%
          {\newcunit\printfield{volume}%
            \printfield{part}}%
          {\iffieldundef{part}%
            {\ifthenelse{\iffieldnums{pages}\AND%
                \iffieldundef{bookpagination}\AND\iffieldnums{volume}}%
              {\newcunit\printfield[shortvol]{volume}%
                \postvolpunct%
                \printfield{pages}}%
              {\newcunit\printfield{volume}%
                \addcomma\addspace%
                \printfield{pages}}}%
            {\newcunit\printfield{volume}%
              \printfield{part}%
              \addcomma\addspace%
              \printfield{pages}}}}%
        {\newcunit\printfield{volume}%
          \printfield{part}%
          \newcunit
          \printfield{chapter}}}%
      {\iffieldundef{part}%
        {\ifthenelse{\iffieldnums{postnote}\AND%
            \iffieldundef{pagination}\AND\iffieldnums{volume}}%
          {\newcunit\printfield[shortvol]{volume}%
            \postvolpunct%
            \usebibmacro{semel:postnote}}%
          {\newcunit\printfield{volume}%
            \addcomma\addspace%
            \usebibmacro{semel:postnote}}}%
        {\newcunit\printfield{volume}%
          \printfield{part}%
          \addcomma\addspace%
          \usebibmacro{semel:postnote}}}}}%
  {\usebibmacro{fullpostnote}}%
  \global\togglefalse{cms@usedvol}}%

\newbibmacro*{volume+or+volumes}{% Volume fix (modified)
  \ifboolexpr{ (
    test {\iffieldundef{maintitle}}%
    or
    togl {cms@vol}%
    )
    and
    not togl {cms@postvol}%
    and
    not togl {cms@usedvol}%
  }%
  {\global\togglefalse{cms@vol}%
    \ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\printfield{volumes}}%
    {\printfield{volume}%
      \printfield{part}}}%
  {\ifboolexpr{%
      togl {cms@hidevolumes}%
      and
      (
      not test {\iffieldundef{volume}}%
      or
      not test {\iffieldundef{part}}%
      or
      togl {cms@usedvol}%
      )
    }%
    {\global\togglefalse{cms@vol}}%
    {\global\togglefalse{cms@vol}%
      \printfield{volumes}}}}

\newbibmacro*{crossref:volume+postnote}{%
  \IfBeginWith{\thefield{entrytype}}{mv}%
  {\usebibmacro{extract+mt+vol}}%
  {}%
  \ifcsdef{cbx@incollpgn}%
  {\restorefield{pagination}{\cbx@incollpgn}}%
  {}%
  \ifcsdef{cbx@incollbkpgn}%
  {\restorefield{bookpagination}{\cbx@incollbkpgn}}%
  {}%
  \iffieldundef{volume}% Volume fix (unfinished)
  {\ifcsdef{cbx@incollvol}%
    {\restorefield{volume}{\cbx@incollvol}%
      \ifcsdef{cbx@incollpart}{\restorefield{part}{\cbx@incollpart}}{}%
      \iffieldundef{postnote}%
      {\ifcsdef{cbx@incollpages}%
        {\restorefield{pages}{\cbx@incollpages}%
          \usebibmacro{pages+cref+print}}%
        {\iffieldundef{pages}%
          {\newcunit\printfield{volume}\printfield{part}}%
          {\usebibmacro{pages+cref+print}}}}%
      {\usebibmacro{postnote+cref+print}}}%
    {\iffieldundef{part}%
      {\ifcsdef{cbx@incollpart}%
        {\restorefield{part}{\cbx@incollpart}%
          \iffieldundef{postnote}%
          {\ifcsdef{cbx@incollpages}%
            {\restorefield{pages}{\cbx@incollpages}%
              \usebibmacro{pages+cref+print}}%
            {\iffieldundef{pages}%
              {\newcunit\printfield{volume}\printfield{part}}%
              {\usebibmacro{pages+cref+print}}}}%
          {\usebibmacro{postnote+cref+print}}}%
        {\ifcsdef{cbx@incollpages}%
          {\restorefield{pages}{\cbx@incollpages}%
            \usebibmacro{fullpostnote}}%
          {\usebibmacro{fullpostnote}}}}%
      {\iffieldundef{postnote}%
        {\ifcsdef{cbx@incollpages}%
          {\restorefield{pages}{\cbx@incollpages}%
            \usebibmacro{pages+cref+print}}%
          {\iffieldundef{pages}%
            {\newcunit\printfield{volume}\printfield{part}}%
            {\usebibmacro{pages+cref+print}}}}%
        {\usebibmacro{postnote+cref+print}}}}}%
  {\iffieldundef{part}%
    {\ifcsdef{cbx@incollpart}%
      {\restorefield{part}{\cbx@incollpart}}%
      {}}%
    {}%
    \iffieldundef{maintitle}% More elaborate test ???
    {\iffieldundef{postnote}%
      {\ifcsdef{cbx@incollpages}%
        {\restorefield{pages}{\cbx@incollpages}%
          \usebibmacro{pages+cref+print}}%
        {\iffieldundef{pages}%
          {\newcunit\printfield{volume}\printfield{part}}%
          {\usebibmacro{pages+cref+print}}}}%
      {\usebibmacro{postnote+cref+print}}}%
    {\ifboolexpr{%
        test {\ifcsdef{cbx@incollvol}}%
        and
        (
        not test {\iffieldequalcs{volume}{cbx@incollvol}}%
        or
        togl {cms@xrefvol}% Necessary ???
        )
      }%
      {\restorefield{volume}{\cbx@incollvol}%
        \iffieldundef{part}%
        {\ifcsdef{cbx@incollpart}{\restorefield{part}{\cbx@incollpart}}{}}%
        {\ifboolexpr{%
            test {\ifcsdef{cbx@incollpart}}%
            and
            (
            not test {\iffieldequalcs{part}{cbx@incollpart}}%
            or
            togl {cms@xrefpart}%
            )
          }%
          {\clearfield{part}\restorefield{part}{\cbx@incollpart}}%
          {\clearfield{part}}}%
        \iffieldundef{postnote}%
        {\ifcsdef{cbx@incollpages}%
          {\restorefield{pages}{\cbx@incollpages}%
            \usebibmacro{pages+cref+print}}%
          {\iffieldundef{pages}%
            {\newcunit\printfield{volume}\printfield{part}}%
            {\usebibmacro{pages+cref+print}}}}%
        {\usebibmacro{postnote+cref+print}}}%
      {\ifboolexpr{%
          test {\ifcsdef{cbx@incollpart}}%
          and
          (
          not test {\iffieldequalcs{part}{cbx@incollpart}}%
          or
          togl {cms@xrefpart}%
          )
        }%
        {\iffieldundef{postnote}%
          {\ifcsdef{cbx@incollpages}%
            {\restorefield{pages}{\cbx@incollpages}%
              \printfield{part}\newcunit\printfield{pages}}%
            {\iffieldundef{pages}%
              {\printfield{part}}%
              {\printfield{part}\newcunit\printfield{pages}}}}%
          {\printfield{part}\newcunit\usebibmacro{semel:postnote}}}%
        {\ifcsdef{cbx@incollpages}%
          {\restorefield{pages}{\cbx@incollpages}%
            \usebibmacro{fullpostnote}}%
          {\usebibmacro{fullpostnote}}}}}}%
  \usebibmacro{print+noteref}}%

\newbibmacro*{pages+cref+print}{% Reusable chunk for above
  \iffieldundef{part}%
  {\ifthenelse{\iffieldnums{pages}\AND%
      \iffieldundef{bookpagination}\AND\iffieldnums{volume}}%
    {\newcunit\printfield[shortvol]{volume}%
      \postvolpunct%
      \printfield{pages}}%
    {\newcunit\printfield{volume}%
      \addcomma\addspace%
      \printfield{pages}}}%
  {\newcunit\printfield{volume}%
    \printfield{part}%
    \addcomma\addspace%
    \printfield{pages}}}

\newbibmacro*{postnote+cref+print}{% Reusable chunk for above
  \iffieldundef{part}%
  {\ifthenelse{\iffieldnums{postnote}\AND%
      \iffieldundef{pagination}\AND\iffieldnums{volume}}%
    {\newcunit\printfield[shortvol]{volume}%
      \postvolpunct%
      \usebibmacro{semel:postnote}}%
    {\newcunit\printfield{volume}%
      \addcomma\addspace%
      \usebibmacro{semel:postnote}}}%
  {\newcunit\printfield{volume}%
    \printfield{part}%
    \addcomma\addspace%
    \usebibmacro{semel:postnote}}}

\newbibmacro*{inreffullpostnote}{%
  \global\togglefalse{cms@usedvol}%
  \iffieldundef{postnote}%
  {\iffieldundef{chapter}%
    {\iffieldundef{pages}%
      {\newcunit%\addcomma\addspace% Change to axe spurious comma
        \printlist[][-\value{listtotal}]{lista}}%
      {\postnotedelim%
        \printfield{pages}}}%
    {\postnotedelim%
      \printfield{chapter}}}%
  {\postnotewrapper%delim%
    \usebibmacro{semel:postnote}}}

\newbibmacro*{xrefprenote}{%
  \ifboolexpr{% Kludgy fix for spurious idem
    test {\ifdefvoid{\blx@idemtracker}}%
    or
    test {\ifbibliography}%
  }%
  {}{\blx@idemtracker}%
  \iffieldundef{volume}{}{\savefield{volume}{\cbx@incollvol}}%
  \iffieldundef{pages}{}{\savefield{pages}{\cbx@incollpages}}%
  \iffieldundef{part}{}{\savefield{part}{\cbx@incollpart}}%
  \iffieldundef{pagination}{}{\savefield{pagination}{\cbx@incollpgn}}%
  \iffieldundef{bookpagination}{}{\savefield{bookpagination}%
    {\cbx@incollbkpgn}}% The next line saves the child's backrefs
  \iflistundef{pageref}{}{\savelist{pageref}{\cbx@incollpgref}}}%

\newbibmacro*{xrefpostnote}{%
  \iftoggle{cms@xrefurl}%
  {\ifbibliography%
    {\usebibmacro{bib+doi+url}}%
    {\usebibmacro{cite+doi+url}}}%
  {}%
  \ifcsdef{cbx@incollpgref}% Here we print and clear the child's
  {\restorelist{pageref}{\cbx@incollpgref}% backrefs
  \newunit%
  \usebibmacro{pageref}%
  \global\let\cbx@incollpgref\undefined}%
  {}%
  \togglefalse{cms@xrefvol}%
  \togglefalse{cms@xrefpart}%
  \global\togglefalse{cms@usedvol}%
  \global\let\cbx@incollvol\undefined% Volume fix
  \global\let\cbx@incollpages\undefined%
  \global\let\cbx@incollpart\undefined%
  \global\let\cbx@incollpgn\undefined%
  \global\let\cbx@incollbkpgn\undefined}%

\newbibmacro*{hlpunct}{%
  \iftoggle{cms@headlessnote}%
  {\iftoggle{cms@reprintfrom}{\setunit{\addspace}}{}}%
  {\newcunit\newblock}}

\newbibmacro*{journalprenote}{%
  \iffieldundef{prenote}%
  {\bibsentence}%
  {\usebibmacro{prenote}}}

\newbibmacro*{choose+surname}{%
  \ifboolexpr{%
    test {\ifciteseen}%
    and
    not togl {cms@noneshort}%
    }%
  {}%
  {\printnames{labelname}\savefield{fullhash}{\bbx@lasthash}%
    \ifthenelse{\iffieldequalstr{labelnamesource}{shortauthor}\OR%
      \iffieldequalstr{labelnamesource}{author}}%
    {\clearname{author}}%
    {\iffieldequalstr{labelnamesource}{shorteditor}%
      {\ifnameundef{namea}%
        {\newcunit\usebibmacro{editstrg}}%
        {\newcunit\usebibmacro{parteditstrg}}}%%
      {\iffieldequalstr{labelnamesource}{editor}%
        {\newcunit\usebibmacro{editstrg}}%
        {\iffieldequalstr{labelnamesource}{translator}%
          {\newcunit\usebibmacro{transstrg}}%
          {\iffieldequalstr{labelnamesource}{namea}%
            {\newcunit\usebibmacro{parteditstrg}}%
            {\iffieldequalstr{labelnamesource}{nameb}%
              {\newcunit\usebibmacro{parttransstrg}}%
              {\iffieldequalstr{labelnamesource}{namec}%
                {\newcunit\usebibmacro{compilestrg}}%
                {}}}}}}}}}%

\newbibmacro*{clear+labelname}{%
  \iffieldequalstr{labelnamesource}{shortauthor}%
  {\clearname{author}\clearname{shortauthor}}%
  {\iffieldequalstr{labelnamesource}{shorteditor}%
    {\ifnameundef{namea}%
      {\clearname{editor}\clearname{shorteditor}}%
      {\clearname{namea}\clearname{shorteditor}}}%
    {\clearname{\thefield{labelnamesource}}}}}

\@ifpackagelater{biblatex}{2012/11/20}% for biblatex 2.4
{\DeclareLabelname{\field{shortauthor} \field{author}%
    \field{shorteditor} \field{namea} \field{editor}%
    \field{nameb} \field{translator} \field{namec}}}%
{\DeclareLabelname{shortauthor,author,shorteditor,namea,%
    editor,nameb,translator,namec}}

\DeclareLabeltitle[legislation]{%
  \field{shorttitle}%
  \field{titleaddon}%
  \field{title}}%

\DeclareDataInheritance{collection}{suppcollection}{%
  \inherit{title}{title}
  \inherit{subtitle}{subtitle}
  \inherit{titleaddon}{titleaddon}}

\DeclareDataInheritance{mvbook}{incollection}{%
  \inherit{title}{maintitle}
  \inherit{subtitle}{mainsubtitle}
  \inherit{titleaddon}{maintitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{book,collection}{letter}{%
  \inherit{title}{booktitle}
  \inherit{subtitle}{booksubtitle}
  \inherit{titleaddon}{booktitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{book}{incollection}{%
  \inherit{title}{booktitle}
  \inherit{subtitle}{booksubtitle}
  \inherit{titleaddon}{booktitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{audio,music,video}{audio,music,video}{%
  \inherit{title}{booktitle}
  \inherit{subtitle}{booksubtitle}
  \inherit{titleaddon}{booktitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{mvbook,mvcollection}{letter}{%
  \inherit{title}{maintitle}
  \inherit{subtitle}{mainsubtitle}
  \inherit{titleaddon}{maintitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{mvcollection}{book}{% MT revision
  \inherit{title}{maintitle}
  \inherit{subtitle}{mainsubtitle}
  \inherit{titleaddon}{maintitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\AtEndPreamble{%
  \iftoggle{cms@inheritshhand}%
  {\DeclareDataInheritance{*}{*}{%
      \inherit{shorthand}{shorthand}
      \inherit{shorthandintro}{shorthandintro}
    }}{}%
  \iftoggle{cms@blogurl}% 17th ed. blogs w/ comments
  {\DeclareDataInheritance{article}{review,suppperiodical}{%
      \inherit{url}{url}%
    }}{}%
  \@ifpackageloaded{endnotes}%
  {\patchcmd\theendnotes
    {\enoteformat}
    {\toggletrue{cms@endnote}\enoteformat}
    {}
    {\blx@err@patch{'endnotes' package}}}%
  {}%
  \iftoggle{cms@strict}%
  {\let\splitfootnoterule\footnoterule
    \renewcommand\footnoterule{}%
    \advance\skip\footins 4\p@\@plus2\p@\relax
    \gdef\split@prev{0}
    \let\pagefootnoterule\footnoterule
    % \def\splitfootnoterule{\kern-3\p@ \hrule \kern2.6\p@}
    \def\footnoterule{\relax
      \ifnum\split@prev=\z@
      \pagefootnoterule
      \else
      \splitfootnoterule
      \fi
      \xdef\split@prev{\the\insertpenalties}%
    }}%
  {}%
  \ifboolexpr{% Needed for nameaddon 'first' option in notes
    test {\ifdefvoid{\blx@idemtracker}}%
    and
    togl {cms@subseqnona}%
  }%
  {\let\blx@idemtracker\blx@idemtracker@context}%
  {}}%

\DeclareDataInheritance{*}{*}{%
  \noinherit{namea}
  \noinherit{nameb}
  \noinherit{nameatype}
  \noinherit{sortyear}
  \noinherit{sortname}
  \noinherit{sorttitle}
  \noinherit{urlyear}
  \noinherit{urlmonth}
  \noinherit{urlday}
  \noinherit{urlyeardivision}
  \noinherit{urlhour}
  \noinherit{urlminute}
  \noinherit{doi}
  \noinherit{eprint}
  \noinherit{eprinttype}
  \noinherit{url}}

\DeclareDataInheritance{mvbook,mvcollection,mvproceedings,mvreference}%
{*}{% ???
  \noinherit{year}
  \noinherit{month}
  \noinherit{day}
  \noinherit{yeardivision}
  \noinherit{endyear}
  \noinherit{endmonth}
  \noinherit{endday}
  \noinherit{endyeardivision}
  \noinherit{origyear}
  \noinherit{origmonth}
  \noinherit{origday}
  \noinherit{origyeardivision}
  \noinherit{origendyear}
  \noinherit{origendmonth}
  \noinherit{origendday}
  \noinherit{origendyeardivision}}

\DeclareSortingTemplate{cms}{% Updated for biblatex > 3.7
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{namea}
    \field{editor}
    \field{nameb}
    \field{translator}
    \field{namec}
    \field{sorttitle}
    \field{journaltitle}
    \field{organization}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
}

\DeclareSortExclusion{misc,online}{organization}
\DeclareSortExclusion{inreference,mvreference,reference}{%
  author,editor,namea,nameb,namec,translator}

\DeclareSortingTemplate{shortjournal}{%
  \sort{
    \field{shortjournal}
  }
}

\DeclareSortingTemplate{shortseries}{%
  \sort{
    \field{shortseries}
  }
}

\newbibmacro*{compilestrg}{%
  \ifthenelse{\value{namec}>1\OR\ifandothers{namec}}%
  {\bibstring{compilers}}%
  {\bibstring{compiler}}%
  \clearname{namec}}%

\newbibmacro*{transstrg}{%
  \ifthenelse{\value{translator}>1\OR\ifandothers{translator}}%
    {\ifnamesequal{translator}{namec}%
      {\bibstring{transcompilers}%
        \clearname{namec}}%
      {\bibstring{translators}}}%
    {\ifnamesequal{translator}{namec}%
      {\bibstring{transcompiler}%
        \clearname{namec}}%
      {\bibstring{translator}}}%
    \clearname{translator}}%

\newbibmacro*{parttransstrg}{%
  \ifthenelse{\value{nameb}>1\OR\ifandothers{nameb}}%
    {\ifnamesequal{nameb}{namec}%
      {\bibstring{transcompilers}%
        \clearname{namec}}%
      {\bibstring{translators}}}%
    {\ifnamesequal{nameb}{namec}%
      {\bibstring{transcompiler}%
        \clearname{namec}}%
      {\bibstring{translator}}}%
    \clearname{nameb}}%

\newbibmacro*{editstrg}{% Test added for 0.9
  \ifthenelse{\iffieldundef{editortype}\OR%
    \iffieldequalstr{editortype}{editor}}%
  {\ifthenelse{\value{editor}>1\OR\ifandothers{editor}}%
    {\ifthenelse{\ifnamesequal{editor}{translator}\AND%
        \ifnamesequal{editor}{namec}}%
      {\bibstring{editortranscompilers}%
        \clearname{translator}%
        \clearname{namec}}%
      {\ifnamesequal{editor}{namec}%
        {\bibstring{editorcompilers}%
          \clearname{namec}}%
        {\ifnamesequal{editor}{translator}%
          {\bibstring{editortranslators}%
            \clearname{translator}}%
          {\bibstring{editors}}}}}%
    {\ifthenelse{\ifnamesequal{editor}{translator}\AND%
        \ifnamesequal{editor}{namec}}%
      {\bibstring{editortranscompiler}%
        \clearname{translator}%
        \clearname{namec}}%
      {\ifnamesequal{editor}{namec}%
        {\bibstring{editorcompiler}%
          \clearname{namec}}%
        {\ifnamesequal{editor}{translator}%
          {\bibstring{editortranslator}%
            \clearname{translator}}%
          {\bibstring{editor}}}}}}%
  {\ifbibxstring{\thefield{editortype}}%
    {\ifthenelse{\value{editor}>1\OR\ifandothers{editor}}%
      {\bibstring{\thefield{editortype}s}}%
      {\bibstring{\thefield{editortype}}}}%
    {\printtext[capital]{\thefield{editortype}}}}%
  \clearname{editor}}%

\newbibmacro*{parteditstrg}{%
  \ifthenelse{\iffieldundef{nameatype}\OR%
    \iffieldequalstr{nameatype}{editor}}%
  {\ifthenelse{\value{namea}>1\OR\ifandothers{namea}}%
    {\ifthenelse{\ifnamesequal{namea}{nameb}\AND%
        \ifnamesequal{namea}{namec}}%
      {\bibstring{editortranscompilers}%
        \clearname{nameb}%
        \clearname{namec}}%
      {\ifnamesequal{namea}{namec}%
        {\bibstring{editorcompilers}%
          \clearname{namec}}%
        {\ifnamesequal{namea}{nameb}%
          {\bibstring{editortranslators}%
            \clearname{nameb}}%
          {\bibstring{editors}}}}}%
    {\ifthenelse{\ifnamesequal{namea}{nameb}\AND%
        \ifnamesequal{namea}{namec}}%
      {\bibstring{editortranscompiler}%
        \clearname{nameb}%
        \clearname{namec}}%
      {\ifnamesequal{namea}{namec}%
        {\bibstring{editorcompiler}%
          \clearname{namec}}%
        {\ifnamesequal{namea}{nameb}%
          {\bibstring{editortranslator}%
            \clearname{nameb}}%
          {\bibstring{editor}}}}}}%
  {\ifbibxstring{\thefield{nameatype}}%
    {\ifthenelse{\value{namea}>1\OR\ifandothers{namea}}%
      {\bibstring{\thefield{nameatype}s}}%
      {\bibstring{\thefield{nameatype}}}}%
    {\printtext[capital]{\thefield{nameatype}}}}%
  \clearname{namea}}%

\newbibmacro*{clearorigin}{%
  \toggletrue{cms@origcite}%
  \ifthenelse{\ifuseauthor\AND\NOT\ifnameundef{author}}%
  {\ifnameundef{bookauthor}%
    {\savefield{fullhash}{\bbx@lasthash}%
      \clearname{author}}%
    {\ifnamesequal{author}{bookauthor}%
      {\clearname{bookauthor}%
        \savefield{fullhash}{\bbx@lasthash}%
        \clearname{author}}%
      {\savefield{fullhash}{\bbx@lasthash}%
        \clearname{author}}}}%
  {\clearname{author}}}%

\newbibmacro*{clearpublin}{%
  \toggletrue{cms@origcite}%
  \ifthenelse{\ifuseauthor\AND\NOT\ifnameundef{author}}%
  {\ifnameundef{bookauthor}%
    {\savefield{fullhash}{\bbx@lasthash}%
      \clearname{author}}%
    {\ifnamesequal{author}{bookauthor}%
      {\clearname{bookauthor}%
        \savefield{fullhash}{\bbx@lasthash}%
        \clearname{author}}%
      {\savefield{fullhash}{\bbx@lasthash}%
        \clearname{author}}}}%
  {\clearname{author}}%
  \ifthenelse{\ifentrytype{collection}\OR\ifentrytype{proceedings}\OR%
    \ifentrytype{mvcollection}\OR\ifentrytype{mvproceedings}}%
  {}%
  {\clearname{namea}%
    \clearname{nameb}}%
  \clearfield{nameaddon}%
  \ifthenelse{\(\ifentrytype{periodical}\OR\ifentrytype{mvbook}\OR%
    \ifentrytype{mvcollection}\OR\ifentrytype{mvproceedings}\OR%
    \ifentrytype{mvreference}\OR\ifentrytype{collection}\OR%
    \ifentrytype{proceedings}\OR\ifentrytype{reference}\OR%
    \ifentrytype{suppbook}\OR\ifentrytype{suppcollection}\)\OR%
    \(\(\ifentrytype{audio}\OR\ifentrytype{music}\OR%
    \ifentrytype{video}\)\AND\(\iffieldundef{booktitle}\AND%
    \iffieldundef{entrysubtype}\)\)}% Song w/o album?
  {}%
  {\clearfield{title}%
    \clearfield{subtitle}%
    \clearfield{titleaddon}%
    \clearfield{usere}%
    \clearlist{language}%
    \ifthenelse{\ifentrytype{music}\OR\ifentrytype{audio}}%
    {\clearfield{note}\clearfield{howpublished}\clearfield{eventyear}%
      \clearfield{eventmonth}}%
    {}}%
  \ifentrytype{letter}%
  {\iftoggle{cms@switchdates}%
    {\clearfield{year}\clearfield{month}\clearfield{yeardivision}}%
    {\clearfield{origyear}\clearfield{origmonth}\clearfield{origyeardivision}}%
    \clearfield{origlocation}}%
  {}%
  \clearfield{reprinttitle}%
}

%%%% Related macros from biblatex.def %%%%

\renewcommand*{\begrelateddelim}{%
  \ifcitation{\newcunitpunct}%
  {\ifboolexpr{%
      togl {cms@fullnote}%
      or
      togl {cms@shortnote}%
    }%
    {\newcunitpunct}%
    {\newunitpunct}}}%

\newcommand*{\begrelateddelimreviewof}{%
  \ifcitation{\newcunitpunct}%
  {\ifboolexpr{%
      togl {cms@fullnote}%
      or
      togl {cms@shortnote}%
    }%
    {\newcunitpunct}%
    {\newunitpunct}}}

\newcommand*{\relateddelimshort}{%
  \ifnumequal{\value{bbx:relatedcount}}{\value{bbx:relatedtotal}}%
    {\addsemicolon\addspace\bibstring{and}\space}%
    {\addsemicolon\addspace}}%

\newbibmacro*{related:reviewof}[1]{%
  \iftoggle{cms@shortnote}%
  {\entrydata*{#1}{%
      \cmsrelhyper{\printfield[citetitle]{labeltitle}}}}%
  {\entrydata*{#1}{%
      \printtext[cmsdefrelhypertarget]{%
        \let\newunit\newcunit%
        \iffieldundef{title}%
        {}%
        {\printtext[title]{%
            \printfield[tnoformat]{title}%
            \setunit{\subtitlepunct}%
            \printfield[stnoformat]{subtitle}}}%
        \newcunit%
        \ifnameundef{author}%
        {\newcunit%
          \ifbibliography%
          {\usebibmacro{byeditor+others}}%
          {\usebibmacro{cbyeditor+others}}}%
        {\bibstring{byauthor}\addspace%
          \printnames[byauthor]{author}%
          \ifbibliography%
          {\newcunit\usebibmacro{byeditor+others}}%
          {\newcunit\usebibmacro{cbyeditor+others}}}%
        \setunit{\ctitleaddonpunct}%
        \printfield{titleaddon}}}}}%

\newbibmacro*{related:commenton}[1]{%
  \iftoggle{cms@shortnote}%
  {\entrydata*{#1}{%
      \iffieldequalstr{authortype}{anon}%
      {\bibleftbracket\printnames{labelname}%
        \bibrightbracket\classicpunct}%
      {\iffieldequalstr{authortype}{anon?}%
        {\bibleftbracket\printnames{labelname}?%
          \bibrightbracket\classicpunct}%
        {\cmsrelnamehyper{\printnames{labelname}}%
          \isdot\classicpunct}}%
      \usebibmacro{cms+relextra+test}}}%
  {\ifbibliography%
    {\entrydata*{#1}{%
        \ifentryinbib{\strfield{clonesourcekey}}%
        {\iffieldequalstr{authortype}{anon}%
          {\bibleftbracket\printnames{labelname}%
            \bibrightbracket\classicpunct}%
          {\iffieldequalstr{authortype}{anon?}%
            {\bibleftbracket\printnames{labelname}?%
              \bibrightbracket\classicpunct}%
            {\printnames{labelname}%
              \isdot\classicpunct}}%
          \usebibmacro{cms+relextra+test}}%
        {\usebibmacro{at+every+item}\toggletrue{cms@fullnote}%
          \iffieldundef{savedyear}{}{\clearfield{year}}%
          \iffieldundef{savedmonth}{}{\clearfield{month}}%
          \iffieldundef{savedyeardivision}{}{\clearfield{yeardivision}}%
          \iffieldundef{savedurl}{}{\clearfield{url}}%
          \iffieldundef{savedaddendum}{}{\clearfield{addendum}}%
          \usebibmacro{bib:related:full}}}}%
    {\entrydata*{#1}{%
        \ifentryseen{\thefield{clonesourcekey}}%
        {\iffieldequalstr{authortype}{anon}%
          {\bibleftbracket\printnames{labelname}%
            \bibrightbracket\classicpunct}%
          {\iffieldequalstr{authortype}{anon?}%
            {\bibleftbracket\printnames{labelname}?%
              \bibrightbracket\classicpunct}%
            {\cmsrelnamehyper{\printnames{labelname}}%
              \isdot\classicpunct}}%
          \usebibmacro{cms+relextra+test}}%
        {\usebibmacro{at+every+item}%
          \iffieldundef{savedurl}{}{\clearfield{url}}%
          \iffieldundef{savedaddendum}{}{\clearfield{addendum}}%
          \listcsxadd{blx@bsee@\the\c@refsection}{\strfield{clonesourcekey}}%
          \usebibmacro{cite:related:full}}}}}}

% Used inside previous to allow chains of relatedtype "commenton"
% entries to mimic online thread structure.  In particular it stops
% the printing of auto-generated title fields.

\newbibmacro*{cms+relextra+test}{%
  \ifboolexpr{%
    test {\iffieldequalstr{relatedtype}{commenton}}%
    and
    (
    test {\ifentrytype{review}}%
    or
    test {\ifentrytype{suppperiodical}}%
    or
    (
    test {\ifentrytype{online}}%
    and
    test {\IfBeginWith{\thefield{title}}{CCCCCC}}%
    ))
  }%
  {\entrydata{\thefield{clonesourcekey}}{%
      \ifboolexpr{%
        test {\iffieldundef{extratitle}}%
        and
        test {\iffieldundef{extraname}}%
      }%
      {}%
      {\ifcsundef{cms@xfield}%
        {\ifentrytype{online}%
          {\setunit{\addspace}%
            \printtext[parens]{%
              \printdate%
              \iffieldundef{hour}%
              {}%
              {\newcunit\printtime}}}%
          {\setunit{\addspace}%
            \printtext[parens]{%
              \printeventdate%
              \iffieldundef{eventhour}%
              {}%
              {\newcunit\printeventtime}}}}%
        {\setunit{\shortextrapunct}%
          \usebibmacro{shortnote+extrafield}}}}}%
  {\cmsrelhyper{\printfield[citetitle]{labeltitle}}}}

\newrobustcmd*{\cmsrelnamehyper}[1]{%
  \ifhyperref%
  {\ifboolexpr{%
      test {\iffieldequalstr{relatedtype}{commenton}}%
      and
      (
      test {\ifentrytype{review}}%
      or
      test {\ifentrytype{suppperiodical}}%
      or
      (
      test {\ifentrytype{online}}%
      and
      test {\IfBeginWith{\thefield{title}}{CCCCCC}}%
      ))
    }%
    {\iffieldequalstr{savedrelatedtype}{commenton}%
      {\iftoggle{cms@allshort}%
        {#1}%
        {\bibhyperlink{\strfield{clonesourcekey}}{#1}}}%
      {\cmsrelhyper{#1}}}%
    {#1}}%
  {#1}}

\renewbibmacro*{related:origpubas}[1]{%
  \entrydata*{#1}{%
    \usebibmacro{at+every+item}%
    \usebibmacro{cite:origfull}}}%

\renewbibmacro*{related:reprintfrom}[1]{%
  \entrydata*{#1}{%
    \usebibmacro{at+every+item}%
    \nopunct% ???
    \usebibmacro{cite:origpubl}}}%

\renewbibmacro*{related:bytranslator}[1]{%
  \entrydata{#1}{%
    \usebibmacro{at+every+item}%
    \renewbibmacro*{name:hook}[1]{%
      \ifnumequal{\value{listcount}}{1}%
      {\begingroup
        \mkrelatedstringtext{%
          \lbx@initnamehook{##1}}%
        \endgroup}%
      {}}%
    \printnames[bytranslator]{translator}%
    \setunit*{\addspace\bibstring[\mkrelatedstringtext]{astitle}\addspace}%
    \clearname{translator}%
    \usebibmacro{cite:origfull}}}%

\renewbibmacro*{related:default}[1]{%
  \entrydata*{#1}{%
    \printtext[cmsdefrelhypertarget]{%
      \usedriver%
      {\ifnameundef{savedauthor}%
        {\ifnameundef{savededitor}%
          {}%
          {\ifnamesequal{editor}{savededitor}%
            {\iftoggle{cms@headlessnote}%
              {}%
              {\clearname{editor}}}%
            {}}}%
        {\ifnamesequal{author}{savedauthor}%
          {\iftoggle{cms@headlessnote}%
            {}%
            {\clearname{author}}}%
          {}}%
        \togglefalse{cms@headlessnote}%
        \usebibmacro{at+every+item}%
        \renewbibmacro*{related:init}{}%
        \DeclareNameAlias{sortname}{default}%
        \renewbibmacro*{pageref}{}%
        \toggletrue{cms@fullnote}%
        \togglefalse{cms@shortnote}}%\nopunct
      {cite:\thefield{entrytype}}}}}%

\newbibmacro*{related:maintitle}[1]{%
  \entrydata*{#1}{%
    \ifthenelse{\ifentrytype{mvbook}\OR\ifentrytype{mvcollection}\OR%
      \ifentrytype{mvproceedings}\OR\ifentrytype{mvreference}}%
    {\iffieldundef{volumes}{}{\savefield*{volumes}{\cms@mtvolumes}}%
      \iftoggle{cms@reprintfrom}%
      {}%
      {\bibstring{in}\nopunct}}%
    {\ifcsdef{cms@mtvolumes}{\restorefield{savedvolumes}{\cms@mtvolumes}}{}%
      \ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
      {\ifthenelse{\iffieldundef{volumes}\AND\iffieldundef{savedvolumes}}%
        {\bibsstring{thiscite}\nopunct}%
        {\iffieldundef{volumes}%
          {\printfield[volumes]{savedvolumes}}%
          {\printfield{volumes}\clearfield{volumes}}%
          \newcunit\bibsstring{thiscite}%
          \nopunct}}%
      {\iffieldundef{volume}%
        {\printfield[xrefpart]{part}\usebibmacro{mt:ofvols}}%
        {\iffieldundef{part}%
          {\printfield{volume}\usebibmacro{mt:ofvols}}%
          {\printfield{volume}\usebibmacro{mt:ofvols}\printfield{part}}}}%
      \ifcsdef{cms@mtpages}{\restorefield{pages}{\cms@mtpages}}{}%
      \ifcsdef{cms@mtpagination}{\restorefield{bookpagination}%
        {\cms@mtpagination}}{}%
      \ifcsdef{cms@mtchapter}{\restorefield{chapter}{\cms@mtchapter}}{}%
      \ifcsdef{cms@mtauthor}%
      {\savename*{author}{\cms@mtsecauthor}%
        \ifcsequal{cms@mtauthor}{cms@mtsecauthor}%
        {\clearname{author}}%
        {}}%
      {}%
      \ifcsdef{cms@mteditor}%
      {\savename*{editor}{\cms@mtseceditor}%
        \ifcsequal{cms@mteditor}{cms@mtseceditor}%
        {\clearname{editor}}%
        {}}%
      {}%
      \ifcsdef{cms@mttranslator}%
      {\savename*{translator}{\cms@mtsectranslator}%
        \ifcsequal{cms@mttranslator}{cms@mtsectranslator}%
        {\clearname{translator}}%
        {}}%
      {}%
      \ifcsdef{cms@mtnamec}%
      {\savename*{namec}{\cms@mtsecnamec}%
        \ifcsequal{cms@mtnamec}{cms@mtsecnamec}%
        {\clearname{namec}}%
        {}}%
      {}\iftoggle{cms@reprintfrom}{\newcunit}{}}%
    \ifboolexpr{%
      test {\ifbibliography}%
      and
      not togl {cms@reprintfrom}%
    }%
    {\printtext[cmsdefrelhypertarget]{%
        \usedriver%
        {\ifnameundef{savedauthor}%
          {\ifnameundef{savededitor}%
            {\ifnameundef{savedtranslator}%
              {\ifnameundef{savednamec}%
                {}%
                {\ifnamesequal{namec}{savednamec}%
                  {\clearname{namec}}%
                  {}}}%
              {\ifnamesequal{translator}{savedtranslator}%
                {\clearname{translator}}%
                {}}}%
            {\ifnamesequal{editor}{savededitor}%
              {\clearname{editor}}%
              {}}}%
          {\ifnamesequal{author}{savedauthor}%
            {\clearname{author}}%
            {}}%
          \clearfield{volume}\clearfield{part}%
          \clearfield{maintitle}%\clearfield{volumes}%
          \clearfield{crossref}\clearfield{xref}%
          \usebibmacro{at+every+item}%
          \renewbibmacro*{related:init}{}%
          \DeclareNameAlias{sortname}{default}%
          \renewbibmacro*{pageref}{}%
          \renewbibmacro*{editor}{}%
          \renewbibmacro*{author/editor}{}%
          \clearfield{nameaddon}%
          \toggletrue{cms@mtvolpunct}}%
        {\thefield{entrytype}}}}%
    {\printtext[cmsdefrelhypertarget]{%
        \usedriver%
        {\ifnameundef{savedauthor}%
          {\ifnameundef{savededitor}%
            {\ifnameundef{savedtranslator}%
              {\ifnameundef{savednamec}%
                {}%
                {\ifnamesequal{namec}{savednamec}%
                  {\clearname{namec}}%
                  {}}}%
              {\ifnamesequal{translator}{savedtranslator}%
                {\clearname{translator}}%
                {}}}%
            {\ifnamesequal{editor}{savededitor}%
              {\clearname{editor}}%
              {}}}%
          {\ifnamesequal{author}{savedauthor}%
            {\clearname{author}}%
            {}}%
          \clearfield{volume}\clearfield{part}%
          \clearfield{maintitle}%\clearfield{volumes}%
          \clearfield{crossref}\clearfield{xref}%
          \usebibmacro{at+every+item}%
          \renewbibmacro*{related:init}{}%
          \DeclareNameAlias{sortname}{default}%
          \renewbibmacro*{pageref}{}%
          \renewbibmacro*{editor}{}%
          \renewbibmacro*{author/editor}{}%
          \clearfield{nameaddon}%
          \toggletrue{cms@fullnote}%
          \togglefalse{cms@shortnote}}%
        {cite:\thefield{entrytype}}}}}}%

\newbibmacro*{mt:ofvols}{% MT -- used by previous
  \iftoggle{cms@hidevolumes}%
  {\clearfield{volumes}}%
  {\ifthenelse{\iffieldundef{volumes}\AND\iffieldundef{savedvolumes}}%
    {}%
    {\addspace\bibstring{of}\addspace%
      \iffieldundef{volumes}%
      {\printfield[default]{savedvolumes}}%
      {\printfield[default]{volumes}\clearfield{volumes}}}}}%

\newbibmacro*{extract+mt+vol}{% MT fix
  \ifthenelse{\iffieldequalstr{relatedtype}{maintitle}\OR%
    \iffieldequalstr{relatedtype}{maintitlenc}}%
  {\setcounter{cms@reviewcount}{\value{instcount}}%
    \ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {\entrydata{\thefield{related}}{%
        \iffieldundef{volume}{}{\savefield{volume}{\cms@mtvolume}}%
        \iffieldundef{part}{}{\savefield{part}{\cms@mtpart}}}}%
    {}%
    \ifcsundef{cms@mtvolume}{}{\restorefield{volume}{\cms@mtvolume}}%
    \ifcsundef{cms@mtpart}{}{\restorefield{part}{\cms@mtpart}}%
    \csgundef{cms@mtvolume}\csgundef{cms@mtpart}}%
  {}}

\newbibmacro*{extract+clonekey+note}{%
  \entrydata{\thefield{related}}{%
    \ifboolexpr{%
      test {\ifentryseen{\thefield{clonesourcekey}}}%
      and
      not togl {cms@citecrossref}%
    }%
    {\savefield{clonesourcekey}{\cms@shortmtkey}}%
    {}}\iftoggle{cms@noterefs}{\addtocounter{instcount}{-1}}{}}%

\newbibmacro*{extract+clonekey+bib}{%
  \entrydata{\thefield{related}}{%
    \ifboolexpr{%
      test {\ifentryinbib{\strfield{clonesourcekey}}}%
      and
      not togl {cms@bibcrossref}%
    }%
    {\savefield{clonesourcekey}{\cms@shortmtkey}}%
    {}}}%

\letbibmacro*{related:maintitlenc}{related:maintitle}% MT fix

\renewbibmacro*{related:multivolume}[1]{%
  \entrydata*{#1}{%
    \usebibmacro{at+every+item}%
    \ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {}%
    {\printtext{%
        \printfield{volume}%
        \printfield{part}}%
      \setunit{\addcolon\addspace}}%
    \usebibmacro{ctitle+stitle}%
    \ifboolexpr{%
      test {\ifnamesequal{author}{savedauthor}}%
      or
      test {\ifnameundef{author}}%
    }%
    {}%
    {\usebibmacro{bytypestrg}{author}{author}%
      \setunit{\addspace}%
      \printnames[byauthor]{author}%
      \newcunit\newblock}%
    \ifboolexpr{%
      test {\ifnamesequal{namea}{savednamea}}%
      or
      test {\ifnameundef{namea}}%
    }%
    {\ifboolexpr{%
        test {\ifnamesequal{editor}{savededitor}}%
        or
        test {\ifnameundef{editor}}%
      }%
      {\ifboolexpr{%
          test {\ifnamesequal{nameb}{savednameb}}%
          or
          test {\ifnameundef{nameb}}%
        }%
        {}%
        {\bibstring{cbytranslator}\addspace%
          \printnames[bytranslator]{nameb}\newcunit}}%
      {\usebibmacro{cbyeditor+others}%
        \newcunit}}%
    {\usebibmacro{cpart+editor+translator}%
      \newcunit}%
    \usebibmacro{date}}}%

\renewbibmacro*{related:origpubin}[1]{%
  \entrydata*{#1}{%
    \usebibmacro{at+every+item}%
    \usebibmacro{cmsyear}%
    \ifboolexpr{%
      test {\iflistsequal{publisher}{savedpublisher}}%
      or
      test {\iflistundef{publisher}}%
    }%
    {}%
    {\midsentence% Why is this kludge necessary?
      \setunit{\addspace\bibstring[\mkrelatedstringtext]{bypublisher}\space}%
      \printlist{publisher}%
      \setunit{\addcomma\space}%
      \iflistsequal{location}{savedlocation}%
      {}%
      {\printlist{location}}}}}

\newbibmacro*{related:short}[1]{% For cross-refs in bib.
  \entrydata*{#1}{%
    \toggletrue{cms@noidem}%
    \togglefalse{cms@fullnote}%
    \toggletrue{cms@shortnote}%
    \usebibmacro{cite:short}{\thefield{entrytype}}}}%

\DeclareFieldFormat{title:hook}{%
  \begingroup
  \mkrelatedstringtext{%
    \lbx@inittitlehook{#1}}%
  \endgroup
  \mkbibemph{#1}}

\DeclareFieldFormat{title:hook:alt}{%
  \iftoggle{cms@reprintmt}%
  {\begingroup
    \mkrelatedstringtext{%
      \lbx@inittitlehook{#1}}%
    \endgroup}%
  {\lbx@inittitlehook{#1}}% Inside entries don't use main doc. lang.
  \mkbibemph{#1}}

\DeclareFieldFormat{ititle:hook}{%
  \begingroup
  \mkrelatedstringtext{%
    \lbx@inittitlehook{#1}}%
  \endgroup
  \iffieldundef{issuesubtitle}%
  {\mkbibquote{#1}}%
  {\mkbibquote{#1\subtitlepunct\printfield{issuesubtitle}}}}

\DeclareFieldFormat{chapter:hook}{%
  \begingroup
  \mkrelatedstringtext{%
    \lbx@inittitlehook{\bibxstring{chapter}}%
    \bibstring{chapter}~#1\addspace\bibstring{in}}%
  \endgroup}%

\DeclareFieldFormat{avchapter:hook}{%
  \begingroup
  \mkrelatedstringtext{%
    \lbx@inittitlehook{\bibxstring{chapter}}%
    \bibstring{chapter}~#1}
  \endgroup}%

\DeclareFieldFormat{muschapter:hook}{%
  \begingroup
  \mkrelatedstringtext{%
    \lbx@inittitlehook{\bibxstring{track}}%
    \bibstring{track}~#1}%
  \endgroup}

\DeclareFieldFormat{volume:hook}{%
  \begingroup
  \mkrelatedstringtext{%
    \lbx@inittitlehook{\bibxstring{volume}}%
    \bibstring{volume}~#1}%
  \endgroup}%

\DeclareFieldFormat{parttoo:hook}{%
  \ifnumerals{#1}%
  {\addcomma\addspace\bibstring[\mkrelatedstringtext]{partvolume}~#1}%
  {\addcomma\addspace\ifcapital{\MakeCapital{#1}}{#1}}}

\DeclareFieldFormat{part:hook}{%
  \begingroup
  \ifnumerals{#1}%
  {\mkrelatedstringtext{%
      \lbx@inittitlehook{\bibxstring{partvolume}}%
      \bibstring{partvolume}~#1}}%
  {\mkrelatedstringtext{\lbx@inittitlehook{#1}}%
    \ifcapital{\MakeCapital{#1}}{#1}}%
  \endgroup}

\DeclareFieldFormat{shorthand:hook}{%
  \lbx@inittitlehook{#1}%
  #1}

\DeclareFieldFormat{sitnoformat}{#1}
\DeclareFieldFormat{sjtnoformat}{#1}
\DeclareFieldFormat{stnoformat}{#1}
\DeclareFieldFormat{sbtnoformat}{#1}
\DeclareFieldFormat{smtnoformat}{#1}
\DeclareFieldFormat{itnoformat}{#1}
\DeclareFieldFormat{jtnoformat}{#1}
\DeclareFieldFormat{jtsnoformat}{#1}
\DeclareFieldFormat{tnoformat}{#1}
\DeclareFieldFormat{btnoformat}{#1}
\DeclareFieldFormat{mtnoformat}{#1}

\providetoggle{cms@reprintmt}

\newbibmacro*{cms:titlehook}{% Needed for full drivers in reprintfrom
  \ifthenelse{\iffieldundef{chapter}\OR\NOT\(\ifentrytype{audio}\OR%
    \ifentrytype{inbook}\OR\ifentrytype{incollection}\OR%
    \ifentrytype{inproceedings}\OR\ifentrytype{letter}\OR%
    \ifentrytype{music}\OR\ifentrytype{video}\)}%
  {\iffieldundef{issuetitle}%
    {\iffieldundef{title}%
      {\iffieldundef{booktitle}%
        {\iffieldundef{journaltitle}% Switched order for 17th ed.
          {\iffieldundef{maintitle}%
            {\ifthenelse{\iffieldequalstr{relatedtype}{maintitle}\OR%
                \iffieldequalstr{relatedtype}{maintitlenc}}%
              {\DeclareFieldAlias{tnoformat}{title:hook}%
                \DeclareFieldAlias{stnoformat}{citetitle}%
                \DeclareFieldAlias[video]{title}{default}%
                \DeclareFieldAlias[audio]{title}{default}%
                \DeclareFieldAlias[music]{title}{default}%
                \DeclareFieldAlias{title}{default}%
                \DeclareFieldAlias[periodical]{shorttitle}{series}}%
              {}}%
            {\toggletrue{cms@reprintmt}%
              \ifthenelse{\(\iffieldundef{volume}\AND\iffieldundef{part}\)%
                \OR\ifentrytype{inbook}\OR\ifentrytype{incollection}\OR%
                \ifentrytype{inproceedings}\OR\ifentrytype{letter}}%
              {\DeclareFieldAlias{mtnoformat}{title:hook}%
                \DeclareFieldAlias{smtnoformat}{title}%
                \DeclareFieldAlias{maintitle}{default}}%
              {\iffieldundef{volume}%
                {\DeclareFieldAlias{part}{part:hook}%
                  \let\cms@ofwrap\mkrelatedstringtext}%
                {\DeclareFieldAlias{volume}{volume:hook}%
                  \DeclareFieldAlias{part}{parttoo:hook}%
                  \let\cms@ofwrap\mkrelatedstringtext}}}}%
          {\DeclareFieldAlias{jtnoformat}{title:hook}%
            \DeclareFieldAlias{sjtnoformat}{title}%
            \DeclareFieldAlias{journaltitle}{default}%
            \DeclareFieldAlias{injournaltitle}{default}%
            \DeclareFieldAlias{shortjournal}{series}%
            \DeclareFieldAlias{inshortjournal}{series}%
            \DeclareFieldAlias{jtsnoformat}{title:hook}}}%
        {\DeclareFieldAlias{btnoformat}{title:hook}%
          \DeclareFieldAlias{sbtnoformat}{title}%
          \DeclareFieldAlias{booktitle}{default}}}%
      {\DeclareFieldAlias{tnoformat}{title:hook}%
        \DeclareFieldAlias{stnoformat}{citetitle}%
        \DeclareFieldAlias[video]{title}{default}%
        \DeclareFieldAlias[audio]{title}{default}%
        \DeclareFieldAlias[music]{title}{default}%
        \DeclareFieldAlias{title}{default}%
        \DeclareFieldAlias[periodical]{shorttitle}{series}}}%
    {\DeclareFieldAlias{itnoformat}{ititle:hook}%
      \DeclareFieldAlias{issuetitle}{default}}}%
  {\ifthenelse{\ifentrytype{audio}\OR\ifentrytype{music}\OR%
      \ifentrytype{video}}%
    {\iffieldundef{title}%
      {\ifentrytype{music}%
        {\DeclareFieldAlias[music]{chapter}{muschapter:hook}%
          \let\cms@ofwrap\mkrelatedstringtext}%
        {\DeclareFieldAlias{chapter}{avchapter:hook}%
          \let\cms@ofwrap\mkrelatedstringtext}}%
      {\DeclareFieldAlias{tnoformat}{title:hook}%
        \DeclareFieldAlias{stnoformat}{citetitle}%
        \DeclareFieldAlias[video]{title}{default}%
        \DeclareFieldAlias[audio]{title}{default}%
        \DeclareFieldAlias[music]{title}{default}}}%
    {\DeclareFieldAlias{chapter}{chapter:hook}}}}%

\newbibmacro*{cite:origfull}{%
  \printtext[cmsdefrelhypertarget]{%
    \usedriver
    {\DeclareNameAlias{sortname}{default}\clearfield{postnote}%
      \clearname{author}\clearfield{userf}\clearfield{shorthand}%
      \toggletrue{cms@fullnote}\toggletrue{cms@headlessnote}%
      \frenchspacing}%
    {cite:\thefield{entrytype}}}}

\newbibmacro*{cite:origpubl}{%
  \printtext[cmsdefrelhypertarget]{%
    \usedriver
    {\DeclareNameAlias{sortname}{default}\clearfield{postnote}%
      \usebibmacro{clearpublin}\clearfield{shorthand}%
      \clearfield{crossref}\clearfield{xref}%
      \toggletrue{cms@bookcitexref}\global\toggletrue{cms@reprintfrom}%
      \toggletrue{cms@fullnote}\toggletrue{cms@headlessnote}%
      \toggletrue{cms@origpublished}\frenchspacing%
      \usebibmacro{cms:titlehook}}%
    {cite:\thefield{entrytype}}}\global\togglefalse{cms@reprintfrom}}%

\newbibmacro*{cite:related:full}{%
  \printtext[cmsdefrelhypertarget]{%
    \usedriver
    {\DeclareNameAlias{sortname}{default}\frenchspacing}%
    {cite:\thefield{entrytype}}}}%

\newbibmacro*{bib:related:full}{%
  \printtext[cmsdefrelhypertarget]{%
    \usedriver
    {\DeclareNameAlias{sortname}{default}\frenchspacing}%
    {\thefield{entrytype}}}}%

\DeclareFieldFormat{cmsdefrelhypertarget}{%
  \ifhyperref%
  {\ifbibliography%
    {\ifentryinbib{\strfield{clonesourcekey}}%
      {#1}%
      {\hypertarget{cite.\the\c@refsection @\thefield{clonesourcekey}}{#1}}}%
    {\bibhypertarget{\thefield{clonesourcekey}}{#1}}}%
  {#1}}

\newrobustcmd*{\cmsrelhyper}[1]{%
  \ifhyperref%
  {\ifbibliography%
    {\ifentryinbib{\strfield{clonesourcekey}}%
      {\bibhyperref[\strfield{clonesourcekey}]{#1}}%
      {#1}}%
    {\iftoggle{cms@allshort}%
      {\IfSubStr{\thefield{savedoptions}}{skipbib}%
        {\bibhyperref[\strfield{clonesourcekey}]{#1}}%%
        {\bibhyperref[\thefield{savedentrykey}]{#1}}}%
      {\iftoggle{cms@fullnote}%
        {\ifentryseen{\thefield{clonesourcekey}}%
          {\bibhyperlink{\strfield{clonesourcekey}}{#1}}%
          {#1}}%
        {\bibhyperlink{\thefield{savedentrykey}}{#1}}}}}%
  {#1}}%

\newbibmacro*{at+every+item}{%
  \ifboolexpr{%
    test {\iffieldundef{origyear}}%
    or
    test {\iffieldundef{year}}%
    or
    not test {\iffieldint{year}}%
    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}}%
      {}}}}%

\endinput
