% Last modified: Wed 03 May 2023 06:54:57 PM CDT

% Permission is granted to copy, distribute and/or modify this
% software under the terms of the LaTeX Project Public License (LPPL),
% version 1.3.
%
% The LPPL maintenance status of this software is 'author-maintained'.
%
% This software is provided 'as is', without warranty of any kind,
% either expressed or implied, including, but not limited to, the
% implied warranties of merchantability and fitness for a particular
% purpose.

\ProvidesFile{windycity.bbx}[2023/05/03 Windy City bibliography style
  for biblatex]
\@ifpackagelater{biblatex}{2019/08/17}
  {}
  {\PackageError{biblatex}
     {Outdated 'biblatex' package}
     {Windy City is for biblatex v3.13 and above.\MessageBreak
      You are using: '\csuse{ver@biblatex.sty}'.\MessageBreak
      This is a fatal error. I'm aborting now.}%
   \endinput}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Bibliography and Entry Options  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\providetoggle{annotate}
\DeclareBiblatexOption{entry,global}[boolean]{annotate}[true]{%
  \settoggle{annotate}{#1}}%

\DeclareBiblatexOption{global}[boolean]{collsonly}[true]{%
  \ifstrequal{#1}{true}
    {\ExecuteBibliographyOptions{mincrossrefs=1,minxrefs=1}%
     \AtBeginBibliography{\blx@key@bibcheck{collsonly}}}
    {}}

\providetoggle{dashed}
\DeclareBiblatexOption{global}[boolean]{dashed}[true]{%
  \settoggle{dashed}{#1}}%

\providetoggle{doi}
\DeclareBiblatexOption{entry,global}[boolean]{doi}[true]{%
  \settoggle{doi}{#1}}

\providetoggle{eprint}
\DeclareBiblatexOption{entry,global}[boolean]{eprint}[true]{%
  \settoggle{eprint}{#1}}

\providetoggle{ibid}
\DeclareBiblatexOption{global}[boolean]{ibid}[true]{%
  \ifstrequal{#1}{true}
    {\toggletrue{ibid}%
     \toggletrue{ibidpage}%
     \toggletrue{short}}%
    {\togglefalse{ibid}}}

\providetoggle{ibidpage}
\DeclareBiblatexOption{global}[boolean]{ibidpage}[true]{%
  \settoggle{ibidpage}{#1}}%

\providetoggle{isbn}
\DeclareBiblatexOption{entry,global}[boolean]{isbn}[true]{%
  \settoggle{isbn}{#1}}%

\providetoggle{issn}
\DeclareBiblatexOption{entry,global}[boolean]{isnn}[true]{%
  \settoggle{issn}{#1}}%

\providetoggle{library}
\DeclareBiblatexOption{entry,global}[boolean]{library}[true]{%
  \settoggle{library}{#1}}%

\providetoggle{listvols}
\DeclareBiblatexOption{entry}[boolean]{listvols}[true]{%
  \settoggle{listvols}{#1}}%

\providetoggle{newauth}
\DeclareBiblatexOption{entry}[boolean]{newauth}[true]{%
  \settoggle{newauth}{#1}}%

\providetoggle{noauth}
\DeclareBiblatexOption{entry}[boolean]{noauth}[true]{%
  \settoggle{noauth}{#1}}%

\providetoggle{noetal}
\DeclareBiblatexOption{entry,global}[boolean]{noetal}[true]{%
  \settoggle{noetal}{#1}}%

\DeclareBiblatexOption{global}[boolean]{nolos}[true]{%
  \ifstrequal{#1}{true}
    {\AtBeginBibliography{\blx@key@bibcheck{nolos}}}
    {}}

\providetoggle{nopages}
\DeclareBiblatexOption{global}[boolean]{nopages}[true]{%
  \settoggle{nopages}{#1}}%

\providetoggle{noplace}
\DeclareBiblatexOption{entry}[boolean]{noplace}[true]{%
  \settoggle{noplace}{#1}}%

\providetoggle{noreprint}
\DeclareBiblatexOption{entry}[boolean]{noreprint}[true]{%
  \settoggle{noreprint}{#1}}%

\providetoggle{reflist}
\DeclareBiblatexOption{global}[boolean]{reflist}[true]{%
  \ifstrequal{#1}{true}
    {\toggletrue{reflist}%
     \ExecuteBibliographyOptions{sorting=nyt}}%
    {\togglefalse{reflist}}}

\providetoggle{short}
\DeclareBiblatexOption{global}[boolean]{short}[true]{%
  \ifstrequal{#1}{true}
    {\toggletrue{short}%
     \toggletrue{shortfirst}}%
    {\togglefalse{short}}}

\DeclareBiblatexOption{global}[boolean]{shortafter}[true]{%
  \settoggle{short}{#1}}%

\providetoggle{shortfirst}
\DeclareBiblatexOption{global}[boolean]{shortfirst}[true]{%
  \settoggle{shortfirst}{#1}}%

\providetoggle{shortlinks}
\DeclareBiblatexOption{global}[boolean]{shortlinks}[true]{%
  \ifstrequal{#1}{true}
    {\toggletrue{shortlinks}%
     \AtBeginBibliography{\togglefalse{shortlinks}}}
    {}}

\providetoggle{skipdate}
\DeclareBiblatexOption{entry}[boolean]{skipdate}[true]{%
  \settoggle{skipdate}{#1}}%

\providetoggle{swapauth}
\DeclareBiblatexOption{entry}[boolean]{swapauth}[true]{%
  \settoggle{swapauth}{#1}}%

\providetoggle{swaptrans}
\providetoggle{swaptrans:bookbooktitle}
\providetoggle{swaptrans:booktitle}
\providetoggle{swaptrans:issuetitle}
\providetoggle{swaptrans:maintitle}
\providetoggle{swaptrans:series}
\providetoggle{swaptrans:title}
\DeclareBiblatexOption{entry}[boolean]{swaptrans}[true]{%
  \settoggle{swaptrans:title}{#1}%
  \settoggle{swaptrans:bookbooktitle}{#1}%
  \settoggle{swaptrans:booktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{swaptrans:bookbooktitle}[true]{%
  \settoggle{swaptrans:bookbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{swaptrans:booktitle}[true]{%
  \settoggle{swaptrans:booktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{swaptrans:issuetitle}[true]{%
  \settoggle{swaptrans:issuetitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{swaptrans:maintitle}[true]{%
  \settoggle{swaptrans:maintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{swaptrans:series}[true]{%
  \settoggle{swaptrans:series}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{swaptrans:title}[true]{%
  \settoggle{swaptrans:title}{#1}}%
% Short forms of the options above:
\DeclareBiblatexOption{entry}[boolean]{swaptrans:book}[true]{%
  \settoggle{swaptrans:booktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{swaptrans:bookbook}[true]{%
  \settoggle{swaptrans:bookbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{swaptrans:issue}[true]{%
  \settoggle{swaptrans:issuetitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{swaptrans:main}[true]{%
  \settoggle{swaptrans:maintitle}{#1}}%

\providetoggle{swapvol}
\DeclareBiblatexOption{entry}[boolean]{swapvol}[true]{%
  \settoggle{swapvol}{#1}}%

\providetoggle{swapvol:global}
\DeclareBiblatexOption{global}[boolean]{swapvol}[true]{%
  \settoggle{swapvol}{#1}%
  \settoggle{swapvol:global}{#1}}%

\providetoggle{url}
\DeclareBiblatexOption{entry,global}[boolean]{url}[true]{%
  \settoggle{url}{#1}}%

% Options for formatting titles and other fields:

\providetoggle{emph:blogtitle}
\providetoggle{emph:booktitle}
\providetoggle{emph:bookbooktitle}
\providetoggle{emph:issuetitle}
\providetoggle{emph:journaltitle}
\providetoggle{emph:labeltitle}
\providetoggle{emph:maintitle}
\providetoggle{emph:origtitle}
\providetoggle{emph:shortbooktitle}
\providetoggle{emph:shorthand}
\providetoggle{emph:shortmaintitle}
\providetoggle{emph:title}
\providetoggle{emph}
\DeclareBiblatexOption{entry}[boolean]{emph:blogtitle}[true]{%
  \settoggle{emph:blogtitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:bookbooktitle}[true]{%
  \settoggle{emph:bookbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:booktitle}[true]{%
  \settoggle{emph:booktitle}{#1}%
  \settoggle{emph:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:issuetitle}[true]{%
  \settoggle{emph:issuetitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:journal}[true]{%
  \settoggle{emph:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:journaltitle}[true]{%
  \settoggle{emph:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:maintitle}[true]{%
  \settoggle{emph:maintitle}{#1}%
  \settoggle{emph:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:origtitle}[true]{%
  \settoggle{emph:origtitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:shortbooktitle}[true]{%
  \settoggle{emph:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:shorthand}[true]{%
  \settoggle{emph:shorthand}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:shortmaintitle}[true]{%
  \settoggle{emph:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:shorttitle}[true]{%
  \settoggle{emph:labeltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph:title}[true]{%
  \settoggle{emph:title}{#1}%
  \settoggle{emph:labeltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{emph}[true]{%
  \settoggle{emph:title}{#1}%
  \settoggle{emph:labeltitle}{#1}}%

\providetoggle{ifcapital:blogtitle}
\providetoggle{ifcapital:booktitle}
\providetoggle{ifcapital:bookbooktitle}
\providetoggle{ifcapital:issuetitle}
\providetoggle{ifcapital:journaltitle}
\providetoggle{ifcapital:labeltitle}
\providetoggle{ifcapital:maintitle}
\providetoggle{ifcapital:origtitle}
\providetoggle{ifcapital:shortbooktitle}
\providetoggle{ifcapital:shorthand}
\providetoggle{ifcapital:shortmaintitle}
\providetoggle{ifcapital:title}
\providetoggle{ifcapital}
\DeclareBiblatexOption{entry}[boolean]{ifcapital:blogtitle}[true]{%
  \settoggle{ifcapital:blogtitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:bookbooktitle}[true]{%
  \settoggle{ifcapital:bookbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:booktitle}[true]{%
  \settoggle{ifcapital:booktitle}{#1}%
  \settoggle{ifcapital:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:issuetitle}[true]{%
  \settoggle{ifcapital:issuetitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:journal}[true]{%
  \settoggle{ifcapital:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:journaltitle}[true]{%
  \settoggle{ifcapital:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:maintitle}[true]{%
  \settoggle{ifcapital:maintitle}{#1}%
  \settoggle{ifcapital:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:origtitle}[true]{%
  \settoggle{ifcapital:origtitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:shortbooktitle}[true]{%
  \settoggle{ifcapital:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:shorthand}[true]{%
  \settoggle{ifcapital:shorthand}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:shortmaintitle}[true]{%
  \settoggle{ifcapital:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:shorttitle}[true]{%
  \settoggle{ifcapital:labeltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital:title}[true]{%
  \settoggle{ifcapital:title}{#1}%
  \settoggle{ifcapital:labeltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{ifcapital}[true]{%
  \settoggle{ifcapital:title}{#1}%
  \settoggle{ifcapital:labeltitle}{#1}}%

\providetoggle{noformat:blogtitle}
\providetoggle{noformat:booktitle}
\providetoggle{noformat:bookbooktitle}
\providetoggle{noformat:issuetitle}
\providetoggle{noformat:journaltitle}
\providetoggle{noformat:labeltitle}
\providetoggle{noformat:maintitle}
\providetoggle{noformat:origtitle}
\providetoggle{noformat:shortbooktitle}
\providetoggle{noformat:shorthand}
\providetoggle{noformat:shortmaintitle}
\providetoggle{noformat:title}
\providetoggle{noformat}
\DeclareBiblatexOption{entry}[boolean]{noformat:blogtitle}[true]{%
  \settoggle{noformat:blogtitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:bookbooktitle}[true]{%
  \settoggle{noformat:bookbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:booktitle}[true]{%
  \settoggle{noformat:booktitle}{#1}%
  \settoggle{noformat:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:issuetitle}[true]{%
  \settoggle{noformat:issuetitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:journal}[true]{%
  \settoggle{noformat:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:journaltitle}[true]{%
  \settoggle{noformat:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:maintitle}[true]{%
  \settoggle{noformat:maintitle}{#1}%
  \settoggle{noformat:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:origtitle}[true]{%
  \settoggle{noformat:orig}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:shortbooktitle}[true]{%
  \settoggle{noformat:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:shorthand}[true]{%
  \settoggle{noformat:shorthand}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:shortmaintitle}[true]{%
  \settoggle{noformat:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:shorttitle}[true]{%
  \settoggle{noformat:labeltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat:title}[true]{%
  \settoggle{noformat:labeltitle}{#1}%
  \settoggle{noformat:title}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{noformat}[true]{%
  \settoggle{noformat:labeltitle}{#1}%
  \settoggle{noformat:title}{#1}}%

\providetoggle{quotes:blogtitle}
\providetoggle{quotes:booktitle}
\providetoggle{quotes:bookbooktitle}
\providetoggle{quotes:issuetitle}
\providetoggle{quotes:journaltitle}
\providetoggle{quotes:labeltitle}
\providetoggle{quotes:maintitle}
\providetoggle{quotes:origtitle}
\providetoggle{quotes:shortbooktitle}
\providetoggle{quotes:shorthand}
\providetoggle{quotes:shortmaintitle}
\providetoggle{quotes:title}
\providetoggle{quotes}
\DeclareBiblatexOption{entry}[boolean]{quotes:blogtitle}[true]{%
  \settoggle{quotes:blogtitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:bookbooktitle}[true]{%
  \settoggle{quotes:bookbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:booktitle}[true]{%
  \settoggle{quotes:booktitle}{#1}%
  \settoggle{quotes:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:issuetitle}[true]{%
  \settoggle{quotes:issuetitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:journal}[true]{%
  \settoggle{quotes:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:journaltitle}[true]{%
  \settoggle{quotes:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:maintitle}[true]{%
  \settoggle{quotes:maintitle}{#1}%
  \settoggle{quotes:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:origtitle}[true]{%
  \settoggle{quotes:origtitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:shortbooktitle}[true]{%
  \settoggle{quotes:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:shorthand}[true]{%
  \settoggle{quotes:shorthand}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:shortmaintitle}[true]{%
  \settoggle{quotes:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:shorttitle}[true]{%
  \settoggle{quotes:labeltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes:title}[true]{%
  \settoggle{quotes:labeltitle}{#1}%
  \settoggle{quotes:title}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{quotes}[true]{%
  \settoggle{quotes:labeltitle}{#1}%
  \settoggle{quotes:title}{#1}}%

\providetoggle{sentencecase:blogtitle}
\providetoggle{sentencecase:booktitle}
\providetoggle{sentencecase:bookbooktitle}
\providetoggle{sentencecase:issuetitle}
\providetoggle{sentencecase:journaltitle}
\providetoggle{sentencecase:labeltitle}
\providetoggle{sentencecase:maintitle}
\providetoggle{sentencecase:origtitle}
\providetoggle{sentencecase:shortbooktitle}
\providetoggle{sentencecase:shorthand}
\providetoggle{sentencecase:shortmaintitle}
\providetoggle{sentencecase:title}
\providetoggle{sentencecase}
\DeclareBiblatexOption{entry}[boolean]{sentencecase:blogtitle}[true]{%
  \settoggle{sentencecase:blogtitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:bookbooktitle}[true]{%
  \settoggle{sentencecase:bookbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:booktitle}[true]{%
  \settoggle{sentencecase:booktitle}{#1}%
  \settoggle{sentencecase:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:issuetitle}[true]{%
  \settoggle{sentencecase:issuetitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:journal}[true]{%
  \settoggle{sentencecase:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:journaltitle}[true]{%
  \settoggle{sentencecase:journaltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:maintitle}[true]{%
  \settoggle{sentencecase:maintitle}{#1}%
  \settoggle{sentencecase:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:origtitle}[true]{%
  \settoggle{sentencecase:origtitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:shortbooktitle}[true]{%
  \settoggle{sentencecase:shortbooktitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:shorthand}[true]{%
  \settoggle{sentencecase:shorthand}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:shortmaintitle}[true]{%
  \settoggle{sentencecase:shortmaintitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:shorttitle}[true]{%
  \settoggle{sentencecase:labeltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase:title}[true]{%
  \settoggle{sentencecase:title}{#1}%
  \settoggle{sentencecase:labeltitle}{#1}}%
\DeclareBiblatexOption{entry}[boolean]{sentencecase}[true]{%
  \settoggle{sentencecase:title}{#1}%
  \settoggle{sentencecase:labeltitle}{#1}}%
\DeclareBiblatexOption{global}[boolean]{sentencecase}[true]{%
  \settoggle{sentencecase:blogtitle}{#1}%
  \settoggle{sentencecase:booktitle}{#1}%
  \settoggle{sentencecase:bookbooktitle}{#1}%
  \settoggle{sentencecase:issuetitle}{#1}%
  \settoggle{sentencecase:journaltitle}{#1}%
  \settoggle{sentencecase:labeltitle}{#1}%
  \settoggle{sentencecase:maintitle}{#1}%
  \settoggle{sentencecase:origtitle}{#1}%
  \settoggle{sentencecase:shortbooktitle}{#1}%
  \settoggle{sentencecase:shortmaintitle}{#1}%
  \settoggle{sentencecase:title}{#1}}%

% For setting 'minbibnames' and such, see CMOS, 17th ed., 14.76 and
% 15.29. For 'citetracker' and 'loccittracker', 'constrict' is too
% strict but seems to work well for 'ibidtracker'.

\ExecuteBibliographyOptions{%
  abbreviate=true,
  autocite=footnote,
  autopunct=true,
  block=none,
  citetracker=context,
  dashed=true,
  date=long,
  dateabbrev=false,
  dateusetime=true,
  doi=true,
  eprint=true,
  ibidtracker=constrict,
  idemtracker=false,
  indexing=true,
  labeldate=year,
  labeldateparts=true,
  loccittracker=context,
  minbibnames=7,
  maxbibnames=10,
  mincitenames=1,
  maxcitenames=3,
  mincrossrefs=2,
  minxrefs=2,
  nohashothers=false,
  pagetracker=page,
  parentracker=true,
  sortcites=false,
  sorting=nty,
  time=12h,
  timezones=true,
  uniquelist=minyear,
  uniquename=minfull,
  url=true,
  urldate=long,
  useeditor=true,
  useprefix=false,
  usetranslator=true}

\DeclareLanguageMapping{english}{american-windycity}
\DeclareLanguageMappingSuffix{-windycity}

\DeclareLabeldate{%
  \field{label}
  \field{setlabel}
  \field{bookyear}
  \field{date}
  \field{year}
  \field{origdate}
  \field{urldate}
  \literal{nodate}}
\DeclareLabelname{%
  \field{author}
  \field{editor}
  \field{translator}
  \field{editora}
  \field{translatora}}
\DeclareLabelname[inbook,incollection]{%
  \field{author}
  \field{bookauthor}
  \field{editor}
  \field{translator}
  \field{editora}
  \field{translatora}}
\DeclareSortingTemplate{nty}{%
  \sort{\field{presort}}
  \sort[final]{\field{sortkey}}
  \sort{%
    \field{sortname}
    \field{author}
    \field{bookauthor}
    \field{editor}
    \field{translator}
    \field{editora}
    \field{sorttitle}
    \field{title}
    \field{booktitle}
    \field{bookbooktitle}
    \field{blogtitle}
    \field{journaltitle}}
  \sort{%
    \field{sorttitle}
    \field{title}
    \field{booktitle}
    \field{bookbooktitle}
    \field{blogtitle}
    \field{journaltitle}}
  \sort{%
    \field{sortyear}
    \field{year}
    \field{labelyear}}
  \sort{\field{month}}
  \sort{\field{day}}
  \sort{\field{hour}}
  \sort{\field{minute}}
  \sort{%
    \field{volume}
    \literal{0}}}
\DeclareSortingTemplate{nyt}{%
  \sort{\field{presort}}
  \sort[final]{\field{sortkey}}
  \sort{%
    \field{sortname}
    \field{author}
    \field{bookauthor}
    \field{editor}
    \field{translator}
    \field{editora}
    \field{sorttitle}
    \field{title}
    \field{booktitle}
    \field{bookbooktitle}
    \field{blogtitle}
    \field{journaltitle}}
  \sort{%
    \field{sortyear}
    \field{origyear}
    \field{labelyear}
    \field{year}}
  \sort{\field{month}}
  \sort{\field{day}}
  \sort{\field{hour}}
  \sort{\field{minute}}
  \sort{%
    \field{sorttitle}
    \field{title}
    \field{booktitle}
    \field{bookbooktitle}
    \field{blogtitle}
    \field{journaltitle}}
  \sort{%
    \field{volume}
    \literal{0}}}

% When 'journal', 'journaltitle', 'organization', 'blogtitle' or
% 'collection' goes in the author's position.

\DeclareStyleSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \pertype{article}
      \pertype{review}
      \step[notfield=author, final]
      \step[notfield=editor, final]
      \step[notfield=translator, final]
      \step[fieldsource=journal]
      \step[fieldsource=journaltitle]
      \step[fieldset=author, origfieldval]
      \step[fieldsource=author,
            match=\regexp{(.+)},
            replace=\regexp{\\mkbibemph{{$1}}}]
      \step[fieldset=options, fieldvalue={,newauth}, append]
      \step[fieldset=verba, fieldvalue=journaltitle]
      \step[fieldsource=shortjournal]
      \step[fieldset=shortauthor, origfieldval]
      \step[fieldsource=shortauthor,
            match=\regexp{(.+)},
            replace=\regexp{\\mkbibemph{{$1}}}]
      \step[fieldsource=journaltitleaddon, final]
      \step[fieldset=nameaddon, origfieldval]
      \step[fieldsource=nameaddon,
            match=\regexp{(.+)},
            replace=\regexp{\\mkbibbrackets{$1}}]
    }
  }
}
\DeclareStyleSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \pertype{online}
      \step[notfield=author, final]
      \step[notfield=editor, final]
      \step[notfield=translator, final]
      \step[fieldsource=blogtitle]
      \step[fieldset=author, origfieldval]
      \step[fieldsource=author,
            match=\regexp{(.+)},
            replace=\regexp{\\mkbibemph{{$1}}}]
      \step[fieldset=options, fieldvalue={,newauth}, append]
      \step[fieldset=verba, fieldvalue=blogtitle]
      \step[fieldsource=shortblog]
      \step[fieldset=shortauthor, origfieldval]
      \step[fieldsource=shortauthor,
            match=\regexp{(.+)},
            replace=\regexp{\\mkbibemph{{$1}}}]
      \step[fieldsource=blogtitleaddon, final]
      \step[fieldset=nameaddon, origfieldval]
      \step[fieldsource=nameaddon,
            match=\regexp{(.+)},
            replace=\regexp{\\mkbibparens{$1}}]
    }
  }
}
\DeclareStyleSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \pertype{inreference}
      \pertype{reference}
      \step[notfield=author, final]
      \step[fieldsource=organization]
      \step[fieldset=author, origfieldval]
      \step[fieldsource=author,
            match=\regexp{(.+)},
            replace=\regexp{{$1}}]
      \step[fieldset=options, fieldvalue={,newauth}, append]
      \step[fieldset=verba, fieldvalue=organization]
      \step[fieldsource=shortorganization]
      \step[fieldset=shortauthor, origfieldval]
      \step[fieldsource=shortauthor,
            match=\regexp{(.+)},
            replace=\regexp{{$1}}]
    }
  }
}
\DeclareStyleSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite=false]{
      \pertype{unpublished}
      \step[notfield=author, final]
      \step[fieldsource=collection]
      \step[fieldset=sortname, origfieldval]
      \step[fieldsource=sortname,
            match=\regexp{(.+)},
            replace=\regexp{{$1}}]
    }
  }
}

% Save the entry key of every editor, translator, and title.

\DeclareStyleSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite, foreach={title,booktitle,bookbooktitle}]{
      \step[fieldsource=entrykey]
      \step[fieldset=$MAPLOOPkey, origfieldval]
      \step[notfield=$MAPLOOP, final]
      \step[fieldset=$MAPLOOPkey, null]
    }
    \map[overwrite, foreach={%
         editor,editora,editorb,editorc,translator,translatora,translatorb}]{
      \step[fieldsource=entrykey]
      \step[fieldset=$MAPLOOPtype, fieldvalue={,}, appendstrict]
      \step[fieldset=$MAPLOOPtype, origfieldval, append]
      \step[notfield=$MAPLOOP, final]
      \step[fieldset=$MAPLOOPtype, null]
    }
  }
}

% Workarounds to get the correct 'labeldate'.

\DeclareStyleSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite=false]{
      \pertype{inbook}
      \pertype{bookinbook}
      \step[notfield=options, final]
      \step[fieldsource=year, final]
      \step[fieldset=setlabel, origfieldval]
    }
  }
}
\DeclareStyleSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite=false]{
      \pertype{inbook}
      \pertype{bookinbook}
      \step[fieldsource=options, notmatch=\regexp{swapvol}, final]
      \step[fieldsource=year, final]
      \step[fieldset=setlabel, origfieldval]
    }
  }
}

% For 'collsonly' and 'nolos' options and the '@reference' entry type.

\defbibcheck{collsonly}{%
  \ifentrytype{inbook}
    {\iffieldundef{crossref}
       {}
       {\skipentry}}%
    {\ifentrytype{incollection}
       {\iffieldundef{crossref}
          {}
          {\iffieldundef{chapter}
             {}
             {\skipentry}}}}}
\defbibcheck{nolos}{%
  \iffieldundef{shorthand}
    {}
    {\skipentry}}%
\defbibcheck{reference}{%
  \ifentrytype{reference}
    {\skipentry}%
    {}}

%%%%%%%%%%%%%%%%%%%%%%%%
%%  Data Inheritance  %%
%%%%%%%%%%%%%%%%%%%%%%%%

% As of biblatex 3.14 or biber 2.14 (or thereabouts), '\inherit' no
% longer works for 'options'.

\ResetDataInheritance
\DefaultInheritance[\except{*}{review}{all=false}]{all=true,override=false}
\DeclareDataInheritance{*}{incollection,inbook,letter,review}{%
  \inherit[override=true]{titlekey}{booktitlekey}
  \inherit[override=true]{booktitlekey}{bookbooktitlekey}
  \inherit[override=true]{editor}{editora}
  \inherit[override=true]{editora}{editorb}
  \inherit[override=true]{editorb}{editorc}
  \inherit[override=true]{editortype}{editoratype}
  \inherit[override=true]{editoratype}{editorbtype}
  \inherit[override=true]{editorbtype}{editorctype}
  \inherit[override=true]{translatortype}{translatoratype}
  \inherit[override=true]{translatoratype}{translatorbtype}
  \inherit{author}{bookauthor}
  \inherit{authortype}{bookauthortype}
  \inherit{shortauthor}{shortbookauthor}
  \inherit{editoraddon}{editoraaddon}
  \inherit{translator}{translatora}
  \inherit{translatora}{translatorb}
  \inherit{title}{booktitle}
  \inherit{booktitle}{bookbooktitle}
  \inherit{subtitle}{booksubtitle}
  \inherit{booksubtitle}{bookbooksubtitle}
  \inherit{titleaddon}{booktitleaddon}
  \inherit{booktitleaddon}{bookbooktitleaddon}
  \inherit{shorttitle}{shortbooktitle}
  \inherit{volume}{bookvolume}
  \inherit{bookvolume}{bookbookvolume}
  \inherit{options}{options}}
\DeclareDataInheritance{collection}{collection,inbook}{%
  \inherit{year}{bookyear}
  \inherit{endyear}{endbookyear}}
\DeclareDataInheritance{*}{*}{%
  \noinherit{crossref}
  \noinherit{entryset}
  \noinherit{entrysubtype}
  \noinherit{execute}
  \noinherit{ids}
  \noinherit{label}
  \noinherit{presort}
  \noinherit{related}
  \noinherit{relatedoptions}
  \noinherit{relatedstring}
  \noinherit{relatedtype}
  \noinherit{shorthand}
  \noinherit{shorthandintro}
  \noinherit{sortkey}
  \noinherit{xref}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Other Basic Settings  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\let\cbx@bibstring\empty
\let\cbx@deflabel\empty
\let\cbx@keyhash\empty
\let\cbx@namelist\empty
\let\anona\empty
\let\anonb\empty
\let\crossreflist\empty
\let\title@format\empty
\let\pluga\empty
\let\plugb\empty
\let\xtitle\empty

\let\xeditor\empty
\let\yeditor\empty
\let\edtypes\empty
\let\transtypes\empty

\providetoggle{authposition}
\providetoggle{atleastone}
\providetoggle{bibliography}
\providetoggle{ibid:loccit}
\providetoggle{multicite}

\providetoggle{cbx:collection}
\providetoggle{cbx:first}
\providetoggle{cbx:idem}
\providetoggle{cbx:short}
\providetoggle{cbx:skipdate}

\providetoggle{collection}
\providetoggle{collection:bk}
\providetoggle{collection:ib}
\providetoggle{collection:icbk}
\providetoggle{collection:icib}

\providetoggle{edshift}
\providetoggle{noed}
\providetoggle{notrans}

\newcommand*{\AtBeginLists}{%
  \renewcommand*{\newunitpunct}{\addperiod\space}%
  \let\bibstring\biblstring
  \global\undef\bbx@lasthash
  \blx@key@bibcheck{reference}}%

\newcommand*{\AtEveryItem}{%
  \global\toggletrue{authposition}%
  \global\togglefalse{cbx:short}}%

\AtBeginBibliography{\AtBeginLists}%
\AtBeginShorthands{\AtBeginLists}%
\AtEveryBibitem{%
  \global\toggletrue{bibliography}%
  \AtEveryItem}%
\AtEveryLositem{\AtEveryItem}%
\DeclareNumChars{.[]?}

\defbibenvironment{reflist}
  {\global\toggletrue{reflist}%
   \list{}{%
     \leftmargin\bibhang
     \itemindent-\leftmargin
     \itemsep\bibitemsep
     \parsep\bibparsep}}
  {\endlist
   \global\togglefalse{reflist}}%
  {\item}

\renewbibmacro*{bibindex}{%
  \ifbibindex
    {\indexnames{labelname}}%
    {}}
\renewbibmacro*{citeindex}{%
  \ifciteindex
    {\indexnames{labelname}}%
    {}}

%%%%%%%%%%%%%%%%%%%%%
%%  Field Formats  %%
%%%%%%%%%%%%%%%%%%%%%

% Generic formats:

\DeclareFieldFormat{brackets}{\mkbibbrackets{#1}}
\DeclareFieldFormat{capital}{\MakeCapital{#1}}
\DeclareFieldFormat{emph}{\mkbibemph{#1}}
\DeclareFieldFormat{ifcapital}{\ifcapital{\MakeCapital{#1}}{#1}}
\DeclareFieldFormat{noformat}{#1}
\DeclareFieldFormat{parens}{\mkbibparens{#1}}
\DeclareFieldFormat{quotes}{\mkbibquote{#1}}
\DeclareFieldFormat{sentencecase}{\MakeSentenceCase{#1}}

% Name formats (defaults set in biblatex.def):

\DeclareNameAlias{author}{sortname}
\DeclareNameAlias{afterword}{sortname}
\DeclareNameAlias{bookauthor}{sortname}
\DeclareNameAlias{editor}{sortname}
\DeclareNameAlias{editora}{sortname}
\DeclareNameAlias{editorb}{sortname}
\DeclareNameAlias{editorc}{sortname}
\DeclareNameAlias{foreword}{sortname}
\DeclareNameAlias{introduction}{sortname}
\DeclareNameAlias{preface}{sortname}
\DeclareNameAlias{translator}{sortname}

\DeclareIndexNameAlias{author}{default}
\DeclareIndexNameAlias{afterword}{default}
\DeclareIndexNameAlias{bookauthor}{default}
\DeclareIndexNameAlias{editor}{default}
\DeclareIndexNameAlias{editora}{default}
\DeclareIndexNameAlias{editorb}{default}
\DeclareIndexNameAlias{editorc}{default}
\DeclareIndexNameAlias{foreword}{default}
\DeclareIndexNameAlias{introduction}{default}
\DeclareIndexNameAlias{preface}{default}
\DeclareIndexNameAlias{translator}{default}

% Affixes like 'Jr.', should appear last, delimited with a comma, when
% the name is inverted. See CMOS, 17th ed., 6.43 and 16.41, and the
% example in 14.75.

\renewbibmacro*{name:family-given}[4]{%
  \ifuseprefix
    {\usebibmacro{name:delim}{#3#1}%
     \usebibmacro{name:hook}{#3#1}%
     \mkbibcompletenamefamilygiven{%
       \ifdefvoid{#3}
         {}
         {\ifcapital
            {\mkbibnameprefix{\MakeCapital{#3}}\isdot}%
            {\mkbibnameprefix{#3}\isdot}%
          \ifprefchar{}{\bibnamedelimc}}%
       \mkbibnamefamily{#1}\isdot
       \ifdefvoid{#4}
         {}
         {\bibnamedelimd\mkbibnamesuffix{#4}\isdot}%
       \ifdefvoid{#2}
         {}
         {\revsdnamepunct\bibnamedelimd\mkbibnamegiven{#2}\isdot}}}
    {\usebibmacro{name:delim}{#1}%
     \usebibmacro{name:hook}{#1}%
     \mkbibcompletenamefamilygiven{%
       \mkbibnamefamily{#1}\isdot
       \ifboolexpe{ test {\ifdefvoid{#2}}
                    and test {\ifdefvoid{#3}}}
         {}
         {\revsdnamepunct}%
       \ifdefvoid{#2}
         {}
         {\bibnamedelimd\mkbibnamegiven{#2}\isdot}%
       \ifdefvoid{#3}
         {}
         {\bibnamedelimd\mkbibnameprefix{#3}\isdot}%
       \ifdefvoid{#4}
         {}
         {\revsdnamepunct\bibnamedelimd\mkbibnamesuffix{#4}\isdot}}}}

\renewcommand*{\mkbibindexname}[4]{%
  \ifuseprefix
    {\ifdefvoid{#3}{}{#3 }%
     \@firstofone #1% remove spurious braces
     \ifdefvoid{#4}{}{ #4}%
     \ifdefvoid{#2}{}{, #2}%
     \ifdefvoid{#3}{}{%
       \actualoperator
       \MakeCapital{#3} %
       #1%
       \ifdefvoid{#4}{}{ #4}%
       \ifdefvoid{#2}{}{, #2}}}
    {\@firstofone #1% remove spurious braces
     \ifboolexpe{test {\ifdefvoid{#2}}
                 and test {\ifdefvoid{#3}}}
       {}
       {,}%
     \ifdefvoid{#2}{}{ #2}%
     \ifdefvoid{#3}{}{ #3}%
     \ifdefvoid{#4}{}{, #4}}}

% Title formats:

\DeclareFieldAlias{blogtitle}{emph}
\DeclareFieldAlias{bookbooktitle}{emph}
\DeclareFieldAlias{booktitle}{emph}
\DeclareFieldAlias{journaltitle}{emph}
\DeclareFieldAlias{labeltitle}{emph}
\DeclareFieldAlias{maintitle}{emph}
\DeclareFieldAlias{shortbooktitle}{emph}
\DeclareFieldAlias{shortmaintitle}{emph}
\DeclareFieldAlias{title}{emph}

\DeclareIndexFieldFormat{indextitle}{%
  \usebibmacro{index:title}{\index}{\mkbibemph{#1}}}
\renewbibmacro*{index:title}[2]{%
  \usebibmacro{index:field}{#1}{\thefield{indexsorttitle}}{#2}}%

\DeclareFieldAlias{blogtitleaddon}{parens}
\DeclareFieldAlias{journaltitleaddon}{brackets}
\DeclareFieldAlias{titleaddon}{brackets}

\DeclareFieldFormat[article,incollection,online,reference,review,thesis]
  {title}{\mkbibquote{#1}}
\DeclareFieldFormat[article,incollection,online,reference,review,thesis]
  {labeltitle}{\mkbibquote{#1}}
\DeclareIndexFieldFormat[article,incollection,reference,review,thesis]
  {indextitle}{\usebibmacro{index:title}{\index}{\mkbibquote{#1}}}

\DeclareFieldFormat[letter,misc,patent]{title}{#1}
\DeclareFieldFormat[letter,misc,patent]{labeltitle}{#1}
\DeclareIndexFieldFormat[letter,misc,patent]
  {indextitle}{\usebibmacro{index:title}{\index}{#1}}

\DeclareFieldAlias[inbook]{title}{emph}
\DeclareFieldAlias[inbook]{labeltitle}{emph}
\DeclareIndexFieldAlias[inbook]{indextitle}{indextitle}
\DeclareFieldAlias[book]{origtitle}{emph}

\DeclareFieldFormat{chapter}{\bibstring{chapter}\space #1}
\DeclareFieldAlias{issuetitle}{noformat}

\DeclareFieldFormat[unpublished]
  {title}{\usebibmacro{unpublished:format}{#1}}
\DeclareFieldFormat[unpublished]
  {labeltitle}{\usebibmacro{unpublished:format}{#1}}
\DeclareIndexFieldFormat[unpublished]
  {indextitle}{\usebibmacro{index:title}{\index}{% Macro below won't work here
    \iffieldundef{collection}{\mkbibquote{#1}}{#1}}}
\newbibmacro*{unpublished:format}[1]{%
  \iffieldundef{collection}
    {\mkbibquote{#1}}%
    {#1}}%

% Other field formats:

\DeclareFieldAlias{addendum}{ifcapital}
\DeclareFieldFormat{annotation}{\\[\bibitemsep] #1}
\DeclareFieldAlias{doi}{url}
\DeclareFieldFormat{edition}{%
  \ifinteger{#1}
    {\mkbibordedition{#1}~\bibstring{edition}}%
    {\ifcapital{\MakeCapital{#1}}{#1}}}
\DeclareFieldAlias{endmonth}{month}
\DeclareFieldAlias{howpublished}{ifcapital}
\DeclareFieldAlias{issue}{capital}
\DeclareFieldFormat{journum}{%
  \ifnumeral{#1}
    {no\adddotspace\printfield{number}}%
    {nos\adddotspace\printfield{number}}}
\DeclareFieldFormat{labelyear}{%
  \ifboolexpr{ test {\iffieldundef{year}}
               and test {\iffieldundef{bookyear}}}
    {\biblcstring{#1}}%
    {\ifbibstring{#1}{\bibstring{#1}}{\stripzeros{#1}}}}
\DeclareListFormat{location}{#1}
\DeclareFieldFormat{month}{\mkbibmonth{#1}}%
\DeclareFieldAlias{note}{ifcapital}
\DeclareFieldAlias{pages}{noformat}
\DeclareFieldFormat{part}{\bibstring{part}\space#1}
\DeclareFieldAlias{postnote}{noformat}
\DeclareListFormat{publisher}{#1}
\DeclareFieldAlias{pubstate}{ifcapital}
\DeclareFieldAlias{season}{capital}% deprecated
\DeclareFieldAlias{series}{ifcapital}
\DeclareFieldAlias{yeardivision}{capital}

% A shorthand should be italicized if the title that it abbreviates is
% also italicized. See CMOS, 17th ed., 14.60. Set italics for it in
% the bibliography database with '\emph{}' or '\mkbibemph{}'.

\DeclareFieldAlias{shorthand}{noformat}
\DeclareFieldFormat[article,incollection,online,reference,review,thesis]
  {shorthand}{\mkbibquote{#1}}
\DeclareFieldAlias{shorthandintro}{ifcapital}
\DeclareFieldAlias{type}{ifcapital}
\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat{urldate}{\bibstring{urlseen}\space#1}

\newbibmacro*{test:format}[2]{%
  \iftoggle{noformat:#1}
    {\iftoggle{ifcapital:#1}
       {\usebibmacro{print:#2}{#1}{noformat}{ifcapital}}%
       {\iftoggle{sentencecase:#1}
          {\usebibmacro{print:#2}{#1}{noformat}{sentencecase}}%
          {\usebibmacro{print:#2}{#1}{noformat}{noformat}}}}
    {\iftoggle{sentencecase:#1}
       {\iftoggle{emph:#1}
          {\usebibmacro{print:#2}{#1}{emph}{sentencecase}}%
          {\iftoggle{quotes:#1}
             {\usebibmacro{print:#2}{#1}{quotes}{sentencecase}}%
             {\usebibmacro{print:#2}{#1}{#1}{sentencecase}}}}
       {\iftoggle{emph:#1}
          {\iftoggle{ifcapital:#1}
             {\usebibmacro{print:#2}{#1}{emph}{ifcapital}}%
             {\usebibmacro{print:#2}{#1}{emph}{noformat}}}
          {\iftoggle{quotes:#1}
             {\iftoggle{ifcapital:#1}
                {\usebibmacro{print:#2}{#1}{quotes}{ifcapital}}%
                {\usebibmacro{print:#2}{#1}{quotes}{noformat}}}
             {\iftoggle{ifcapital:#1}
                {\usebibmacro{print:#2}{#1}{#1}{ifcapital}}%
                {\usebibmacro{print:#2}{#1}{#1}{noformat}}}}}}}

\newbibmacro*{print:field}[3]{%
  \printtext[#2]{\printfield[#3]{#1}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Bibliography Aliases  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DeclareDriverSourcemap[datatype=bibtex]{
  \map{
    \step[typesource=periodical,     typetarget=article]
    \step[typesource=image,          typetarget=artwork]
    \step[typesource=booklet,        typetarget=book]
    \step[typesource=manual,         typetarget=book]
    \step[typesource=mvbook,         typetarget=book]
    \step[typesource=mvcollection,   typetarget=book]
    \step[typesource=proceedings,    typetarget=book]
    \step[typesource=report,         typetarget=book]
    \step[typesource=techreport,     typetarget=book]
    \step[typesource=bookinbook,     typetarget=inbook]
    \step[typesource=conference,     typetarget=incollection]
    \step[typesource=inproceedings,  typetarget=incollection]
    \step[typesource=suppbook,       typetarget=incollection]
    \step[typesource=suppcollection, typetarget=incollection]
    \step[typesource=electronic,     typetarget=online]
    \step[typesource=www,            typetarget=online]
    \step[typesource=inreference,    typetarget=reference]
    \step[typesource=mathesis,       typetarget=thesis]
    \step[typesource=phdthesis,      typetarget=thesis]
  }
  \map{
    \step[fieldsource=school,        fieldtarget=institution]
    \step[fieldsource=address,       fieldtarget=location]
    \step[fieldsource=journal,       fieldtarget=journaltitle]
  }
}

\DeclareBibliographyAlias{collection}{book}
\DeclareBibliographyAlias{cite:collection}{cite:book}
\DeclareBibliographyAlias{*}{book}

\DeclareBibliographyAlias{inbook}{incollection}
\DeclareBibliographyAlias{letter}{incollection}
\DeclareBibliographyAlias{cite:inbook}{cite:incollection}
\DeclareBibliographyAlias{cite:letter}{cite:incollection}

%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Author's Position  %%
%%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand*{\revsdnamedelim}{%
  \iftoggle{bibliography}
    {\addcomma}%
    {}}

\newbibmacro*{author+bookauthor+etc}{%
  \iftoggle{noauth}
    {\usebibmacro{authpos+deflabel}}%
    {\usebibmacro{author+bookauthor}%
     \ifnameundef{\cbx@namelist}
       {\usebibmacro{editors:a}%
        \ifnameundef{\cbx@namelist}
          {\toggletrue{noauth}%
           \usebibmacro{unpublished:collection}%
           \usebibmacro{authpos+deflabel}}%
          {\usebibmacro{addplus+etc}%
           \usebibmacro{namehash+etc}}}
       {\usebibmacro{namehash+etc}}}}

\newbibmacro*{authpos+deflabel}{%
  \global\togglefalse{authposition}%
  \renewcommand*{\cbx@deflabel}{default}}%

\newbibmacro*{author+bookauthor}{%
  \ifboolexpr{ togl {swapauth}
               and ( test {\ifentrytype{book}}
               or test {\ifentrytype{collection}}
               or test {\ifentrytype{inbook}}
               or test {\ifentrytype{incollection}} )}
    {}
    {\ifboolexpr{ togl {collection:ib}
                  and togl {swapvol}}
      {\usebibmacro{shortnames}{bookauthor}}%
      {\ifnameundef{author}
         {\usebibmacro{shortnames}{bookauthor}%
          \usebibmacro{test:authortypes}{bookauthor}}%
         {\usebibmacro{shortnames}{author}%
          \usebibmacro{test:authortypes}{author}}}}}

\newbibmacro*{shortnames}[1]{%
  \ifboolexpr{ test {\ifnameundef{short#1}}
               or togl {cbx:first}
               or togl {bibliography}}
    {\renewcommand*{\cbx@namelist}{#1}}%
    {\renewcommand*{\cbx@namelist}{short#1}}}

\newbibmacro*{test:authortypes}[1]{%
  \iffieldundef{#1type}
    {}
    {\let\authtypes\empty
     \forcsvfield{\listadd\authtypes}{#1type}%
     \usebibmacro{types:shared}{\authtypes}}}

\newbibmacro*{types:shared}[1]{%
  \ifinlist{anon}{#1}
    {\renewcommand*{\anona}{\bibopenbracket}%
     \renewcommand*{\anonb}{\bibclosebracket}}%
    {\ifinlist{anon?}{#1}
       {\renewcommand*{\anona}{\bibopenbracket}%
        \renewcommand*{\anonb}{\addquestion\bibclosebracket}}%
       {\ifboolexpr{ test {\ifinlist{pseudo}{#1}}
                     and not togl {cbx:short}}
          {\renewcommand*{\anonb}{\space\mkbibbrackets{\bibstring{pseudo}}}}
          {}}}}

\newbibmacro*{namehash+etc}{%
  \usebibmacro{printnames+etc}%
  \ifboolexpr{ togl {authposition}% false in 'crossref' macro
               or togl {multicite}}
    {\savefield{namehash}{\bbx@lasthash}%
     \usebibmacro{authpos+deflabel}%
     \newunit}%
    {\setunit{\addcomma\space}}}

\newbibmacro*{unpublished:collection}{%
  \ifboolexpr{ test {\iffieldundef{collection}}
               and test {\iffieldundef{shortcollection}}}
    {}
    {\ifboolexpr{ togl {cbx:short}
                  and not test {\iffieldundef{shortcollection}}}
       {\iftoggle{shortlinks}
          {\printtext[bibhyperref]{\printfield{shortcollection}}}
          {\printfield{shortcollection}}}
       {\iftoggle{shortlinks}
          {\printtext[bibhyperref]{\printfield{collection}}}
          {\printfield{collection}}}}}

\newbibmacro*{supplement}{%
  \ifnameundef{afterword}
    {\ifnameundef{foreword}
       {\ifnameundef{introduction}
          {\renewcommand*{\cbx@namelist}{preface}%
           \renewcommand*{\cbx@bibstring}{preface}}%
          {\renewcommand*{\cbx@namelist}{introduction}%
           \renewcommand*{\cbx@bibstring}{introduction}}}
       {\renewcommand*{\cbx@namelist}{foreword}%
        \renewcommand*{\cbx@bibstring}{foreword}}}
    {\renewcommand*{\cbx@namelist}{afterword}%
     \renewcommand*{\cbx@bibstring}{afterword}}%
  \usebibmacro{printnames+etc}%
  \savefield{namehash}{\bbx@lasthash}%
  \usebibmacro{authpos+deflabel}}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Editors and Translators  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% For editors and translators in the author's position.

\newbibmacro*{editors:a}{%
  \usebibmacro{test:ed:a}%
  \usebibmacro{test:trans:a}%
  \iftoggle{swapvol}
    {\ifboolexpr{ test {\ifinlist{maintitle}{\edtypes}}
                  or test {\ifinlist{maintitle}{\transtypes}}}
       {\usebibmacro{test:swaptrans:a}{maintitle}}%
       {\usebibmacro{test:swaptrans:a}{booktitle}}}
    {\usebibmacro{test:swaptrans:a}{title}}}

\newbibmacro*{test:ed:a}{%
  \renewcommand*{\do}[1]{%
    \ifnameundef{##1}
      {\toggletrue{noed}}%
      {\togglefalse{noed}%
       \renewcommand*{\xeditor}{##1}%
       \let\edtypes\empty
       \forcsvfield{\listadd\edtypes}{\xeditor type}%
       \usebibmacro{test:a:types}{\edtypes}{noed}}}% needs '%'
  \docsvlist{editor,editora,editorb,editorc}}%

\newbibmacro*{test:trans:a}{%
  \renewcommand*{\do}[1]{%
    \ifnameundef{##1}
      {\toggletrue{notrans}}%
      {\togglefalse{notrans}%
       \renewcommand*{\yeditor}{##1}%
       \let\transtypes\empty
       \forcsvfield{\listadd\transtypes}{\yeditor type}%
       \usebibmacro{test:a:types}{\transtypes}{notrans}}}% needs '%'
  \docsvlist{translator,translatora,translatorb}}%

\newbibmacro*{test:a:types}[2]{%
  \ifboolexpr{ test {\ifinlist{issuetitle}{#1}}
               or test {\ifinlist{series}{#1}}}
    {\toggletrue{#2}}%
    {\ifinlist{maintitle}{#1}
       {\iftoggle{collection:bk}
          {\iftoggle{swapvol}
             {\listbreak}%
             {\toggletrue{#2}}}
          {\toggletrue{#2}}}
       {\ifboolexpr{ togl {collection:bk}
                     and togl {swapvol}}
          {\toggletrue{#2}}%
          {\usebibmacro{test:a:keys}{#1}{#2}}}}}

\newbibmacro*{test:a:keys}[2]{%
  \xifinlist{\thefield{\xtitle titlekey}}{#1}
    {\ifboolexpr{ togl {collection:ib}
                  and togl {swapvol}}
       {\toggletrue{#2}}%
       {\ifboolexpr{ togl {swapvol}
                     and ( togl {collection:icbk}
                     or togl {collection:icib} )}
          {\toggletrue{#2}}%
          {\listbreak}}}
    {\listbreak}}%

\newbibmacro*{test:swaptrans:a}[1]{%
  \iftoggle{swaptrans:#1}
    {\toggletrue{swaptrans}%
     \iftoggle{notrans}
       {\usebibmacro{ed:a:combos}}%
       {\usebibmacro{trans:a:combos}}%
     \togglefalse{swaptrans}}%
    {\iftoggle{noed}
       {\usebibmacro{trans:a:combos}}%
       {\usebibmacro{ed:a:combos}}}}

\newbibmacro*{ed:a:combos}{%
  \iftoggle{noed}
    {}
    {\usebibmacro{edcombos:a}}}

\newbibmacro*{trans:a:combos}{%
  \iftoggle{notrans}
    {}
    {\usebibmacro{transcombos:a}}}

% For editors and translators after the author's position.

\newbibmacro*{editors:b}{%
  \usebibmacro{test:ed:b}%
  \usebibmacro{test:trans:b}%
  \ifdefstring{\xtitle}{book}
    {\usebibmacro{test:swaptrans:b}{booktitle}}%
    {\ifdefstring{\xtitle}{bookbook}
       {\usebibmacro{test:swaptrans:b}{bookbooktitle}}%
       {\usebibmacro{test:swaptrans:b}{title}}}}

\newbibmacro*{test:ed:b}{%
  \renewcommand*{\do}[1]{%
    \ifnameundef{##1}
      {\toggletrue{noed}}%
      {\togglefalse{noed}%
       \renewcommand*{\xeditor}{##1}%
       \let\edtypes\empty
       \forcsvfield{\listadd\edtypes}{\xeditor type}%
       \usebibmacro{test:b:types}{\edtypes}{noed}}}% needs '%'
  \docsvlist{editor,editora,editorb,editorc}}%

\newbibmacro*{test:trans:b}{%
  \renewcommand*{\do}[1]{%
    \ifnameundef{##1}
      {\toggletrue{notrans}}%
      {\togglefalse{notrans}%
       \renewcommand*{\yeditor}{##1}%
       \let\transtypes\empty
       \forcsvfield{\listadd\transtypes}{\yeditor type}%
       \usebibmacro{test:b:types}{\transtypes}{notrans}}}% needs '%'
  \docsvlist{translator,translatora,translatorb}}%

\newbibmacro*{test:b:types}[2]{%
  \ifboolexpr{ test {\ifinlist{issuetitle}{#1}}
               or test {\ifinlist{maintitle}{#1}}
               or test {\ifinlist{series}{#1}}}
    {\toggletrue{#2}}%
    {\ifinlist{booktitle}{#1}
       {\ifdefstring{\xtitle}{book}
          {\usebibmacro{test:b:keys}{#1}{#2}}%
          {\toggletrue{#2}}}
       {\ifinlist{bookbooktitle}{#1}
          {\ifdefstring{\xtitle}{bookbook}
             {\usebibmacro{test:b:keys}{#1}{#2}}%
             {\toggletrue{#2}}}
          {\usebibmacro{test:b:keys}{#1}{#2}}}}}

\newbibmacro*{test:b:keys}[2]{%
  \xifinlist{\thefield{\xtitle titlekey}}{#1}
    {\listbreak}%
    {\toggletrue{#2}}}

\newbibmacro*{test:swaptrans:b}[1]{%
  \iftoggle{swaptrans:#1}
    {\toggletrue{swaptrans}%
     \usebibmacro{trans:b:combos}%
     \usebibmacro{ed:b:combos}%
     \togglefalse{swaptrans}}%
    {\usebibmacro{ed:b:combos}%
     \usebibmacro{trans:b:combos}}}

\newbibmacro*{ed:b:combos}{%
  \iftoggle{noed}
    {\usebibmacro{ed:b:second}}%
    {\usebibmacro{edcombos:a}%
     \usebibmacro{pluga+etc}%
     \usebibmacro{editoraddon}{editor}%
     \usebibmacro{editoraddon}{editora}%
     \usebibmacro{ed:b:second}%
     \usebibmacro{editoraddon}{editora}}}

\newbibmacro*{trans:b:combos}{%
  \iftoggle{notrans}
    {}
    {\usebibmacro{transcombos:a}%
     \usebibmacro{pluga+etc}}}

\newbibmacro*{pluga+etc}{%
  \usebibmacro{edtranspunct:a}%
  \usebibmacro{pluga+printnames}%
  \usebibmacro{edtranspunct:b}}%

\newbibmacro*{edtranspunct:a}{%
  \iftoggle{authposition}
    {}
    {\iftoggle{edshift}
       {\setunit{\addcomma\space}}%
       {\newunit}}}

\newbibmacro*{pluga+printnames}{%
  \renewcommand*{\pluga}{%
    \bibstring{\cbx@bibstring}\space}%
  \usebibmacro{printnames+etc}}%

\newbibmacro*{edtranspunct:b}{%
  \iftoggle{edshift}
    {\setunit{\addcomma\space}}%
    {\newunit}}%

\newbibmacro*{ed:b:second}{%
  \usebibmacro{test:ed:b}%
  \iftoggle{noed}
    {}
    {\usebibmacro{edcombos:a}%
     \usebibmacro{pluga+etc}}}

% For editors and translators of an 'issuetitle', 'maintitle', or 'series'.

\newbibmacro*{editors:c}[1]{%
  \usebibmacro{test:ed:c}{#1}%
  \usebibmacro{test:trans:c}{#1}%
  \iftoggle{swaptrans:#1}
    {\toggletrue{swaptrans}%
     \usebibmacro{trans:c:combos}%
     \usebibmacro{ed:c:combos}{#1}%
     \togglefalse{swaptrans}}%
    {\usebibmacro{ed:c:combos}{#1}%
     \usebibmacro{trans:c:combos}}}

\newbibmacro*{test:ed:c}[1]{%
  \renewcommand*{\do}[1]{%
    \ifnameundef{##1}
      {\toggletrue{noed}}%
      {\togglefalse{noed}%
       \renewcommand*{\xeditor}{##1}%
       \let\edtypes\empty
       \forcsvfield{\listadd\edtypes}{\xeditor type}%
       \ifinlist{#1}{\edtypes}
         {\listbreak}%
         {\toggletrue{noed}}}}% needs '%'
  \docsvlist{editor,editora,editorb,editorc}}%

\newbibmacro*{test:trans:c}[1]{%
  \renewcommand*{\do}[1]{%
    \ifnameundef{##1}
      {\toggletrue{notrans}}%
      {\togglefalse{notrans}%
       \renewcommand*{\yeditor}{##1}%
       \let\transtypes\empty
       \forcsvfield{\listadd\transtypes}{\yeditor type}%
       \ifinlist{#1}{\transtypes}
         {\listbreak}%
         {\toggletrue{notrans}}}}% needs '%'
  \docsvlist{translator,translatora,translatorb}}%

\newbibmacro*{ed:c:combos}[1]{%
  \iftoggle{noed}
    {}
    {\usebibmacro{edtranspunct:c}%
     \usebibmacro{edcombos:a}%
     \usebibmacro{pluga+printnames}%
     \setunit{\addcomma\space}%
     \usebibmacro{editoraddon}{editor}%
     \usebibmacro{editoraddon}{editora}%
     \usebibmacro{ed:c:second}{#1}%
     \setunit{\addcomma\space}%
     \usebibmacro{editoraddon}{editora}}}

\newbibmacro*{edtranspunct:c}{%
  \ifboolexpr{ togl {collection:bk}
               and togl {swapvol}}
    {\newunit}%
    {\setunit{\addcomma\space}}}

\newbibmacro*{trans:c:combos}{%
  \iftoggle{notrans}
    {}
    {\usebibmacro{edtranspunct:c}%
     \usebibmacro{transcombos:a}%
     \usebibmacro{pluga+printnames}}}

\newbibmacro*{ed:c:second}[1]{%
  \usebibmacro{test:ed:c}{#1}%
  \iftoggle{noed}
    {}
    {\usebibmacro{edtranspunct:c}%
     \usebibmacro{edcombos:a}%
     \usebibmacro{pluga+printnames}}}

% Macros common to 'editors:a', 'editors:b', and 'editors:c'.

\newbibmacro*{edcombos:a}{%
  \usebibmacro{shortnames}{\xeditor}%
  \ifnamesequal{\xeditor}{\yeditor}
    {\clearname{\yeditor}%
     \toggletrue{notrans}%
     \usebibmacro{edcombos:b}{\edtypes}{edtrans}%
     \iftoggle{atleastone}
       {\usebibmacro{types:shared}{\edtypes}}%
       {\usebibmacro{edcombos:b}{\transtypes}{edtrans}%
        \usebibmacro{types:shared}{\transtypes}}}
    {\usebibmacro{edcombos:c}%
     \usebibmacro{types:shared}{\edtypes}}}

\newbibmacro*{transcombos:a}{%
  \usebibmacro{shortnames}{\yeditor}%
  \ifnamesequal{\xeditor}{\yeditor}
    {\clearname{\xeditor}%
     \toggletrue{noed}%
     \usebibmacro{transcombos:b}{\edtypes}{transed}%
     \iftoggle{atleastone}
       {\usebibmacro{types:shared}{\edtypes}}%
       {\usebibmacro{transcombos:b}{\transtypes}{transed}%
        \usebibmacro{types:shared}{\transtypes}}}
    {\usebibmacro{transcombos:c}%
     \usebibmacro{types:shared}{\transtypes}}}

\newbibmacro*{edcombos:b}[2]{%
  \togglefalse{atleastone}%
  \renewcommand*{\do}[1]{%
    \ifinlist{##1}{#1}
      {\toggletrue{atleastone}%
       \listbreak}%
      {}}% needs '%'
  \docsvlist{comptrans,comp,compiler,comped,compex,comprev,compup,transcomp}%
  \iftoggle{atleastone}
    {\renewcommand*{\cbx@bibstring}{comptrans}}%
    {\docsvlist{extrans,ex,excomp,exed,expander,exrev,exup,transex}%
     \iftoggle{atleastone}
       {\renewcommand*{\cbx@bibstring}{extrans}}%
       {\docsvlist{revtrans,rev,revcomp,reved,revex,reviser,revup,transrev}%
        \iftoggle{atleastone}
          {\renewcommand*{\cbx@bibstring}{revtrans}}%
          {\docsvlist{uptrans,up,upcomp,updater,uped,upex,uprev,transup}%
           \iftoggle{atleastone}
             {\renewcommand*{\cbx@bibstring}{uptrans}}%
             {\renewcommand*{\cbx@bibstring}{#2}}}}}}

\newbibmacro*{edcombos:c}{%
  \renewcommand*{\do}[1]{%
    \ifboolexpr{ test {\ifinlist{##1}{\edtypes}}
                 or test {\ifstrequal{##1}{editor}}}
      {\usebibmacro{swapstrings}{##1}%
       \listbreak}%
      {}}% needs '%'
  \docsvlist{comp,comped,compex,compiler,comprev,comptrans,compup,ed,edcomp,edex,edrev,edtrans,edup,
             ex,excomp,exed,expander,exrev,extrans,exup,rev,revcomp,reved,revex,reviser,revtrans,
             revup,transcomp,transed,transex,transrev,transup,up,upcomp,updater,uped,upex,uprev,
             uptrans,editor}}%

\newbibmacro*{transcombos:b}[2]{%
  \togglefalse{atleastone}%
  \renewcommand*{\do}[1]{%
    \ifinlist{##1}{#1}
      {\toggletrue{atleastone}%
       \listbreak}%
      {}}% needs '%'
  \docsvlist{transcomp,comp,comped,compex,compiler,comprev,comptrans,compup}%
  \iftoggle{atleastone}
    {\renewcommand*{\cbx@bibstring}{transcomp}}%
    {\docsvlist{transex,ex,excomp,exed,expander,exrev,extrans,exup}%
     \iftoggle{atleastone}
       {\renewcommand*{\cbx@bibstring}{transex}}%
       {\docsvlist{transrev,rev,revcomp,reved,revex,reviser,revtrans,revup}%
        \iftoggle{atleastone}
          {\renewcommand*{\cbx@bibstring}{transrev}}%
          {\docsvlist{transup,up,upcomp,updater,uped,upex,uprev,uptrans}%
           \iftoggle{atleastone}
             {\renewcommand*{\cbx@bibstring}{transup}}%
             {\renewcommand*{\cbx@bibstring}{#2}}}}}}

\newbibmacro*{transcombos:c}{%
  \renewcommand*{\do}[1]{%
    \ifboolexpr{ test {\ifinlist{##1}{\transtypes}}
                 or test {\ifstrequal{##1}{translator}}}
      {\usebibmacro{swapstrings}{##1}%
       \listbreak}%
      {}}% needs '%'
  \docsvlist{comptrans,edtrans,extrans,revtrans,transcomp,transed,transex,transrev,transup,uptrans,
             translator}}%

\newbibmacro*{swapstrings}[1]{%
  \iftoggle{swaptrans}
    {\ifstrequal{#1}{comptrans}
       {\renewcommand*{\cbx@bibstring}{transcomp}}%
       {\ifstrequal{#1}{edtrans}
          {\renewcommand*{\cbx@bibstring}{transed}}%
          {\ifstrequal{#1}{extrans}
             {\renewcommand*{\cbx@bibstring}{transex}}%
             {\ifstrequal{#1}{revtrans}
                {\renewcommand*{\cbx@bibstring}{transrev}}%
                {\ifstrequal{#1}{transcomp}
                   {\renewcommand*{\cbx@bibstring}{comptrans}}%
                   {\ifstrequal{#1}{transed}
                      {\renewcommand*{\cbx@bibstring}{edtrans}}%
                      {\ifstrequal{#1}{transex}
                         {\renewcommand*{\cbx@bibstring}{extrans}}%
                         {\ifstrequal{#1}{transrev}
                            {\renewcommand*{\cbx@bibstring}{revtrans}}%
                            {\ifstrequal{#1}{transup}
                               {\renewcommand*{\cbx@bibstring}{uptrans}}%
                               {\ifstrequal{#1}{uptrans}
                                  {\renewcommand*{\cbx@bibstring}{transup}}%
                                  {\renewcommand*{\cbx@bibstring}{#1}}}}}}}}}}}}
    {\renewcommand*{\cbx@bibstring}{#1}}}

\newbibmacro*{addplus+etc}{%
  \iftoggle{cbx:short}
    {}
    {\usebibmacro{addplus}%
     \renewcommand*{\plugb}{%
       \addcomma\space\bibsstring{\cbx@bibstring}}}}

\newbibmacro*{addplus}{%
  \ifnameundef{\xeditor}
    {\ifnameundef{\yeditor}
       {}
       {\ifnumgreater{\value{\yeditor}}{1}
          {\edef\cbx@bibstring{\cbx@bibstring +}}%
          {}}}
    {\ifnumgreater{\value{\xeditor}}{1}
       {\edef\cbx@bibstring{\cbx@bibstring +}}%
       {}}}

\newbibmacro*{editoraddon}[1]{%
  \ifboolexpr{ test {\iffieldundef{#1addon}}
               or not test {\ifdefstring{\xeditor}{#1}}}
    {}
    {\nopunct\printfield{#1addon}%
     \clearfield{#1addon}}}

%%%%%%%%%%%%%%%%%%%%%%%%
%%  Names and Dashes  %%
%%%%%%%%%%%%%%%%%%%%%%%%

\newbibmacro*{printnames+etc}{%
  \ifboolexpr{ togl {authposition}
               and togl {bibliography}
               and togl {dashed}}
    {\usebibmacro{bibnamedash+printnames}}%
    {\usebibmacro{printnames}}%
  \usebibmacro{handle}%
  \usebibmacro{nameaddon}%
  \usebibmacro{newauth+location}%
  \usebibmacro{a:labeldate+extradate}%
  \usebibmacro{clearnames+empty}}%

\newbibmacro*{bibnamedash+printnames}{%
  \ifboolexpr{ test {\iffieldequals{namehash}{\bbx@lasthash}}
               and not test \iffirstonpage}
    {\ifboolexpr{ test {\ifnameundef{author}}
                  and test {\ifnameundef{bookauthor}}}
       {\bibnamedash\plugb}%
       {\bibnamedash}}%
    {\usebibmacro{printnames}}}

\renewcommand*{\bibnamedash}{%
  \rule[2.4pt]{3em}{0.2pt}%
  \global\toggletrue{blx@insert}}%

\newbibmacro*{printnames}{%
  \ifnameundef{\cbx@namelist}
    {}
    {\iftoggle{noetal}
       {\pluga\anona\printnames[\cbx@deflabel][-\value{listtotal}]{%
          \cbx@namelist}\anonb\plugb}%
       {\pluga\anona\printnames[\cbx@deflabel]{%
          \cbx@namelist}\anonb\plugb}}}

% A screen name precedes 'nameaddon' and can be omitted from short
% citations. See CMOS, 17th ed., 14.209.

\newbibmacro*{handle}{%
  \ifboolexpr{ test {\iffieldundef{handle}}
               or togl {cbx:short}}
    {}
    {\space
     \printfield[parens]{handle}%
     \clearfield{handle}}}

% Omit addons in short citations. See CMOS, 17th ed., 14.80 and
% 14.209.

\newbibmacro*{nameaddon}{%
  \ifboolexpr{ test {\iffieldundef{nameaddon}}
               or togl {cbx:short}}
    {}
    {\space
     \iftoggle{newauth}
       {\printfield[noformat]{nameaddon}%
        \clearfield{nameaddon}}%
       {\printfield[brackets]{nameaddon}%
        \clearfield{nameaddon}}}}

\newbibmacro*{newauth+location}{%
  \iftoggle{newauth}
    {\ifboolexpr{ test {\ifentrytype{article}}
                  and togl {bibliography}}
       {\usebibmacro{article:location}%
        \newunit}%
       {}}
    {}}

\newbibmacro*{clearnames+empty}{%
  \clearname{\cbx@namelist}%
  \let\cbx@namelist\empty
  \let\anona\empty
  \let\anonb\empty
  \let\pluga\empty
  \let\plugb\empty}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Titles and Subtitles  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand*{\subtitlepunct}{\ifterm{\space}{:\space}}%

\newbibmacro*{title+labeldate}{%
  \usebibmacro{title+titleaddon}{}%
  \iftoggle{bibliography}
    {\usebibmacro{b:labeldate+extradate}}%
    {}}

\newbibmacro*{title+titleaddon}[1]{%
  \iffieldundef{#1title}
    {}
    {\renewcommand*{\xtitle}{#1}%
     \usebibmacro{title+shortlinks}{#1}%
     \usebibmacro{titleaddon}{#1}%
     \clearfield{#1title}}}

\newbibmacro*{title+shortlinks}[1]{%
  \iftoggle{shortlinks}
    {\printtext[bibhyperref]{%
       \usebibmacro{test:format}{#1title}{title}}}
    {\usebibmacro{test:format}{#1title}{title}}}

\newbibmacro*{print:title}[3]{%
  \printtext[#2]{%
    \printfield[#3]{#1}%
    \iffieldundef{\xtitle subtitle}
      {}
      {\subtitlepunct
       \printfield[#3]{\xtitle subtitle}}%
    \isdot}}%

\newbibmacro*{titleaddon}[1]{%
  \iffieldundef{#1titleaddon}
    {}
    {\addspace% '\space' has issues with quotation marks
     \printfield{#1titleaddon}}}

\newbibmacro*{shorttitle+crossref}[1]{%
  \ifboolexpr{ togl {collection:#1bk}
               and togl {swapvol}}
    {\usebibmacro{shorttitle}{main}}%
    {\ifboolexpr{ togl {collection:#1ib}
                  and togl {swapvol}}
       {\usebibmacro{shorttitle}{book}}%
       {\usebibmacro{shorttitle}{label}}}}

\newbibmacro*{shorttitle}[1]{%
  \renewcommand*{\xtitle}{#1}%
  \clearfield{#1subtitle}%
  \ifstrequal{#1}{label}
    {\usebibmacro{title+shortlinks}{label}}%
    {\iffieldundef{short#1title}
      {\usebibmacro{title+shortlinks}{#1}}%
      {\usebibmacro{title+shortlinks}{short#1}}}}

\renewbibmacro*{booktitle}{%
  \iffieldundef{booktitle}
    {}
    {\usebibmacro{title+titleaddon}{book}%
     \usebibmacro{bybookauthor+pages}}}

\newbibmacro*{bookbooktitle}[1]{%
  \iffieldundef{bookbooktitle}
    {}
    {\ifstrequal{#1}{in}
       {\newunit\bibstring{in}\space}%
       {}% needs '%'
     \usebibmacro{title+titleaddon}{bookbook}}}

\newbibmacro*{issuetitle}{%
  \iffieldundef{issuetitle}
    {}
    {\iffieldequalstr{issuetitle}{special issue}
       {}
       {\bibstring{in}\space
        \usebibmacro{title+titleaddon}{issue}%
        \usebibmacro{editors:c}{issuetitle}}%
     \newunit\bibstring{special}%
     \setunit{\addcomma\space}}}

\newbibmacro*{origtitle}{%
  \iffieldundef{origtitle}
    {}
    {\newunit
     \bibstring{origpub}%
     \space
     \usebibmacro{title+titleaddon}{orig}%
     \setunit{\addspace}% not '\setunit{\space}'
     \printtext[parens]{%
       \usebibmacro{loc+pub+etc}{orig}%
       \ifboolexpr{ togl {bibliography}
                    and togl {reflist}}
         {}
         {\usebibmacro{year+endyear}{orig}}}}}

%%%%%%%%%%%%%%%%%%%
%%  Collections  %%
%%%%%%%%%%%%%%%%%%%

\newbibmacro*{test:collection}{%
  \ifboolexpr{ test {\ifentrytype{book}}
               or test {\ifentrytype{collection}}}
    {\usebibmacro{test:collection:bk}}%
    {\ifboolexpr{ test {\ifentrytype{inbook}}
                  or test {\ifentrytype{incollection}}
                  or test {\ifentrytype{letter}}}
       {\usebibmacro{test:collection:icbk+etc}}%
       {}}}

\newbibmacro*{test:collection:bk}{%
  \ifboolexpr{ test {\iffieldundef{booktitle}}
               and test {\iffieldundef{bookbooktitle}}
               and test {\iffieldundef{bookvolume}}
               and test {\iffieldundef{bookbookvolume}}
               and not test {\iffieldundef{title}}
               and not test {\iffieldundef{maintitle}}
               and not test {\iffieldundef{volume}}}
    {\toggletrue{collection}%
     \toggletrue{collection:bk}}%
    {}}

\newbibmacro*{test:collection:icbk+etc}{%
  \ifboolexpr{ test {\iffieldundef{bookbooktitle}}
               and test {\iffieldundef{volume}}
               and test {\iffieldundef{bookbookvolume}}
               and not test {\iffieldundef{title}}
               and not test {\iffieldundef{booktitle}}
               and not test {\iffieldundef{maintitle}}
               and not test {\iffieldundef{bookvolume}}}
    {\toggletrue{collection}%
     \toggletrue{collection:icbk}}%
    {\ifentrytype{inbook}
       {\usebibmacro{test:collection:ib}}%
       {\usebibmacro{test:collection:icib}}}}

\newbibmacro*{test:collection:ib}{%
  \ifboolexpr{ test {\iffieldundef{maintitle}}
               and test {\iffieldundef{bookbooktitle}}
               and test {\iffieldundef{bookvolume}}
               and test {\iffieldundef{bookbookvolume}}
               and not test {\iffieldundef{title}}
               and not test {\iffieldundef{booktitle}}
               and not test {\iffieldundef{volume}}}
    {\toggletrue{collection}%
     \toggletrue{collection:ib}}%
    {}}

\newbibmacro*{test:collection:icib}{%
  \ifboolexpr{ test {\iffieldundef{maintitle}}
               and test {\iffieldundef{volume}}
               and test {\iffieldundef{bookbookvolume}}
               and not test {\iffieldundef{booktitle}}
               and not test {\iffieldundef{bookbooktitle}}
               and not test {\iffieldundef{bookvolume}}}
    {\toggletrue{collection}%
     \toggletrue{collection:icib}}%
    {}}

%%%%%%%%%%%%%%%%%%%%%%%
%%  Dates and Times  %%
%%%%%%%%%%%%%%%%%%%%%%%

% The next command should work well enough for most languages but can
% be overridden by lbx files.

\renewcommand*{\mkdaterangefull}[2]{%
  \begingroup
    \blx@metadateinfo{#2}%
    \ifboolexpr{ test {\iffieldundef{#2year}}
                 and test {\iffieldundef{#2month}}}
      {\blx@nounit}%
      {\printtext[#2date]{%
         \datecircaprint
         \iffieldundef{#2season}
           {\csuse{mkbibdate#1}{#2year}{#2month}{#2day}%
            \blx@printtime{#2}{}}%
           {\csuse{mkbibseasondate#1}{#2year}{#2season}}%
         \dateuncertainprint
         \dateeraprint{#2year}%
         \ifboolexpr{ test {\iffieldundef{#2endyear}}
                      and test {\iffieldundef{#2endmonth}}}
           {}
           {\iffieldequalstr{#2endyear}{}
              {\mbox{\bibdaterangesep}}%
              {\bibdaterangesep
               \enddatecircaprint
               \iffieldundef{#2season}
                 {\csuse{mkbibdate#1}{#2endyear}{#2endmonth}{#2endday}%
                  \blx@printtime{#2}{end}}%
                 {\csuse{mkbibseasondate#1}{#2endyear}{#2endseason}}%
               \enddateuncertainprint
               \dateeraprint{#2endyear}}}}}% needs '%'
  \endgroup}%

\newbibmacro*{issue+month+etc}[1]{%
  \iffieldundef{year}
    {\ifstrequal{#1}{parens}
       {\setunit{\space}}%
       {\setunit{\addcomma\space}}%
     \usebibmacro{pubstate}{#1}}%
    {\ifboolexpr{ test {\iffieldundef{volume}}
                  and test {\iffieldundef{number}}}
       {\iffieldundef{month}
          {\usebibmacro{issue+season+year}}%
          {\usebibmacro{reflist+year+day}%
           \printdate}}%
       {\iffieldundef{month}
          {\setunit{\space}%
           \usebibmacro{reflist+issue+season}}%
          {\usebibmacro{reflist+year+day}%
           \ifstrequal{#1}{parens}
             {\setunit{\space}%
              \printtext[parens]{\printdate}}%
             {\newunit
              \usebibmacro{pubstate}{date}}}}}}

\newbibmacro*{pubstate}[1]{%
  \iftoggle{authposition}
    {\iffieldequalstr{pubstate}{forthcoming}
       {\printfield{pubstate}%
        \clearfield{pubstate}}%
       {\usebibmacro{labeldate+date}{#1}}}
    {\iffieldundef{pubstate}
       {\usebibmacro{labeldate+date}{#1}}%
       {\iffieldequalstr{pubstate}{preprint}
          {\newunit
           \bibstring{preprint}%
           \setunit{\space}}%
          {\iffieldequalstr{pubstate}{prepub}
             {\newunit% necessary if no 'date'
              \bibstring{prepub}%
              \setunit{\addcomma\space}%
              \printdate}%
             {\iffieldequalstr{pubstate}{working}
                {\newunit
                 \bibstring{working}%
                 \setunit{\addcomma\space}}%
                {\ifstrequal{#1}{parens}
                   {\printtext[parens]{\printfield{pubstate}}}
                   {\printfield{pubstate}}}}}}}}

\newbibmacro*{labeldate+date}[1]{%
  \ifstrequal{#1}{label}
    {\printlabeldate}%
    {\ifstrequal{#1}{date}
       {\ifboolexpr{ test {\iffieldundef{year}}
                     and test {\iffieldundef{month}}}
         {\iffieldundef{yeardivision}
            {\printfield{season}}% deprecated
            {\printfield{yeardivision}}}
         {\printdate}}%
       {}}}

\newbibmacro*{reflist+year+day}{%
  \ifboolexpr{ togl {bibliography}
               and togl {reflist}
               and test {\iffieldundef{day}}
               and test {\iffieldundef{season}}% deprecated
               and test {\iffieldundef{yeardivision}}}
   {\iffieldundef{endyear}
       {\clearfield{year}}%
       {\iffieldsequal{year}{endyear}
          {\clearfield{year}%
           \clearfield{endyear}}%
          {}}}
    {}}

% Treat 'yeardivision' and 'season' as alternatives for 'issue'.

\newbibmacro*{issue+season+year}{%
  \iffieldundef{issue}
    {\usebibmacro{labeldate+date}{date}}%
    {\ifboolexpr{ test {\iffieldundef{season}}% deprecated
                  and test {\iffieldundef{yeardivision}}}
      {\printfield{issue}%
       \setunit{\addspace}% not '\addspace'
       \printfield{year}}%
      {\usebibmacro{labeldate+date}{date}}}}

\newbibmacro*{reflist+issue+season}{%
  \ifboolexpr{ togl {bibliography}
               and togl {reflist}}
    {\ifboolexpr{ test {\iffieldundef{issue}}
                  and test {\iffieldundef{season}}% deprecated
                  and test {\iffieldundef{yeardivision}}}
       {}
       {\clearfield{year}%
        \printtext[parens]{\usebibmacro{issue+season+year}}}}
    {\printtext[parens]{\usebibmacro{issue+season+year}}}}

% Per CMOS, 17th ed., 14.119, print the publication year of the
% last-mentioned title.

\newbibmacro*{year+bookyear}{%
  \ifboolexpr{ togl {bibliography}
               and togl {reflist}}
    {\ifboolexpr{ test {\iffieldundef{year}}
                  or test {\iffieldundef{bookyear}}
                  or test {\iffieldsequal{year}{bookyear}}}
       {}
       {\ifboolexpr{ togl {collection}
                     and togl {swapvol}}
          {\usebibmacro{year+endyear}{}}%
          {\usebibmacro{year+endyear}{book}}}}
    {\ifboolexpr{ test {\iffieldundef{year}}
                  and test {\iffieldundef{bookyear}}}
       {\usebibmacro{pubstate}{label}}%
       {\iffieldundef{bookyear}
          {\usebibmacro{year+endyear}{}}%
          {\ifboolexpr{ togl {collection}
                        and togl {swapvol}
                        and not test {\iffieldundef{year}}}
             {\usebibmacro{year+endyear}{}}%
             {\usebibmacro{year+endyear}{book}}}}}}

\newbibmacro*{year+endyear}[1]{%
  \iffieldundef{#1year}
    {}
    {\ifboolexpr{ togl {bibliography}
                  and togl {reflist}
                  and test {\iffieldsequal{#1year}{label}}}
       {}
       {\printfield{#1year}%
        \usebibmacro{endyear}{#1}}}}

\newbibmacro*{endyear}[1]{%
  \ifboolexpr{ test {\iffieldundef{#1endyear}}
               or test {\iffieldsequal{#1year}{#1endyear}}}
    {}
    {\textendash\printfield{#1endyear}}}

\newbibmacro*{year+month+day}[1]{%
  \ifboolexpr{ togl {bibliography}
               and togl {reflist}
               and test {\iffieldundef{month}}
               and test {\iffieldundef{season}}% deprecated
               and test {\iffieldundef{yeardivision}}}
    {}
    {\usebibmacro{labeldate+date}{#1}}}

% For reference lists.

\newbibmacro*{a:labeldate+extradate}{%
  \ifboolexpr{ togl {noauth}
               or not togl {authposition}}
    {}
    {\usebibmacro{labeldate+extradate}}}

\newbibmacro*{b:labeldate+extradate}{%
  \iftoggle{noauth}
    {\usebibmacro{labeldate+extradate}}%
    {}}

\newbibmacro*{labeldate+extradate}{%
  \ifboolexpr{ togl {bibliography}
               and togl {reflist}
               and not togl {skipdate}}
    {\newunit
     \usebibmacro{reflist+origyear}%
     \usebibmacro{labeldate+endyear}%
     \printfield{extradate}%
     \iffieldnums{labelyear}
       {\bibsentence\newunit}%
       {\newunit}}% for 'n.d.'
    {}}

\newbibmacro*{reflist+origyear}{%
  \iffieldundef{origyear}
    {}
    {\printtext[parens]{\usebibmacro{year+endyear}{orig}}%
     \space}}%

\newbibmacro*{labeldate+endyear}{%
  \ifboolexpr{ togl {collection}
               and togl {swapvol:global}
               and test {\iffieldundef{label}}
               and not test {\iffieldundef{bookyear}}
               and not test {\iffieldsequal{year}{bookyear}}}
    {\usebibmacro{year+endyear}{book}}%
    {\usebibmacro{pubstate}{label}}}

%%%%%%%%%%%%%%%%%
%%  Locations  %%
%%%%%%%%%%%%%%%%%

\newbibmacro*{article:location}{%
  \iflistundef{location}
    {}
    {\nopunct\setunit{\space}%
     \printtext[parens]{\printlist{location}}}%
     \clearlist{location}}%

\newbibmacro*{loc+pub+etc}[1]{%
  \ifboolexpr{ test {\iflistundef{#1location}}
               and test {\iflistundef{#1publisher}}}
    {}
    {\usebibmacro{pubcount}%
     \whileboolexpr{ test {\ifnumless{\value{pubcount}}{\value{#1location}}}
                     or test {\ifnumless{\value{pubcount}}{\value{#1publisher}}}}
       {\stepcounter{pubcount}%
        \usebibmacro{#1loc+#1pub}{\value{pubcount}}%
        \setunit{\addsemicolon\space}}%
     \setunit{\addcomma\space}}}

\newbibmacro*{pubcount}{%
  \ifltxcounter{pubcount}
    {\setcounter{pubcount}{0}}%
    {\newcounter{pubcount}}}

\newbibmacro*{loc+pub}[1]{%
  \ifboolexpr{ test {\iflistundef{location}}
               and togl {noplace}}
    {\bibstring{noplace}%
     \setunit{\addcolon\space}}%
    {\iflistundef{location}
       {}
       {\printlist[location][#1-#1]{location}%
        \setunit{\addcolon\space}}}% needs '%'
  \printlist[publisher][#1-#1]{publisher}}%

\newbibmacro*{origloc+origpub}[1]{%
  \iflistundef{origlocation}
    {}
    {\printlist[location][#1-#1]{origlocation}%
     \setunit{\addcolon\space}}% needs '%'
  \printlist[publisher][#1-#1]{origpublisher}}%

\newbibmacro*{institution+venue}{%
  \ifboolexpr{ test {\iflistundef{institution}}
               and test {\iflistundef{venue}}}
    {}
    {\iflistundef{institution}
       {\printfield{venue}}%
       {\printlist{institution}}%
     \setunit{\addcomma\space}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Second Tier Macros  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%

\newbibmacro*{pageref+finentry}{%
  \newunit
  \usebibmacro{pageref}%
  \newunit
  \usebibmacro{annotation}%
  \finentry}%

\newbibmacro*{newauth}{%
  \iftoggle{newauth}
    {\iftoggle{bibliography}
       {\clearfield{\thefield{verba}}}
       {\toggletrue{noauth}}}
    {}}

\newbibmacro*{author+title+etc}{%
  \usebibmacro{author+bookauthor+etc}%
  \usebibmacro{title+labeldate}%
  \usebibmacro{note}%
  \usebibmacro{editors:b}}%

\newbibmacro*{articles}{%
  \iftoggle{newauth}
    {\printunit{\newunitpunct}}%
    {\newunit}%
  \usebibmacro{part}%
  \usebibmacro{issuetitle}%
  \usebibmacro{title+titleaddon}{journal}%
  \usebibmacro{article:series}%
  \usebibmacro{article:location}%
  \usebibmacro{volume}%
  \iftoggle{newauth}
    {\newunit}%
    {\setunit{\addcomma\space}}%
  \iffieldequalstr{type}{newsmag}
    {\usebibmacro{issue+month+etc}{}%
     \usebibmacro{periodical:number}}%
    {\usebibmacro{periodical:number}%
     \iffieldequalstr{pubstate}{prepub}
       {\usebibmacro{issue+month+etc}{}}%
       {\usebibmacro{issue+month+etc}{parens}}}% needs '%'
  \toggletrue{edshift}%
  \usebibmacro{edition}{noformat}}%

% If an article has an electronic article ID, don't print its page
% range in the bibliography. See CMOS, 17th ed., 14.174.

\newbibmacro*{colon+pages+etc}{%
  \ifboolexpr{ test {\iffieldundef{pages}}
               or not test {\iffieldundef{eid}}}
    {}
    {\ifboolexpr{ togl {bibliography}
                  and togl {reflist}}
       {\ifboolexpr{test {\iffieldundef{number}}
                    and test {\iffieldundef{month}}
                    and test {\iffieldundef{issue}}
                    and test {\iffieldundef{season}}% deprecated
                    and test {\iffieldundef{yeardivision}}}
          {\setunit{\addcolon}%
           \printfield{pages}}%
          {\setunit{\addcolon\space}%
           \printfield{pages}}}
       {\usebibmacro{colon+pages}}}}

\newbibmacro*{doi+finentry+etc}{%
  \usebibmacro{doi+url+etc}%
  \usebibmacro{isbn}%
  \usebibmacro{issn}%
  \usebibmacro{library}%
  \usebibmacro{pageref+finentry}}%

\newbibmacro*{artworks}{%
  \usebibmacro{author+bookauthor+etc}%
  \usebibmacro{title+titleaddon}{}%
  \newunit
  \usebibmacro{year+month+day}{date}%
  \usebibmacro{type+typeaddon}%
  \usebibmacro{note}%
  \newunit
  \usebibmacro{institution+venue}%
  \printlist{location}%
  \setunit{\addcomma\space}}%

\newbibmacro*{author+collection+etc}{%
  \usebibmacro{test:collection}%
  \usebibmacro{author+bookauthor+etc}%
  \ifboolexpr{ togl {collection:bk}
               and togl {swapvol}}
    {\usebibmacro{maintitle+note+etc}%
     \usebibmacro{volume+number+etc}{}%
     \usebibmacro{title+titleaddon}{}%
     \toggletrue{edshift}%
     \usebibmacro{byauthor}%
     \usebibmacro{editors:b}%
     \usebibmacro{volumes+series+etc}{}}%
    {\usebibmacro{title+labeldate}%
     \usebibmacro{byauthor}%
     \iffieldundef{maintitle}
       {\usebibmacro{note+edition+etc}%
        \usebibmacro{volumes+series+etc}{}}%
       {\usebibmacro{editors:b}%
        \usebibmacro{volumes+series+etc}{}%
        \usebibmacro{maintitle+note+etc}}}
  \usebibmacro{date+loc+etc}%
  \usebibmacro{origtitle}}%

\newbibmacro*{author+incollection+etc}{%
  \usebibmacro{test:collection}%
  \usebibmacro{test:bookauthor}%
  \ifboolexpr{ test {\ifnameundef{afterword}}
               and test {\ifnameundef{foreword}}
               and test {\ifnameundef{introduction}}
               and test {\ifnameundef{preface}}}
    {\usebibmacro{author+bookauthor+etc}%
     \iffieldundef{title}
       {\usebibmacro{booktitle}%
        \usebibmacro{editors:b}}%
       {\ifboolexpr{ togl {collection:ib}
                     and togl {swapvol}
                     and not togl {collection:icib}}
          {\usebibmacro{booktitle}%
           \usebibmacro{editors:b}}%
          {\usebibmacro{title+labeldate}%
           \usebibmacro{byauthor}%
           \usebibmacro{editors:b}%
           \usebibmacro{chapter+in}}}}
    {\usebibmacro{supplement}%
     \newunit
     \bibstring{\cbx@bibstring}\space}}%

\newbibmacro*{crossref+incollections}{%
  \iffieldundef{crossref}
    {\usebibmacro{incollections}}%
    {\xifinlist{\thefield{crossref}}{\crossreflist}
       {\ifnumgreater{\value{\thefield{crossref}}}{0}
          {\usebibmacro{crossref+entrydata}%
           \usebibmacro{pages}}%
          {\usebibmacro{incollections}}}
       {\listxadd{\crossreflist}{\thefield{crossref}}%
        \ifcsdef{c@\thefield{crossref}}
          {\setcounter{\thefield{crossref}}{0}}%
          {\newcounter{\thefield{crossref}}}% needs '%'
           \usebibmacro{incollections}}}}

\newbibmacro*{websites}{%
  \ifboolexpr{ test {\iffieldundef{blogtitle}}
               and test {\iffieldundef{journaltitle}}
               and test {\iflistundef{organization}}}
    {}
    {\usebibmacro{title+titleaddon}{blog}%
     \newunit
     \usebibmacro{title+titleaddon}{journal}%
     \newunit
     \printlist{organization}%
     \setunit{\addcomma\space}}}

\newbibmacro*{reviews}{%
  \iftoggle{noauth}
    {\bibsentence}%
    {\usebibmacro{author+bookauthor+etc}}%
  \usebibmacro{title+labeldate}%
  \usebibmacro{note}%
  \newunit
  \iftoggle{newauth}
    {\bibstring{reviewnoauth}}%
    {\bibstring{review}}%
  \setunit{\space}%
  \iffieldundef{crossref}
    {\usebibmacro{title+titleaddon}{book}}%
    {\entrydata{\thefield{crossref}}{%
      {\usebibmacro{title+titleaddon}{}}}}
  \setunit{\addcomma\space}%
  \renewcommand*{\pluga}{\bibstring{by}\space}%
  \renewcommand*{\cbx@namelist}{bookauthor}%
  \usebibmacro{printnames+etc}%
  \setunit{\addcomma\space}%
  \toggletrue{edshift}%
  \usebibmacro{editors:b}}%

\newbibmacro*{standards}{%
  \usebibmacro{author+bookauthor+etc}%
  \usebibmacro{title+labeldate}%
  \usebibmacro{note+edition+etc}%
  \usebibmacro{volumes+series+etc}{}%
  \iftoggle{bibliography}
    {\newunit
     \usebibmacro{loc+pub+year}}%
    {\setunit{\addspace}% not '\setunit{\space}'
     \printtext[parens]{\usebibmacro{loc+pub+year}}}}

\newbibmacro*{thesis:type+pubstate}{%
  \ifentrytype{mathesis}
    {\bibstring{mathesis}%
     \setunit{\addcomma\space}}%
    {\ifentrytype{phdthesis}
       {\bibstring{phdthesis}%
        \setunit{\addcomma\space}}%
       {\iffieldundef{type}
         {\usebibmacro{pubstate}{}}%
         {\iffieldbibstring{type}
            {\bibstring{\thefield{type}}}
            {\printfield{type}}%
          \setunit{\addcomma\space}}}}}

\newbibmacro*{inst+loc+date}{%
  \usebibmacro{institution+venue}%
  \printlist{location}%
  \setunit*{\addcomma\space}%
  \usebibmacro{year+month+day}{date}}%

\newbibmacro*{type+typeaddon}{%
  \iffieldundef{type}
    {}
    {\newunit
     \printfield{type}%
     \iffieldundef{typeaddon}
       {\setunit{\addcomma\space}}%
       {\iffieldstart{typeaddon}{,}
          {}
          {\setunit{\space}}%
        \printfield{typeaddon}%
        \setunit{\space}}}}

\newbibmacro*{unpublished:series}{%
  \iffieldundef{series}
    {}
    {\newunit
     \usebibmacro{series+seriesaddon}%
     \iffieldundef{collection}
       {\setunit{\addcomma\space}}%
       {\newunit}}}

\newbibmacro*{manuscripts}{%
  \iffieldundef{title}
    {\toggletrue{skipdate}%
     \usebibmacro{author+bookauthor+etc}%
     \usebibmacro{type+typeaddon}}%
    {\usebibmacro{author+bookauthor+etc}%
     \usebibmacro{title+titleaddon}{}%
     \usebibmacro{type+typeaddon}%
     \setunit{\addcomma\space}%
     \usebibmacro{year+month+day}{label}%
     \iffieldundef{type}
       {\newunit
        \usebibmacro{unpublished:collection}}%
       {}}
  \usebibmacro{unpublished:note+etc}}%

%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Third Tier Macros  %%
%%%%%%%%%%%%%%%%%%%%%%%%%

\renewbibmacro*{annotation}{%
  \iftoggle{annotate}
    {\printfield{annotation}}%
    {}}

\newbibmacro*{note}{%
  \iffieldundef{note}
    {}
    {\iftoggle{edshift}
       {\setunit{\addcomma\space}%
        \togglefalse{edshift}}%
       {\newunit}%
     \printfield{note}}}

\newbibmacro*{part}{%
  \iffieldundef{part}
    {}
    {\setunit{\addcomma\space}%
     \iffieldnum{part}
       {\printfield{part}}%
       {\printfield[noformat]{part}}%
     \setunit{\addcomma\space}%
     \clearfield{part}}}

\newbibmacro*{article:series}{%
  \iffieldundef{series}
    {}
    {\iftoggle{newauth}
       {\newunit}%
       {\setunit{\addcomma\space}}%
     \usebibmacro{series+seriesaddon}}}

\newbibmacro*{volume}{%
  \iffieldundef{volume}
    {}
    {\setunit{\space}%
     \printfield[noformat]{volume}}}

% On how to format the issue number of periodicals, see CMOS, 17th
% ed., 14.171 and 15.47.

\newbibmacro*{periodical:number}{%
  \iffieldundef{number}
    {}
    {\ifboolexpr{ togl {bibliography}
                  and togl {reflist}
                  and test {\iffieldundef{issue}}
                  and test {\iffieldundef{season}}% deprecated
                  and test {\iffieldundef{yeardivision}}
                  and test {\iffieldundef{month}}
                  and not test {\iffieldundef{volume}}}
       {\setunit{\space}%
        \printfield[parens]{number}}%
       {\setunit{\addcomma\space}%
        \printfield[journum]{number}}}}

\newbibmacro*{colon+pages}{%
  \ifboolexpr{ test {\iffieldundef{month}}
               and test {\iffieldundef{year}}
               and test {\iffieldundef{issue}}}
    {\setunit{\addcolon}%
     \printfield{pages}}%
    {\ifboolexpr{ test {\iffieldundef{month}}
                  and test {\iffieldundef{year}}}
       {\setunit{\addcolon\space}%
        \printfield{pages}}%
       {\ifboolexpr{ test {\iffieldundef{number}}
                     and test {\iffieldundef{volume}}}
          {\setunit{\addcomma\space}%
           \printfield{pages}}%
          {\setunit{\addcolon\space}%
           \printfield{pages}}}}}

\newbibmacro*{doi+url+etc}{%
  \ifboolexpr{ test {\iffieldundef{howpublished}}
               and test {\iffieldundef{url}}
               and test {\iffieldundef{doi}}
               and test {\iffieldundef{eprint}}
               and test {\iffieldundef{addendum}}
               or ( togl {shortfirst} and not togl {bibliography} )}
    {}
    {\usebibmacro{eid}%
     \newunit
     \printfield{howpublished}%
     \newunit
     \printfield[noformat]{version}%
     \newunit
     \usebibmacro{urldate+url}%
     \newunit
     \usebibmacro{doi}%
     \newunit
     \usebibmacro{eprint+etc}%
     \newunit
     \printfield{addendum}}}

\newbibmacro*{isbn}{%
  \iffieldundef{isbn}
    {}
    {\iftoggle{bibliography}
       {\iftoggle{isbn}
          {\newunit
           \printfield{isbn}}%
          {}}
       {}}}

\newbibmacro*{issn}{%
  \iffieldundef{issn}
    {}
    {\iftoggle{bibliography}
       {\iftoggle{issn}
          {\newunit
           \printfield{issn}}%
          {}}
       {}}}

\newbibmacro*{library}{%
  \iffieldundef{library}
    {}
    {\iftoggle{bibliography}
       {\iftoggle{library}
          {\newunit
           \printfield{library}}%
          {}}
       {}}}

\newbibmacro*{maintitle+note+etc}{%
  \iffieldundef{maintitle}
    {}
    {\usebibmacro{title+titleaddon}{main}%
     \usebibmacro{note}%
     \usebibmacro{edition}{}%
     \usebibmacro{editors:c}{maintitle}}}

\newbibmacro*{volume+number+etc}[1]{%
  \iffieldundef{#1volume}
    {}
    {\usebibmacro{swapvol+pages}%
     \iffieldundef{series}
       {\newunit}%
       {\setunit{\addcomma\space}}%
     \iffieldnum{#1volume}
       {\printfield[volume]{#1volume}%
        \usebibmacro{volume:number}}%
       {\bibstring{volumes}\space
        \printfield[noformat]{#1volume}}%
     \clearfield{#1volume}%
     \usebibmacro{part}%
     \iftoggle{collection}
       {\iftoggle{swapvol}
          {\addcomma\space}%
          {\space\bibstring{of}\space}}%
       {\iffieldundef{maintitle}
          {}
          {\space\bibstring{of}\space}}}}

\renewbibmacro*{byauthor}{%
  \ifboolexpr{ test {\ifnameundef{author}}
               or togl {noauth}}
    {}
    {\iftoggle{edshift}
       {\renewcommand*{\pluga}{%
          \setunit{\addcomma\space}\bibstring{by}\space}}%
       {\renewcommand*{\pluga}{\newunit\bibstring{by}\space}}%
     \renewcommand*{\cbx@namelist}{author}%
     \usebibmacro{test:authortypes}{author}%
     \usebibmacro{printnames+etc}}}

\newbibmacro*{volumes+series+etc}[1]{%
  \usebibmacro{volumes}%
  \usebibmacro{book:series}%
  \usebibmacro{pages}%
  \usebibmacro{volume+number+etc}{#1}%
  \usebibmacro{book:number}%
  \usebibmacro{part}}%

\newbibmacro*{note+edition+etc}{%
  \usebibmacro{note}%
  \usebibmacro{edition}{}%
  \usebibmacro{editors:b}}%

\newbibmacro*{edition}[1]{%
  \iffieldundef{edition}
    {}
    {\iftoggle{edshift}
       {\setunit{\addcomma\space}}%
       {\newunit}%
     \iffieldbibstring{edition}
       {\bibstring{\thefield{edition}}}
       {\ifstrequal{#1}{noformat}
          {\printfield[noformat]{edition}}%
          {\printfield{edition}}}}}

\newbibmacro*{date+loc+etc}{%
  \ifboolexpr{ test {\iflistundef{location}}
               and test {\iflistundef{publisher}}}
    {\newunit
     \usebibmacro{reflist+year+day}%
     \printdate}%
    {\iffieldundef{origtitle}
       {\iftoggle{bibliography}
          {\newunit
           \usebibmacro{orig+etc}}%
          {\setunit{\addspace}% not '\setunit{\space}'
           \printtext[parens]{\usebibmacro{orig+etc}}}}
       {\newunit
        \usebibmacro{loc+pub+etc}{}%
        \setunit{\addcomma\space}%
        \usebibmacro{year+bookyear}}}}

\newbibmacro*{test:bookauthor}{%
  \ifboolexpr{ test {\ifnamesequal{author}{bookauthor}}
               or test {\ifnamesequal{afterword}{bookauthor}}
               or test {\ifnamesequal{foreword}{bookauthor}}
               or test {\ifnamesequal{introduction}{bookauthor}}
               or test {\ifnamesequal{preface}{bookauthor}}}
    {\clearname{bookauthor}}%
    {\iftoggle{noauth}
       {\clearname{bookauthor}}%
       {}}}

\newbibmacro*{bybookauthor+pages}{%
  \ifnameundef{bookauthor}
    {}
    {\renewcommand*{\pluga}{%
       \setunit{\addcomma\space}\bibstring{by}\space}%
     \renewcommand*{\cbx@namelist}{bookauthor}%
     \usebibmacro{test:authortypes}{bookauthor}%
     \usebibmacro{printnames+etc}%
     \usebibmacro{pages}}}

\newbibmacro*{chapter+in}{%
  \iftoggle{collection:ib}
    {}
    {\newunit
     \iffieldundef{chapter}
       {\bibstring{in}\space}%
       {\printfield{chapter}\space
        \bibstring{in}\space}}}

\newbibmacro*{incollections}{%
  \iftoggle{collection:ib}
    {\usebibmacro{incollections:ib}}%
    {\ifboolexpr{ togl {collection:icbk}
                  or togl {collection:icib}}
      {\usebibmacro{incollections:ic}}%
      {\usebibmacro{bookbooktitle}{in}%
       \toggletrue{edshift}%
       \usebibmacro{booktitle}%
       \usebibmacro{note+edition+etc}%
       \iffieldundef{volume}
         {\iffieldundef{bookvolume}%
            {\usebibmacro{volumes+series+etc}{bookbook}}%
            {\usebibmacro{volumes+series+etc}{book}}}
         {\usebibmacro{volumes+series+etc}{}}}}
  \usebibmacro{date+loc+etc}%
  \usebibmacro{origtitle}}%

\newbibmacro*{crossref+entrydata}{%
  \renewcommand*{\cbx@deflabel}{labelname}%
  \global\toggletrue{cbx:short}%
  \entrydata{\thefield{crossref}}{%
    \ifboolexpr{ togl {bibliography}
                 and togl {reflist}}
      {\usebibmacro{parencite:new}}%
      {\usebibmacro{author+bookauthor+etc}%
       \usebibmacro{shorttitle+crossref}{ic}}%
    \usebibmacro{cite:volume}}}

\newbibmacro*{pages}{%
  \iffieldundef{pages}
    {}
    {\iftoggle{bibliography}
       {\setunit{\addcomma\space}%
        \printfield{pages}%
        \clearfield{pages}%
        \togglefalse{edshift}}%
       {}}}

\newbibmacro*{loc+pub+year}{%
  \usebibmacro{loc+pub+etc}{}%
  \iffieldundef{pubstate}
    {\usebibmacro{year+month+day}{date}}%
    {\usebibmacro{pubstate}{}}}

% Thanks to David Fussner's biblatex-chicago for pointing me to this
% command by Philipp Lehman. Source:
% https://groups.google.com/forum/#!topic/comp.text.tex/kG003fkZK1I

\newrobustcmd*{\iffieldstart}[2]{%
  \iffieldundef{#1}
    {\@secondoftwo}% originally '\@gobbletwo'
    {\begingroup
     \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}}%

\newbibmacro*{series+seriesaddon}{%
  \printfield{series}%
  \usebibmacro{seriesaddon}%
  \ifterm
    {\printunit{\isdot\addcomma\space}}%
    {\setunit{\addcomma\space}}%
  \usebibmacro{editors:c}{series}}%

\newbibmacro*{unpublished:note+etc}{%
  \ifboolexpr{ test {\ifentrytype{unpublished}}
               and not test {\iffieldundef{collection}}}
    {\usebibmacro{note}%
     \usebibmacro{editors:b}%
     \usebibmacro{unpublished:series}%
     \newunit
     \printfield{volume}%
     \newunit
     \usebibmacro{inst+loc+date}}%
    {}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Fourth and Higher Tier Macros  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newbibmacro*{eid}{%
  \iffieldundef{eid}
    {}
    {\iftoggle{bibliography}
       {\setunit{\addcolon\space}}%
       {\newunit}%
     \printfield{eid}}}

\newbibmacro*{urldate+url}{%
  \iffieldundef{url}
    {}
    {\iftoggle{url}
       {\printurldate
        \newunit
        \printfield{url}}%
       {}}}

\newbibmacro*{doi}{%
  \iffieldundef{doi}
    {}
    {\iftoggle{doi}
       {\printfield{doi}}%
       {}}}

\newbibmacro*{eprint+etc}{%
  \iffieldundef{eprint}
    {}
    {\iftoggle{eprint}
       {\usebibmacro{eprint}}%
       {}}}

\newbibmacro*{volumes}{%
  \iffieldundef{volumes}
    {}
    {\ifboolexpr{ togl {collection}
                  or ( not togl {bibliography}
                  and not togl {listvols}
                  and not test {\iffieldundef{postnote}} )}
       {}
       {\newunit
        \printfield{volumes}%
        \clearfield{volumes}}}}

\newbibmacro*{book:series}{%
  \iffieldundef{series}
    {}
    {\usebibmacro{pages}%
     \newunit
     \usebibmacro{series+seriesaddon}}}

\newbibmacro*{swapvol+pages}{%
  \ifboolexpr{ togl {collection}
               and togl {swapvol}}
    {}
    {\usebibmacro{pages}}}

\newbibmacro*{volume:number}{%
  \iffieldundef{number}
    {}
    {\addcomma\space
     \printfield[journum]{number}%
     \clearfield{number}}}

\newbibmacro*{book:number}{%
  \iffieldundef{number}
    {}
    {\ifentrytype{letter}
       {\usebibmacro{letter:number}}%
       {\usebibmacro{other:number}}}}

\newbibmacro*{letter:number}{%
  \iftoggle{bibliography}
    {\setunit{\addcomma\space}%
     \printfield[journum]{number}}%
    {}}

\newbibmacro*{other:number}{%
  \ifboolexpr{ test {\ifinlist{series}{\edtypes}}
               or test {\ifinlist{series}{\transtypes}}}
    {\setunit{\addcomma\space}%
     \printfield{number}}%
    {\setunit{\addspace}% not '\setunit{\space}'
     \printfield{number}}}

\newbibmacro*{orig+etc}{%
  \usebibmacro{loc+pub+etc}{orig}%
  \ifboolexpr{ togl {bibliography}
               and togl {reflist}}
    {}
    {\usebibmacro{year+endyear}{orig}}%
  \usebibmacro{reprint}%
  \usebibmacro{loc+pub+etc}{}%
  \setunit{\addcomma\space}%
  \usebibmacro{year+bookyear}}%

\newbibmacro*{reprint}{%
  \ifboolexpr{ test {\iffieldundef{origyear}}
               and test {\iflistundef{origpublisher}}
               or togl {noreprint}}
    {}
    {\iftoggle{bibliography}
       {\newunit}%
       {\setunit{\addsemicolon\space}}%
     \bibstring{reprint}%
     \addcomma\space}}%

\newbibmacro*{incollections:ib}{%
  \iftoggle{swapvol}
    {\usebibmacro{note}%
     \usebibmacro{edition}{}%
     \usebibmacro{volumes+series+etc}{}%
     \usebibmacro{title+titleaddon}{}%
     \toggletrue{edshift}%
     \usebibmacro{byauthor}%
     \usebibmacro{editors:b}}%
    {\usebibmacro{volume+number+etc}{}%
     \toggletrue{edshift}%
     \usebibmacro{booktitle}%
     \usebibmacro{note+edition+etc}%
     \usebibmacro{volumes+series+etc}{}}}

\newbibmacro*{incollections:ic}{%
  \iftoggle{swapvol}
    {\iftoggle{collection:icbk}
       {\usebibmacro{maintitle+note+etc}}%
       {\usebibmacro{bookbooktitle}{}%
        \toggletrue{edshift}%
        \usebibmacro{note+edition+etc}}%
     \usebibmacro{volumes+series+etc}{book}%
     \toggletrue{edshift}%
     \usebibmacro{booktitle}%
     \usebibmacro{editors:b}}%
    {\toggletrue{edshift}%
     \usebibmacro{booktitle}%
     \usebibmacro{editors:b}%
     \usebibmacro{volume+number+etc}{book}%
     \iftoggle{collection:icbk}
       {\usebibmacro{maintitle+note+etc}}%
       {\usebibmacro{bookbooktitle}{}%
        \toggletrue{edshift}%
        \usebibmacro{note+edition+etc}}%
     \usebibmacro{volumes+series+etc}{book}}}

\newbibmacro*{seriesaddon}{%
  \iffieldundef{seriesaddon}
    {}
    {\ifterm
       {\printunit{\isdot\addcomma\space}}%
       {\setunit{\addcomma\space}}%
     \printfield{seriesaddon}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Bibliography Drivers  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DeclareBibliographyDriver{shorthand}{%
  \usedriver
    {\DeclareNameAlias{author}{sortname}}%
    {\thefield{entrytype}}%
  \iftoggle{annotate}
    {\global\togglefalse{annotate}%
     \usebibmacro{pageref+finentry}%
     \global\toggletrue{annotate}}%
    {\usebibmacro{pageref+finentry}}}

\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{newauth}%
  \usebibmacro{author+title+etc}%
  \usebibmacro{articles}%
  \usebibmacro{colon+pages+etc}%
  \usebibmacro{doi+finentry+etc}}%

\DeclareBibliographyDriver{artwork}{%
  \usebibmacro{bibindex}%
  \usebibmacro{artworks}%
  \usebibmacro{doi+finentry+etc}}%

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author+collection+etc}%
  \usebibmacro{doi+finentry+etc}}%

\DeclareBibliographyDriver{incollection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author+incollection+etc}%
  \usebibmacro{crossref+incollections}%
  \usebibmacro{doi+finentry+etc}}%

\DeclareBibliographyDriver{misc}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author+bookauthor+etc}%
  \usebibmacro{title+labeldate}%
  \newunit
  \printfield{userb}%
  \usebibmacro{doi+finentry+etc}}%

\DeclareBibliographyDriver{online}{%
  \usebibmacro{bibindex}%
  \usebibmacro{newauth}%
  \usebibmacro{author+title+etc}%
  \newunit
  \usebibmacro{websites}%
  \usebibmacro{issue+month+etc}{parens}%
  \usebibmacro{doi+finentry+etc}}%

\DeclareBibliographyDriver{patent}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author+title+etc}%
  \newunit
  \printfield{number}%
  \newunit
  \printfield{addendum}%
  \usebibmacro{pageref+finentry}}%

\DeclareBibliographyDriver{review}{%
  \usebibmacro{bibindex}%
  \usebibmacro{newauth}%
  \usebibmacro{reviews}%
  \usebibmacro{articles}%
  \usebibmacro{colon+pages+etc}%
  \usebibmacro{doi+finentry+etc}}%

\DeclareBibliographyDriver{standard}{%
  \usebibmacro{bibindex}%
  \usebibmacro{standards}%
  \usebibmacro{doi+finentry+etc}}%

\DeclareBibliographyDriver{thesis}{%
  \usebibmacro{bibindex}%
  \usebibmacro{author+title+etc}%
  \newunit
  \usebibmacro{thesis:type+pubstate}%
  \usebibmacro{inst+loc+date}%
  \usebibmacro{doi+finentry+etc}}%

\DeclareBibliographyDriver{unpublished}{%
  \usebibmacro{bibindex}%
  \iffieldundef{collection}
    {\usebibmacro{author+title+etc}%
     \newunit
     \usebibmacro{type+typeaddon}%
     \usebibmacro{pubstate}{}%
     \usebibmacro{unpublished:series}%
     \usebibmacro{inst+loc+date}}%
    {\usebibmacro{manuscripts}}%
  \usebibmacro{doi+finentry+etc}}%

\endinput
