% This is a biblatex citation style file, originally adapted from
% Lehman's authoryear-comp.cbx.  It is heavily modified, and contains
% the common code for providing inline citations (and a reference
% list) for the two author-date styles of the Chicago Manual of Style,
% 17th edition.

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

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

\newbool{cbx:parens}
\newbool{cms:bracket}
\newbool{cms:extraparens}
\newbool{cms:comma}
\newbool{cms:atcite}
\newbool{cms:tcit}
\newbool{cms:postsh}

% 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@inlineibid}
\providetoggle{cms@origlabel}
\providetoggle{cms@bothlabelold}
\providetoggle{cms@bothlabelnew}
\providetoggle{cms@fulldate}
\providetoggle{cms@switchdates}
\providetoggle{cms@los}
\providetoggle{cms@avdate}
\providetoggle{cms@ordate}
\providetoggle{cms@nodates}
\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@authorparens}
\providetoggle{cms@strippunct}
\providetoggle{cms@postspace}
\providetoggle{cms@modpostnote}
\providetoggle{cms@ukord}
\providetoggle{cms@fullnote}% For the legal entry types
\providetoggle{cms@shortnote}% Ditto

\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@shser}
\providetoggle{cms@addendum}
\providetoggle{cms@hidevolumes}% Modify Volume fix
\providetoggle{cms@notitle}% For classical short notes
\providetoggle{cms@comprange}
\providetoggle{cms@compyears}

\providetoggle{cms@jrcomma}% Comma after Jr./Sr.

\providetoggle{cms@strict}
\providetoggle{cms@headlessnote}% Keep
\providetoggle{cms@noibid}% Keep
\providetoggle{cms@namedash}
\providetoggle{cms@nona}
\providetoggle{cms@subseqnona}
\providetoggle{cms@usecompiler}% Keep
\providetoggle{cms@origpublished}% Keep
\providetoggle{cms@annotation}% Keep
\providetoggle{cms@cbxannote}
\providetoggle{cms@postposit}% Keep
\providetoggle{cms@fullshhand}%
\providetoggle{cms@allshort}% For legal types
\providetoggle{cms@noneshort}% Ditto
\providetoggle{cms@legalnotes}% Ditto
\providetoggle{cms@supranotes}% Ditto
\providetoggle{cms@running@text}% For Jurisdiction entries
\providetoggle{cms@vol}%
\providetoggle{cms@crossref}%
\providetoggle{cms@bookcrossref}
\providetoggle{cms@gencite}
\providetoggle{cms@genallnames}
\providetoggle{cms@xrefurl}
\providetoggle{cms@related}
\providetoggle{cms@linkit}
\providetoggle{cms@linkname}
\providetoggle{cms@leaveit}
\providetoggle{cms@authortitle}
\providetoggle{cms@shortrelated}

\AtEveryCitekey{%
  \iffieldundef{userc}%
  {}%
  {\nocite{\thefield{userc}}}%
  \global\csundef{@cmsst}}%

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

\DeclareBibliographyOption[string]{avdate}[true]{%
  \ifcsdef{cms@opt@avdate@#1}%
  {\csuse{cms@opt@avdate@#1}}%
  {\blx@err@invopt{avdate=#1}{}}}%
\def\cms@opt@avdate@true{%
  \DeclareLabeldate[music,review,standard,suppperiodical,video]% 17th ed.
  {\field{eventdate} \field{origdate} \field{date} \field{year}%
    \field{urldate} \literal{nodate}}%
    \toggletrue{cms@avdate}}%
\def\cms@opt@avdate@false{%
  \togglefalse{cms@avdate}}%

\DeclareBibliographyOption[string]{cmsdate}[off]{% Implement origyear as
  \ifcsdef{cms@global@cmsdate@#1}% labelyear. Sorting will be an issue.
  {\csuse{cms@global@cmsdate@#1}}%
  {\csuse{cms@global@cmsdate@off}\cms@warning@noline%
    {'cmsdate=#1' isn't a valid option.\MessageBreak
      The default - 'off' - has been set.\MessageBreak
      Please see biblatex-chicago.pdf for valid\MessageBreak
      option keys}}}%
\def\cms@global@cmsdate@on{%
  \toggletrue{cms@origlabel}%
  \ExecuteBibliographyOptions{cmsorigdate=true}}%
\def\cms@global@cmsdate@new{%
  \toggletrue{cms@bothlabelnew}%
  \ExecuteBibliographyOptions{cmsorigdate=true}}%
\def\cms@global@cmsdate@old{%
  \toggletrue{cms@bothlabelold}%
  \ExecuteBibliographyOptions{cmsorigdate=true}}%
\def\cms@global@cmsdate@both{%
  \toggletrue{cms@bothlabelold}%
  \ExecuteBibliographyOptions{cmsorigdate=true}}%
\def\cms@global@cmsdate@full{}%
\def\cms@global@cmsdate@off{}%

\DeclareBibliographyOption[string]{cmsorigdate}[true]{% ? Also need new macros
  \ifcsdef{cms@opt@origdate@#1}% for printing dates.  Worth it ?
  {\csuse{cms@opt@origdate@#1}}%
  {\blx@err@invopt{cmsorigdate=#1}{}}}%
\def\cms@opt@origdate@true{%
  \DeclareLabeldate{\field{origdate} \field{origyear} \field{date}%
    \field{year} \field{eventdate} \field{urldate}%
    \literal{nodate}}%
  \DeclareLabeldate[patent]{\field{date} \field{year}%
    \field{eventdate} \field{origdate} \field{origyear}%
    \field{urldate}}%
  \global\toggletrue{cms@ordate}}%
\def\cms@opt@origdate@false{\togglefalse{cms@ordate}}%

\DeclareEntryOption[string]{cmsdate}[off]{% Trying to implement origyear as
  \ifcsdef{cms@opt@cmsdate@#1}% labelyear. Sorting will be an issue.
  {\csuse{cms@opt@cmsdate@#1}}%
  {\csuse{cms@opt@cmsdate@off}\cms@warning@noline%
    {'cmsdate=#1' isn't a valid option.\MessageBreak
      The default - 'off' - has been set.\MessageBreak
      Please see biblatex-chicago.pdf for valid\MessageBreak
      option keys}}}%
\def\cms@opt@cmsdate@on{%
  \toggletrue{cms@origlabel}}%
\def\cms@opt@cmsdate@new{%
  \toggletrue{cms@bothlabelnew}}%
\def\cms@opt@cmsdate@old{%
  \toggletrue{cms@bothlabelold}}%
\def\cms@opt@cmsdate@both{%
  \toggletrue{cms@bothlabelold}}%
\def\cms@opt@cmsdate@full{%
  \toggletrue{cms@fulldate}}%
\def\cms@opt@cmsdate@off{}%

\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,entry}[boolean]{genallnames}[true]{%
  \settoggle{cms@genallnames}{#1}}%

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

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

\DeclareBiblatexOption{global,type,entry}[boolean]{hyperall}[true]{%
  \settoggle{cms@linkit}{#1}\settoggle{cms@linkname}{#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]{dashed}[true]{%
  \settoggle{cms@namedash}{#1}}

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

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

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

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

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

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

\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,type,entry}[boolean]{nodates}[true]{%
  \settoggle{cms@nodates}{#1}}%

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

\DeclareBibliographyOption[boolean]{shorthandfull}[true]{%
  \settoggle{cms@fullshhand}{#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@crossref}%
  \togglefalse{cms@bookcrossref}}%
\def\cms@opt@lxref@true{%
  \toggletrue{cms@crossref}}%
\def\cms@opt@lxref@false{%
  \togglefalse{cms@crossref}}%
\def\cms@opt@lxref@notes{%
  \togglefalse{cms@crossref}}%
\def\cms@opt@lxref@bib{%
  \toggletrue{cms@crossref}}%

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

\DeclareBiblatexOption{global,entry}[boolean]{xrefurl}[true]{%
  \settoggle{cms@xrefurl}{#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}[boolean]{seriesabbrev}[true]{%
  \settoggle{cms@shser}{#1}}

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

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

% 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}}%

% The field-exclusion options %

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

\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}[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 option.\MessageBreak
      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@nona}{true}}%
\def\cms@gopt@na@cite{\settoggle{cms@nona}{true}}%
\def\cms@gopt@na@bib{}%
\def\cms@gopt@na@first{\settoggle{cms@subseqnona}{true}}%
\def\cms@gopt@na@citefirst{\settoggle{cms@nona}{true}}%
\def\cms@gopt@na@bibfirst{\settoggle{cms@subseqnona}{true}}%

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

\ExecuteBibliographyOptions{includeall,hidevolumes,booklongxref,related,%
  ctitleaddon,ptitleaddon,jtitleaddon,journalabbrev=notes,legalnotes,%
  supranotes,dashed,bibannotesep,citeannotesep,nameaddonsep=space}%

\ExecuteBibliographyOptions[standard]{useeditor=false,usenamec=false}%
\ExecuteBibliographyOptions[dataset]{authortitle=true,nodates=false}%
\ExecuteBibliographyOptions[misc]{nodates=false}%

\ExecuteBibliographyOptions[article,review,suppperiodical]{labeltitleyear=true}

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

\AtEndPreamble{%
  \iftoggle{cms@los}%  Automatic sorting by shorthand when it appears
  {\DeclareSourcemap{% at the head of the entry.
      \maps[datatype=bibtex]{
        \map{
          \step[fieldsource=shorthand, final]
          \step[fieldset=sortname, origfieldval]}}}}%
  {}%
  \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}%
    }}%
  {}}

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

%% This is an ugly kludge, only required because we need the extradate
%% mechanism for authorless articles in magazines where the
%% journaltitle takes the place of the author, and the labelname
%% mechanism won't accept non-name fields. No other idea presenting
%% itself, we use the extratitleyear mechanism in these 3 types, and
%% this declaration keeps any article with an author from interfering
%% with it. It means we can't simply print the labeltitle for these
%% entry types.

\DeclareLabeltitle[article,review,suppperiodical]{%
  \field{shortauthor}
  \field{author}
  \field{shorteditor}
  \field{namea}
  \field{editor}
  \field{nameb}
  \field{translator}
  \field{namec}
  \field{shortjournal}
  \field{journaltitle}}%

\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}{incollection}{%
  \inherit{title}{booktitle}
  \inherit{subtitle}{booksubtitle}
  \inherit{titleaddon}{booktitleaddon}
  \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{mvbook,mvcollection}{letter}{%
  \inherit{title}{maintitle}
  \inherit{subtitle}{mainsubtitle}
  \inherit{titleaddon}{maintitleaddon}
  \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{*}{*}{%
  \noinherit{namea}
  \noinherit{nameb}
  \noinherit{sortyear}
  \noinherit{sortname}
  \noinherit{sorttitle}
  \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}}

% More authordate options %

\DeclareExtradate{%
  \scope{
    \field{labelyear}
    \field{year}
  }
  \scope{
    \field{verbc}
  }
}

\DeclareSortingTemplate{cms}{% Updated to >3.7 format
  \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{sortyear}
    \field{labelyear}
    \field{year}
    \field{origyear}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{endyear}
    \field{eventendyear}
    \field{origendyear}
  }
  \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}
  }
}

\DeclareLabelname{\field{shortauthor} \field{author}%
  \field{shorteditor} \field{namea} \field{editor}%
  \field{nameb} \field{translator} \field{namec}}%

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

\DeclareBibliographyOption[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\space}

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

\@ifpackagelater{biblatex}{2011/01/04}%
{}%
{\PackageError{biblatex}%
  {Outdated 'biblatex' package}%
  {The Chicago style requires biblatex v1.1 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}{*!?}}

%%%% 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}}

%%%% Macros from authoryear-comp.cbx, revised for CMS %%%%

\newbibmacro*{cite:init}{%
  \ifnumless{\value{multicitecount}}{2}%
    {\global\boolfalse{cbx:parens}%
     \global\undef\cbx@lasthash%
     \global\undef\cbx@lastyear}%
    {\iffieldundef{prenote}%
       {}%
       {\global\undef\cbx@lasthash%
	\global\undef\cbx@lastyear}}}%

\newbibmacro*{cite:reinit}{%
  \global\undef\cbx@lasthash%
  \global\undef\cbx@lastyear}%

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

\newbibmacro*{cite}{%
  \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}%
  {\usebibmacro{cite:ibid}}%
  {\ifboolexpr{%
      togl {cms@authortitle}%
      or
      test {\iffieldequalstr{entrysubtype}{classical}}%
    }% Similar to notes+bib
    {\iffieldundef{shorthand}%
      {\ifthenelse{\ifnameundef{labelname}\OR
          \ifentrytype{inreference}\OR
          \ifentrytype{reference}\OR
          \ifentrytype{mvreference}}% Simplified for CMS
        {\usebibmacro{cite:label}%
          \setunit{\cms@testspace}% Is this right?
          \usebibmacro{cite:reinit}}%
        {\iffieldequals{fullhash}{\cbx@lasthash}%
          {\iffieldundef{postnote}%
            {\setunit{\multicitedelim}}%
            {}%
            \usebibmacro{cite:label}}%
          {\iffieldequals{fullhash}{\cbx@lastyear}%
            {}%
            {\usebibmacro{cmsbracketname}% For names in []
              \ifthenelse{\ifentrytype{misc}\AND%
                \iffieldequalstr{entrysubtype}{classical}}%
              {\cms@testspace}{\newcunit}}% Wrong?
            \ifthenelse{\ifentrytype{manual}\OR\ifentrytype{standard}}%
            {\printtext[cmshyper]{\printfield[citetitle]{labeltitle}}}%
            {\usebibmacro{cite:label}}%
            \iffieldundef{postnote}%
            {\savefield{fullhash}{\cbx@lasthash}}%
            {\savefield{fullhash}{\cbx@lastyear}}}}}%
      {\usebibmacro{cite:shorthand+title}}}%
    {\iffieldundef{shorthand}%
      {\ifthenelse{\ifnameundef{labelname}\OR
          \ifentrytype{inreference}\OR
          \ifentrytype{reference}\OR
          \ifentrytype{mvreference}}% Simplified for CMS
        {\usebibmacro{cite:label}%
          \setunit{\nameyeardelim}%cms@testspace%
          \usebibmacro{cmscitesortdate}%
          \usebibmacro{cite:reinit}}%
        {\iffieldequals{fullhash}{\cbx@lasthash}%
          {\ifboolexpr{%
              test {\iffieldundef{postnote}}%
              and
              not bool {cms:atcite}%
            }%
            {\setunit{\compcitedelim}}%
            {}%
            \usebibmacro{cmscitesortdate}}%
          {\iffieldequals{fullhash}{\cbx@lastyear}% Is this right?
            {}%
            {\usebibmacro{cmsbracketname}%
              \setunit{\nameyeardelim}}%
            \usebibmacro{cmscitesortdate}%
            \iffieldundef{postnote}%
            {\savefield{fullhash}{\cbx@lasthash}}%
            {\savefield{fullhash}{\cbx@lastyear}}}}}%
      {\usebibmacro{cite:shorthand}}}}%
  \ifnumless{\value{citecount}}{\value{citetotal}}%
  {\setunit{\multicitedelim}}{}}% ???

\newbibmacro*{cmsbracketname}{%
  \iffieldequalstr{authortype}{anon}%
  {\printtext[cmsnamehyper]{\bibleftbracket\printnames{labelname}%
      \bibrightbracket}}%
  {\iffieldequalstr{authortype}{anon?}%
    {\printtext[cmsnamehyper]{\bibleftbracket\printnames{labelname}?%
        \bibrightbracket}}%
    {\printtext[cmsnamehyper]{\printnames{labelname}}}}}%

\newbibmacro*{citeyear}{%
  \ifboolexpr{%
    togl {cms@authortitle}%
    or
    test {\iffieldequalstr{entrysubtype}{classical}}%
  }%
  {\iffieldundef{shorthand}%
    {\usebibmacro{citeyear:noshort}}%
    {\iftoggle{cms@los}%
      {\usebibmacro{citeyear:noshort}}%
      {\usebibmacro{cite:shorthand+title}}}}%
  {\iffieldundef{shorthand}%
    {\usebibmacro{citeyear:noshort}}%
    {\iftoggle{cms@los}%
      {\usebibmacro{citeyear:noshort}}%
      {\usebibmacro{cite:shorthand}}}}%
  \setunit{\multicitedelim}}%

\newbibmacro*{citeyear:noshort}{%
  \ifboolexpr{%
    togl {cms@authortitle}%
    or
    test {\iffieldequalstr{entrysubtype}{classical}}%
  }% Altered for CMS
  {\iffieldequals{fullhash}{\cbx@lasthash}%
    {\iffieldundef{postnote}%
      {\setunit{\multicitedelim}}%
      {}%
      \usebibmacro{cite:label}}%
    {\usebibmacro{cite:label}%
      \iffieldundef{postnote}%
      {\savefield{fullhash}{\cbx@lasthash}}%
      {}}}%
  {\iffieldequals{fullhash}{\cbx@lasthash}%
    {\ifboolexpr{%
        test {\iffieldundef{postnote}}%
        and
        not bool {cms:atcite}%
      }%
      {\setunit{\compcitedelim}}%
      {}%
      \usebibmacro{cmscitesortdate}}%
    {\usebibmacro{cmscitesortdate}%
      \iffieldundef{postnote}%
      {\savefield{fullhash}{\cbx@lasthash}}%
      {}}}}%

\def\cms@choose@unit{%
  \ifboolexpr{%
    togl {cms@notitle}%
    and
    bool {cbx:parens}%
  }%
  {\printunit}%
  {\setunit}}

\newbibmacro*{textcite}{%
  \iftoggle{cms@los}%
  {\usebibmacro{textcite:authshort}}%
  {\usebibmacro{textcite:citeshort}}}%

\newbibmacro*{textcite:authshort}{%
  \iffieldequals{fullhash}{\cbx@lasthash}%
  {\ifbool{cbx:parens}%
    {}%
    {\iftoggle{cms@notitle}%
      {}%
      {\printunit{%
          \global\booltrue{cbx:parens}%
          \cms@testspace\bibopenparen}}}%
    \iffieldundef{postnote}%
    {\iffieldequals{fullhash}{\cbx@lastyear}%
      {\setunit{\multicitedelim}%
        \global\undef\cbx@lastyear}%
      {\ifboolexpr{%
          togl {cms@authortitle}%
          or
          test {\iffieldequalstr{entrysubtype}{classical}}%
          or
          bool {cms:atcite}%
        }%
        {\setunit{\multicitedelim}}%
        {\setunit{\compcitedelim}}}}%
    {\ifbool{cbx:parens}%
      {\cms@choose@unit{\multicitedelim}}%
      {\printunit{%
          \global\booltrue{cbx:parens}%
          \cms@testspace\bibopenparen}}}%
    \ifboolexpr{%
      togl {cms@authortitle}%
      or
      test {\iffieldequalstr{entrysubtype}{classical}}%
    }%
    {\usebibmacro{cite:label}}%
    {\usebibmacro{cmscitesortdate}}}%
  {\iffieldundef{shorthand}%
    {\ifthenelse{\ifnameundef{labelname}\OR
        \ifentrytype{inreference}\OR
        \ifentrytype{reference}\OR
        \ifentrytype{mvreference}}%
      {\ifboolexpr{%
          togl {cms@authortitle}%
          or
          test {\iffieldequalstr{entrysubtype}{classical}}%
        }%
        {\ifentrytype{customc}%
          {\setunit{%
              \global\booltrue{cbx:parens}%
              \multicitedelim}%\bibopenparen%
            \ifnumequal{\value{citecount}}{1}%
            {\usebibmacro{prenote}\clearfield{prenote}}%
            {}%
            \savefield{postnote}{\cms@tempz}\clearfield{postnote}%
            \usebibmacro{cite:label}%
            \restorefield{postnote}{\cms@tempz}}%
          {\setunit{%
              \global\booltrue{cbx:parens}%
              \cms@testspace\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}%
            {\usebibmacro{prenote}}%
            {}%
            \usebibmacro{cite:label}}}%
        {\usebibmacro{cite:label}%
          \ifboolexpr{%
            togl {cms@gencite}%
            and
            (
            test {\iffinalcitedelim}%
            or
            togl {cms@genallnames}%
            )
          }%
          {\thegen}%
          {}%
          \setunit{%
            \global\booltrue{cbx:parens}%
            \cms@testspace\bibopenparen}%
          \ifnumequal{\value{citecount}}{1}%
          {\usebibmacro{prenote}}%
          {}%
          \usebibmacro{cmscitesortdate}}}%
      {\printtext[cmsnamehyper]{%
          \printnames{labelname}%
          \ifboolexpr{%
            togl {cms@gencite}%
            and
            (
            test {\iffinalcitedelim}%
            or
            togl {cms@genallnames}%
            )
          }%
          {\thegen}%
          {}}%
        \ifboolexpr{%
          togl {cms@notitle}%
          and
          not test {\iffieldundef{postnote}}%
        }%
        {\printunit{%
            \global\booltrue{cbx:parens}%
            \cms@testspace\bibopenparen}}%
        {\setunit{%
            \global\booltrue{cbx:parens}%
            \cms@testspace\bibopenparen}}%
        \ifnumequal{\value{citecount}}{1}%
        {\usebibmacro{prenote}}%
        {}%
        \ifboolexpr{%
          togl {cms@authortitle}%
          or
          test {\iffieldequalstr{entrysubtype}{classical}}%
        }%
        {\ifthenelse{\ifentrytype{manual}\OR\ifentrytype{standard}}%
          {\printtext[cmshyper]{\printfield[citetitle]{labeltitle}}}%
          {\usebibmacro{cite:label}}}%
        {\usebibmacro{cmscitesortdate}}%
        \savefield{fullhash}{\cbx@lasthash}}}%
    {\printtext[cmsnamehyper]{%
        \printfield{shorthand}%
        \ifboolexpr{%
          togl {cms@gencite}%
          and
          (
          test {\iffinalcitedelim}%
          or
          togl {cms@genallnames}%
          )
        }%
        {\thegen}%
        {}}%
      \ifboolexpr{%
        togl {cms@notitle}%
        and
        not test {\iffieldundef{postnote}}%
      }%
      {\printunit{%
          \global\booltrue{cbx:parens}%
          \cms@testspace\bibopenparen}}%
      {\setunit{%
          \global\booltrue{cbx:parens}%
          \cms@testspace\bibopenparen}}%
      \ifnumequal{\value{citecount}}{1}%
      {\usebibmacro{prenote}}%
      {}%
      \ifboolexpr{%
        togl {cms@authortitle}%
        or
        test {\iffieldequalstr{entrysubtype}{classical}}%
      }%
      {\ifthenelse{\ifentrytype{manual}\OR\ifentrytype{standard}}%
        {\printtext[cmshyper]{\printfield[citetitle]{labeltitle}}}%
        {\usebibmacro{cite:label}}}%
      {\usebibmacro{cmscitesortdate}}%
      \savefield{fullhash}{\cbx@lasthash}}%
    \stepcounter{textcitecount}}% Added ???
  \setunit{%
    \ifbool{cbx:parens}%
    {\bibcloseparen\global\boolfalse{cbx:parens}}%
    {}%
    \textcitedelim}}% Not \multicitedelim ???

\newbibmacro*{textcite:citeshort}{%
  \iffieldequals{fullhash}{\cbx@lasthash}%
  {\ifbool{cms:postsh}%
    {\ifciteibid%
      {\ifbool{cbx:parens}%
        {\iffieldundef{postnote}%
          {}%
          {\printunit{\multicitedelim}}}%
        {\iffieldundef{postnote}%
          {}%
          {\printunit{%
              \global\booltrue{cbx:parens}%
              \cms@testspace\bibopenparen}}}}%
      {\global\boolfalse{cms:postsh}%
        \ifbool{cbx:parens}%
        {\printunit{\bibcloseparen\global\boolfalse{cbx:parens}%
            \textcitedelim}%
          \usebibmacro{textcite:mainref}}%
        {\printunit{\textcitedelim}%
          \usebibmacro{textcite:mainref}}}}%
    {\ifbool{cbx:parens}%
      {}%
      {\iftoggle{cms@notitle}%
        {}%
        {\printunit{%
            \global\booltrue{cbx:parens}%
            \cms@testspace\bibopenparen}}}%
      \iffieldundef{shorthand}%
      {\iffieldundef{postnote}%
        {\iffieldequals{fullhash}{\cbx@lastyear}%
          {\setunit{\multicitedelim}%
            \global\undef\cbx@lastyear}%
          {\ifboolexpr{%
              togl {cms@authortitle}%
              or
              test {\iffieldequalstr{entrysubtype}{classical}}%
              or
              bool {cms:atcite}%
            }%
            {\setunit{\multicitedelim}}%
            {\setunit{\compcitedelim}}}}%
        {\ifbool{cbx:parens}%
          {\cms@choose@unit{\multicitedelim}}%
          {\printunit{%
              \global\booltrue{cbx:parens}%
              \cms@testspace\bibopenparen}}}%
        \ifboolexpr{%
          togl {cms@authortitle}%
          or
          test {\iffieldequalstr{entrysubtype}{classical}}%
        }%
        {\usebibmacro{cite:label}}%
        {\usebibmacro{cmscitesortdate}}}%
      {\iffieldundef{postnote}%
        {\iffieldequals{fullhash}{\cbx@lastyear}%
          {\global\undef\cbx@lastyear}%
          {}}%
        {}%
        \setunit{\multicitedelim}%
        \printtext[bibhyperref]{%
          \printfield{shorthand}}}}}%
  {\global\boolfalse{cms:postsh}%
    \usebibmacro{textcite:mainref}}%
  \setunit{%
    \ifbool{cbx:parens}%
    {\bibcloseparen\global\boolfalse{cbx:parens}}%
    {}%
    \textcitedelim}}% Not \multicitedelim ???

\newbibmacro*{textcite:mainref}{%
  \iffieldundef{shorthand}%
  {\ifthenelse{\ifnameundef{labelname}\OR
      \ifentrytype{inreference}\OR
      \ifentrytype{reference}\OR
      \ifentrytype{mvreference}}%
    {\ifboolexpr{%
        togl {cms@authortitle}%
        or
        test {\iffieldequalstr{entrysubtype}{classical}}%
      }%
      {\ifentrytype{customc}%
        {\setunit{%
            \global\booltrue{cbx:parens}%
            \multicitedelim}%\bibopenparen%
          \ifnumequal{\value{citecount}}{1}%
          {\usebibmacro{prenote}\clearfield{prenote}}%
          {}%
          \savefield{postnote}{\cms@tempz}\clearfield{postnote}%
          \usebibmacro{cite:label}%
          \restorefield{postnote}{\cms@tempz}}%
        {\setunit{%
            \global\booltrue{cbx:parens}%
            \cms@testspace\bibopenparen}%
          \ifnumequal{\value{citecount}}{1}%
          {\usebibmacro{prenote}}%
          {}%
          \usebibmacro{cite:label}}}%
      {\usebibmacro{cite:label}%
        \ifboolexpr{%
          togl {cms@gencite}%
          and
          (
          test {\iffinalcitedelim}%
          or
          togl {cms@genallnames}%
          )
        }%
        {\thegen}%
        {}%
        \setunit{%
          \global\booltrue{cbx:parens}%
          \cms@testspace\bibopenparen}%
        \ifnumequal{\value{citecount}}{1}%
        {\usebibmacro{prenote}}%
        {}%
        \usebibmacro{cmscitesortdate}}}%
    {\printtext[cmsnamehyper]{\printnames{labelname}%
        \ifboolexpr{%
          togl {cms@gencite}%
          and
          (
          test {\iffinalcitedelim}%
          or
          togl {cms@genallnames}%
          )
        }%
        {\thegen}%
        {}}%
      \ifboolexpr{%
          togl {cms@notitle}%
          and
          not test {\iffieldundef{postnote}}%
        }%
        {\printunit{%
            \global\booltrue{cbx:parens}%
            \cms@testspace\bibopenparen}}%
        {\setunit{%
            \global\booltrue{cbx:parens}%
            \cms@testspace\bibopenparen}}%
      \ifnumequal{\value{citecount}}{1}%
      {\usebibmacro{prenote}}%
      {}%
      \ifboolexpr{%
        togl {cms@authortitle}%
        or
        test {\iffieldequalstr{entrysubtype}{classical}}%
      }%
      {\ifthenelse{\ifentrytype{manual}\OR\ifentrytype{standard}}%
        {\printtext[cmshyper]{\printfield[citetitle]{labeltitle}}}%
        {\usebibmacro{cite:label}}}%
      {\usebibmacro{cmscitesortdate}}%
      \savefield{fullhash}{\cbx@lasthash}}}%
  {\printtext[bibhyperref]{%
      \printfield{shorthand}}%
    \iffieldundef{postnote}%
    {}%
    {\printunit{%
        \global\booltrue{cbx:parens}%
        \cms@testspace\bibopenparen}}%
    \savefield{fullhash}{\cbx@lasthash}%
    \global\booltrue{cms:postsh}}%
  \stepcounter{textcitecount}}

\newbibmacro*{textcite:postnote}{%
  \iffieldundef{postnote}%
  {}%
  {\savefield{fullhash}{\cbx@lastyear}%
    \iftoggle{blx@keepunit}{}{\postnotewrapper}% Shorthand or notitle
    \printfield{postnote}}%
  \ifthenelse{\value{multicitecount}=\value{multicitetotal}}%
  {\setunit{}%
    \printtext{%
      \ifbool{cbx:parens}%
      {\bibcloseparen\global\boolfalse{cbx:parens}}%
      {}}}%
  {\setunit{%
      \ifbool{cbx:parens}%
      {\bibcloseparen\global\boolfalse{cbx:parens}}%
      {}%
      \textcitedelim}}}% Not \multicitedelim ???

\newbibmacro*{cite:shorthand}{%
  \iftoggle{cms@los}%
  {\iffieldequals{fullhash}{\cbx@lasthash}%
    {\ifbool{cms:atcite}%
      {\setunit{\multicitedelim}}%
      {\setunit{\compcitedelim}}%
      \usebibmacro{cmscitesortdate}}%
    {\printtext[cmsnamehyper]{\printfield{shorthand}}%
      \setunit{\nameyeardelim}%
      \usebibmacro{cmscitesortdate}%
      \savefield{fullhash}{\cbx@lasthash}}}%
  {\printtext[cmsyearhyper]{\printfield{shorthand}}%
    \usebibmacro{cite:reinit}}}%

\newbibmacro*{cite:shorthand+title}{%
  \iftoggle{cms@los}%
  {\iffieldequals{fullhash}{\cbx@lasthash}%
    {\setunit{\multicitedelim}%
      \usebibmacro{cite:label}}%
    {\printtext[cmsnamehyper]{\printfield{shorthand}}%
      \setunit{\addcomma\addspace}% FIXME: wrong in 16th _and_ 17th eds?
      \ifthenelse{\ifentrytype{standard}\OR\ifentrytype{manual}}%
      {\printtext[cmshyper]{\printfield[citetitle]{labeltitle}}}%
      {\usebibmacro{cite:label}}%
      \savefield{fullhash}{\cbx@lasthash}}}%
  {\printtext[cmsyearhyper]{\printfield{shorthand}}%
    \usebibmacro{cite:reinit}}}%

\newbibmacro*{cite:label}{% Test this
  \iftoggle{cms@notitle}%
  {}%
  {\iffieldundef{label}%
    {\ifthenelse{\iffieldequalstr{entrysubtype}{magazine}\AND\NOT%
        \ifentrytype{periodical}}% Simplifies .bib creation
      {\ifboolexpr{%
          not test {\iffieldundef{shortjournal}}%
          and
          ((
          test {\ifcitation}%
          and
          togl {cms@citejtabb}%
          )
          or
          (
          test {\ifbibliography}%
          and
          togl {cms@bibjtabb}%
          ))
        }%
        {\printtext[cmshyper]{\printfield[shortjournal]{shortjournal}}}%
        {\printtext[cmshyper]{\printfield[journaltitle]{journaltitle}}}}%
      {\ifthenelse{\ifentrytype{manual}\OR\ifentrytype{standard}}%
        {\printtext[cmshyper]{\printlist{organization}}}%
        {\ifboolexpr{%
            test {\ifentrytype{video}}%
            and
            test {\iffieldequalstr{entrysubtype}{tvepisode}}%
            and
            not test {\iffieldundef{title}}%
            and
            not test {\iffieldundef{booktitle}}%
          }%
          {\iffieldundef{shorttitle}%
            {\printtext[cmshyper]{%
                \printfield{booktitle}%
                \setunit{\subtitlepunct}%
                \printfield[booksubtitle]{booksubtitle}}% (?)
              \setunit{\ctitleaddonpunct}%
              \printfield{booktitleaddon}%
              \iffieldundef{booktitleaddon}{}{\addcomma\addspace}}%
            {\printtext[cmshyper]{\printfield[citetitle]{labeltitle}}%
              \setunit{\ctitleaddonpunct}%
              \printfield{booktitleaddon}%
              \iffieldundef{booktitleaddon}{}{\addcomma\addspace}}}%
          {\ifthenelse{\ifentrytype{article}\OR\ifentrytype{review}\OR%
              \ifentrytype{suppperiodical}}%
            {\iffieldundef{shorttitle}% Authorless articles w/o subtype
              {\printtext[cmshyper]{\printfield[citetitle]{title}}}%
              {\printtext[cmshyper]{\printfield[citetitle]{shorttitle}}}}%
            {\printtext[cmshyper]{\printfield[citetitle]{labeltitle}}}}}}}%
    {\printtext[cmshyper]{\printfield{label}}}%
    \global\booltrue{cms:atcite}}}%

\newbibmacro*{cite:labelyear+extrayear}{%
  \ifboolexpr{ (
    test {\ifentrytype{music}}%
    or
    test {\ifentrytype{review}}%
    or
    test {\ifentrytype{standard}}%
    or
    test {\ifentrytype{suppperiodical}}%
    or
    test {\ifentrytype{video}}%
    )
    and
    togl {cms@avdate}%
  }%
  {\usebibmacro{cite:av+labelyear+extrayear}}%
  {\iftoggle{cms@ordate}%
    {\usebibmacro{cite:origfirst+labelyear+extrayear}}%
    {\usebibmacro{cite:standard+labelyear+extrayear}}}}%

\newbibmacro*{cite:standard+labelyear+extrayear}{%
  \ifthenelse{\iffieldundef{labelyear}\OR%
    \iffieldequalstr{labelyear}{nodate}}%
  {\iftoggle{cms@nodates}%
    {\printtext[cmsyearhyper]{\bibstring{nodate}}}%
    {}}% For CMS?
  {\printtext[cmsyearhyper]{%
      \iffieldundef{year}%
      {\iffieldundef{eventyear}%
        {\iffieldundef{origyear}%
          {\iffieldundef{userd}%
            {\iftoggle{cms@nodates}%
              {\bibstring{nodate}}%
              {}}%
            {\printurldateextra}}%
          {\printorigdateextra}}%
        {\printeventdateextra}}%
      {\printdateextra}}}}%

\newbibmacro*{cite:origfirst+labelyear+extrayear}{%
  \ifthenelse{\iffieldundef{labelyear}\OR%
    \iffieldequalstr{labelyear}{nodate}}%
  {\iftoggle{cms@nodates}%
    {\printtext[cmsyearhyper]{\bibstring{nodate}}}% For CMS?
    {}}%
  {\printtext[cmsyearhyper]{%
      \iffieldundef{origyear}%
      {\iffieldundef{year}%
        {\iffieldundef{eventyear}%
          {\iffieldundef{userd}%
            {\iftoggle{cms@nodates}%
              {\bibstring{nodate}}%
              {}}%
            {\printurldateextra}}%
          {\printeventdateextra}}%
        {\printdateextra}}%
      {\printorigdateextra}}}}%

\newbibmacro*{cite:av+labelyear+extrayear}{%
  \ifthenelse{\iffieldundef{labelyear}\OR%
    \iffieldequalstr{labelyear}{nodate}}%
  {\iftoggle{cms@nodates}%
    {\printtext[cmsyearhyper]{\bibstring{nodate}}}% For CMS?
    {}}%
  {\printtext[cmsyearhyper]{%
      \iffieldundef{eventyear}%
      {\iffieldundef{origyear}%
        {\iffieldundef{year}%
          {\iffieldundef{userd}%
            {\iftoggle{cms@nodates}%
              {\bibstring{nodate}}%
              {}}%
            {\printurldateextra}}%
          {\printdateextra}}%
        {\printorigdateextra}}%
      {\printeventdateextra}}}}%

\newbibmacro*{cmscitesortdate}{% Attempt to solve date-related problems
  \ifboolexpr{%
    test {\iffieldundef{origyear}}%
    or
    not test {\iffieldint{origyear}}%
  }%
  {\usebibmacro{cmsciteyear}}%
  {\iffieldint{year}%
    {\ifboolexpr{% Needed for date ranges
        test {\iffieldundef{endyear}}%
        or
        not test {\iffieldnum{endyear}}%
      }%
      {\ifthenelse{\thefield{origyear}>\thefield{year}}%
        {\toggletrue{cms@switchdates}%
          \usebibmacro{cmsciteyear}}%
        {\usebibmacro{cmsciteyear}}}%
      {\ifthenelse{\thefield{origyear}>\thefield{endyear}}%
        {\toggletrue{cms@switchdates}%
          \usebibmacro{cmsciteyear}}%
        {\usebibmacro{cmsciteyear}}}}%
    {\usebibmacro{cmsciteyear}}}%
  \global\boolfalse{cms:atcite}}%

\newbibmacro*{cmsciteyear}{%
  \ifentrytype{patent}% Fix for double year w/cmsdate
  {\usebibmacro{cite:standard+labelyear+extrayear}}
  {\iftoggle{cms@origlabel}%
    {\usebibmacro{cite:origyear+labelyear}}%
    {\iftoggle{cms@bothlabelnew}%
      {\usebibmacro{cite:bothyear+oldstyle}}%
      {\iftoggle{cms@bothlabelold}%
        {\usebibmacro{cite:bothyear+oldstyle}}%
        {\ifboolexpr{%
            togl {cms@fulldate}%
            and
            not test {\iffieldequalstr{labeldatesource}{year}}%
            and
            not test {\iffieldequalstr{labeldatesource}{origyear}}%
          }%
          {\printtext[cmsyearhyper]{%
              \csuse{print\strfield{labeldatesource}date}%
              \iffieldundef{\strfield{labeldatesource}hour}%
              {}% Consistency(?)
              {\newcunit\csuse{print\strfield{labeldatesource}time}}}}%
          {\usebibmacro{cite:labelyear+extrayear}}}}}}}%
  % \ifcsdef{@cms@tempdate}%
  % {\toggletrue{\@cms@tempdate}}%
  % {}%

\newbibmacro*{cite:origyear+labelyear}{%
  \ifboolexpr{ (
    test {\ifentrytype{music}}%
    or
    test {\ifentrytype{review}}%
    or
    test {\ifentrytype{standard}}%
    or
    test {\ifentrytype{suppperiodical}}%
    or
    test {\ifentrytype{video}}%
    )
    and
    togl {cms@avdate}%
  }%
  {\usebibmacro{cite:av+labelyear+extrayear}}%
  {\iftoggle{cms@switchdates}%
    {\usebibmacro{cite:labelyear+extrayear}}%
    {\iffieldundef{origyear}%
      {\iftoggle{cms@ordate}% ???
        {}%
        {\clearfield{extradate}\clearfield{extratitleyear}}%
        \usebibmacro{cite:standard+labelyear+extrayear}}%
      {\iftoggle{cms@ordate}%
        {\usebibmacro{cite:origfirst+labelyear+extrayear}}%
        {\clearfield{extradate}\clearfield{extratitleyear}%
          \printtext[cmsyearhyper]{%
            \printorigdateextra}}}}}}% \usebibmacro{origyear+endyear}

\newbibmacro*{cite:bothyear+oldstyle}{%
  \ifboolexpr{ (
    test {\ifentrytype{music}}%
    or
    test {\ifentrytype{review}}%
    or
    test {\ifentrytype{standard}}%
    or
    test {\ifentrytype{suppperiodical}}%
    or
    test {\ifentrytype{video}}%
    )
    and
    togl {cms@avdate}%
  }%
  {\usebibmacro{cite:av+labelyear+extrayear}}%
  {\iftoggle{cms@switchdates}%
    {\printtext[cmsyearhyper]{%
        \bibopenparen%
        \usebibmacro{cite:labelyear+extrayear}%
        \bibcloseparen%
        \clearfield{extradate}\clearfield{extratitleyear}%
        \addspace%
        \printorigdateextra}}% \usebibmacro{origyear+endyear}
    {\iffieldundef{origyear}% ???
      {\iftoggle{cms@ordate}%
        {}%
        {\clearfield{extradate}\clearfield{extratitleyear}}%
        \usebibmacro{cite:standard+labelyear+extrayear}}%
      {\iftoggle{cms@ordate}% Added test for year field ???
        {\iffieldundef{year}%
          {\usebibmacro{cite:origfirst+labelyear+extrayear}}%
          {\printtext[cmsyearhyper]{%
              \bibopenparen%
              \usebibmacro{cite:origfirst+labelyear+extrayear}%
              \bibcloseparen%
              \setunit{\addspace}%\addspace% ???
              \clearfield{extradate}\clearfield{extratitleyear}%
              \printdateextra}}}%\usebibmacro{year+endyear}
        {\iffieldundef{year}%
          {\usebibmacro{cite:origfirst+labelyear+extrayear}}%
          {\printtext[cmsyearhyper]{%
              \bibopenparen%
              \clearfield{extradate}\clearfield{extratitleyear}%
              \printorigdateextra%
              % \usebibmacro{origyear+endyear}%
              \bibcloseparen%
              \addspace%
              \usebibmacro{cite:standard+labelyear+extrayear}}}}}}}}%

\newbibmacro*{cite:save}{%
  \savefield{entrykey}{\cbx@lastkey}}%

\newbibmacro*{cite:ibid}{%
  \iftoggle{cms@noibid}%
  {\blx@ibidreset%
    \usebibmacro{cite}}%
  {\ifthenelse{\iffieldundef{prenote}\AND%
      \iffieldundef{postnote}}%
    {\blx@ibidreset%
      \usebibmacro{cite}%
      \PackageWarning{biblatex-chicago}%
      {Empty Ibidem citation}}%
    {\toggletrue{cms@inlineibid}}}}%

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

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

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

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

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

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

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}%
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citetitle}
  {\boolfalse{citetracker}%
    \boolfalse{pagetracker}%
    \usebibmacro{prenote}}
  {\ifciteindex
      {\indexfield{indextitle}}
      {}%
   \ifthenelse{\ifentrytype{article}\OR\ifentrytype{review}\OR
         \ifentrytype{suppperiodical}}%
     {\iffieldundef{shorttitle}%
       {\iffieldundef{title}%
         {\iffieldundef{shortjournal}%
           {\iffieldundef{journaltitle}
             {}%
             {\printtext[cmsyearhyper]{\printfield{journaltitle}}}}%
           {\printtext[cmsyearhyper]{\printfield{shortjournal}}}}%
         {\printtext[cmsyearhyper]{\printfield{title}}}}%
       {\printtext[cmsyearhyper]{\printfield[title]{shorttitle}}}}%
     {\printtext[cmsyearhyper]{\printfield[citetitle]{labeltitle}}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citetitle}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{indextitle}}
     {}%
   \ifthenelse{\ifentrytype{article}\OR\ifentrytype{review}\OR
         \ifentrytype{suppperiodical}}%
     {\iffieldundef{title}%
       {\iffieldundef{journaltitle}
         {}%
         {\printtext[cmsyearhyper]{\printfield{journaltitle}}}}%
       {\printtext[cmsyearhyper]{\printfield{title}}}}%
     {\printtext[cmsyearhyper]{\printfield{title}}}}%
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\atcite}
  {\usebibmacro{cite:init}%
    \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \toggletrue{cms@authortitle}%
    \usebibmacro{cite}}
  {}%\multicitedelim
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\atpcite}[\mkbibparens]
  {\usebibmacro{cite:init}%
    \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \toggletrue{cms@authortitle}%
    \usebibmacro{cite}}
  {}%\multicitedelim
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeincite}[\cmswrap]% Used in fields of other entries
  {\usebibmacro{cite:init}%
    \usebibmacro{backref+check}%
    \togglefalse{blx@skipbib}%
    \togglefalse{cms@authortitle}%
    \togglefalse{cms@fulldate}%
    \usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}%\multicitedelim
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeincitef}[\cmswrapf]%
  {\usebibmacro{cite:init}%
    \usebibmacro{backref+check}%
    \togglefalse{blx@skipbib}%
    \togglefalse{cms@authortitle}%
    \togglefalse{cms@fulldate}%
    \usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}%\multicitedelim
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\cmshypercite}[\cmswraphy]% For CustomC comments
  {\usebibmacro{cite:init}%
    \usebibmacro{backref+check}%
    \togglefalse{blx@skipbib}%
    \togglefalse{cms@authortitle}%
    \togglefalse{cms@fulldate}%
    \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \usebibmacro{cite}}
  {}%\multicitedelim
  {}%\usebibmacro{postnote} Stops double printing

\DeclareCiteCommand{\fullciteincite}% For use in annotation fields
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
    \toggletrue{cms@fullnote}%
    \togglefalse{cms@shortnote}%
    \usebibmacro{cite:driver}%
    \usebibmacro{footcite:save}%
    \usebibmacro{cite:save}}
  {\multicitedelim}
  {}

\def\cmswrap#1{%
  \ifbool{cbx:parens}{\global\booltrue{cms:tcit}}{}% For \textcites
  \blx@initunit#1%
  \ifdef{\blx@thepostpunct}%
  {\ifdefvoid{\abx@field@postpunct}%
    {\blx@dopostpunct}{}}%
  {}%
  \global\let\abx@field@postpunct\@empty%
  \ifbool{cms:tcit}{\global\booltrue{cbx:parens}\global\boolfalse{cms:tcit}}%
  {}}

\def\cmswrapf#1{%
  \ifbool{cbx:parens}{\global\booltrue{cms:tcit}}{}% For \textcites
  \blx@initunit#1\ifdef{\blx@thepostpunct}{\cms@cicpunct}{}%
  \ifbool{cms:tcit}{\global\booltrue{cbx:parens}\global\boolfalse{cms:tcit}}%
  {}}

\def\cmswraphy#1{%
  \ifbool{cbx:parens}{\global\booltrue{cms:tcit}}{}% For \textcites
  #1%
  \ifbool{cms:tcit}{\global\booltrue{cbx:parens}\global\boolfalse{cms:tcit}}%
  {}}

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

%%% Commands, macros and formats for the Legal entry types %%%

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

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

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

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

\newbibmacro*{cite:full}{%
  \iftoggle{cms@noneshort}%
  {\ifboolexpr{%
      test {\ifciteibid}%
      and
      not test {\iffirstonpage}%
      and
      not togl {cms@noibid}%
    }%
    {\togglefalse{cms@fullnote}%
      \toggletrue{cms@shortnote}%
      \usebibmacro{legal:ibid}}%
    {\usebibmacro{cite:driver}}}%
  {\ifboolexpr{%
      test {\ifciteseen}%
      or
      togl {cms@allshort}%
    }%
    {\togglefalse{cms@fullnote}%
      \toggletrue{cms@shortnote}%
      \ifboolexpr{%
        test {\ifciteibid}%
        and
        not test {\iffirstonpage}%
        and
        not togl {cms@noibid}%
      }%
      {\usebibmacro{legal:ibid}}%
      {\usebibmacro{cite:short}}}%
    {\usebibmacro{cite:driver}}}}

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

\newbibmacro*{cite:short}{%
  \iffieldundef{shorthand}%
  {\ifentrytype{jurisdiction}%
    {\usebibmacro{cite:short:jurisdiction}}%
    {\ifentrytype{legal}%
      {\usebibmacro{cite:short:legal}}%
      {\ifentrytype{legislation}%
        {\usebibmacro{cite:short:legislation}}%
        {\usebibmacro{cite}}}}}
  {\usebibmacro{cite:shorthand:legal}}}%

\newbibmacro*{cite:short:jurisdiction}{%
  \iffieldundef{labeltitle}%
  {}%
  {\ifboolexpr{%
    togl {cms@allshort}%
    or
    test {\ifbibliography}%
  }%
  {\printtext[bibhyperref]{%
      \printfield[citetitle]{labeltitle}}}%
  {\printtext[cmshyperlink]{%
      \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?
  \usebibmacro{juridpostnote}}%

\newbibmacro*{cite:short:legal}{%
  \iffieldundef{labeltitle}%
  {}%
  {\ifboolexpr{%
    togl {cms@allshort}%
    or
    test {\ifbibliography}%
  }%
  {\printtext[bibhyperref]{%
      \printfield[citetitle]{labeltitle}}}%
  {\printtext[cmshyperlink]{%
      \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}%
  \ifboolexpr{%
    togl {cms@supranotes}%
    and
    test {\iffootnote}%
  }%
  {\newcunit%
    \printtext{\bibstring{supranote}\addnbspace%
      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}}% ??
  {}%
  \usebibmacro{juridpostnote}}%

\newbibmacro*{cite:short:legislation}{%
  \iffieldequalstr{entrysubtype}{constitution}%
  {\usebibmacro{clegis+news+title}%
    \setunit{\addspace}%
    \printfield[juridnum]{number}%
    \newcunit%
    \printfield{part}%
    \newcunit%
    \printfield{chapter}}%
  {\iffieldequalstr{labeltitlesource}{shorttitle}%
    {\ifboolexpr{%
        togl {cms@allshort}%
        or
        test {\ifbibliography}%
      }%
      {\printtext[bibhyperref]{%
          \printfield[citetitle]{labeltitle}}}%
      {\printtext[cmshyperlink]{%
          \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}}%
        {}%
        \ifboolexpr{%
          togl {cms@allshort}%
          or
          test {\ifbibliography}%
        }%
        {\printtext[bibhyperref]{%
            \printfield[citetitle]{labeltitle}}}%
        {\printtext[cmshyperlink]{%
            \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 {\iffieldequalstr{entrysubtype}{un}}%
    or
    test {\iffieldequalstr{entrysubtype}{hearing}}%
    )
  }%
  {\newcunit%
    \printtext{\bibstring{supranote}\addnbspace%
      \ref{cbx@\csuse{cbx@f@\thefield{entrykey}}}}}% ??
  {}%
  \usebibmacro{juridpostnote}}%

\newbibmacro*{cite:shorthand:legal}{%
  \iftoggle{cms@allshort}%
  {\printtext[bibhyperref]{%
      \printfield{shorthand}}}%
  {\printtext[cmshyperlink]{%
      \printfield{shorthand}}}%
  \ifboolexpr{%
    test {\iffootnote}%
    and
    togl {cms@supranotes}%
    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}}}%
      \newcunit}}% ??
  {\newcunit}% ??
  \iffieldundef{postnote}%
  {\global\togglefalse{cms@fullnote}%
    \global\togglefalse{cms@shortnote}}%
  {\usebibmacro{semel:postnote}%
    \global\togglefalse{cms@fullnote}%
    \global\togglefalse{cms@shortnote}}}%

\newbibmacro*{cms:shorthandintro}{% For changing the citedas phrase
  \iffieldundef{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}}}}%
    {%\addspace%\setunit{\addspace}% Ditto
      \printfield{shorthandintro}}}}

\newbibmacro*{footcite:save}{%
  \ifboolexpr{%
    test {\iffootnote}%
    and
    (
    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}}}%
  {}}%

\newbibmacro*{legal:ibid}{%
  \ifboolexpr{%
    togl {cms@noibid}%
    or
    test {\ifbibliography}% Needed for inheritshorthand option
  }%
  {\global\toggletrue{cms@shortnote}%
    \global\togglefalse{cms@fullnote}%
    \usebibmacro{cite:short}%
    \usebibmacro{cite:save}}%
  {\printtext[bibhyperlink]{%
      \bibsstring[\mkbibemph]{ibidem}}%\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}}%
    {}}\usebibmacro{postnote}}% FIXME?

\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}%
  }}%\newcunit\newblock}

\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}%
      {}%
      {\newunit%
        \bibstring{cbytranslator}\addspace%
        \printnames[bytranslator]{nameb}}}}}

\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*{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}}}%

\newbibmacro*{cite+doi+url}{% 16th ed.
  \ifboolexpr{%
    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}}%
  {}}%

\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}}}

\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[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}}

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

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

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

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

\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{juridnum}{\bibcpstring{number}\addspace #1}%

\DeclareFieldFormat{jourvol}{#1}

\DeclareFieldFormat{shortvol}{#1}

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

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

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

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

\newbibmacro*{patenttitle+stitle}{% Unify Patent entries across 2 AD styles
  \printtext{%
    \printfield{title}%
    \setunit{\subtitlepunct}%
    \printfield[subtitle]{subtitle}}%
  \setunit{\ptitleaddonpunct}%
  \printfield{titleaddon}%
  \setunit{\addspace}%
  \usebibmacro{language+transtitle}%
  \newunit\newblock}

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

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

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

\DeclareFieldFormat[patent]{subtitle}{%
  \iffieldundef{subtitle}%
  {}%
  {\MakeSentenceCase*{#1}}}

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

\DeclareFieldAlias[dataset]{citetitle}[dataset]{title}

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

%%% Textcite commands taken verbatim from authoryear-comp.cbx %%%

\DeclareCiteCommand{\cbx@textcite}
  {\usebibmacro{cite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {}%
  {\usebibmacro{textcite:postnote}}

\DeclareCiteCommand{\textcite}[\cbx@textcite@init\cbx@textcite]
  {\gdef\cbx@savedkeys{}%
   \citetrackerfalse%
   \pagetrackerfalse%
   \DeferNextCitekeyHook%
   \usebibmacro{cite:init}}
  {\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}%
     {\protected@xappto\cbx@savedcites{()(\thefield{multipostnote})}%
      \global\clearfield{multipostnote}}%
     {}%
   \xappto\cbx@savedkeys{\thefield{entrykey},}%
   \iffieldequals{fullhash}{\cbx@lasthash}%
     {}%
     {\ifboolexpr{% The shorthand isn't a name, but the ID of a whole work.
         togl {cms@los}% Hence we don't treat it as common to what follows.
         or
         test {\iffieldundef{shorthand}}%
       }%
       {\savefield{fullhash}{\cbx@lasthash}}%
       {\global\undef\cbx@lasthash}%
       \stepcounter{textcitetotal}}}%
  {}%
  {\protected@xappto\cbx@savedcites{%
     [\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}

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

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

\let\cbx@textcites@init\cbx@textcite@init
\pretocmd{\cbx@textcites@init}{\UseNextMultiCiteHook}{}{}

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

\DeclareCiteCommand{\cms@gentextcite@i}
  {\usebibmacro{cite:init}%
    \toggletrue{cms@gencite}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {}%
  {\usebibmacro{textcite:postnote}%
    \togglefalse{cms@gencite}}%

\DeclareCiteCommand{\cms@gentextcite}[\cbx@textcite@init\cms@gentextcite@i]
  {\gdef\cbx@savedkeys{}%
   \citetrackerfalse%
   \pagetrackerfalse%
   \DeferNextCitekeyHook%
   \usebibmacro{cite:init}}
  {\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}%
     {\protected@xappto\cbx@savedcites{()(\thefield{multipostnote})}%
      \global\clearfield{multipostnote}}%
     {}%
   \xappto\cbx@savedkeys{\thefield{entrykey},}%
   \iffieldequals{fullhash}{\cbx@lasthash}%
     {}%
     {\ifboolexpr{%
         togl {cms@los}%
         or
         test {\iffieldundef{shorthand}}%
       }%
       {\savefield{fullhash}{\cbx@lasthash}}%
       {\global\undef\cbx@lasthash}%
       \stepcounter{textcitetotal}}}
  {}%
  {\protected@xappto\cbx@savedcites{%
     [\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}

\DeclareMultiCiteCommand{\cms@gentextcite@is}{\cms@gentextcite@i}{}
\DeclareMultiCiteCommand{\cms@gentextcites}[\cbx@textcites@init\cms@gentextcite@is]{\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 %%%

\DeclareMultiCiteCommand{\cites}{\cite}{\setunit{\multicitedelim}}

\DeclareMultiCiteCommand{\parencites}[\mkbibparens]{\parencite}%
   {\setunit{\multicitedelim}}

\DeclareMultiCiteCommand{\footcites}[\mkbibfootnote]{\footcite}%
   {\setunit{\multicitedelim}}

\DeclareMultiCiteCommand{\footcitetexts}[\mkbibfootnotetext]%
   {\footcitetext}{\setunit{\multicitedelim}}

\DeclareCitePunctuationPosition{\citeincitef}{d}

\DeclareCitePunctuationPosition{\cmshypercite}{d}

\DeclareCitePunctuationPosition{\citeincitefs}{d}

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

\DeclareMultiCiteCommand{\citeincitefs}[\cmswrapf]{\citeincite}%
{\setunit{\multicitedelim}}%

\DeclareMultiCiteCommand{\fullciteincites}{\fullciteincite}%
{\setunit{\multicitedelim}}

\DeclareCiteCommand{\bibxrefcite}
  {\usebibmacro{cite:init}%
    \usebibmacro{backref+check}}%\usebibmacro{clearalmostall}} (?)
  {\usebibmacro{xref-in:}%
    \blx@ibidreset% For authordate style
    \usebibmacro{cite}}
  {}%
  {}%

\DeclareCiteCommand{\origfullcite}
  {\usebibmacro{backref+check}%
    \nopunct\unspace%
    \savebibmacro{cmsbibsortdate}%
    \renewbibmacro*{cmsbibsortdate}{}}%
  {\usedriver
    {\DeclareNameAlias{sortname}{default}\clearfield{postnote}%
      \clearname{author}\clearfield{userf}%\toggletrue{cms@fullnote}%
      \toggletrue{cms@headlessnote}\frenchspacing}%
    {\thefield{entrytype}}%
    \iflistundef{pageref}{}{\newunit\usebibmacro{pageref}}}%
  {\multicitedelim}%
  {\restorebibmacro{cmsbibsortdate}}

\DeclareCiteCommand{\origpublcite}% Similar to above, w/o title.
  {\usebibmacro{backref+check}%
    \nopunct%\unspace% Remove otherlang test for 3.16.
    \savebibmacro{cmsbibsortdate}%
    \renewbibmacro*{cmsbibsortdate}{}}%
  {\usedriver
    {\DeclareNameAlias{sortname}{default}\clearfield{postnote}%
      \usebibmacro{clearpublin}\usebibmacro{cms:titlehook}%
      \toggletrue{cms@headlessnote}%\toggletrue{cms@fullnote}%
      \toggletrue{cms@origpublished}\frenchspacing}%
    {\thefield{entrytype}}%
    \iflistundef{pageref}{}{\newunit\usebibmacro{pageref}}}%
  {\multicitedelim}%
  {\restorebibmacro{cmsbibsortdate}}

%%%% 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{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 -- Mostly non-title %%%%

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

\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}}}}%

\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}}}}%

\DeclareFieldFormat{bibnote}{\MakeCapital{#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[customc]{title}{%
  \ifboolexpr{%
    test {\iffieldundef{nameaddon}}%
    or
    togl {cms@nona}%
  }%
  {\mkbibemph{\bibstring{see}}%
    \addspace%
    #1}%
  {#1}}

\DeclareFieldFormat[customc]{citetitle}{%
  \iffieldequalstr{pubstate}{cms-generated}% Comments 17th ed.
  {\ifbibstring{#1}%
    {\bibstring{#1}}%
    {#1}%
    \StrGobbleRight{\strfield{entrykey}}{8}[\cms@aa]%
    \addspace\cmshypercite{\cms@aa}}%
  {\ifnameundef{author}%
    {#1}%
    {\ifboolexpr{%
        test {\iffieldundef{nameaddon}}%
        or
        togl {cms@nona}%
      }%
      {\mkbibemph{\bibstring{see}}%
        \addspace%
        #1}%
      {\printfield{nameaddon}\addspace #1}}}}

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

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

\DeclareFieldFormat[periodical]{shorttitle}{\mkbibemph{#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[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}%
  \OR\NOT\iffieldundef{urlmonth}\OR\NOT\iffieldundef{eventmonth}%
  \OR\NOT\iffieldundef{origmonth}}%
  {#1}%
  {\printfield{userd}\addspace #1}}

\DeclareFieldFormat[video]{date}{% Generalize userd ???
  \ifthenelse{\iffieldundef{userd}\OR\NOT\iffieldundef{urlyear}%
    \OR\NOT\iffieldundef{eventyear}\OR\NOT\iffieldundef{urlmonth}%
    \OR\NOT\iffieldundef{eventmonth}}%
  {#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}\space #1}%
  {\printfield{userd}\addspace #1}}

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

\DeclareFieldFormat[music]{urldate}{% 16th ed.
  \ifthenelse{\iffieldundef{userd}\OR\NOT\iffieldundef{eventyear}%
    \OR\NOT\iffieldundef{origyear}}%
  {\bibstring{urlseen}\space #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}\space #1}%
    {\printfield{userd}\addspace #1}}}

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

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

\DeclareFieldFormat{extratitleyear}{%
  \iffieldnums{labelyear}%
  {\mknumalph{#1}}%
  {\mkbibparens{\mknumalph{#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{usere}{[#1]} % Better than mkbibbrackets?

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

\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{jourser}{%
  \ifinteger{#1}%
  {\mkbibordseries{#1}%
    \addnbspace%
    \bibstring{jourser}}%
  {\ifbibstring{#1}{\bibstring{#1}}{#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{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}}

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

\DeclareFieldFormat{annotation}{#1}%

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

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

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

\DeclareFieldFormat{cmshyper}{% Control number of elements hyperlinked
  \ifboolexpr{%
    togl {cms@authortitle}%
    or
    test {\iffieldequalstr{entrysubtype}{classical}}%
  }%
  {\iftoggle{blx@skipbib}%
    {\iftoggle{cms@shortrelated}%
      {\ifentryinbib{\strfield{clonesourcekey}}%
        {\bibhyperref[\strfield{clonesourcekey}]{#1}}%
        {#1}}%
      {#1}}%
    {\bibhyperref{#1}}}%
  {\iftoggle{cms@linkit}%
    {\iftoggle{blx@skipbib}%
      {\iftoggle{cms@shortrelated}%
        {\ifentryinbib{\strfield{clonesourcekey}}%
          {\bibhyperref[\strfield{clonesourcekey}]{#1}}%
          {#1}}%
        {#1}}%
      {\bibhyperref{#1}}}%
    {#1}}}%

\DeclareFieldFormat{cmsyearhyper}{% Only link when in ref list
  \iftoggle{blx@skipbib}
  {\iftoggle{cms@shortrelated}%
    {\ifentryinbib{\strfield{clonesourcekey}}%
      {\bibhyperref[\strfield{clonesourcekey}]{#1}}%
      {#1}}%
    {#1}}%
  {\bibhyperref{#1}}}%

\DeclareFieldFormat{cmsnamehyper}{% Two cases: 1. only a name is present
  \ifboolexpr{%                                2. new user option hypername
    togl {cms@nodates}%
    or
    togl {cms@authortitle}%
    or
    test {\iffieldequalstr{entrysubtype}{classical}}%
    or
    not test {\iffieldundef{labeldate}}%
  }%
  {\iftoggle{cms@linkname}%
    {\iftoggle{blx@skipbib}%
      {\iftoggle{cms@shortrelated}%
        {\ifentryinbib{\strfield{clonesourcekey}}%
          {\bibhyperref[\strfield{clonesourcekey}]{#1}}%
          {#1}}%
        {#1}}%
      {\bibhyperref{#1}}}%
    {#1}}%
  {\iftoggle{blx@skipbib}%
    {\iftoggle{cms@shortrelated}%
      {\ifentryinbib{\strfield{clonesourcekey}}%
        {\bibhyperref[\strfield{clonesourcekey}]{#1}}%
        {#1}}%
      {#1}}%
    {\bibhyperref{#1}}}}

%%%% 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}%
  {\printunit{\relatedpunct}}}%

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

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

\newcommand*{\cbytypeeditor}{% Needed?
  \iffieldundef{editortype}%
    {\bibstring{cbytypeeditor}}%
    {\bibstring{cbytype\thefield{editortype}}}}

\renewcommand*{\multicitedelim}{\addsemicolon\space}

\newcommand*{\cms@testspace}{% FIXME
  \ifboolexpr{%
    test {\ifnumequal{\spacefactor}{\blx@sf@dot}}%
    and
    not test {\ifbibliography}%
  }%
  {\addnbspace}%
  {\addspace}}%

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

\renewcommand*{\nameyeardelim}{%
  \ifboolexpr{%
    (
    togl {cms@bothlabelnew}%
    or
    togl {cms@bothlabelold}%
    )
    and
    (
    not test {\iffieldundef{year}}%
    and
    not test {\iffieldundef{origyear}}%
    )
  }%
  {\cms@testspace}%
  {\cms@pre@punct%
    \ifboolexpr{%
      test {\iffieldundef{labelyear}}%
      or
      (
      test {\iffieldundef{userd}}%
      and
      test {\iffieldequalstr{labeldatesource}{url}}%
      )
      or
      test {\iffieldequalstr{labelyear}{nodate}}%
      or
      togl {cms@fulldate}%
      or
      bool {cms:comma}%
    }%
    {\addcomma\addspace}%
    {\iffieldundef{origyear}%
      {\iffieldundef{year}%
        {\cms@testspace}%
        {\ifboolexpr{%
            test {\iffieldnums{year}}%
            or
            test {\iffieldstart{year}{[}}%] For backward compatibility
          }%
          {\cms@testspace}%
          {\addcomma\addspace}}}%
      {\cms@testspace}}\global\boolfalse{cms:comma}}}

\newrobustcmd*{\cms@citepunct@helper}[1]{%
  \begingroup
  \blx@metadateinfo{#1}%
  \ifboolexpr{%
    test {\if@cms@bracket}%
    and
    not togl {cms@noyearbrackets}%
  }%
  {}%
  {\if@cms@circa%
    {\global\booltrue{cms:comma}}%
    {\if@cms@adfirst%
      {\iffieldnum{#1year}%
        {\ifboolexpr{%
            test {\ifdefstring\blx@dateera{christian}}%
            and
            not test {\iffieldequalstr{#1dateera}{bce}}%
            and
            test {\ifnumless{\thefield{#1year}}\blx@dateeraauto}%
          }%
          {\global\booltrue{cms:comma}}%
          {}}%
        {}}%
      {\ifboolexpr{%
          test {\ifdefstring\blx@languagename{french}}%
          or
          test {\ifdefstring\blx@languagename{dutch}}%
        }%
        {\ifboolexpr{%
            not test {\iffieldequalstr{#1dateunspecified}{yearindecade}}%
            or
            togl {cms@alwaysrange}%
            or
            togl {cms@decaderange}%
          }%
          {}%
          {\global\booltrue{cms:comma}}}%
        {\ifboolexpr{%
            test {\ifdefstring\blx@languagename{brazilian}}%
            or
            test {\ifdefstring\blx@languagename{brazil}}%
            or
            test {\ifdefstring\blx@languagename{romanian}}%
          }%
          {\ifboolexpr{%
              test {\iffieldundef{#1dateunspecified}}%
              or
              togl {cms@alwaysrange}%
            }%
            {}%
            {\ifboolexpr{%
                (
                test {\iffieldequalstr{#1dateunspecified}{yearindecade}}%
                and
                not togl {cms@decaderange}%
                )
                or
                (
                test {\iffieldequalstr{#1dateunspecified}{yearincentury}}%
                and
                not togl {cms@centuryrange}%
                )
              }%
              {\global\booltrue{cms:comma}}%
              {}}}%
          {}}}}}%
  \endgroup}

\newrobustcmd*{\cms@pre@punct}{%
  \iftoggle{cms@origlabel}%
  {\cms@citepunct@helper{orig}}%
  {\ifdefstring\abx@field@labeldatesource{year}%
    {\cms@citepunct@helper{}}%
    {\ifdefstring\abx@field@labeldatesource{origyear}%
      {\cms@citepunct@helper{orig}}%
      {\ifdefstring\abx@field@labeldatesource{nodate}%
        {}%
        {\cms@citepunct@helper{\abx@field@labeldatesource}}}}}}

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

\newcommand*{\reprintpunct}{%
  \ifthenelse{\ifentrytype{artwork}\OR\ifentrytype{image}}%
  {}%
  {\ifentrytype{dataset}%
    {\setunit{\addspace}}%
    {\printunit{\addcomma\addspace}}}}

\newcommand*{\postvolpunct}{\addcolon}%

\newcommand*{\parttrans}{%
  {\bibstring{bytranslator}\space}}%

\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}{\bibstring{byeditor}\addspace}%

\newcommand*{\partcomp}{%
  {\bibstring{bycompiler}\space}}%

\newcommand*{\parteditandcomp}{%
  {\bibstring{byeditorcp}\space}}%

\newcommand*{\parttransandcomp}{%
  {\bibstring{bytranslatorcp}\space}}%

\newcommand*{\partedittransandcomp}{%
  {\bibstring{byeditortrcp}\space}}%

\newcommand*{\parteditandtrans}{%
  {\bibstring{byeditortr}\space}}%

\newcommand*{\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}{% Cf. N&B style
  \ifboolexpr{%
    test {\ifciteibid}%
    and
    (
    test {\ifentrytype{jurisdiction}}%
    or
    test {\ifentrytype{legal}}%
    or
    test {\ifentrytype{legislation}}%
    )
  }%
  {\addspace}%
  {\iftoggle{cms@inlineibid}%
    {\togglefalse{cms@inlineibid}%
      \iffieldundef{prenote}% Bug fix
      {}%
      {\setunit{\cms@testspace}}}%
    {\iffieldequalstr{entrysubtype}{classical}% For Notes+Bib, too?
      {\DeclareNumChars*{abcdeABCDE:}%
        \iffieldpages{postnote}%
        {\setunit{\cms@testspace}}%
        {\newcunit}}%
      {\newcunit}\DeclareNumChars{.}}}}

\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}{% Otherwise you get an inaccurate comma.
  \iffieldequalstr{editortype}{none}%
  {\newunit}%\addperiod\addspace
  {\newcunit}}%\addcomma\addspace

\newcommand*{\nameadelim}{% Otherwise you get an inaccurate comma.
  \iffieldequalstr{nameatype}{none}%
  {\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
  \ifboolexpr{%
    togl {cms@annotation}%
    or
    togl {cms@cbxannote}%
  }%
    {\usebibmacro{entrytail}}%
    {}%
  \finentry}

\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}%
    {\let\bbx@lasthash\undefined}%
    {\usebibmacro{author/editor}%
     \ifthenelse{\ifnameundef{holder}\OR
                 \ifnamesequal{author}{holder}}%
       {}%
       {\setunit{\addspace}%
        \printtext[parens]{\printnames{holder}}}}}

\renewbibmacro*{byauthor}{%
  \ifthenelse{\ifuseauthor\OR
              \ifnameundef{author}}%
    {}%
    {\bibstring{by}\addspace%
     \printnames[byauthor]{author}}}

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

\renewbibmacro*{bybookauthor}{%
  \ifnameundef{bookauthor}%
    {}%
    {\ifnamesequal{author}{bookauthor}%
      {}%
      {\bibstring{by}\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?
  {\ifentrytype{video}%
    {\newcunit\newblock}%
    {\newunit\newblock}}%
  {\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}}}%
    {\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*{video+tv+title}{% For 17th ed.
  \ifboolexpr{%
    test {\iffieldequalstr{entrysubtype}{tvepisode}}%
    and
    (
    not test {\iffieldundef{title}}%
    and
    not test {\iffieldundef{booktitle}}%
    )
  }%
  {\printtext{%
      \printfield{booktitle}%
      \setunit{\subtitlepunct}%
      \printfield[booksubtitle]{booksubtitle}}%
    \setunit{\ptitleaddonpunct}%
    \printfield{booktitleaddon}%
  \ifundef\bbx@lasthash{}{\newcunit}}%
  {\usebibmacro{video+title}% Simplifies trad style
    \iffieldundef{booktitle}% Comma after italics, period after quotes
    {\setunit{\ctitleaddonpunct}}%
    {\setunit{\ptitleaddonpunct}}%\setunit{\addspace}\newblock%
    \printfield{titleaddon}%\usebibmacro{title+stitle}%
    \setunit{\addspace}\newblock%\bibsentence
    \usebibmacro{language+transtitle}}}

\newbibmacro*{reference+title}{%
  \ifboolexpr{%
    test {\iffieldequals{title}{\bbx@lasthash}}%
    and
    not test {\iffirstonpage}%
    and
    togl {cms@namedash}%
  }%
  {\printtext{\bibnamedash}}%
  {\usebibmacro{italtitle+stitle}%
    \savefield{title}{\bbx@lasthash}}}

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

\newbibmacro*{type+inst+year}{%
  \printfield{type}%
  \newcunit
  \printlist{institution}%
  \setunit*{\addcomma\space}%
  \printdate}% Was printfield{year}?

\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}%
        \newunit%
        \printlist{institution}}}%
    {\iflistundef{institution}%
      {\newcunit\printfield{number}%
        \newunit%
        \printlist{organization}}%
      {\printlist{organization}%
        \newcunit%
        \printfield{number}%
        \newcunit%
        \printlist{institution}}}}}

\newbibmacro*{author+org}{%
  \ifnameundef{author}%
  {\ifnameundef{editor}%
    {\iflistundef{organization}%
      {\let\bbx@lasthash\undefined}%
      {\ifboolexpr{%
          test {\iflistequals{organization}{\bbx@lasthash}}%
          and
          not test {\iffirstonpage}%
          and
          togl {cms@namedash}%
        }%
        {\printtext{\bibnamedash}}%
        {\iftoggle{cms@authorparens}%
          {\bibopenparen\printlist{organization}\bibcloseparen}%
          {\printlist{organization}}%
          \savelist{organization}{\bbx@lasthash}}}}%
    {\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{bytranslator}%
    \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}%
    {}%
    {\bibstring{withcommentator}\addspace%
     \printnames[withcommentator]{commentator}}}

\newbibmacro*{cwithannotator}{%
  \ifnameundef{annotator}%
    {}%
    {\bibstring{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}\space%
    \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}\space%
     \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}\space%
     \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*{cms-in:}{% Fix for 0.9a compat.
  \iftoggle{cms@origpublished}%
  {}%
  {\bibstring{in}%
    \setunit{\addspace}}}

\newbibmacro*{xref-in:}{%
  \iffieldundef{volume}{}{\savefield{volume}{\cbx@incollvol}}%
  \iffieldundef{part}{}{\savefield{part}{\cbx@incollpart}}%
  \bibstring{in}\setunit{\addspace}}% Changed for related:reprintfrom

\newbibmacro*{chapincoll}{%
  \iffieldundef{chapter}%
  {}%
  {\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@origpublished}%
      {\DeclareFieldAlias{booktitle}{title:hook}}%
      {\DeclareFieldAlias{booktitle}{title:hook:alt}}%
      \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*{music+origdate}{%
  \iffieldequalstr{pubstate}{reprint}% 17th ed.
  {}%
  {\iftoggle{cms@switchdates}% Date fix
    {\ifthenelse{\iffieldundef{year}\AND\iffieldundef{month}\AND%
        \iffieldundef{yeardivision}}%
      {}%
      {\usebibmacro{cmsorigdate}}}%
    {\ifthenelse{\iffieldundef{origyear}\AND\iffieldundef{origmonth}\AND%
        \iffieldundef{origyeardivision}}%
      {}%
      {\usebibmacro{cmsorigdate}}}%
    \iffieldundef{pubstate}%
    {}%
    {\iffieldbibstring{pubstate}%
      {\newunit\biblstring{\thefield{pubstate}}}%
      {\newunit\printfield[prenote]{pubstate}}}}}%

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

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

\newbibmacro*{series+or+shortser}{%
  \iffieldundef{shortseries}%
  {\printfield{series}}%
  {\iftoggle{cms@shser}%
    {\printfield{shortseries}}%
    {\printfield{series}}}}

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

\newbibmacro*{publ+loc+year}{%
  \printlist{location}%
  \iflistundef{publisher}%
  {\setunit*{\addcomma\addspace}}%
  {\setunit*{\addcolon\addspace}}%
  \printlist{publisher}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{date}% For the author-date style.  Tricky.
}%

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

\newbibmacro*{howpubl+loc+year}{%
  \printlist{location}%
  \iffieldundef{howpublished}%
  {\setunit*{\addcomma\space}}%
  {\setunit*{\addcolon\space}}%
  \printfield{howpublished}%
  \setunit*{\addcomma\space}%
  \usebibmacro{date}%
}%

\newbibmacro*{inst+loc+year}{%
  \printlist{location}%
  \iflistundef{institution}%
  {\setunit*{\addcomma\space}}%
  {\setunit*{\addcolon\space}}%
  \printlist{institution}%
  \setunit*{\addcomma\space}%
  \usebibmacro{date}%
}%

\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%
        \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?
  \printlist{location}%
  \iflistundef{organization}%
  {\iflistundef{publisher}%
    {\setunit*{\addcomma\addspace}}%
    {\setunit*{\addcolon\addspace}}}%
  {\setunit*{\addcolon\addspace}}%
  \printlist{organization}%
  \setunit*{\addcomma\space}%
  \printlist{publisher}%
  \setunit*{\addcomma\addspace}%
  \usebibmacro{date}}

\newbibmacro*{year+in+parens}{%
  \iffieldundef{volume}%
  {noformat}%
  {parens}}

\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 the Misc type.
  \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*{cmsbookdate}{%
  \ifthenelse{\iffieldundef{year}\AND\iffieldundef{origyear}}%
  {\newunit}%
  {\iftoggle{cms@switchdates}%
    {\iffieldundef{origyear}%
      {\newunit}%
      {\newcunit\printorigdate}}%
    {\iffieldundef{year}%
      {\newunit}%
      {\newcunit\printdate}}}}

\renewbibmacro*{date}{% Adding the test solved some issues in 0.9 with
  \iftoggle{cms@switchdates}%
  {\ifthenelse{\iffieldundef{origyear}\AND\iffieldundef{origmonth}%
    \AND\iffieldundef{origday}\AND\iffieldundef{origyeardivision}}%
    {}%
    {\printorigdate}}%
  {\ifthenelse{\iffieldundef{year}\AND\iffieldundef{month}%
    \AND\iffieldundef{day}\AND\iffieldundef{yeardivision}}% Punctuation in some
    {}%  entry types (Misc).  The whole \printdate thing may need further work.
    {\printdate}}}

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

\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*{journal+sub}[1]{%
  \ifboolexpr{%
    not test {\iffieldundef{shortjournal}}%
    and
    ((
    test {\ifcitation}%
    and
    togl {cms@citejtabb}%
    )
    or
    (
    test {\ifbibliography}%
    and
    togl {cms@bibjtabb}%
    ))
  }%
  {\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*{chap+pag}{%
  \printfield{chapter}%
  \setunit*{\addcomma\space}%
  \printfield{pages}}

\newbibmacro*{mag+news+date}{%
  \ifboolexpr{%
    (
    test {\ifnameundef{author}}%
    or
    not test {\ifuseauthor}%
    )
    and
    not togl {cms@origpublished}%
  }%
  {\usebibmacro{date+issue}{a}}%
  {\usebibmacro{mag+date+issue}}}

\newbibmacro*{date+issue}[1]{%
  \iffieldundef{maintitle}%
  {\ifblank{#1}{\newcunit\newblock}{\newunit\newblock}}%
  {\printtext{%
      \printfield{maintitle}%
      \setunit{\subtitlepunct}%
      \printfield[mainsubtitle]{mainsubtitle}}%
    \setunit{\jtitleaddonpunct}%
    \printfield{maintitleaddon}%
    \newcunit\newblock}%
  \printfield{usera}% For network ID and possible section of newspaper.
  \setunit*{\addcomma\addspace}\newblock%
  \iffieldundef{issue}%
  {\iffieldundef{number}%
    {\usebibmacro{date}%
      \usebibmacro{time+stamp}}% 17th ed.
    {\iftoggle{cms@numbermonth}%
      {\usebibmacro{date}}%
      {\usebibmacro{cmsyear}}%
      \setunit*{\addcomma\addspace}% Starred version for when the
      \printfield[journum]{number}}}% month isn't printed because of
  {\printfield{issue}% the toggle.
    \setunit{\addspace}%
    \usebibmacro{cmsyear}}}

\newbibmacro*{mag+date+issue}{%
  \usebibmacro{journal+sub}{in}%
  \setunit{\addspace}%
  \printlist[periodplace]{location}%
  \newunit\newblock
  \usebibmacro{date+issue}{}}

\newbibmacro*{cmsyear}{%
  \iftoggle{cms@switchdates}%
  {\clearfield{extradate}\clearfield{extratitleyear}\printorigdateextra}%
  {\clearfield{extradate}\clearfield{extratitleyear}\printdateextra}}%

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

\newbibmacro*{cperiodical+ser+vol+num}[1]{% For periodical entries,
  \ifboolexpr{% no subtype
    not test {\iffieldundef{shorttitle}}%
    and
    ((
    togl {cms@citejtabb}%
    and
    test {\ifcitation}%
    )
    or
    (
    togl {cms@bibjtabb}%
    and
    test {\ifbibliography}%
    )
    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}?
  \ifthenelse{\iffieldundef{#1year}\AND\iffieldundef{#1month}\AND%
    \iffieldundef{issue}\AND\iffieldundef{#1yeardivision}}% New, more accurate
  {\iffieldundef{volume}% test, also in article
    {\newcunit%
      \printfield[journum]{number}%
      \clearfield{number}%
      \setunit{\addcomma\addspace}}%
    {\printfield[jourvol]{volume}%
      \setunit{\addcomma\addspace}}}%
  {\printfield[jourvol]{volume}%
    \newcunit%
    \printfield[journum]{number}%
    \clearfield{number}%
    \setunit{\addcomma\addspace}}}% Moved eid for 17th ed.

\newbibmacro*{periodical+date+issue}{% For periodical type &
  \ifboolexpr{% no subtype
    not test {\iffieldundef{shorttitle}}%
    and
    ((
    togl {cms@citejtabb}%
    and
    test {\ifcitation}%
    )
    or
    (
    togl {cms@bibjtabb}%
    and
    test {\ifbibliography}%
    )
    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}%
  \newunit\newblock
  \usebibmacro{date+issue}{}}

\renewbibmacro*{postnote}{%
  \iffieldundef{postnote}%
  {}%
  {\postnotewrapper%\setunit{\postnotewrapper}
    \printfield{postnote}}}

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

\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*{clearpublin}{%
  \clearname{author}\clearfield{shorthand}%
  \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{proceedings}\OR%
    \ifentrytype{collection}\OR\ifentrytype{reference}\OR%
    \ifentrytype{suppbook}\OR\ifentrytype{suppcollection}\)\OR%
    \(\(\ifentrytype{audio}\OR\ifentrytype{music}\OR%
    \ifentrytype{video}\)\AND\(\iffieldundef{booktitle}\AND%
    \iffieldundef{entrysubtype}\)\)}%
  {}%
  {\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}}%
  {\ifthenelse{\ifentrytype{article}\OR\ifentrytype{periodical}\OR%
      \ifentrytype{review}\OR\ifentrytype{suppperiodical}}%
    {\iffieldundef{issuetitle}% For reprintfrom (?)
      {\clearname{editor}\clearfield{note}\renewbibmacro*{bibreprint}{}}%
      {}}%
    {}}%
  \clearfield{reprinttitle}%
}

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

\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:origpubin}[1]{%
  \entrydata*{#1}{%
    \usebibmacro{at+every+item}%
    \usebibmacro{cmsyear}%
    \ifboolexpr{%
      test {\iflistsequal{publisher}{savedpublisher}}%
      or
      test {\iflistundef{publisher}}%
    }%
      {}%
      {\setunit{\addspace\bibstring[\mkrelatedstringtext]{bypublisher}\space}%
       \printlist{publisher}%
       \setunit{\addcomma\space}%
       \iflistsequal{location}{savedlocation}%
         {}%
         {\printlist{location}}}}}

\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}\space}%
    \clearname{translator}%
    \usebibmacro{cite:origfull}}}%

\renewbibmacro*{related:default}[1]{%
  \entrydata*{#1}{%
    \usedriver
    {\ifnameundef{savedauthor}%
      {\ifnameundef{savededitor}%
        {}%
        {\ifnamesequal{editor}{savededitor}%
          {\clearname{editor}}%
          {}}}%
      {\ifnamesequal{author}{savedauthor}%
        {\clearname{author}}%
        {}}%
      \usebibmacro{at+every+item}%
      \renewbibmacro*{cmsbibsortdate}{}%
      \renewbibmacro*{related:init}{}%
      \DeclareNameAlias{sortname}{default}%
      \renewbibmacro*{pageref}{}}%
    {\thefield{entrytype}}}}

\letbibmacro*{related:maintitlenc}{related:multivolume}% From N & B
\letbibmacro*{related:maintitle}{related:multivolume}%

\renewbibmacro*{related:multivolume}[1]{%
  \entrydata*{#1}{%
    \usebibmacro{at+every+item}%
    \ifthenelse{\iffieldundef{volume}\AND\iffieldundef{part}}%
    {}%
    {\printtext{%
        \printfield{volume}%
        \printfield{part}}%
      \setunit{\addcolon\space}}%
    \usebibmacro{italtitle+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{bytranslator}\addspace%
          \printnames[bytranslator]{nameb}\newcunit}}%
      {\usebibmacro{byeditor+others}%
        \newcunit\newblock}}%
    {\usebibmacro{part+editor+translator}%
      \newcunit}%
    \usebibmacro{date}}}%

\newbibmacro*{related:commenton}[1]{% 17th ed.
  \togglefalse{cms@fulldate}% Let cloned entry set it
  \togglefalse{cms@authortitle}% Ditto
  \toggletrue{cms@shortrelated}% This allows us to provide a hyperlink
  \entrydata*{#1}{%
    \ifnumequal{\value{bbx:relatedcount}}{1}%
    {\global\boolfalse{cms:atcite}\usebibmacro{cite:reinit}}{}%
    \usebibmacro{cite}}}

\newbibmacro*{related:short}[1]{% For cross-refs in ref list
  \togglefalse{cms@fulldate}% Let cloned entry set it
  \togglefalse{cms@authortitle}% Ditto
  \toggletrue{cms@shortrelated}% This allows us to provide a hyperlink
  \entrydata*{#1}{%
    \nocite{\thefield{clonesourcekey}}% Ensure it appears in ref list
    \ifnumequal{\value{bbx:relatedcount}}{1}%
    {\global\boolfalse{cms:atcite}\usebibmacro{cite:reinit}}{}%
    \usebibmacro{cite}}}

\providetoggle{cms@reprintmt}%

\newbibmacro*{cite:origfull}{%
  \printtext[cmshypertarget]{% Field format is spurious
    \usedriver
    {\DeclareNameAlias{sortname}{default}\clearfield{postnote}%
      \clearname{author}\clearfield{userf}\clearfield{shorthand}%
      \toggletrue{cms@headlessnote}\frenchspacing%
      \renewbibmacro*{cmsbibsortdate}{}}%
    {\thefield{entrytype}}}}

\newbibmacro*{cite:origpubl}{%
  \printtext[cmshypertarget]{% Field format is spurious
    \usedriver
    {\DeclareNameAlias{sortname}{default}\clearfield{postnote}%
      \usebibmacro{clearpublin}\clearfield{shorthand}%
      \toggletrue{cms@headlessnote}\toggletrue{cms@origpublished}%
      \frenchspacing\renewbibmacro*{cmsbibsortdate}{}%
      \usebibmacro{cms:titlehook}}%
    {\thefield{entrytype}}}}

\newbibmacro*{at+every+item}{%
  \ifboolexpr{% AD requires this here because cmsbibsortdate=null
    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