\ProvidesFile{biblatex-ms.def}
[\abx@cptid]

% ------------------------------------------------------------------
% FORMATTING COMMANDS
% ------------------------------------------------------------------

% Generic formatting commands and hooks
% ------------------------------------------------------------------

% Used in citations, bibliography and bibliography lists

% Define namepart keys from datamodel constant list
% \namepart<namepart>   -> \namepartfamily
% \namepart<namepart>i  -> \namepartfamilyi
% \namepart<namepart>un -> \namepartfamilyun
\def\do#1{%
  \csdef{mkbibname#1}##1{##1}%
  \blx@kv@defkey{blx@opt@namepart}{#1}{\csdef{namepart#1}{##1}}%
  \blx@kv@defkey{blx@opt@namepart}{#1i}{\csdef{namepart#1i}{##1}}%
  \blx@kv@defkey{blx@opt@namepart}{#1un}{\csdef{namepart#1un}{##1}}}
\expandafter\docsvlist\expandafter{\blx@datamodel@constant@nameparts}

% legacy aliases
% set empty defaults so we can check if they have been redefined
\let\mkbibnamefirst\@empty
\let\mkbibnamelast\@empty
\let\mkbibnameaffix\@empty

\AtEndPreamble{%
  \ifdefempty\mkbibnamelast
    {\let\@mkbibnamelastsaved\mkbibnamefamily}% not redefined by user
    {\blx@warning@noline{%
       Attempt to redefine deprecated '\string\mkbibnamelast'.\MessageBreak
       Please use '\string\mkbibnamefamily' instead.\MessageBreak
       Using '\string\mkbibnamefamily'}%
     \let\@mkbibnamelastsaved\mkbibnamelast
     \let\mkbibnamefamily\@mkbibnamelastsaved}%
  % Now redefine it in case it's used
  \def\mkbibnamelast{%
    \blx@warning@noline{%
      '\string\mkbibnamelast' is deprecated.\MessageBreak
       Please use '\string\mkbibnamefamily'.\MessageBreak
       Using '\string\mkbibnamefamily'}%
    \@mkbibnamelastsaved}

  \ifdefempty\mkbibnamefirst
    {\let\@mkbibnamefirstsaved\mkbibnamegiven}% not redefined by user
    {\blx@warning@noline{%
       Attempt to redefine deprecated '\string\mkbibnamefirst'.\MessageBreak
       Please use '\string\mkbibnamegiven' instead.\MessageBreak
       Using '\string\mkbibnamegiven'}%
     \let\@mkbibnamefirstsaved\mkbibnamefirst
     \let\mkbibnamegiven\@mkbibnamefirstsaved}%
  % Now redefine it in case it's used
  \def\mkbibnamefirst{%
    \blx@warning@noline{%
      '\string\mkbibnamefirst' is deprecated.\MessageBreak
       Please use '\string\mkbibnamegiven'.\MessageBreak
       Using '\string\mkbibnamegiven'}%
    \@mkbibnamefirstsaved}

  \ifdefempty\mkbibnameaffix
    {\let\@mkbibnameaffixsaved\mkbibnamesuffix}% not redefined by user
    {\blx@warning@noline{%
       Attempt to redefine deprecated '\string\mkbibnameaffix'.\MessageBreak
       Please use '\string\mkbibnamesuffix' instead.\MessageBreak
       Using '\string\mkbibnamesuffix'}%
     \let\@mkbibnameaffixsaved\mkbibnameaffix
     \let\mkbibnamesuffix\@mkbibnameaffixsaved}%
  % Now redefine it in case it's used
  \def\mkbibnameaffix{%
    \blx@warning@noline{%
      '\string\mkbibnameaffix' is deprecated.\MessageBreak
       Please use '\string\mkbibnamesuffix'.\MessageBreak
       Using \string\mkbibnamesuffix}%
    \@mkbibnameaffixsaved}}

\newcommand*{\bibellipsis}{[\textellipsis\unkern]\midsentence}

% Delimiters used in citations, bibliography and bibliography lists
\DeclareDelimFormat{multinamedelim}{\addcomma\space}
\DeclareDelimFormat{finalnamedelim}{%
  \ifnumgreater{\value{liststop}}{2}{\finalandcomma}{}%
  \addspace\bibstring{and}\space}
\DeclareDelimFormat{revsdnamedelim}{}
\DeclareDelimFormat{andothersdelim}{\addspace}

\DeclareDelimFormat{multilistdelim}{\addcomma\space}
\DeclareDelimFormat{finallistdelim}{%
  \ifnumgreater{\value{liststop}}{2}{\finalandcomma}{}%
  \addspace\bibstring{and}\space}
\DeclareDelimFormat{andmoredelim}{\addspace}

\newcommand*{\multicitedelim}{\addsemicolon\space}
\newcommand*{\multicitesubentrydelim}{\addcomma}
\newcommand*{\multiciterangedelim}{\bibrangedash}
\newcommand*{\multicitesubentryrangedelim}{\multiciterangedelim}

\newcommand*{\compcitedelim}{\addcomma\space}

\newcommand*{\supercitedelim}{\addcomma}
\newcommand*{\supercitesubentrydelim}{\supercitedelim}
\newcommand*{\superciterangedelim}{\bibrangedash}
\newcommand*{\supercitesubentryrangedelim}{\superciterangedelim}

\DeclareDelimFormat{prenotedelim}{\addspace}
\DeclareDelimFormat{postnotedelim}{\addcomma\space}
\DeclareDelimAlias{multiprenotedelim}{prenotedelim}
\DeclareDelimAlias{multipostnotedelim}{postnotedelim}
\DeclareDelimFormat{extpostnotedelim}{\addspace}
\newcommand*{\volcitedelim}{\addcomma\space}
\newcommand*{\textcitedelim}{%
  \iffinalcitedelim
    {\ifnumgreater{\value{textcitetotal}}{2}
       {\iftextcitepunct{\finalandsemicolon}{\finalandcomma}}{}%
     \addspace\bibstring{and}}
    {\iftextcitepunct{\addsemicolon}{\addcomma}}%
  \space}


% context-sensitive delimiters
% retain compatibility with \labelnamepunct et al.
% The seemingly redundant definitions are needed because
% hard-coded punctuation was replaced by context-sensitive
% delimiters, changes to here need to be made explicitly
% to avoid unwanted effects of redefining the global delimiter.
\DeclareDelimFormat{authortypedelim}{\addcomma\space}
\DeclareDelimFormat{editortypedelim}{\addcomma\space}
\DeclareDelimFormat{translatortypedelim}{\addcomma\space}
\DeclareDelimFormat{namelabeldelim}{\addspace}
\DeclareDelimFormat{nametitledelim}{\addcomma\space}
\DeclareDelimFormat[bib,biblist]{nametitledelim}{\labelnamepunct}
\DeclareDelimFormat[textcite]{nametitledelim}{\addspace}
\DeclareDelimFormat{nameyeardelim}{\addspace}
\DeclareDelimFormat[textcite]{nameyeardelim}{\addspace}
\DeclareDelimFormat[bib,biblist]{nameyeardelim}{\addspace}
\DeclareDelimFormat{nonameyeardelim}{\addspace}
\DeclareDelimFormat[textcite]{nonameyeardelim}{\addspace}
\DeclareDelimFormat[bib,biblist]{nonameyeardelim}{\addspace}
\DeclareDelimFormat{dateeradelim}{\addspace}
\DeclareDelimFormat{datecircadelim}{\addspace}

% This is a provisional definition for \iffinalcitedelim{<true>}{<false>}, a
% test that should expand <true> if the next non-compact citation delimiter
% is the last one in the citation list printed by \textcite or \textcites.
\newcommand*{\iffinalcitedelim}{\@secondoftwo}

% Expand <true> if the citation labels in the citation list printed by \textcite
% or \textcites contains the serial comma \finalandcomma
\newcommand*{\iftextcitepunct}{%
  \ifboolexpr{ not test {\ifdefempty{\finalandsemicolon}}
    and test {\ifnumgreater{\value{textcitemaxnames}}{2}} }}

% Counters for the number of citation labels separated by non-compact delimiters
% in the citation list printed by \textcite or \textcites. Counter values should
% be managed by the citation style.
\newcounter{textcitecount}
\newcounter{textcitetotal}
\setcounter{textcitecount}{0}
\setcounter{textcitetotal}{0}

% Counters for the maximum number of names among citation labels in the citation
% list printed by \textcite or \textcites. Counter value should be managed by
% the citation style.
\newcounter{textcitemaxnames}
\setcounter{textcitemaxnames}{0}

% Used in the bibliography and bibliography lists

\newcommand*{\newunitpunct}{\addperiod\space}
\newcommand*{\entrysetpunct}{\addsemicolon\space}
\newcommand*{\finentrypunct}{\addperiod}
\newcommand*{\labelnamepunct}{\newunitpunct}
\newcommand*{\subtitlepunct}{\newunitpunct}
\newcommand*{\intitlepunct}{\addcolon\space}
\newcommand*{\bibpagespunct}{\addcomma\space}
\newcommand*{\bibeidpunct}{\addcomma\space}
\newcommand*{\bibpagerefpunct}{\addspace}
\newcommand*{\revsdnamepunct}{\addcomma}
\newcommand*{\bibnamedash}{%
  \ifdimless{\leftmargin}{0.75em}
    {\mbox{\textemdash\space}}
    {\makebox[\leftmargin][l]{%
       \ifdimless{\leftmargin}{1.25em}
         {\textendash}
         {\textemdash}}}}
\newcommand*{\relatedpunct}{\addspace}
\newcommand*{\relateddelim}{\adddot\par\nobreak}
\newcommand*{\begrelateddelim}{\newunitpunct}
\newcommand*{\begrelateddelimmultivolume}{\newunitpunct\par\nobreak}
% Examples of use, uncommenting these would break backwards compatibility
%\newcommand*{\begrelateddelimorigpubin}{\addspace}
%\newcommand*{\begrelateddelimorigpubas}{\addspace}
\newcommand{\mkrelatedstringtext}{\textmainlang}

% Used for indexing

\newcommand*{\bibindexnamedelima}{ }
\newcommand*{\bibindexnamedelimb}{ }
\newcommand*{\bibindexnamedelimc}{ }
\newcommand*{\bibindexnamedelimd}{ }
\newcommand*{\bibindexnamedelimi}{ }
\newcommand*{\bibindexinitperiod}{.}
\newcommand*{\bibindexinitdelim}{ }
\newcommand*{\bibindexinithyphendelim}{.-}

% \bibsetup is a generic hook controlling the (low-level) layout of
% the bibliography and bibliography lists. The default
% definition should work fine in most cases.
% There are a few other penalties and parameters that could be adjusted
% here, but we don't do that by default for backwards compatibility
% reasons.
% * \finalhyphendemerits can be set to 0 to allow hyphenation
%   in the penultimate line

\newcommand*{\bibsetup}{%
  \interlinepenalty=5000\relax
  \widowpenalty=10000\relax
  \clubpenalty=10000\relax
  \raggedbottom
  \frenchspacing
  \biburlsetup}

% The penalties above are not specific to biblatex. These are
% low-level TeX features. \interlinepenalty is the penalty assigned
% to page breaks within a paragraph (i.e., in this case, a
% bibliography entry); \clubpenalty is an additional penalty
% assigned to page breaks after the first line of a paragraph;
% \widowpenalty is an additional penalty assigned to page breaks
% before the last line of a paragraph. Note that the value 10000
% means 'infinite' as far as TeX is concerned. Setting a penalty to
% 10000 will unconditionally suppress the respective breakpoint.
%
% The net effect of the above settings is as follows. Breaking a
% bibliography entry across pages is discouraged, but not suppressed
% altogether. If a bibliography entry spans less than four lines,
% TeX will always keep it on one page. If it spans four or more
% lines, it may be broken across pages, provided that there are at
% least two lines on the page before and after the break.
%
% These penalties should normally be used in conjunction with
% \raggedbottom. If you don't like that and remove \raggedbottom
% from the definition of \bibsetup, make sure to provide some
% stretchability between bibliography entries by setting \bibitemsep
% to a suitable value, e.g.:
%
% \setlength{\bibitemsep}{0.5\baselineskip plus 0.5\baselineskip}
%
% Using \frenchspacing in the bibliography is recommended. If you
% want more visual separation, try the package option 'block=space'.
% This will yield better results than \nonfrenchspacing.

% If \frenchspacing is removed here, it may also have to be removed
% from \blx@beglang@spacefactors, for example with
% \let\blx@beglang@spacefactors\@empty

% \citesetup is a generic hook for citations.

\newcommand*{\citesetup}{%
  \biburlsetup}

% Local setup for \url; see comments in url.sty for details.

\newcounter{biburlbigbreakpenalty}
\newcounter{biburlbreakpenalty}
\newcounter{biburlnumpenalty}
\newcounter{biburlucpenalty}
\newcounter{biburllcpenalty}

\setcounter{biburlbigbreakpenalty}{100}
\setcounter{biburlbreakpenalty}{200}

\newmuskip\biburlbigskip
\newmuskip\biburlnumskip
\newmuskip\biburlucskip
\newmuskip\biburllcskip

% I'd have preferred \setlength here, but calc does not support
% muglue (yet?).
% https://github.com/plk/biblatex/issues/889
% See also https://tex.stackexchange.com/q/188215/
\biburlbigskip=0mu plus 3mu\relax
\biburlnumskip=0mu\relax
\biburlucskip=0mu\relax
\biburllcskip=0mu\relax

\newcommand*{\biburlsetup}{%
  \Urlmuskip\biburlbigskip
  \mathchardef\UrlBigBreakPenalty=\value{biburlbigbreakpenalty}\relax
  \mathchardef\UrlBreakPenalty=\value{biburlbreakpenalty}\relax
  \def\UrlBigBreaks{\do\:\do\-}%
  \def\UrlBreaks{%
    \do\.\do\@\do\/\do\\\do\!\do\_\do\|\do\;\do\>\do\]\do\)\do\}%
    \do\,\do\?\do\'\do\+\do\=\do\#\do\$\do\&\do\*\do\^\do\"}%
  \ifnumgreater{\value{biburlnumpenalty}}{0}
    {\def\do##1{%
       \appto\UrlSpecials{%
         \do##1{%
           \mathchar`##1
           \mskip\biburlnumskip
           \penalty\value{biburlnumpenalty}}}}%
     \do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\0}
    {}%
  \ifnumgreater{\value{biburlucpenalty}}{0}
    {\def\do##1{%
       \appto\UrlSpecials{%
         \do##1{%
           \mathchar`##1
           \mskip\biburlucskip
           \penalty\value{biburlucpenalty}}}}%
     \do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J
     \do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T
     \do\U\do\V\do\W\do\X\do\Y\do\Z}
    {}%
  \ifnumgreater{\value{biburllcpenalty}}{0}
    {\def\do##1{%
       \appto\UrlSpecials{%
         \do##1{%
           \mathchar`##1
           \mskip\biburllcskip
           \penalty\value{biburllcpenalty}}}}%
     \do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j
     \do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t
     \do\u\do\v\do\w\do\x\do\y\do\z}
    {}%
  \let\do=\noexpand}

% The above code allows linebreaks before numbers and letters.
% This is often the only way to break DOIs. It also allows breaks
% after hyphens and adjusts \Urlmuskip to add some stretchability
% to URLs.

% The default font of the bibliography and the bibliography lists.
% We simply reset the current font to the global defaults.

\newcommand*{\bibfont}{\normalfont\normalsize}

% Some length registers which may be used to fine-tune the
% (high-level) layout of the bibliography.

% Default \bibhang to 1em if \parindent is 0 for some reason
\setlength{\bibhang}{\ifnumequal{\parindent}{0}{1em}{\parindent}}
\setlength{\biblabelsep}{2\labelsep}
\setlength{\bibitemsep}{\itemsep}
\setlength{\bibnamesep}{0pt}
\setlength{\bibinitsep}{0pt}
\setlength{\bibparsep}{0pt}

% Miscellaneous facilities
% ------------------------------------------------------------------

% The counter 'abbrvpenalty' holds the penalty used in short or
% abbreviated bibliography strings. For example, a linebreak in
% expressions such as "et al." or "ed. by" is unfortunate, but should
% still be possible to prevent overfull boxes. We use TeX's
% \hyphenpenalty (normally 50) as the default value. The idea is
% making TeX treat the whole expression as if it were a single,
% hyphenatable word as far as line-breaking is concerned. If you
% dislike such linebreaks, use a higher value. If you do not mind
% them at all, set this counter to zero. If you want to suppress them
% unconditionally, set it to 10000.
\defcounter{abbrvpenalty}{\hyphenpenalty}

% The counter 'highnamepenalty' also holds a penalty affecting the
% line-breaking of names. This penalty is inserted between smaller
% chunks of a name, for example between the first and the middle
% name. The default value is \hyphenpenalty. If you dislike such
% linebreaks, use a higher value. If you do not mind them at all,
% set this counter to zero. If you prefer the traditional BibTeX
% behavior, set it to 10000.
\defcounter{highnamepenalty}{\hyphenpenalty}

% The counter 'lownamepenalty' holds a penalty which affects the
% line-breaking of names. This penalty is inserted between larger
% chunks of a name, for example between the chunk consisting of all
% first names and the last name. The default value is half the
% \hyphenpenalty. If you dislike such linebreaks, use a higher
% value. If you do not mind them at all, set this counter to zero.
\defcounter{lownamepenalty}{\hyphenpenalty/2}

% Note that default values assigned to the above counters are
% deliberately very low to prevent overfull boxes. This implies that
% you will hardly notice any effect on line-breaking if the text is
% set justified. If you set these counters to 10000 to suppress the
% respective breakpoints, you will notice their effect but you may
% also be confronted with overfull boxes. Keep in mind that
% line-breaking in the bibliography is often more difficult than in
% the body text and that you can not resort to rephrasing a
% sentence. In some cases it may be preferable to set the entire
% bibliography \raggedright (by modifying \bibsetup) to prevent
% suboptimal linebreaks. In this case, even the very low default
% penalties will make a visible difference.

% File name prefixes for external abstracts and annotations
\newcommand*{\bibabstractprefix}{bibabstract-}
\newcommand*{\bibannotationprefix}{bibannotation-}

% Print acronyms in small caps if possible
\newcommand*{\mkbibacro}[1]{%
  \ifcsundef{\f@encoding/\f@family/\f@series/sc}
    {#1}
    {\textsc{\MakeLowercase{#1}}}}

% Convert HH to hh for time formatting
\newcommand*{\mktimehh}[1]{%
  \ifnumless{#1}{13}
    {#1}
    {\number\numexpr#1-12\relax}}

% ------------------------------------------------------------------
% ADDITIONAL PACKAGE OPTIONS
% ------------------------------------------------------------------

% Style of compressed page ranges in back references

\DeclareBibliographyOption[string]{backrefstyle}{%
  \ifcsdef{abx@opt@pagerefstyle@#1}
    {\letcs\abx@pagerefstyle{abx@opt@pagerefstyle@#1}}
    {\PackageError{biblatex}
       {Option 'backrefstyle=#1' invalid}
       {The option you have supplied is invalid.\MessageBreak
        See the biblatex manual for valid option keys
        and possible values}}}
\newcommand*{\abx@pagerefstyle}{1}
\csdef{abx@opt@pagerefstyle@none}{-1}
\csdef{abx@opt@pagerefstyle@two}{0}
\csdef{abx@opt@pagerefstyle@three}{1}
\csdef{abx@opt@pagerefstyle@two+}{2}
\csdef{abx@opt@pagerefstyle@three+}{3}
\csdef{abx@opt@pagerefstyle@all+}{4}

% arXiv path/format selector
%
% abs    = abstract page
% ps     = PostScript version
% pdf    = PDF version
% format = format selector

\DeclareBibliographyOption[string]{arxiv}{\def\abx@arxivpath{#1}}
\newcommand*{\abx@arxivpath}{abs}

% ------------------------------------------------------------------
% FIELD FORMATS (#1 is the value of the field)
% ------------------------------------------------------------------

% The fallback used by \printfield

\DeclareFieldFormat{default}{#1}

% The default used by \citefield

\DeclareFieldFormat{citefield}{#1}

% Used in citations

\DeclareFieldFormat{citetitle}{\mkbibemph{#1}}
\DeclareFieldFormat
  [article,inbook,incollection,inproceedings,patent,thesis,unpublished]
  {citetitle}{\mkbibquote{#1\isdot}}
\DeclareFieldFormat
  [suppbook,suppcollection,suppperiodical]
  {citetitle}{#1}
% label{end}year can be a localisation string to allow for "no date" etc.
\DeclareFieldFormat{labelyear}{% = the '1995' part in 'Jones 1995a'
  \ifbibstring{#1}{\bibstring{#1}}{\mkyearzeros{#1}}}
\DeclareFieldFormat{labelendyear}{% = the '1995' part in 'Jones 1995a'
  \ifbibstring{#1}{\bibstring{#1}}{\mkyearzeros{#1}}}
\DeclareFieldFormat{extradate}{%
  \iffieldnums{labelyear}
    {\mknumalph{#1}}
    {\mkbibparens{\mknumalph{#1}}}}
\DeclareFieldFormat{labelalpha}{#1}%
\DeclareFieldFormat{extraalpha}{\mknumalph{#1}}%
\DeclareFieldFormat{shorthand}{#1\isdot}
\DeclareFieldFormat{shorthandintro}{%
  \ifcapital{\MakeCapital{#1}}{#1}\isdot}
% citation commands
\DeclareFieldFormat{prenote}{#1\isdot}
\DeclareFieldFormat{postnote}{\mkpageprefix[pagination][\mknormrange]{#1}}
\DeclareFieldFormat{volcitevolume}{\bibstring{volume}\ppspace#1}
\DeclareFieldFormat{volcitepages}{\mkpageprefix[pagination][\mknormrange]{#1}}
\DeclareFieldFormat{volcitenote}{\mkvolcitenote#1}
\newrobustcmd*{\mkvolcitenote}[2]{%
  \printtext[volcitevolume]{#1}%
  \ifblank{#2}{}{\volcitedelim\printtext[volcitepages]{#2}}}

% multicite commands
\DeclareFieldAlias{multiprenote}{prenote}
\DeclareFieldAlias{multipostnote}{postnote}

% Used by \citeurl

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

% Used in the bibliography and bibliography lists

\DeclareFieldFormat{doi}{%
  \mkbibacro{DOI}\addcolon\space
  \ifhyperref
    {\href{https://doi.org/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}
\DeclareFieldFormat{edition}{%
  \ifinteger{#1}
    {\mkbibordedition{#1}~\bibstring{edition}}
    {#1\isdot}}
\DeclareFieldFormat{eprint}{%
  \iffieldundef{eprinttype}
    {eprint}
    {\thefield{eprinttype}}%
  \addcolon\space
  \ifhyperref
    {\url{#1}}
    {\nolinkurl{#1}}%
  \iffieldundef{eprintclass}
    {}
    {\addspace\mkbibparens{\thefield{eprintclass}}}}
\DeclareFieldFormat{eprint:hdl}{%
  HDL\addcolon\space
  \ifhyperref
    {\href{http://hdl.handle.net/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}
\DeclareFieldAlias{eprint:HDL}{eprint:hdl}
\DeclareFieldFormat{eprint:arxiv}{%
  arXiv\addcolon\space
  \ifhyperref
    {\href{https://arxiv.org/\abx@arxivpath/#1}{%
       \nolinkurl{#1}%
       \iffieldundef{eprintclass}
         {}
         {\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}
    {\nolinkurl{#1}%
     \iffieldundef{eprintclass}
       {}
       {\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}
\DeclareFieldAlias{eprint:arXiv}{eprint:arxiv}
\DeclareFieldFormat{eprint:jstor}{%
  JSTOR\addcolon\space
  \ifhyperref
    {\href{http://www.jstor.org/stable/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}
\DeclareFieldAlias{eprint:JSTOR}{eprint:jstor}
\DeclareFieldFormat{eprint:pubmed}{%
  PMID\addcolon\space
  \ifhyperref
    {\href{http://www.ncbi.nlm.nih.gov/pubmed/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}
\DeclareFieldAlias{eprint:PubMed}{eprint:pubmed}
\DeclareFieldFormat{eprint:googlebooks}{%
  Google Books\addcolon\space
  \ifhyperref
    {\href{http://books.google.com/books?id=#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}
\DeclareFieldAlias{eprint:Google Books}{eprint:googlebooks}
\DeclareFieldFormat{file}{\url{#1}}
\DeclareFieldFormat{isbn}{\mkbibacro{ISBN}\addcolon\space #1}
\DeclareFieldFormat{isrn}{\mkbibacro{ISRN}\addcolon\space #1}
\DeclareFieldFormat{issn}{\mkbibacro{ISSN}\addcolon\space #1}
\DeclareFieldFormat{journaltitle}{\mkbibemph{#1\isdot}}
\DeclareFieldFormat{issuetitle}{\mkbibemph{#1}}
\DeclareFieldFormat{maintitle}{\mkbibemph{#1}}
\DeclareFieldFormat{booktitle}{\mkbibemph{#1}}
\DeclareFieldFormat{chapter}{\bibstring{chapter}~#1}
\DeclareFieldFormat{month}{\mkbibmonth{#1}}
\DeclareFieldFormat{note}{#1\isdot}
\DeclareFieldFormat{number}{#1}% number in a series
\DeclareFieldFormat[article,periodical]{number}{#1}% number of a journal
\DeclareFieldFormat{pages}{\mkpageprefix[bookpagination]{#1}}
\DeclareFieldFormat{pagetotal}{\mkpagetotal[bookpagination]{#1}}
\DeclareFieldFormat{part}{.#1}% physical part of a logical volume
\DeclareFieldFormat{series}{#1}% publication series
\DeclareFieldFormat[article,periodical]{series}{% series of a journal
  \ifinteger{#1}
    {\mkbibordseries{#1}~\bibstring{jourser}}
    {\ifbibstring{#1}{\bibstring{#1}}{#1}}}
\DeclareFieldFormat{pubstate}{\ifbibstring{#1}{\bibstring{#1}}{#1}}
\DeclareFieldFormat{title}{\mkbibemph{#1}}
\DeclareFieldFormat
  [article,inbook,incollection,inproceedings,patent,thesis,unpublished]
  {title}{\mkbibquote{#1\isdot}}
\DeclareFieldFormat
  [suppbook,suppcollection,suppperiodical]
  {title}{#1}
\DeclareFieldFormat{type}{\ifbibstring{#1}{\bibstring{#1}}{#1}}
\DeclareFieldFormat{url}{\mkbibacro{URL}\addcolon\space\url{#1}}
\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{urlseen}\space#1}}
\DeclareFieldFormat{version}{\bibstring{version}~#1}
\DeclareFieldFormat{volume}{\bibstring{volume}~#1}% volume of a book
\DeclareFieldFormat[article,periodical]{volume}{#1}% volume of a journal
\DeclareFieldFormat{volumes}{#1~\bibstring{volumes}}
\DeclareFieldFormat{related}{#1}
\DeclareFieldFormat{related:multivolume}{#1}
\DeclareFieldFormat{related:origpubin}{\mkbibparens{#1}}
\DeclareFieldFormat{related:origpubas}{\mkbibparens{#1}}
\DeclareFieldFormat{relatedstring:default}{#1\printunit{\relatedpunct}}
\DeclareFieldFormat{relatedstring:reprintfrom}{#1\addspace}

% Generic formats for \printtext and \printfield

\DeclareFieldFormat{emph}{\mkbibemph{#1}}
\DeclareFieldFormat{bold}{\mkbibbold{#1}}
\DeclareFieldFormat{smallcaps}{\textsc{#1}}
\DeclareFieldFormat{parens}{\mkbibparens{#1}}
\DeclareFieldFormat{brackets}{\mkbibbrackets{#1}}
\DeclareFieldFormat{bibhyperref}{\bibhyperref{#1}}
\DeclareFieldFormat{bibhyperlink}{\bibhyperlink{\thefield{entrykey}}{#1}}
\DeclareFieldFormat{bibhypertarget}{\bibhypertarget{\thefield{entrykey}}{#1}}
\DeclareFieldFormat{titlecase}{#1}
\DeclareFieldFormat{noformat}{#1}

% ------------------------------------------------------------------
% LITERAL LIST FORMATS (#1 is the current item)
% ------------------------------------------------------------------

% Formatting directives for literal lists
% ------------------------------------------------------------------

\DeclareListWrapperFormat{default}{#1}

% The fallback used by \printlist

\DeclareListFormat{default}{%
  \usebibmacro{list:delim}{#1}%
  \usebibmacro{list:langswitchon}%
  #1\isdot
  \usebibmacro{list:langswitchoff}%
  \usebibmacro{list:andothers}}

% The default used by \citelist

\DeclareListAlias{citelist}{default}
\DeclareListWrapperAlias{citelist}{default}

% Used in the bibliography

\DeclareListFormat{publisher}{%
  \usebibmacro{list:delim}{#1}%
  \usebibmacro{list:langswitchon}%
  #1\isdot
  \usebibmacro{list:langswitchoff}%
  \usebibmacro{list:andothers}}

\DeclareListFormat{language}{%
  \usebibmacro{list:delim}{%
    \ifbibstring{#1}
      {\bibxstring{#1}}
      {\ifbibstring{lang#1}
         {\bibxstring{lang#1}}
         {#1}}}%
  \usebibmacro{list:langswitchon}%
  \ifbibstring{#1}
    {\bibstring{#1}}
    {\ifbibstring{lang#1}
       {\bibstring{lang#1}}
       {#1}}%
  \usebibmacro{list:langswitchoff}%
  \usebibmacro{list:andothers}}

\DeclareListFormat{origlanguage}{%
  \usebibmacro{list:delim}{%
    \ifbibstring{#1}
      {\bibxstring{#1}}
      {\ifbibstring{lang#1}
         {\bibxstring{lang#1}}
         {#1}}}%
  \usebibmacro{list:langswitchon}%
  \ifbibstring{#1}
    {\bibstring{#1}}
    {\ifbibstring{lang#1}
       {\bibstring{lang#1}}
       {#1}}%
  \usebibmacro{list:langswitchoff}%
  \usebibmacro{list:andothers}}


\DeclareListFormat{lfromoriglanguage}{%
  \begingroup
  \blx@bibstringnormal
  \usebibmacro{list:delim}{%
    \ifbibstring{from#1}
      {\bibxlstring{from#1}}
      {\ifbibstring{lang#1}
         {\bibxlstring{lang#1}}
         {#1}}}%
  \usebibmacro{list:langswitchon}%
  \ifbibstring{from#1}
    {\bibstring{from#1}}
    {\ifbibstring{lang#1}
       {\biblstring{lang#1}}
       {#1}}%
  \usebibmacro{list:langswitchoff}%
  \usebibmacro{list:andothers}%
  \endgroup}

\DeclareListFormat{sfromoriglanguage}{%
  \begingroup
  \blx@bibstringnormal
  \usebibmacro{list:delim}{%
    \ifbibstring{from#1}
      {\bibxsstring{from#1}}
      {\ifbibstring{lang#1}
         {\bibxsstring{lang#1}}
         {#1}}}%
  \usebibmacro{list:langswitchon}%
  \ifbibstring{from#1}
    {\bibstring{from#1}}
    {\ifbibstring{lang#1}
       {\bibsstring{lang#1}}
       {#1}}%
  \usebibmacro{list:langswitchoff}%
  \usebibmacro{list:andothers}%
  \endgroup}

\newbibmacro*{list:langswitchon}{%
  % begin language for list item mslang
  % Overide language from list item langtag annotation
  % This does two checks since only multiscript fields would have such an annotation
  \begingroup
  \ifcsdef{abx@annotation@literal@item@\currentmsform @\currentmslang @\currentlist @mslang@\thelistcount}
  {\edef\blx@tempb{\csuse{abx@annotation@literal@item@\currentmsform @\currentmslang @\currentlist @mslang@\thelistcount}}%
    \edef\blx@tempa{\csuse{blx@msmaplang@\blx@tempb}}%
    \begingroup
    \let\currentmslang\blx@tempb
    \ifdef\blx@thefieldlangenv
    {\iftoggle{blx@autofieldlangstrings}
      {\blx@langsetup{\blx@tempa}% must call this to load the .lbx
        \csuse{abx@extras@\blx@tempa}%
        \csuse{abx@strings@\blx@tempa}}
      {}%
      \blx@hook@initfieldlang
      \csname\blx@thefieldlangenv\expandafter\endcsname\expandafter{\blx@tempa}}
    {}}
  {}}

\newbibmacro*{list:langswitchoff}{%
  \endgroup
  \ifcsdef{abx@annotation@literal@item@\currentmsform @\currentmslang @\currentlist @mslang@\thelistcount}
  {% end language for list mslang
    \ifdef\blx@thefieldlangenv
    {\blx@hook@endfieldlang
      \csname end\blx@thefieldlangenv\endcsname}
    {}%
    \endgroup}
  {}}

\DeclareListFormat{location}{%
  \usebibmacro{list:delim}{#1}%
  \usebibmacro{list:langswitchon}%
  #1\isdot
  \usebibmacro{list:langswitchoff}%
  \usebibmacro{list:andothers}}

\DeclareListFormat[patent]{location}{%
  \usebibmacro{list:plain}%
  \ifbibstring{#1}{\bibstring{#1}}{#1\isdot}%
  \usebibmacro{list:andothers}}

\DeclareListFormat{pageref}{%
  \ifnumless{\abx@pagerefstyle}{0}
    {\usebibmacro{list:plain}%
     \ifhyperref
       {\hyperlink{page.#1}{#1}}
       {#1}}
    {\ifnumequal{\value{listcount}}{1}
       {\usebibmacro{pageref:init}}
       {}%
     \usebibmacro{pageref:comp}{#1}%
     \ifnumequal{\value{listcount}}{\value{liststop}}
       {\usebibmacro{pageref:dump}}
       {}}}

\DeclareListAlias{origlocation}{location}
\DeclareListAlias{origpublisher}{publisher}
\DeclareListAlias{institution}{default}
\DeclareListAlias{organization}{default}

\DeclareListWrapperAlias{origlocation}{location}
\DeclareListWrapperAlias{origpublisher}{publisher}
\DeclareListWrapperAlias{institution}{default}
\DeclareListWrapperAlias{organization}{default}

% Auxiliary macros for list formatting directives
% ------------------------------------------------------------------

\newbibmacro*{list:delim}[1]{%
  \ifnumgreater{\value{listcount}}{\value{liststart}}
    {\ifboolexpr{
       test {\ifnumless{\value{listcount}}{\value{liststop}}}
       or
       test \ifmoreitems
     }
       {\printdelim{multilistdelim}}
       {\lbx@finallistdelim{#1}}}
    {}}

\newbibmacro*{list:plain}{%
  \ifnumgreater{\value{listcount}}{\value{liststart}}
    {\printdelim{multilistdelim}}
    {}}

\newbibmacro*{list:andothers}{%
  \ifboolexpr{
    test {\ifnumequal{\value{listcount}}{\value{liststop}}}
    and
    test \ifmoreitems
  }
    {\ifnumgreater{\value{liststop}}{1}
       {\finalandcomma}
       {}%
     \printdelim{andmoredelim}\bibstring{andmore}}
    {}}

\newbibmacro*{pageref:init}{%
  \let\abx@range@hold=\empty
  \def\abx@range@diff{0}%
  \def\abx@range@prev{-1}%
  \def\abx@range@this{0}%
  \def\abx@range@last{-1}}

\newbibmacro*{pageref:comp}[1]{%
  \numdef\abx@range@prev{\abx@range@prev+1}%
  \ifinteger{#1}
    {\def\abx@range@num{#1}%
     \def\abx@range@this{1}%
     \ifnumequal{\abx@range@this}{\abx@range@last}
       {}
       {\def\abx@range@prev{-1}}}
    {\ifrmnum{#1}
       {\numdef\abx@range@num{\rmntonum{#1}}%
        \def\abx@range@this{2}%
        \ifnumequal{\abx@range@this}{\abx@range@last}
          {}
          {\def\abx@range@prev{-1}}}
       {\undef\abx@range@num
        \def\abx@range@this{0}%
        \def\abx@range@prev{-1}}}%
  \ifdef\abx@range@num
    {\ifnumequal{\abx@range@num}{\abx@range@prev}
       {\def\abx@range@hold{#1}%
        \numdef\abx@range@diff{\abx@range@diff+1}}
       {\usebibmacro{pageref:dump}%
        \ifnumgreater{\abx@range@last}{-1}
          {\printdelim{multilistdelim}}
          {}%
        \ifhyperref
          {\hyperlink{page.#1}{#1}}
          {#1}}%
     \edef\abx@range@prev{\abx@range@num}}
    {\usebibmacro{pageref:dump}%
     \ifnumgreater{\abx@range@last}{-1}
       {\printdelim{multilistdelim}}
       {}%
     \ifhyperref
       {\hyperlink{page.#1}{#1}}
       {#1}%
     \def\abx@range@prev{-1}}%
  \edef\abx@range@last{\abx@range@this}}

\newbibmacro*{pageref:dump}{%
  \ifnumgreater{\abx@range@diff}{0}
    {\ifcase\abx@pagerefstyle\relax % two
       \bibrangedash
       \ifhyperref
         {\hyperlink{page.\abx@range@hold}{\abx@range@hold}}
         {\abx@range@hold}%
     \or % three
       \ifnumless{\abx@range@diff}{2}
         {\printdelim{multilistdelim}}
         {\bibrangedash}%
       \ifhyperref
         {\hyperlink{page.\abx@range@hold}{\abx@range@hold}}
         {\abx@range@hold}%
     \or % two+
       \ifnumless{\abx@range@diff}{2}
         {\sqspace
          \ifhyperref
            {\hyperlink{page.\abx@range@hold}{\bibstring{sequens}}}
            {\bibstring{sequens}}}
         {\bibrangedash
          \ifhyperref
            {\hyperlink{page.\abx@range@hold}{\abx@range@hold}}
            {\abx@range@hold}}%
     \or % three+
       \ifnumless{\abx@range@diff}{2}
         {\sqspace
          \ifhyperref
            {\hyperlink{page.\abx@range@hold}{\bibstring{sequens}}}
            {\bibstring{sequens}}}
         {\ifnumless{\abx@range@diff}{3}
            {\sqspace
             \ifhyperref
               {\hyperlink{page.\abx@range@hold}{\bibstring{sequentes}}}
               {\bibstring{sequentes}}}
            {\bibrangedash
             \ifhyperref
               {\hyperlink{page.\abx@range@hold}{\abx@range@hold}}
               {\abx@range@hold}}}%
     \else % all+
       \ifnumless{\abx@range@diff}{2}
         {\sqspace
          \ifhyperref
            {\hyperlink{page.\abx@range@hold}{\bibstring{sequens}}}
            {\bibstring{sequens}}}
         {\sqspace
          \ifhyperref
            {\hyperlink{page.\abx@range@hold}{\bibstring{sequentes}}}
            {\bibstring{sequentes}}}%
     \fi
     \def\abx@range@diff{0}}
    {}}

% ------------------------------------------------------------------
% NAME LIST FORMATS
% ------------------------------------------------------------------

% Formatting directives for name lists
% ------------------------------------------------------------------

\DeclareNameWrapperFormat{default}{#1}

\DeclareNameFormat{given-family}{%
  \ifgiveninits
    {\usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartprefix}
      {\namepartsuffix}}
    {\usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}}%
  \usebibmacro{name:andothers}}

\DeprecateNameFormatWithReplacement{first-last}{given-family}

\DeclareNameFormat{family-given}{%
  \ifgiveninits
    {\usebibmacro{name:family-given}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartprefix}
      {\namepartsuffix}}
    {\usebibmacro{name:family-given}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}}%
  \usebibmacro{name:andothers}}

\DeprecateNameFormatWithReplacement{last-first}{family-given}


\DeclareNameFormat{family-given/given-family}{%
  \ifnumequal{\value{listcount}}{1}
    {\ifgiveninits
       {\usebibmacro{name:family-given}
         {\namepartfamily}
         {\namepartgiveni}
         {\namepartprefix}
         {\namepartsuffix}}
       {\usebibmacro{name:family-given}
         {\namepartfamily}
         {\namepartgiven}
         {\namepartprefix}
         {\namepartsuffix}}%
     \ifboolexpe{%
       test {\ifdefvoid\namepartgiven}
       and
       test {\ifdefvoid\namepartprefix}}
       {}
       {\usebibmacro{name:revsdelim}}}
    {\ifgiveninits
       {\usebibmacro{name:given-family}
         {\namepartfamily}
         {\namepartgiveni}
         {\namepartprefix}
         {\namepartsuffix}}
       {\usebibmacro{name:given-family}
         {\namepartfamily}
         {\namepartgiven}
         {\namepartprefix}
         {\namepartsuffix}}}%
  \usebibmacro{name:andothers}}

\DeprecateNameFormatWithReplacement{last-first/first-last}{family-given/given-family}

\DeclareNameFormat{initsonly}{%
  \usebibmacro{name:given-family}
    {\namepartfamilyi}
    {\namepartgiveni}
    {\namepartprefixi}
    {\namepartsuffixi}%
  \usebibmacro{name:andothers}}

% Fallback used by \printnames
\DeclareNameAlias{default}{given-family}

% Default used by \citename
\DeclareNameAlias{citename}{default}
\DeclareNameWrapperAlias{citename}{default}

% Used in some citations
\DeclareNameFormat{labelname}{%
  \ifcase\value{uniquename}%
    \usebibmacro{name:family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}%
  \or
    \ifuseprefix
      {\usebibmacro{name:given-family}
        {\namepartfamily}
        {\namepartgiveni}
        {\namepartprefix}
        {\namepartsuffixi}}
      {\usebibmacro{name:given-family}
        {\namepartfamily}
        {\namepartgiveni}
        {\namepartprefixi}
        {\namepartsuffixi}}%
  \or
    \usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}%
  \fi
  \usebibmacro{name:andothers}}

% Used in the bibliography
\DeclareNameAlias{sortname}{family-given/given-family}

\DeclareNameAlias{author}{default}
\DeclareNameAlias{bookauthor}{author}
\DeclareNameAlias{editor}{default}
\DeclareNameAlias{editora}{editor}
\DeclareNameAlias{editorb}{editor}
\DeclareNameAlias{editorc}{editor}
\DeclareNameAlias{translator}{default}

\DeclareNameAlias{byauthor}{default}
\DeclareNameAlias{bybookauthor}{byauthor}
\DeclareNameAlias{byeditor}{default}
\DeclareNameAlias{byeditora}{byeditor}
\DeclareNameAlias{byeditorb}{byeditor}
\DeclareNameAlias{byeditorc}{byeditor}
\DeclareNameAlias{bytranslator}{default}

\DeclareNameAlias{withcommentator}{default}
\DeclareNameAlias{withannotator}{default}
\DeclareNameAlias{withintroduction}{default}
\DeclareNameAlias{withforeword}{default}
\DeclareNameAlias{withafterword}{default}

\DeclareNameWrapperAlias{author}{default}
\DeclareNameWrapperAlias{bookauthor}{author}
\DeclareNameWrapperAlias{editor}{default}
\DeclareNameWrapperAlias{editora}{editor}
\DeclareNameWrapperAlias{editorb}{editor}
\DeclareNameWrapperAlias{editorc}{editor}
\DeclareNameWrapperAlias{translator}{default}

\DeclareNameWrapperAlias{byauthor}{default}
\DeclareNameWrapperAlias{bybookauthor}{byauthor}
\DeclareNameWrapperAlias{byeditor}{default}
\DeclareNameWrapperAlias{byeditora}{byeditor}
\DeclareNameWrapperAlias{byeditorb}{byeditor}
\DeclareNameWrapperAlias{byeditorc}{byeditor}
\DeclareNameWrapperAlias{bytranslator}{default}

\DeclareNameWrapperAlias{withcommentator}{default}
\DeclareNameWrapperAlias{withannotator}{default}
\DeclareNameWrapperAlias{withintroduction}{default}
\DeclareNameWrapperAlias{withforeword}{default}
\DeclareNameWrapperAlias{withafterword}{default}

\DeclareFieldFormat{authortype}{#1}
\DeclareFieldFormat{editortype}{#1}
\DeclareFieldFormat{translatortype}{#1}

% Auxiliary macros for name formatting directives
% ------------------------------------------------------------------

\newcommand{\mkbibcompletename}[1]{#1}

\newcommand{\mkbibcompletenamefamily}{\mkbibcompletename}

\newbibmacro*{name:langswitchon}{%
  % begin language for name list item mslang
  \ifdefempty\blx@nmslang
    {}
    {\let\currentmslang\blx@nmslang
     \edef\blx@nmslang{\csuse{blx@msmaplang@\blx@nmslang}}%
     \ifdef\blx@thefieldlangenv
     {\iftoggle{blx@autofieldlangstrings}
       {\blx@langsetup{\blx@nmslang}% must call this to load the .lbx
         \csuse{abx@extras@\blx@nmslang}%
         \csuse{abx@strings@\blx@nmslang}}
       {}%
       \blx@hook@initfieldlang
       \begingroup
       \csname\blx@thefieldlangenv\expandafter\endcsname\expandafter{\blx@nmslang}}
     {}}}

\newbibmacro*{name:langswitchoff}{%
  \ifdefempty\blx@nmslang
    {}
    {\ifdef\blx@thefieldlangenv
    {\blx@hook@endfieldlang
     \csname end\blx@thefieldlangenv\endcsname
     \endgroup}
    {}}}

\newbibmacro*{name:family}[4]{%
  \ifuseprefix
    {\usebibmacro{name:delim}{#3#1}%
     \usebibmacro{name:hook}{#3#1}%
     \usebibmacro{name:langswitchon}%
     \mkbibcompletenamefamily{%
       \ifdefvoid{#3}
         {}
         {\ifcapital
            {\mkbibnameprefix{\MakeCapital{#3}}\isdot}
            {\mkbibnameprefix{#3}\isdot}%
          \ifprefchar{}{\bibnamedelimc}}%
       \mkbibnamefamily{#1}\isdot}}
    {\usebibmacro{name:delim}{#1}%
     \usebibmacro{name:hook}{#1}%
     \usebibmacro{name:langswitchon}%
     \mkbibcompletenamefamily{%
       \mkbibnamefamily{#1}\isdot}}%
  \usebibmacro{name:langswitchoff}}%
\newbibmacro*{name:last}[4]{% legacy alias
  \blx@warning@noline{%
    'name:last' is deprecated, please use 'name:family'}%
  \usebibmacro{name:family}{#1}{#2}{#3}{#4}}

\newcommand{\mkbibcompletenamegivenfamily}{\mkbibcompletename}

\newbibmacro*{name:given-family}[4]{%
  \usebibmacro{name:delim}{#2#3#1}%
  \usebibmacro{name:hook}{#2#3#1}%
  \usebibmacro{name:langswitchon}%
  \mkbibcompletenamegivenfamily{%
    \ifdefvoid{#2}
      {}
      {\mkbibnamegiven{#2}\isdot\bibnamedelimd}%
    \ifdefvoid{#3}
      {}
      {\mkbibnameprefix{#3}\isdot
       \ifprefchar
         {}
         {\ifuseprefix{\bibnamedelimc}{\bibnamedelimd}}}%
    \mkbibnamefamily{#1}\isdot
    \ifdefvoid{#4}{}{\bibnamedelimd\mkbibnamesuffix{#4}\isdot}}%
  \usebibmacro{name:langswitchoff}}
\newbibmacro*{name:first-last}[4]{% legacy alias
  \blx@warning@noline{%
    'name:first-last' is deprecated, please use 'name:given-family'}%
  \usebibmacro{name:given-family}{#1}{#2}{#3}{#4}}

\newcommand{\mkbibcompletenamefamilygiven}{\mkbibcompletename}

\newbibmacro*{name:family-given}[4]{%
  \ifuseprefix
    {\usebibmacro{name:delim}{#3#1}%
     \usebibmacro{name:hook}{#3#1}%
     \usebibmacro{name:langswitchon}%
     \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}%
     \usebibmacro{name:langswitchon}%
     \mkbibcompletenamefamilygiven{%
       \mkbibnamefamily{#1}\isdot
       \ifdefvoid{#4}
         {}
         {\bibnamedelimd\mkbibnamesuffix{#4}\isdot}%
       \ifboolexpe{%
         test {\ifdefvoid{#2}}
         and
         test {\ifdefvoid{#3}}}
         {}
         {\revsdnamepunct}%
       \ifdefvoid{#2}
         {}
         {\bibnamedelimd\mkbibnamegiven{#2}\isdot}%
       \ifdefvoid{#3}
         {}
         {\bibnamedelimd\mkbibnameprefix{#3}\isdot}}}%
   \usebibmacro{name:langswitchoff}}
\newbibmacro*{name:last-first}[4]{% legacy alias
  \blx@warning@noline{%
    'name:last-first' is deprecated, please use 'name:family-given'}%
  \usebibmacro{name:family-given}{#1}{#2}{#3}{#4}}

\newbibmacro*{name:hook}[1]{%
  \ifnumequal{\value{listcount}}{1}
    {\lbx@initnamehook{#1}}
    {}}

\newbibmacro*{name:delim}[1]{%
  \ifnumgreater{\value{listcount}}{\value{liststart}}
    {\ifboolexpr{
       test {\ifnumless{\value{listcount}}{\value{liststop}}}
       or
       test \ifmorenames
     }
       {\printdelim{multinamedelim}}
       {\lbx@finalnamedelim{#1}}}
    {}}

\newbibmacro*{name:revsdelim}{%
  \ifboolexpr{
    (
      test {\ifnumequal{\value{liststop}}{1}}
      and
      test \ifmorenames
    )
    or
    test {\ifnumequal{\value{liststop}}{2}}
  }
    {\printdelim{revsdnamedelim}}
    {}}

\newbibmacro*{name:andothers}{%
  \ifboolexpr{
    test {\ifnumequal{\value{listcount}}{\value{liststop}}}
    and
    test \ifmorenames
  }
    {\ifnumgreater{\value{liststop}}{1}
       {\finalandcomma}
       {}%
     \printdelim{andothersdelim}\bibstring{andothers}}
    {}}

% ------------------------------------------------------------------
% INDEX FORMATS FOR FIELDS (#1 is the value of the field)
% ------------------------------------------------------------------

% There is no need to test if a field to be indexed is empty because
% \indexfield performs this test implicitly.

% The fallback used by \indexfield

\DeclareIndexFieldFormat{default}{\index{#1}}

% Used in the bibliography and in citations

\DeclareIndexFieldFormat{indextitle}{%
  \usebibmacro{index:title}{\index}{#1}}

\newbibmacro*{index:title}[2]{%
  \usebibmacro{index:field}{#1}{\thefield{indexsorttitle}}{\emph{#2}}}

\newbibmacro*{index:field}[3]{%
  \usebibmacro{index:entry}{#1}{\mkbibindexfield{#2}{#3}}}

% Auxiliary macros for field indexing directives
% ------------------------------------------------------------------

\newbibmacro*{index:entry}[2]{%
  \begingroup
  \protected@edef\theindexentry{\unexpanded{#1}{#2}}%
  \theindexentry
  \endgroup}

\newcommand*{\mkbibindexfield}[2]{\mkbibindexentry{#1}{\unexpanded{#2}}}
\newcommand*{\mkbibindexentry}[2]{#1\actualoperator#2}

% ------------------------------------------------------------------
% INDEX FORMATS FOR LITERAL LISTS (#1 is the current item)
% ------------------------------------------------------------------

% The fallback used by \indexlist

\DeclareIndexListFormat{default}{\index{#1}}

% ------------------------------------------------------------------
% INDEX FORMATS FOR NAME LISTS
% ------------------------------------------------------------------

% Indexing directives for name lists
% ------------------------------------------------------------------

% The fallback used by \indexnames

\DeclareIndexNameFormat{default}{%
  \usebibmacro{index:name}
    {\index}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartprefix}
    {\namepartsuffix}}

% Used in citations

\DeclareIndexNameAlias{labelname}{default}

% Used in the bibliography

\DeclareIndexNameAlias{author}{default}
\DeclareIndexNameAlias{editor}{default}
\DeclareIndexNameAlias{bookauthor}{default}

% Auxiliary macros for name indexing directives
% ------------------------------------------------------------------

% When generating an index entry, we need to test which parts of a
% name are actually available to prevent spurious punctuation and
% spaces.
%
% Note that the standard LaTeX \index command simply writes its
% argument to the .idx file without preventing expansion. This means
% that all \ifblank etc. tests are expanded on the way and will not end
% up in the index. The index package, however, prevents expansion.
% This would lead to \ifblank etc. ending up in the .idx file. To avoid
% that, we preprocess the index entry inside an \edef. We use
% \unexpanded to protect the \index command and the actual data from
% expansion. This definition will work with both index.sty and the
% standard indexing facilities.
%
% We also use \ifuseprefix to ensure that the name prefix is handled
% properly. \actualoperator is the so-called actual operator, as
% defined by the 'actual' specifier in the .ist file. The makeindex
% program will use the part preceeding the \actualoperator
% delimiter for sorting. The part after the delimiter is used as the
% index is printed. Note that this is not specific to biblatex, see
% the makeindex documentation for details.

\newcommand*{\actualoperator}{@}
\newcommand*{\subentryoperator}{!}

\newbibmacro*{index:name}[5]{%
  \usebibmacro{index:entry}{#1}{\mkbibindexname{#2}{#3}{#4}{#5}}}

% {<family name>}{<given name>}{<prefix>}{<suffix>}
\newcommand*{\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
     \ifdefvoid{#4}{}{ #4}%
     \ifboolexpe{%
       test {\ifdefvoid{#2}}
       and
       test {\ifdefvoid{#3}}}
       {}
       {,}%
     \ifdefvoid{#2}{}{ #2}%
     \ifdefvoid{#3}{}{ #3}}}

% {<control sequence>}{<control sequence>}
\newcommand*{\mkbibindexsubentry}[2]{%
  \ifblank{#1}{}{\subentryoperator#1\actualoperator#2}}

% Additional macros with subentries

\newbibmacro*{index:name:field}[6]{%
  \usebibmacro{index:name:subentry}{#1}{#2}{#3}{#4}{#5}
    {\thefield{#6}}{\csfield{#6}}}

\newbibmacro*{index:name:title}[5]{%
  \usebibmacro{index:name:subentry}{#1}{#2}{#3}{#4}{#5}
    {\thefield{indexsorttitle}}{\emph{\csfield{indextitle}}}}

\newbibmacro*{index:name:subentry}[7]{%
  \usebibmacro{index:entry}{#1}{%
    \mkbibindexname{#2}{#3}{#4}{#5}\mkbibindexsubentry{#6}{#7}}}

% ------------------------------------------------------------------
% datafieldsets
% ------------------------------------------------------------------

% Some defaults for backwards compat for the biber nosort option
\DeclareDatafieldSet{setnames}{
  \member[datatype=name, fieldtype=list]
}

\DeclareDatafieldSet{settitles}{
  \member[field=title]
  \member[field=booktitle]
  \member[field=eventtitle]
  \member[field=issuetitle]
  \member[field=journaltitle]
  \member[field=maintitle]
  \member[field=origtitle]
}

% ------------------------------------------------------------------
% Driver sourcemaps
% ------------------------------------------------------------------

\DeclareDriverSourcemap[datatype=bibtex]{
  \map{
    \step[fieldset=day, null]
  }
  \map{
    \step[typesource=conference, typetarget=inproceedings]
    \step[typesource=electronic, typetarget=online]
    \step[typesource=www,        typetarget=online]
  }
  \map{
    \step[typesource=mastersthesis, typetarget=thesis, final]
    \step[fieldset=type,            fieldvalue=mathesis]
  }
  \map{
    \step[typesource=phdthesis, typetarget=thesis, final]
    \step[fieldset=type,        fieldvalue=phdthesis]
  }
  \map{
    \step[typesource=techreport, typetarget=report, final]
    \step[fieldset=type,         fieldvalue=techreport]
  }
  \map{
    \step[fieldsource=hyphenation,   fieldtarget=langid]
    \step[fieldsource=address,       fieldtarget=location]
    \step[fieldsource=school,        fieldtarget=institution]
    \step[fieldsource=annote,        fieldtarget=annotation]
    \step[fieldsource=archiveprefix, fieldtarget=eprinttype]
    \step[fieldsource=journal,       fieldtarget=journaltitle]
    \step[fieldsource=primaryclass,  fieldtarget=eprintclass]
    \step[fieldsource=key,           fieldtarget=sortkey]
    \step[fieldsource=pdf,           fieldtarget=file]
  }
}

% ------------------------------------------------------------------
% META-FIELDS
% ------------------------------------------------------------------

\DeclareLabelname{%
  \field{shortauthor}
  \field{author}
  \field{shorteditor}
  \field{editor}
  \field{translator}
}

\DeclareLabeldate{%
  \field{date}
  \field{year}
  \field{eventdate}
  \field{origdate}
  \field{urldate}
  \literal{nodate}
}

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

\DeclareExtradateContext{%
  \field{labelname}
  \field{labeltitle}
}

\DeclareLabeltitle{%
  \field{shorttitle}
  \field{title}
  \field{maintitle}
}

% ------------------------------------------------------------------
% LABELALPHA TEMPLATE
% ------------------------------------------------------------------

\DeclareLabelalphaTemplate{
  \labelelement{
    \field[final]{shorthand}
    \field{label}
    \field[strwidth=3,strside=left,ifnames=1]{labelname}
    \field[strwidth=1,strside=left]{labelname}
  }
  \labelelement{
    \field[strwidth=2,strside=right]{year}
  }
}

% ------------------------------------------------------------------
% LABELALPHA NAME TEMPLATE
% ------------------------------------------------------------------

\DeclareLabelalphaNameTemplate{
  \namepart[use=true, pre=true, strwidth=1, compound=true]{prefix}
  \namepart{family}
}

% ------------------------------------------------------------------
% UNIQUENAME TEMPLATE
% ------------------------------------------------------------------

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

% ------------------------------------------------------------------
% SORTING
% ------------------------------------------------------------------

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

\DeclarePresort{mm}

\DeclareSortingTemplate{shorthand}{
  \sort[final]{
    \field{sortshorthand}
  }
  \sort{
    \field{shorthand}
  }
}

\DeclareSortingTemplate{none}{
  \sort{\citeorder}
  \sort{\intciteorder}
}

\DeclareSortingTemplate{count}{
  \sort[direction=descending]{\citecount}
}

\DeclareSortingTemplate{debug}{
  \sort{
    \field{entrykey}
  }
}

\DeclareSortingTemplate{nty}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{volume}
    \literal{0}
  }
}

\DeclareSortingTemplate{nyt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{volume}
    \literal{0}
  }
}

\DeclareSortingTemplate{nyvt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{volume}
    \literal{0}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
}

\DeclareSortingTemplate{anyt}{
  \sort{
    \field{presort}
  }
  \sort{
    \field{labelalpha}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{volume}
    \literal{0}
  }
}

\DeclareSortingTemplate{anyvt}{
  \sort{
    \field{presort}
  }
  \sort{
    \field{labelalpha}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{volume}
    \literal{0}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
}

\DeclareSortingTemplate{ynt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortyear}
    \field{year}
    \literal{9999}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
}

\DeclareSortingTemplate{ydnt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort[direction=descending]{
    \field{sortyear}
    \field{year}
    \literal{9999}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
}

% ------------------------------------------------------------------
% DATA INHERITANCE (CROSSREF)
% ------------------------------------------------------------------

\DefaultInheritance{all=true,override=false}

\DeclareDataInheritance{mvbook,book}{inbook,bookinbook,suppbook}{%
  \inherit{author}{author}
  \inherit{author}{bookauthor}
}

\DeclareDataInheritance{mvbook}{book,inbook,bookinbook,suppbook}{%
  \inherit{title}{maintitle}
  \inherit{subtitle}{mainsubtitle}
  \inherit{titleaddon}{maintitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{mvcollection,mvreference}
{collection,reference,incollection,inreference,suppcollection}{%
  \inherit{title}{maintitle}
  \inherit{subtitle}{mainsubtitle}
  \inherit{titleaddon}{maintitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{mvproceedings}{proceedings,inproceedings}{%
  \inherit{title}{maintitle}
  \inherit{subtitle}{mainsubtitle}
  \inherit{titleaddon}{maintitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{book}{inbook,bookinbook,suppbook}{%
  \inherit{title}{booktitle}
  \inherit{subtitle}{booksubtitle}
  \inherit{titleaddon}{booktitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{collection,reference}
{incollection,inreference,suppcollection}{%
  \inherit{title}{booktitle}
  \inherit{subtitle}{booksubtitle}
  \inherit{titleaddon}{booktitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

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

\DeclareDataInheritance{periodical}{article,suppperiodical}{%
  \inherit{title}{journaltitle}
  \inherit{subtitle}{journalsubtitle}
  \inherit{titleaddon}{journaltitleaddon}
  \noinherit{shorttitle}
  \noinherit{sorttitle}
  \noinherit{indextitle}
  \noinherit{indexsorttitle}
}

\DeclareDataInheritance{*}{*}{%
  \noinherit{ids}
  \noinherit{crossref}
  \noinherit{xref}
  \noinherit{entryset}
  \noinherit{entrysubtype}
  \noinherit{execute}
  \noinherit{label}
  \noinherit{options}
  \noinherit{presort}
  \noinherit{related}
  \noinherit{relatedoptions}
  \noinherit{relatedstring}
  \noinherit{relatedtype}
  \noinherit{shorthand}
  \noinherit{shorthandintro}
  \noinherit{sortkey}
  \noinherit{langid}
}

% ------------------------------------------------------------------
% MACROS FOR LBX FILES
% ------------------------------------------------------------------

\newcommand*{\lbx@initnamehook}[1]{}
\newcommand*{\lbx@inittitlehook}[1]{}
\newcommand*{\lbx@finalnamedelim}[1]{\printdelim{finalnamedelim}}
\newcommand*{\lbx@finallistdelim}[1]{\printdelim{finallistdelim}}

\newcommand*{\lbx@lfromlang}{%
  \iflistundef{origlanguage}
    {\unspace}
    {\printlist[lfromoriglanguage]{origlanguage}}}

\newcommand*{\lbx@sfromlang}{%
  \iflistundef{origlanguage}
    {\unspace}
    {\printlist[sfromoriglanguage]{origlanguage}}}

% ------------------------------------------------------------------
% MISCELLANEOUS
% ------------------------------------------------------------------

% ordinals

\newcommand*{\mkbibordedition}{\mkbibordinal}
\newcommand*{\mkbibordseries}{\mkbibordinal}

% american

\newrobustcmd*{\uspunctuation}{%
  \DeclareQuotePunctuation{.,}%
  \DeclarePunctuationPairs{comma}{*}}
\newrobustcmd*{\stdpunctuation}{%
  \DeclareQuotePunctuation{}%
  \DeclarePunctuationPairs{comma}{*!?}}

% catalan and french

\newtoggle{smartof}
\newrobustcmd*{\smartof}{\global\toggletrue{smartof}}
\newrobustcmd*{\forceD}[1]{#1}
\newrobustcmd*{\forceDE}[1]{#1}

\AtBeginDocument{%
  \@ifpackageloaded{babel}
    {\ifdef\AutoSpaceBeforeFDP
       {\newrobustcmd*{\EnsureAutoSpaceBeforeFDP}{%
          \iflanguage{french}
            {\AutoSpaceBeforeFDP}
            {}}%
        \appto\bibsetup{\EnsureAutoSpaceBeforeFDP}%
        \appto\citesetup{\EnsureAutoSpaceBeforeFDP}}
       {}}
    {}}

% spanish

\newcounter{smartand}
\defcounter{smartand}{1}
\newrobustcmd*{\forceY}[1]{#1}
\newrobustcmd*{\forceE}[1]{#1}

% ------------------------------------------------------------------
% PREDEFINED HEADINGS
% ------------------------------------------------------------------

\newcommand*{\abx@classtype}{0}
\@ifclassloaded{article}
 {}
 {\@ifclassloaded{book}
   {\def\abx@classtype{1}}
   {\@ifclassloaded{report}
     {\def\abx@classtype{1}}
     {\@ifclassloaded{scrartcl}
        {\def\abx@classtype{2}}
        {\@ifclassloaded{scrbook}
           {\def\abx@classtype{3}}
           {\@ifclassloaded{scrreprt}
              {\def\abx@classtype{3}}
              {\@ifclassloaded{memoir}
                {\ifbool{artopt}
                   {\def\abx@classtype{4}}
                   {\def\abx@classtype{5}}}
                {\ifundef\chapter
                   {}
                   {\def\abx@classtype{1}}}}}}}}}

\defbibheading{none}{}

\def\abx@MakeMarkcase{\MakeUppercase}
\AtBeginDocument{%
  \ifcsundef{MakeMarkcase}{}{\def\abx@MakeMarkcase{\MakeMarkcase}}}

\ifcase\abx@classtype\relax % article
  \defbibheading{bibliography}[\refname]{%
    \section*{#1}%
    \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
  \defbibheading{biblist}[\biblistname]{%
    \section*{#1}%
    \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
  \defbibheading{bibintoc}[\refname]{%
    \section*{#1}%
    \addcontentsline{toc}{section}{#1}%
    \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
  \defbibheading{biblistintoc}[\biblistname]{%
    \section*{#1}%
    \addcontentsline{toc}{section}{#1}%
    \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
  \defbibheading{bibnumbered}[\refname]{%
    \section{#1}}
  \defbibheading{biblistnumbered}[\biblistname]{%
    \section{#1}}
  \defbibheading{subbibliography}[\refname]{%
    \subsection*{#1}}
  \defbibheading{subbibintoc}[\refname]{%
    \subsection*{#1}%
    \addcontentsline{toc}{subsection}{#1}}
  \defbibheading{subbibnumbered}[\refname]{%
    \subsection{#1}}

\or % book/report
  \defbibheading{bibliography}[\bibname]{%
    \chapter*{#1}%
    \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
  \defbibheading{biblist}[\biblistname]{%
    \chapter*{#1}%
    \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
  \defbibheading{bibintoc}[\bibname]{%
    \chapter*{#1}%
    \addcontentsline{toc}{chapter}{#1}%
    \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
  \defbibheading{biblistintoc}[\biblistname]{%
    \chapter*{#1}%
    \addcontentsline{toc}{chapter}{#1}%
    \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
  \defbibheading{bibnumbered}[\bibname]{%
    \chapter{#1}}
  \defbibheading{biblistnumbered}[\biblistname]{%
    \chapter{#1}}
  \defbibheading{subbibliography}[\refname]{%
    \section*{#1}%
    \if@twoside\markright{\abx@MakeMarkcase{#1}}\fi}
  \defbibheading{subbibintoc}[\refname]{%
    \section*{#1}%
    \addcontentsline{toc}{section}{#1}%
    \if@twoside\markright{\abx@MakeMarkcase{#1}}\fi}
  \defbibheading{subbibnumbered}[\refname]{%
    \section{#1}}

\or % scrartcl
  \defbibheading{bibliography}[\refname]{%
    \ifcsundef{bibliography@heading}
      {\ifkomabibtotocnumbered
         {\section{#1}}
         {\ifkomabibtotoc
            {\addsec{#1}}
            {\section*{#1}%
             \ifcsundef{@mkdouble}
               {\@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
               {\@mkdouble{\abx@MakeMarkcase{#1}}}}}}
      {\bibliography@heading{#1}}}
  \defbibheading{biblist}[\biblistname]{%
    \ifcsundef{bibliography@heading}
      {\ifkomabibtotocnumbered
         {\section{#1}}
         {\ifkomabibtotoc
            {\addsec{#1}}
            {\section*{#1}%
             \ifcsundef{@mkdouble}
               {\@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
               {\@mkdouble{\abx@MakeMarkcase{#1}}}}}}
      {\bibliography@heading{#1}}}
  \defbibheading{bibintoc}[\refname]{%
    \addsec{#1}}
  \defbibheading{biblistintoc}[\biblistname]{%
    \addsec{#1}}
  \defbibheading{bibnumbered}[\refname]{%
    \section{#1}}
  \defbibheading{biblistnumbered}[\biblistname]{%
    \section{#1}}
  \defbibheading{subbibliography}[\refname]{%
    \subsection*{#1}%
    \ifcsundef{@mkright}
      {\ifx\@mkboth\@gobbletwo\else\markright{\abx@MakeMarkcase{#1}}\fi}
      {\@mkright{\abx@MakeMarkcase{#1}}}}
  \defbibheading{subbibintoc}[\refname]{%
    \subsection*{#1}%
    \addcontentsline{toc}{subsection}{#1}%
    \ifcsundef{@mkright}
      {\ifx\@mkboth\@gobbletwo\else\markright{\abx@MakeMarkcase{#1}}\fi}
      {\@mkright{\abx@MakeMarkcase{#1}}}}
  \defbibheading{subbibnumbered}[\refname]{%
    \subsection{#1}}

\or % scrbook/scrreprt
  \defbibheading{bibliography}[\bibname]{%
    \ifcsundef{bibliography@heading}
      {\ifkomabibtotocnumbered
         {\chapter{#1}}
         {\ifkomabibtotoc
            {\addchap{#1}}
            {\chapter*{#1}
             \ifcsundef{@mkdouble}
               {\@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
               {\@mkdouble{\abx@MakeMarkcase{#1}}}}}}
      {\bibliography@heading{#1}}}
  \defbibheading{biblist}[\biblistname]{%
    \ifcsundef{bibliography@heading}
      {\ifkomabibtotocnumbered
         {\chapter{#1}}
         {\ifkomabibtotoc
            {\addchap{#1}}
            {\chapter*{#1}
             \ifcsundef{@mkdouble}
               {\@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
               {\@mkdouble{\abx@MakeMarkcase{#1}}}}}}
      {\bibliography@heading{#1}}}
  \defbibheading{bibintoc}[\bibname]{%
    \addchap{#1}}
  \defbibheading{biblistintoc}[\biblistname]{%
    \addchap{#1}}
  \defbibheading{bibnumbered}[\bibname]{%
    \chapter{#1}}
  \defbibheading{biblistnumbered}[\biblistname]{%
    \chapter{#1}}
  \defbibheading{subbibliography}[\refname]{%
    \section*{#1}%
    \ifcsundef{@mkright}
      {\ifx\@mkboth\@gobbletwo\else\markright{\abx@MakeMarkcase{#1}}\fi}
      {\@mkright{\abx@MakeMarkcase{#1}}}}
  \defbibheading{subbibintoc}[\refname]{%
    \addsec{#1}}
  \defbibheading{subbibnumbered}[\refname]{%
    \section{#1}}

\or % memoir (article)
  \ifcsundef{memUChead}{}{\def\abx@MakeMarkcase{\memUChead}}%
  \defbibheading{bibliography}[\refname]{%
    \chapter*{#1}%
    \if@twoside
      \markboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}%
    \else
      \markright{\abx@MakeMarkcase{#1}}%
    \fi
    \ifmemoirbibintoc
      {\phantomsection
       \addcontentsline{toc}{chapter}{#1}}
      {}}
  \defbibheading{biblist}[\biblistname]{%
    \chapter*{#1}%
    \if@twoside
      \markboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}%
    \else
      \markright{\abx@MakeMarkcase{#1}}%
    \fi
    \ifmemoirbibintoc
      {\phantomsection
       \addcontentsline{toc}{chapter}{#1}}
      {}}
  \defbibheading{bibintoc}[\refname]{%
    \chapter*{#1}%
    \if@twoside
      \markboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}%
    \else
      \markright{\abx@MakeMarkcase{#1}}%
    \fi
    \phantomsection
    \addcontentsline{toc}{chapter}{#1}}
  \defbibheading{biblistintoc}[\biblistname]{%
    \chapter*{#1}%
    \if@twoside
      \markboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}%
    \else
      \markright{\abx@MakeMarkcase{#1}}%
    \fi
    \phantomsection
    \addcontentsline{toc}{chapter}{#1}}
  \defbibheading{bibnumbered}[\refname]{%
    \chapter{#1}}
  \defbibheading{biblistnumbered}[\biblistname]{%
    \chapter{#1}}
  \defbibheading{subbibliography}[\refname]{%
    \section*{#1}%
    \if@twoside\markright{\abx@MakeMarkcase{#1}}\fi
    \ifmemoirbibintoc
      {\phantomsection
       \addcontentsline{toc}{section}{#1}}
      {}}
  \defbibheading{subbibintoc}[\refname]{%
    \section*{#1}%
    \if@twoside\markright{\abx@MakeMarkcase{#1}}\fi
    \phantomsection
    \addcontentsline{toc}{section}{#1}}
  \defbibheading{subbibnumbered}[\refname]{%
    \section{#1}}

\or % memoir (book)
  \ifcsundef{memUChead}{}{\def\abx@MakeMarkcase{\memUChead}}%
  \defbibheading{bibliography}[\bibname]{%
    \chapter*{#1}%
    \if@twoside
      \markboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}%
    \else
      \markright{\abx@MakeMarkcase{#1}}%
    \fi
    \ifmemoirbibintoc
      {\phantomsection
       \addcontentsline{toc}{chapter}{#1}}
      {}}
  \defbibheading{biblist}[\biblistname]{%
    \chapter*{#1}%
    \if@twoside
      \markboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}%
    \else
      \markright{\abx@MakeMarkcase{#1}}%
    \fi
    \ifmemoirbibintoc
      {\phantomsection
       \addcontentsline{toc}{chapter}{#1}}
      {}}
  \defbibheading{bibintoc}[\bibname]{%
    \chapter*{#1}%
    \if@twoside
      \markboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}%
    \else
      \markright{\abx@MakeMarkcase{#1}}%
    \fi
    \phantomsection
    \addcontentsline{toc}{chapter}{#1}}
  \defbibheading{biblistintoc}[\biblistname]{%
    \chapter*{#1}%
    \if@twoside
      \markboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}%
    \else
      \markright{\abx@MakeMarkcase{#1}}%
    \fi
    \phantomsection
    \addcontentsline{toc}{chapter}{#1}}
  \defbibheading{bibnumbered}[\bibname]{%
    \chapter{#1}}
  \defbibheading{biblistnumbered}[\biblistname]{%
    \chapter{#1}}
  \defbibheading{subbibliography}[\refname]{%
    \section*{#1}%
    \if@twoside\markright{\abx@MakeMarkcase{#1}}\fi
    \ifmemoirbibintoc
      {\phantomsection
       \addcontentsline{toc}{section}{#1}}
      {}}
  \defbibheading{subbibintoc}[\refname]{%
    \section*{#1}%
    \if@twoside\markright{\abx@MakeMarkcase{#1}}\fi
    \phantomsection
    \addcontentsline{toc}{section}{#1}}
  \defbibheading{subbibnumbered}[\refname]{%
    \section{#1}}

\fi

% ------------------------------------------------------------------
% GENERIC CITATION COMMANDS
% ------------------------------------------------------------------

\DeclareCiteCommand{\fullcite}
  {\usebibmacro{prenote}}
  {\usedriver
     {\DeclareNameAlias{sortname}{default}}
     {\thefield{entrytype}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footfullcite}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usedriver
     {\DeclareNameAlias{sortname}{default}}
     {\thefield{entrytype}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printnames{labelname}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printnames[][1-1]{labelname}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citetitle}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{indextitle}}
     {}%
   \printfield[citetitle]{labeltitle}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citetitle}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{indextitle}}
     {}%
   \printfield[citetitle]{title}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeyear}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printfield{year}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citeyear}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printfield{year}\printfield{extradate}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citedate}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printdate}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citedate}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printdateextra}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeurl}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printfield[citeurl]{url}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\notecite}
  {\printfield{prenote}%
   \setunit*{\printdelim{prenotedelim}}}
  {}
  {}
  {\printfield{postnote}}

\DeclareCiteCommand{\pnotecite}[\mkbibparens]
  {\printfield{prenote}%
   \setunit*{\printdelim{prenotedelim}}}
  {}
  {}
  {\printfield{postnote}}

\DeclareCiteCommand{\fnotecite}[\mkbibfootnote]
  {\printfield{prenote}%
   \setunit*{\printdelim{prenotedelim}}}
  {}
  {}
  {\printfield{postnote}}

\newrobustcmd*{\volcite}{\volcitecmd\cite}
\newrobustcmd*{\pvolcite}{\volcitecmd\parencite}
\newrobustcmd*{\fvolcite}{\volcitecmd\footcite}
\newrobustcmd*{\ftvolcite}{\volcitecmd\footcitetext}
\newrobustcmd*{\svolcite}{\volcitecmd\smartcite}
\newrobustcmd*{\tvolcite}{\volcitecmd\textcite}
\newrobustcmd*{\avolcite}{\volcitecmd\autocite}

\newrobustcmd*{\volcites}{\multivolcitecmd\cites}
\newrobustcmd*{\pvolcites}{\multivolcitecmd\parencites}
\newrobustcmd*{\fvolcites}{\multivolcitecmd\footcites}
\newrobustcmd*{\ftvolcites}{\multivolcitecmd\footcitetexts}
\newrobustcmd*{\svolcites}{\multivolcitecmd\smartcites}
\newrobustcmd*{\tvolcites}{\multivolcitecmd\textcites}
\newrobustcmd*{\avolcites}{\multivolcitecmd\autocites}

\newrobustcmd*{\Cite}{\bibsentence\cite}
\newrobustcmd*{\Parencite}{\bibsentence\parencite}
\newrobustcmd*{\Footcite}{\footcite}
\newrobustcmd*{\Footcitetext}{\footcitetext}
\newrobustcmd*{\Smartcite}{\bibsentence\smartcite}
\newrobustcmd*{\Textcite}{\bibsentence\textcite}
\newrobustcmd*{\Citeauthor}{%
  \@ifstar{\bibsentence\citeauthor*}{\bibsentence\citeauthor}}
\newrobustcmd*{\Citetitle}{\bibsentence\citetitle}

\newrobustcmd*{\Volcite}{\volcitecmd\Cite}
\newrobustcmd*{\Pvolcite}{\volcitecmd\Parencite}
\newrobustcmd*{\Fvolcite}{\volcitecmd\Footcite}
\newrobustcmd*{\Ftvolcite}{\volcitecmd\Footcitetext}
\newrobustcmd*{\Svolcite}{\volcitecmd\Smartcite}
\newrobustcmd*{\Tvolcite}{\volcitecmd\Textcite}
\newrobustcmd*{\Avolcite}{\volcitecmd\Autocite}

\newrobustcmd*{\Volcites}{\multivolcitecmd\Cites}
\newrobustcmd*{\Pvolcites}{\multivolcitecmd\Parencites}
\newrobustcmd*{\Fvolcites}{\multivolcitecmd\Footcites}
\newrobustcmd*{\Ftvolcites}{\multivolcitecmd\Footcitetext}
\newrobustcmd*{\Svolcites}{\multivolcitecmd\Smartcites}
\newrobustcmd*{\Tvolcites}{\multivolcitecmd\Textcites}
\newrobustcmd*{\Avolcites}{\multivolcitecmd\Autocites}

\newrobustcmd*{\Notecite}{\bibsentence\notecite}
\newrobustcmd*{\Pnotecite}{\bibsentence\pnotecite}
\newrobustcmd*{\Fnotecite}{\fnotecite}

\DeclareMultiCiteCommand{\cites}{\cite}{\multicitedelim}
\DeclareMultiCiteCommand{\parencites}[\mkbibparens]{\parencite}{\multicitedelim}
\DeclareMultiCiteCommand{\footcites}[\mkbibfootnote]{\footcite}{\multicitedelim}
\DeclareMultiCiteCommand{\footcitetexts}[\mkbibfootnotetext]
  {\footcitetext}{\multicitedelim}
\DeclareMultiCiteCommand{\smartcites}[\iffootnote\mkbibparens\mkbibfootnote]
  {\smartcite}{\multicitedelim}
\DeclareMultiCiteCommand{\supercites}[\mkbibsuperscript]
  {\supercite}{\supercitedelim}
\DeclareMultiCiteCommand{\textcites}{\textcite}{\multicitedelim}

\newrobustcmd*{\Cites}{\bibsentence\cites}
\newrobustcmd*{\Parencites}{\bibsentence\parencites}
\newrobustcmd*{\Footcites}{\footcites}
\newrobustcmd*{\Footcitetexts}{\footcitetexts}
\newrobustcmd*{\Smartcites}{\bibsentence\smartcites}
\newrobustcmd*{\Textcites}{\bibsentence\textcites}

\DeclareAutoCiteCommand{plain}{\cite}{\cites}
\DeclareAutoCiteCommand{inline}{\parencite}{\parencites}
%\DeclareAutoCiteCommand{footnote}[l]{\footcite}{\footcites}
\DeclareAutoCiteCommand{footnote}[f]{\smartcite}{\smartcites}
\DeclareAutoCiteCommand{superscript}[l]{\supercite}{\supercites}

\newrobustcmd*{\Autocite}{\bibsentence\autocite}
\newrobustcmd*{\Autocites}{\bibsentence\autocites}

% ------------------------------------------------------------------
% GENERIC CITATION MACROS
% ------------------------------------------------------------------

\newbibmacro*{citeindex}{%
  \ifciteindex
    {\indexnames{labelname}%
     \indexfield{indextitle}}
    {}}

\newbibmacro*{shorthandintro}{%
  \iffieldundef{shorthandintro}
    {\iffieldundef{shorthand}
       {}
       {\setunit{\addspace}%
        \printtext[parens]{%
          \bibstring{citedas}\space
          \printfield{shorthand}}}}
    {\setunit{\addspace}%
     \printtext[parens]{\printfield{shorthandintro}}}}

% citation commands

\newbibmacro*{prenote}{%
  \iffieldundef{prenote}
    {}
    {\printfield{prenote}%
     \setunit{\printdelim{prenotedelim}}}}

\newbibmacro*{postnote}{%
  \iffieldundef{postnote}
    {}
    {\setunit{\printdelim{postnotedelim}}%
     \printfield{postnote}}}

% multicite commands

\newbibmacro*{multiprenote}{%
  \iffieldundef{multiprenote}
    {}
    {\printfield{multiprenote}%
     \printdelim{multiprenotedelim}}}

\newbibmacro*{multipostnote}{%
  \iffieldundef{multipostnote}
    {}
    {\printdelim{multipostnotedelim}%
     \printfield{multipostnote}}}

% ------------------------------------------------------------------
% GENERIC BIBLIOGRAPHY MACROS
% ------------------------------------------------------------------

\newbibmacro*{bibindex}{%
  \ifbibindex
    {\indexnames{labelname}%
     \indexfield{indextitle}}
    {}}

\newbibmacro*{author/editor}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{author}}
    {\usebibmacro{editor}}}

\newbibmacro*{author/editor+others}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{author}}
    {\usebibmacro{editor+others}}}

\newbibmacro*{author/translator}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{author}}
    {\usebibmacro{translator}}}

\newbibmacro*{author/translator+others}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{author}}
    {\usebibmacro{translator+others}}}

\newbibmacro*{author/editor/translator}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{author}}
    {\ifboolexpr{
       test \ifuseeditor
       and
       not test {\ifnameundef{editor}}
     }
       {\usebibmacro{editor}}
       {\usebibmacro{translator}}}}

\newbibmacro*{author/editor+others/translator+others}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{author}}
    {\ifboolexpr{
       test \ifuseeditor
       and
       not test {\ifnameundef{editor}}
     }
       {\usebibmacro{editor+others}}
       {\usebibmacro{translator+others}}}}

\newbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\printnames{author}%
     \iffieldundef{authortype}
       {}
       {\setunit{\printdelim{authortypedelim}}%
        \usebibmacro{authorstrg}}}
    {}}

\newbibmacro*{editor}{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\printnames{editor}%
     \setunit{\printdelim{editortypedelim}}%
     \usebibmacro{editorstrg}%
     \clearname{editor}}
    {}}

\newbibmacro*{editor+others}{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\printnames{editor}%
     \setunit{\printdelim{editortypedelim}}%
     \usebibmacro{editor+othersstrg}%
     \clearname{editor}}
    {}}

\newbibmacro*{translator}{%
  \ifboolexpr{
    test \ifusetranslator
    and
    not test {\ifnameundef{translator}}
  }
    {\printnames{translator}%
     \setunit{\printdelim{translatortypedelim}}%
     \usebibmacro{translatorstrg}%
     \clearname{translator}}
    {}}

\newbibmacro*{translator+others}{%
  \ifboolexpr{
    test \ifusetranslator
    and
    not test {\ifnameundef{translator}}
  }
    {\printnames{translator}%
     \setunit{\printdelim{translatortypedelim}}%
     \usebibmacro{translator+othersstrg}%
     \clearname{translator}}
    {}}

\newbibmacro*{authorstrg}{%
  \iffieldundef{authortype}
    {}
    {\printtext[authortype]{%
       \ifbibxstring{\thefield{authortype}}
         {\ifboolexpr{
            test {\ifnumgreater{\value{author}}{1}}
            or
            test {\ifandothers{author}}
          }
            {\bibstring{\thefield{authortype}s}}
            {\bibstring{\thefield{authortype}}}}
         {\thefield{authortype}}}}}

\newbibmacro*{editorstrg}{%
  \printtext[editortype]{%
    \iffieldundef{editortype}
      {\ifboolexpr{
         test {\ifnumgreater{\value{editor}}{1}}
         or
         test {\ifandothers{editor}}
       }
         {\bibstring{editors}}
         {\bibstring{editor}}}
      {\ifbibxstring{\thefield{editortype}}
         {\ifboolexpr{
            test {\ifnumgreater{\value{editor}}{1}}
            or
            test {\ifandothers{editor}}
          }
            {\bibstring{\thefield{editortype}s}}
            {\bibstring{\thefield{editortype}}}}
         {\thefield{editortype}}}}}

\newbibmacro*{editor+othersstrg}{%
  \iffieldundef{editortype}
    {\ifboolexpr{
       test {\ifnumgreater{\value{editor}}{1}}
       or
       test {\ifandothers{editor}}
     }
       {\def\abx@tempa{editors}}
       {\def\abx@tempa{editor}}}
    {\ifboolexpr{
       test {\ifnumgreater{\value{editor}}{1}}
       or
       test {\ifandothers{editor}}
     }
       {\edef\abx@tempa{\thefield{editortype}s}}
       {\edef\abx@tempa{\thefield{editortype}}}}%
  \let\abx@tempb=\empty
  \ifnamesequal{editor}{translator}
    {\appto\abx@tempa{tr}%
     \appto\abx@tempb{\clearname{translator}}}
    {}%
  \ifnamesequal{editor}{commentator}
    {\appto\abx@tempa{co}%
     \appto\abx@tempb{\clearname{commentator}}}
    {\ifnamesequal{editor}{annotator}
       {\appto\abx@tempa{an}%
        \appto\abx@tempb{\clearname{annotator}}}
       {}}%
  \ifnamesequal{editor}{introduction}
    {\appto\abx@tempa{in}%
     \appto\abx@tempb{\clearname{introduction}}}
    {\ifnamesequal{editor}{foreword}
       {\appto\abx@tempa{fo}%
        \appto\abx@tempb{\clearname{foreword}}}
       {\ifnamesequal{editor}{afterword}
          {\appto\abx@tempa{af}%
           \appto\abx@tempb{\clearname{afterword}}}
          {}}}%
  \ifbibxstring{\abx@tempa}
    {\printtext[editortype]{\bibstring{\abx@tempa}}\abx@tempb}
    {\usebibmacro{editorstrg}}}

\newbibmacro*{translatorstrg}{%
  \printtext[translatortype]{%
    \ifboolexpr{
      test {\ifnumgreater{\value{translator}}{1}}
      or
      test {\ifandothers{translator}}
    }
      {\bibstring{translators}}
      {\bibstring{translator}}}}

\newbibmacro*{translator+othersstrg}{%
  \ifboolexpr{
    test {\ifnumgreater{\value{translator}}{1}}
    or
    test {\ifandothers{translator}}
  }
    {\def\abx@tempa{translators}}
    {\def\abx@tempa{translator}}%
  \ifnamesequal{translator}{commentator}
    {\appto\abx@tempa{co}%
     \clearname{commentator}}
    {\ifnamesequal{translator}{annotator}
       {\appto\abx@tempa{an}%
        \clearname{annotator}}
       {}}%
  \ifnamesequal{translator}{introduction}
    {\appto\abx@tempa{in}%
     \clearname{introduction}}
    {\ifnamesequal{translator}{foreword}
       {\appto\abx@tempa{fo}%
        \clearname{foreword}}
       {\ifnamesequal{translator}{afterword}
          {\appto\abx@tempa{af}%
           \clearname{afterword}}
          {}}}%
  \printtext[translatortype]{\bibstring{\abx@tempa}}}

\newbibmacro*{byauthor}{%
  \ifboolexpr{
    test \ifuseauthor
    or
    test {\ifnameundef{author}}
  }
    {}
    {\usebibmacro{bytypestrg}{author}{author}%
     \setunit{\addspace}%
     \printnames[byauthor]{author}}}

\newbibmacro*{bybookauthor}{%
  \ifnamesequal{author}{bookauthor}
    {}
    {\printnames{bookauthor}}}

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

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

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

\newbibmacro*{byholder}{%
  \printnames{holder}}

\newbibmacro*{byeditor+others}{%
  \ifnameundef{editor}
    {}
    {\usebibmacro{byeditor+othersstrg}%
     \setunit{\addspace}%
     \printnames[byeditor]{editor}%
     \clearname{editor}%
     \newunit}%
  \usebibmacro{byeditorx}%
  \usebibmacro{bytranslator+others}}

\newbibmacro*{bytranslator+others}{%
  \ifnameundef{translator}
    {}
    {\usebibmacro{bytranslator+othersstrg}%
     \setunit{\addspace}%
     \printnames[bytranslator]{translator}%
     \clearname{translator}%
     \newunit}%
  \usebibmacro{withothers}}

\newbibmacro*{bytypestrg}[2]{%
  \iffieldundef{#1type}
    {\bibstring{by#2}}
    {\ifbibxstring{by\thefield{#1type}}
       {\bibstring{by\thefield{#1type}}}
       {\printtext{\thefield{#1type}}}}}

\newbibmacro*{byeditor+othersstrg}{%
  \iffieldundef{editortype}
    {\def\abx@tempa{byeditor}}
    {\edef\abx@tempa{by\thefield{editortype}}}%
  \let\abx@tempb=\empty
  \ifnamesequal{editor}{translator}
    {\appto\abx@tempa{tr}%
     \appto\abx@tempb{\clearname{translator}}}
    {}%
  \ifnamesequal{editor}{commentator}
    {\appto\abx@tempa{co}%
     \appto\abx@tempb{\clearname{commentator}}}
    {\ifnamesequal{editor}{annotator}
       {\appto\abx@tempa{an}%
        \appto\abx@tempb{\clearname{annotator}}}
       {}}%
  \ifnamesequal{editor}{introduction}
    {\appto\abx@tempa{in}%
     \appto\abx@tempb{\clearname{introduction}}}
    {\ifnamesequal{editor}{foreword}
       {\appto\abx@tempa{fo}%
        \appto\abx@tempb{\clearname{foreword}}}
       {\ifnamesequal{editor}{afterword}
          {\appto\abx@tempa{af}%
           \appto\abx@tempb{\clearname{afterword}}}
          {}}}%
  \ifbibxstring{\abx@tempa}
    {\printtext{\bibstring{\abx@tempa}}\abx@tempb}
    {\usebibmacro{bytypestrg}{editor}{editor}}}

\newbibmacro*{bytranslator+othersstrg}{%
  \def\abx@tempa{bytranslator}%
  \ifnamesequal{translator}{commentator}
    {\appto\abx@tempa{co}%
     \clearname{commentator}}
    {\ifnamesequal{translator}{annotator}
       {\appto\abx@tempa{an}%
        \clearname{annotator}}
       {}}%
  \ifnamesequal{translator}{introduction}
    {\appto\abx@tempa{in}%
     \clearname{introduction}}
    {\ifnamesequal{translator}{foreword}
       {\appto\abx@tempa{fo}%
        \clearname{foreword}}
       {\ifnamesequal{translator}{afterword}
          {\appto\abx@tempa{af}%
           \clearname{afterword}}
          {}}}%
  \bibstring{\abx@tempa}}

\newbibmacro*{withcommentator}{%
  \ifnameundef{commentator}
    {}
    {\bibstring{withcommentator}%
     \setunit{\addspace}%
     \printnames[withcommentator]{commentator}}}

\newbibmacro*{withannotator}{%
  \ifnameundef{annotator}
    {}
    {\bibstring{withannotator}%
     \setunit{\addspace}%
     \printnames[withannotator]{annotator}}}

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

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

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

\newbibmacro*{withothers}{%
  \usebibmacro{withcommentator}%
  \clearname{commentator}%
  \newunit
  \usebibmacro{withannotator}%
  \clearname{annotator}%
  \newunit
  \usebibmacro{withintroduction}%
  \clearname{introduction}%
  \newunit
  \usebibmacro{withforeword}%
  \clearname{foreword}%
  \newunit
  \usebibmacro{withafterword}%
  \clearname{afterword}}

\newbibmacro*{title}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext[title]{%
       \printfield[titlecase]{title}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{subtitle}}%
     \newunit}%
  \printfield{titleaddon}}

\newbibmacro*{booktitle}{%
  \ifboolexpr{
    test {\iffieldundef{booktitle}}
    and
    test {\iffieldundef{booksubtitle}}
  }
    {}
    {\printtext[booktitle]{%
       \printfield[titlecase]{booktitle}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{booksubtitle}}%
     \newunit}%
  \printfield{booktitleaddon}}

\newbibmacro*{maintitle}{%
  \ifboolexpr{
    test {\iffieldundef{maintitle}}
    and
    test {\iffieldundef{mainsubtitle}}
  }
    {}
    {\printtext[maintitle]{%
       \printfield[titlecase]{maintitle}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{mainsubtitle}}%
     \newunit}%
  \printfield{maintitleaddon}}

% The \iffieldundef{journaltitleaddon} is usually not necessary.
% We need it to ensure that a \setunit* after this macro does the right thing
% for backwards compatibility.
\newbibmacro*{journal}{%
  \ifboolexpr{
    test {\iffieldundef{journaltitle}}
    and
    test {\iffieldundef{journalsubtitle}}
  }
    {}
    {\printtext[journaltitle]{%
       \printfield[titlecase]{journaltitle}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{journalsubtitle}}%
     \newunit}%
  \iffieldundef{journaltitleaddon}
    {}
    {\printfield{journaltitleaddon}}}

% Re \iffieldundef{titleaddon} see the comment about
% \iffieldundef{journaltitleaddon} above.
\newbibmacro*{periodical}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext[title]{%
       \printfield[titlecase]{title}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{subtitle}}%
     \newunit}%
  \iffieldundef{titleaddon}
    {}
    {\printfield{titleaddon}}}

\newbibmacro*{issue}{%
  \ifboolexpr{
    test {\iffieldundef{issuetitle}}
    and
    test {\iffieldundef{issuesubtitle}}
  }
    {}
    {\printtext[issuetitle]{%
       \printfield[titlecase]{issuetitle}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{issuesubtitle}}%
     \newunit}%
  \printfield{issuetitleaddon}}

\newbibmacro*{in:}{%
  \bibstring{in}%
  \printunit{\intitlepunct}}

\newbibmacro*{date}{\printdate}

\newbibmacro*{url+urldate}{%
  \usebibmacro{url}%
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \usebibmacro{urldate}}}

\newbibmacro*{url}{\printfield{url}}
\newbibmacro*{urldate}{\printurldate}

\newbibmacro*{pageref}{%
  \iflistundef{pageref}
    {}
    {\printtext[parens]{%
       \ifnumgreater{\value{pageref}}{1}
         {\bibstring{backrefpages}\ppspace}
         {\bibstring{backrefpage}\ppspace}%
       \printlist[pageref][-\value{listtotal}]{pageref}}}}

\newbibmacro*{setpageref}{%
  \iflistundef{pageref}
    {}
    {\printtext{%
       \ifnumgreater{\value{pageref}}{1}
         {\bibstring{backrefpages}\ppspace}
         {\bibstring{backrefpage}\ppspace}%
       \printlist[pageref][-\value{listtotal}]{pageref}}}}

\newbibmacro*{eprint}{%
  \iffieldundef{eprinttype}
    {\printfield{eprint}}
    {\printfield[eprint:\strfield{eprinttype}]{eprint}}}

\newbibmacro*{annotation}{%
  \begingroup
  \togglefalse{blx@bibliography}%
  \iffieldundef{annotation}
    {\printfile[annotation]{\bibannotationprefix\thefield{entrykey}.tex}}
    {\printfield{annotation}}%
  \endgroup}

\newbibmacro*{abstract}{%
  \iffieldundef{abstract}
    {\printfile[abstract]{\bibabstractprefix\thefield{entrykey}.tex}}
    {\printfield{abstract}}}

\newbibmacro*{related:default}[1]{%
  \entrydata*{#1}{%
    \usedriver
      {\ifnameundef{savedauthor}
         {\ifnameundef{savededitor}
            {}
            {\ifnamesequal{editor}{savededitor}
               {\clearname{editor}}
               {}}}
         {\ifnamesequal{author}{savedauthor}
            {\clearname{author}}
            {}}%
       \DeclareNameAlias{sortname}{default}%
       % from authortitle and authoryear
       \ifbibmacroundef{bbx:dashcheck}
         {}
         {\renewbibmacro*{bbx:dashcheck}[2]{##2}}%
       % authoryear
       \ifbibmacroundef{labeltitle}
         {}
         {\renewbibmacro*{labeltitle}{}}%
       \ifbibmacroundef{date+extradate}
         {}
         {\renewbibmacro*{date+extradate}{}%
          \renewbibmacro*{bbx:ifmergeddate}{\@secondoftwo}}%
       \renewbibmacro*{pageref}{}%
       \renewbibmacro*{related:init}{}}
      {\thefield{entrytype}}}}

\newbibmacro*{related:bytranslator}[1]{%
  \entrydata{#1}{%
    \renewbibmacro*{name:hook}[1]{%
      \ifnumequal{\value{listcount}}{1}
        {\mkrelatedstringtext{\lbx@initnamehook{##1}}}
        {}}%
    \printnames[bytranslator]{translator}%
    \setunit*{\addspace\bibstring[\mkrelatedstringtext]{astitle}\space}%
    \usebibmacro{title}%
    \setunit{\addspace}%
    \printtext[parens]{%
      \printlist{location}%
      \iflistundef{publisher}
        {\setunit*{\addcomma\space}}
        {\setunit*{\addcolon\space}}%
      \printlist{publisher}%
      \setunit*{\addcomma\space}%
      \printdate}}}

\newbibmacro*{related:multivolume}[1]{%
  \entrydata*{#1}{%
    \printtext{%
      \printfield{volume}%
      \printfield{part}}%
    \setunit*{\addcolon\space}%
    \usebibmacro{title}%
    \ifboolexpr{
      test {\ifnamesequal{author}{savedauthor}}
      or
      test {\ifnameundef{author}}
    }
      {}
      {\usebibmacro{bytypestrg}{author}{author}%
       \setunit{\addspace}%
       \printnames[byauthor]{author}
       \newunit\newblock}%
    \ifboolexpr{
      test {\ifnamesequal{editor}{savededitor}}
      or
      test {\ifnameundef{editor}}
    }
      {}
      {\usebibmacro{byeditor+others}%
       \newunit\newblock}%
  \printdate}}

\newbibmacro*{related:origpubin}[1]{%
  \entrydata*{#1}{%
    \printfield{year}%
    \ifboolexpr{
      test {\iflistsequal{publisher}{savedpublisher}}
      or
      test {\iflistundef{publisher}}
    }
      {}
      {\setunit{\addspace\bibstring[\mkrelatedstringtext]{bypublisher}\space}%
       \printlist{publisher}%
       \setunit{\addcomma\space}%
       \iflistsequal{location}{savedlocation}
         {}
         {\printlist{location}}}}}

\newbibmacro*{related:origpubas}[1]{%
  \entrydata*{#1}{%
    \usebibmacro{title}%
    \ifboolexpr{
      test {\iflistsequal{publisher}{savedpublisher}}
      or
      test {\iflistundef{publisher}}
    }
      {}
      {\setunit{\addspace\bibstring[\mkrelatedstringtext]{bypublisher}\space}%
       \printlist{publisher}%
       \setunit{\addcomma\space}%
       \iflistsequal{location}{savedlocation}
         {}
         {\printlist{location}}}}}

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

\newbibmacro*{related:reprintfrom}[1]{%
  \entrydata*{#1}{%
    \iffieldundef{journaltitle}
      {\iffieldundef{maintitle}
         {\printfield[title:hook]{booktitle}}
         {\printfield[title:hook]{maintitle}}%
       \newunit\newblock
       \usebibmacro{byeditor+others}%
       \newunit\newblock
       \printfield{edition}%
       \newunit
       \iffieldundef{volume}
         {}
         {\printfield{volume}%
          \printfield{part}}
       \newunit\newblock
       \usebibmacro{series+number}%
       \newunit\newblock
       \printfield{note}%
       \newunit\newblock
       \usebibmacro{publisher+location+date}%
       \newunit\newblock
       \usebibmacro{chapter+pages}}
      {\renewbibmacro*{journal}{%
         \printfield[title:hook]{journaltitle}}%
       \usebibmacro{journal+issuetitle}%
       \newunit\newblock
       \usebibmacro{byeditor+others}%
       \newunit\newblock
       \usebibmacro{note+pages}}}}

\endinput
