\ProvidesFile{iso.bbx}
  [2026/11/17 v0.4.3 ISO 690 biblatex bibliography style]


\RequirePackage{xpatch}


% Currently available language mappings:
% Czech, English, German, Polish, Slovak, and more.
% You can list them directly with `$ ls *lbx`.
% Or you can check the translation matrix at the wiki page:
% https://github.com/michal-h21/biblatex-iso690/wiki/Translation-Guideline#translation-matrix
\DeclareLanguageMappingSuffix{-iso}
% Currently needed the following additional language strings:
\NewBibliographyString{at,bysupervisor,urlalso,refreshedon,
  director,bydirector,inventor,byinventor,online,film,application,publication}

% PACKAGE OPTIONS

% Define new package options
% These toggle names are internal
\newtoggle{bbx:spcolon}
\newtoggle{bbx:totalpages}
\newtoggle{bbx:shortnum}
\newtoggle{bbx:url}
\newtoggle{bbx:isbn}
\newtoggle{bbx:doi}
\newtoggle{bbx:eprint}
\newtoggle{bbx:articlepubinfo}
\newtoggle{bbx:currentlang}
\newtoggle{bbx:noenddot}
\newtoggle{bbx:bibacrosc}
\newtoggle{bbx:familynamesc}
\newtoggle{bbx:givennamesfirst}

% Print info about package options into .log file
\protected\def\isoblx@info@noline#1{%
  \PackageInfo{biblatex-iso690}{#1\@gobble}}
\let\isoblx@info\isoblx@info@noline
\AtEndOfPackage{%
  \protected\def\isoblx@info#1{%
    \PackageInfo{biblatex-iso690}{#1}}}

% Declare new package options
% Description of these options is in the doc file
% '\isoblx@info@noline' command prints to the .log file
\DeclareBibliographyOption{spacecolon}[true]{%
  \settoggle{bbx:spcolon}{#1}%
  \isoblx@info@noline{Space colon enabled: #1}}

\DeclareBibliographyOption{pagetotal}[true]{%
  \settoggle{bbx:totalpages}{#1}%
  \isoblx@info@noline{Total pages enabled: #1}}

\DeclareBibliographyOption{shortnumeration}[true]{%
  \settoggle{bbx:shortnum}{#1}%
  \isoblx@info@noline{Short numeration enabled: #1}}

\DeclareBibliographyOption{url}[true]{%
  \settoggle{bbx:url}{#1}%
  \isoblx@info@noline{URL field enabled: #1}}

\DeclareBibliographyOption{isbn}[true]{%
  \settoggle{bbx:isbn}{#1}%
  \isoblx@info@noline{ISBN field enabled: #1}}

\DeclareBibliographyOption{doi}[true]{%
  \settoggle{bbx:doi}{#1}%
  \isoblx@info@noline{DOI field enabled: #1}}

\DeclareBibliographyOption{eprint}[true]{%
  \settoggle{bbx:eprint}{#1}%
  \isoblx@info@noline{eprint field enabled: #1}}

\DeclareBibliographyOption{articlepubinfo}[true]{%
  \settoggle{bbx:articlepubinfo}{#1}%
  \isoblx@info@noline{Article publication info enabled: #1}}

\DeclareBibliographyOption{currentlang}[true]{%
  \settoggle{bbx:currentlang}{#1}%
  \isoblx@info@noline{Use current language for the bibliography: #1}}

\DeclareBibliographyOption{noenddot}[true]{%
  \settoggle{bbx:noenddot}{#1}%
  \isoblx@info@noline{Use no end dot for the bibliography entries: #1}}

\DeclareBibliographyOption{bibacrosc}[true]{
  \settoggle{bbx:bibacrosc}{#1}%
  \isoblx@info@noline{Printing acronyms such as ISBN as textsc enabled: #1}}

\DeclareBibliographyOption{familynamesc}[true]{
  \settoggle{bbx:familynamesc}{#1}%
  \isoblx@info@noline{Printing family names as textsc enabled: #1}}

\DeclareBibliographyOption{givennamesfirst}[true]{%
  \settoggle{bbx:givennamesfirst}{#1}%
  \isoblx@info@noline{Printing names as 'given family' except for the first author: #1}}


% Set default package options
\ExecuteBibliographyOptions{%
  spacecolon=false,
  pagetotal=false,
  shortnumeration=false,
  url=true,
  isbn=true,
  doi=true,
  eprint=true,
  articlepubinfo=false,% Printing article publication info is unusual
  maxnames=99,% If possible, all creators should be given in the reference
  minnames=1,% If any names are omitted => first creator + and others (et al.)
  citetracker=true,% Citation tracker in global mode
  autolang=other,% Use the 'langid' language for the entry
  date=year,% Use only years
  urldate=iso,% Use ISO8601 Extended Format (yyyy-mm-dd) for URL 'seen' dates
  origdate=iso,% Use ISO8601 Extended Format (yyyy-mm-dd) for patent appl. dates
  eventdate=long,% Use long format for eventdates
  eventdateusetime=true,% Use time for eventdates
  seconds=true,% iso (ISO8601) format requires 'seconds=true'
  datecirca=true,% Use circa for approximate dates
  currentlang=false,% Use main document language for printing of bibliography strings
  noenddot=false,% Use an end dot for the bibliography entries
  bibacrosc=false,% Printing acronyms such as ISBN as textsc
  familynamesc=false,% Printing family names as textsc
  givennamesfirst=false,% Printing names as given family except for the first author
}



% COMMANDS

% Default definitions of beginning and closing macro
% in bibliography drivers
\newbibmacro*{begentry}{}
\newbibmacro*{finentry}{\finentry}

% The separator between 'titles' and 'subtitles'
\renewcommand*{\subtitlepunct}{\addspacecolon\space}

% The separator between more standard identifiers, like ISBNs or ISSNs.
% Default separator is comma and space. You can use something like
% \renewcommand{\stdidentifierspunct}{\addsemicolon\space}
% in the preamble to change the separator
\newcommand{\stdidentifierspunct}{\addcomma\space}

% The separator between date and dateaddon
\newcommand{\dateaddonpunct}{\addspace}

% The separator between 'dates' and the numeration section
\newcommand{\numerationpunct}{\addcomma\space}

% No seperator or a dot at the very end of an entry
\renewcommand{\finentrypunct}{%
  \iftoggle{bbx:noenddot}
    {}
    {\addperiod}%
}

% A colon preceded with or without space
\newcommand{\addspacecolon}{%
  \iftoggle{bbx:spcolon}
    {\addnbspace\addspcolon}
    {\unspace\addspcolon}%
}

% Context-sensitive delimiters

% The delimiter between mutliple names
\newcommand*{\mkmultinamedelim}{%
  \iftoggle{bbx:givennamesfirst}
    % Standard defintion from biblatex.def
    {\addcomma\space}
    % A semicolon: legacy of older versions of standard / Czech interpretations
    {\addsemicolon\space}%
}
\DeclareDelimFormat{multinamedelim}{\mkmultinamedelim}

% The delimiter before the final name
\newcommand*{\mkfinalnamedelim}{%
  \iftoggle{bbx:givennamesfirst}
    % Standard defintion from biblatex.def
    {\ifnumgreater{\value{liststop}}{2}{\finalandcomma}{}%
    \addspace\bibstring{and}\space}
    % Use consistent name format for all creators
    {\addsemicolon\space}%
}
\DeclareDelimFormat{finalnamedelim}{\mkfinalnamedelim}

% The delimiter between the date and the time
\DeclareDelimFormat{bibdatetimesep}{\addcomma\space}

% Default name format is ALL-CAPS
% use the package option familynamesc
% to change this to textsc
\newcommand{\familynameformat}[1]{%
  \iftoggle{bbx:familynamesc}
    {\textsc{#1}}
    {\MakeUppercase{#1}}%
}
% Thanks Moewew for sugesting this. Make uppercase names only in bibliography.
\AtBeginBibliography{%
  \renewcommand{\mkbibnamefamily}{\familynameformat}%
}

% Default bibliography environment (layout)
\defbibenvironment{bibliography}
  {\list%
     {}%
     {\setlength{\leftmargin}{\bibhang}%
      \setlength{\itemindent}{-\leftmargin}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{\hss##1}}%
  {\endlist}%
  {\item}%



% FIELD FORMATS

% Format title and subtitle as is
\DeclareFieldFormat*{title}{#1}
\DeclareFieldFormat*{subtitle}{#1}

% Format volume field with localisation string
\DeclareFieldFormat{volume}{\bibstring{volume}\addnbspace#1}% volume of a book
% Differentiate volume in journal
\DeclareFieldFormat[article,periodical]{volume}{%
  \iftoggle{bbx:shortnum}
    {\mkbibbold{#1}}
    {\bibstring{jourvol}\addnbspace#1}% volume of a journal
}

% Edition field could be:
% a) numeral: use with localisation string
% b) literal: capitalize given string
\DeclareFieldFormat*{edition}{%
  \ifnumeral{#1}%
    {\mkbibordedition{#1}\addnbspace\bibstring{edition}}%
    {\MakeCapital{#1}}%
}%

% Format pagination for page range
% Always use main document language for this field
\DeclareFieldFormat*{pages}{\mkmlpageprefix[bookpagination]{#1}}
% Differentiate page range in journal
\DeclareFieldFormat[article,periodical]{pages}{%
  \iftoggle{bbx:shortnum}
    {#1}
    {\mkmlpageprefix[bookpagination]{#1}}%
}

% Format pagination for total number of pages
% Always use main document language for this field
\DeclareFieldFormat*{pagetotal}{\mkbibbrackets{\mkmlpagetotal[bookpagination]{#1}}}

% Format number field with localisation string
\DeclareFieldFormat*{number}{\bibstring{number}\addspace #1}
% Differentiate number in journal
\DeclareFieldFormat[article,periodical]{number}{%
  \iftoggle{bbx:shortnum}
    {\mkbibparens{#1}}
    {\bibstring{number}\addspace #1}%
}
% Differentiate number for patent and report: format as is
\DeclareFieldFormat[patent,report]{number}{#1}

% a) url AND no urldate and type is not eBook:
%    use localisation string 'also available from',
%    meaning: the work is not primarily published electronically
% b) (url AND urldate) OR (url AND no urldate and type=eBook):
%    use localisation string 'available from'
\DeclareFieldFormat*{url}{%
  \iffieldundef{urlyear}
    {\iffieldequalstr{type}{eBook}
      {\mainlangbibstringcolon{urlfrom}}
      {\mainlangbibstringcolon{urlalso}}}%
    {\mainlangbibstringcolon{urlfrom}}%
  %\addcolon\space
  \url{#1}%
}

% Format medium type in square brackets
% If available, use the localisation string for the key
\DeclareFieldFormat{howpublished}{%
  \ifbibstring{#1}
    {\mainlangbibstring[\mkbibbrackets]{#1}}
    {\mkbibbrackets{#1}}%
}

% Format type, e.g. type of thesis
% If available, use the localisation string for the key
\DeclareFieldFormat{type}{%
  \ifbibstring{#1}
    {\mainlangbibstring{#1}}
    {#1}%
}
\DeclareFieldFormat[thesis, patent]{type}{%
  \ifbibstring{#1}
    {\mainlangbiblstring{#1}}
    {#1}%
}

% Format supervisor of thesis (precedes the name with a localisation string)
\DeclareFieldFormat{supervisor}{%
  \mainlangbibstring{bysupervisor}\addspace#1}

% \mkbibacro typesets acronyms in small caps by default,
% if you want to pass the value as is (uppercase)
% use the bibacrosc=false package option
% Applies to DOI, ISBN, ISSN, ISAN, ISMN, ISRN, ISWC
\renewcommand*{\mkbibacro}[1]{%
  \iftoggle{bbx:bibacrosc}
    {\ifcsundef{\f@encoding/\f@family/\f@series/sc}
      {#1}
      {\textsc{\MakeLowercase{#1}}}}%
    {#1}%
}

% If we really must handle more than one ISBN and ISSN.
%
% Typically there could be different ISBN / ISSN for printed and electronic
% media versions, but the standard says that the specific copy or instance of
% the document should be cited, so the author should choose the appropriate
% number in the bib file. Otherwise include comma-separated list of numbers in
% the bib field 'isbn' or 'issn'.

% Separator value between more ISBNs / ISSNs is handled by '\stdidentifierspunct'.
% Default format is the name of identifier + space + number:
% e.g. 'ISBN 978-3-642-21665-7'
\DeclareFieldFormat{isbn}{%
  % Execute this rule for the first value of the csv field
  \def\do##1{\mkbibacro{ISBN}\space##1%
    % Execute this rule for the next value(s) of the csv field
    \def\do####1{\stdidentifierspunct\mkbibacro{ISBN}\space####1}}%
  % Process the csv field with \do command
  \docsvfield{isbn}%
}

% Electronic ISBN, the same formatting rules as for ISBN above
\DeclareFieldFormat{eisbn}{%
  \def\do##1{\mkbibacro{eISBN}\space##1%
    \def\do####1{\stdidentifierspunct\mkbibacro{eISBN}\space####1}}%
  \docsvfield{eisbn}%
}

% ISSN, the same formatting rules as for ISBN above
\DeclareFieldFormat{issn}{%
  \def\do##1{\mkbibacro{ISSN}\space##1%
    \def\do####1{\stdidentifierspunct\mkbibacro{ISSN}\space####1}}%
  \docsvfield{issn}%
}

% Electronic ISSN, the same formatting rules as for ISBN above
\DeclareFieldFormat{eissn}{%
  \def\do##1{\mkbibacro{eISSN}\space##1%
    \def\do####1{\stdidentifierspunct\mkbibacro{eISSN}\space####1}}%
  \docsvfield{issn}%
}

% LCCN
\DeclareFieldFormat{lccn}{%
  \mkbibacro{LCCN}\addspace
  \ifhyperref
    {\href{http://lccn.loc.gov/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}%
}

% Format other standard identifiers
% Default format is the name of identifier + space + number
\DeclareFieldFormat{isan}{\mkbibacro{ISAN}\addspace#1}
\DeclareFieldFormat{ismn}{\mkbibacro{ISMN}\addspace#1}
\DeclareFieldFormat{isrn}{\mkbibacro{ISRN}\addspace#1}
\DeclareFieldFormat{iswc}{\mkbibacro{ISWC}\addspace#1}
\DeclareFieldFormat{din}{\mkbibacro{DIN}\addspace#1}

% Format for doi identifier
\xpatchfieldformat{doi}{\mkbibacro{DOI}\addcolon\space}{\mkbibacro{doi}\addcolon}{}{}

% Format for eprint identifiers
\xpatchfieldformat{eprint}{\addcolon\space}{\addcomma\space}%
{}{\PackageWarning{biblatex-iso690}{Patching FieldFormat 'eprint' failed.}}
\xpatchfieldformat{eprint:hdl}{HDL\addcolon\space}{HDL\addcolon}%
{}{\PackageWarning{biblatex-iso690}{Patching FieldFormat 'eprint:hdl' failed.}}
\xpatchfieldformat{eprint:arxiv}{arXiv\addcolon\space}{arXiv\addcolon}%
{}{\PackageWarning{biblatex-iso690}{Patching FieldFormat 'eprint:arxiv' failed.}}
\xpatchfieldformat{eprint:jstor}{JSTOR\addcolon\space}{JSTOR\addcolon}%
{}{\PackageWarning{biblatex-iso690}{Patching FieldFormat 'eprint:jstor' failed.}}
\xpatchfieldformat{eprint:pubmed}{PMID\addcolon\space}{PMID\addcolon}%
{}{\PackageWarning{biblatex-iso690}{Patching FieldFormat 'eprint:pubmed' failed.}}
\xpatchfieldformat{eprint:googlebooks}{Google Books\addcolon\space}{Google Books\addcolon}%
{}{\PackageWarning{biblatex-iso690}{Patching FieldFormat 'eprint:googlebooks' failed.}}

% Format for venue
\DeclareFieldFormat{venue}{#1}

% Format url seen date with preceding localisation string in square brackets
\DeclareFieldFormat{urldate}{\mkbibbrackets{\mainlangbibstring{urlseen}\space#1}}

% Format for an event date
\DeclareFieldFormat{eventdate}{#1}

% Format additional date information as is (use bib file for modifications).
\DeclareFieldFormat{dateaddon}{#1}

% Format circa date with preceding localisation string in square brackets;
% default \datecircaprint is \bibstring{circa}\printdelim{datecircadelim},
% e.g. [ca. 1940].
\DeclareFieldFormat{date}{%
  \ifdatecirca
    {\mkbibbrackets{#1}}%
    {\ifdateannotation{date}{copyright}
      {\textcopyright\addnbthinspace#1}
      {#1}}%
}
\DeclareFieldFormat{origdate}{%
  \ifdatecirca
    {\mkbibbrackets{#1}}%
    {\ifdateannotation{origdate}{copyright}
      {\textcopyright\addnbthinspace#1}
      {#1}}%
}


% Format 'labeldate' the same as 'date' field.
% We use 'labeldate' in 'iso-authoryear' style.
% Format circa date and nodate. Dateaddon and date as is.
\DeclareFieldFormat{labeldate}{%
  \ifdatecirca
    {\mkbibbrackets{#1}}%
    {% Check if there is 'nodate' from 'labeldate'
      \iffieldequalstr{labeldatesource}{nodate}
        % This is a \literal{nodate}, meaning that it uses the 'nodate'
        % localisation string due to default \DeclareLabeldate setting
        {\mkbibbrackets{#1}}%
        {\ifboolexpr{(test {\iffieldundef{origyear}} and
        test {\ifdateannotation{date}{copyright}}) or
        (not test {\iffieldundef{origyear}} and
        test {\ifdateannotation{origdate}{copyright}})}
          {\textcopyright\addnbthinspace#1}
          {#1}}}% This is the go-to format
}

\AtEveryCite{%
\DeclareFieldFormat{labeldate}{%
  \iffieldequalstr{labeldatesource}{nodate}
    {\mkbibbrackets{#1}}%
    {#1}}%
}

% Define names to consider for 'labelname', based on
% the default definition, but adding holder as the
% very first choice for patents.
\DeclareLabelname[patent]{%
  \field{holder}
  \field{shortauthor}
  \field{author}
  \field{shorteditor}
  \field{editor}
  \field{translator}
}

% Define dates to consider for 'labeldate', based on
% the default definition, but without 'urldate' field,
% preventing printing url seen date in place of the year
% of a publication.
\DeclareLabeldate{%
  \field{origdate}% <----- used by patents
  \field{date}
  \field{year}
  \field{dateaddon}% <---- biblatex-iso690 data model extension
  \field{eventdate}
  \literal{nodate}
}

% Sorting based on the default definition, but adding
% holder and origyear to work with patent entry types.
\DeclareSortingTemplate{nyt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sortname}
    \field{holder}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{origyear}
    \field{year}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{volume}
    \literal{0}
  }
}

% Format chapter of book with preceding localisation string
\DeclareFieldFormat{chapter}{\bibstring{chapter}\addnbspace#1\isdot}

% Version field could be:
% a) numeral: use with localisation string
% b) literal: capitalize given string
\DeclareFieldFormat{version}{%
  \ifnumeral{#1}%
    {\bibstring{version}\addnbspace#1}%
    {\MakeCapital{#1}}%
}

% Format library field as is (location information)
\DeclareFieldFormat{library}{#1}

% Format (sub)titles as they are
\DeclareFieldFormat{journaltitle}{#1}
\DeclareFieldFormat{booktitle}{#1}
\DeclareFieldFormat{maintitle}{#1}
\DeclareFieldFormat{issuetitle}{#1}
\DeclareFieldFormat{eventtitle}{#1}
\DeclareFieldFormat{journalsubtitle}{#1}
\DeclareFieldFormat{booksubtitle}{#1}
\DeclareFieldFormat{mainsubtitle}{#1}
\DeclareFieldFormat{issuesubtitle}{#1}
\DeclareFieldFormat{eventsubtitle}{#1}

% Format other / alternative titles in square brackets
\DeclareFieldFormat{titleaddon}{\mkbibbrackets{#1}}
\DeclareFieldAlias{booktitleaddon}{titleaddon}
\DeclareFieldAlias{maintitleaddon}{titleaddon}
\DeclareFieldAlias{eventtitleaddon}{titleaddon}

% Format additional name information in square brackets
\DeclareFieldFormat{nameaddon}{\mkbibbrackets{#1}}



% NAME ALIAS

\newcommand*{\mknamealias}{%
  \iftoggle{bbx:givennamesfirst}
    % Standard defintion from biblatex.def
    % Default name list format is first (given) followed by last (family) name
    {given-family}
    % Default name list format is last (family) followed by first (given) name
    {family-given}%
}
\newcommand*{\mksortnamealias}{%
  \iftoggle{bbx:givennamesfirst}
    % Standard defintion from biblatex.def
    % Default sortname list format is, except for the first name in the list,
    % first (given) name followed by last (family) name
    {family-given/given-family}
    % Default name list format is last (family) followed by first (given) name
    {family-given}%
}
\AtEndOfPackage{%
\DeclareNameAlias{default}{\mknamealias}%
\DeclareNameAlias{sortname}{\mksortnamealias}%
}
\DeclareNameAlias{author}{sortname}
\DeclareNameAlias{editor}{sortname}
\DeclareNameAlias[patent]{holder}{sortname}
% For supervisor, always use the reversed order format:
% given (first) name followed by last (family) name,
% so it may sound more naturally in this order
\DeclareNameAlias{supervisor}{given-family}
% For patents, the author field is supposed to be the inventor
% of the patent, which we always want to have in reverse name order,
% since it may sound more naturally in this order
\DeclareNameAlias[patent]{author}{given-family}
% However, if there is no holder field for a patent,
% author field should be in the default order since it acts
% as a primary creator of the patent at the beginning
% of the bib reference (consistency rule)
\DeclareStyleSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pertype{patent}
      \step[fieldsource=author]
      \step[fieldset=holder, origfieldval]
    }
  }
}




% BIBLIOGRAPHY MACROS

% NAMES MACROS

% Based on author/editor macro
% Adds nameaddon field to author names
\newbibmacro*{names:primary}{%
  \ifboolexpr{test \ifuseholder and test {\ifentrytype{patent}}
                                and not test {\ifnameundef{holder}}}
    {\usebibmacro{byholder}%
    \setunit{\addspace}%
    \printfield{nameaddon}}%
    {\ifboolexpr{test \ifuseauthor and not test {\ifnameundef{author}}}
      {\usebibmacro{author}%
      \setunit{\addspace}%
      \printfield{nameaddon}}%
      {\usebibmacro{editor}}}%
}

% Macro for secondary authors with their role
\newbibmacro*{names:subsidiary}{%
  \usebibmacro{byeditor}%
  \newunit
  \usebibmacro{bytranslator}%
}

% Don't owerwrite default macros to change only delimiters / punctuation,
% declare their format instead.
% https://github.com/michal-h21/biblatex-iso690/issues/68#issuecomment-435650072
\DeclareFieldFormat{editortype}{\mkbibparens{#1}}
\DeclareDelimFormat{editortypedelim}{\addspace}

\DeclareFieldFormat{authortype}{\mkbibparens{#1}}
\DeclareDelimFormat{authortypedelim}{\addspace}

% Macro for printing supervisor field
\newbibmacro*{thesissupervisor}{%
  \ifnameundef{supervisor}
    {}
    {\mainlangbibstring{bysupervisor}%
     \setunit{\addspace}%
     \printnames{supervisor}}%
}

% Macro for printing the inventor of a patent
\newbibmacro*{patentinventor}{%
  \ifnameundef{author}
    {}
    {\mainlangbibstring{inventor}%
     \setunit{\addcolon\space}%
     \usebibmacro{author}}%
}



% TITLES MACROS

% Macro for formatting <prefix>titles
% 1st argument: prefix / type of title (e.g. main, book, event),
%               if empty, 'title' field is handled
% 2nd argument: formatting directive (e.g. emph)
\newbibmacro{titles}[2]{%
  \ifboolexpr{
    test {\iffieldundef{#1title}}
    and
    test {\iffieldundef{#1subtitle}}}
    {}
    {\printtext[#2]{%
       \printfield{#1title}%
       \setunit{\subtitlepunct}%
       \printfield{#1subtitle}}%
     \setunit{\addspace}}%
  \printfield{#1titleaddon}%
  \newunit
}%

% Macro for printing volumes (part of volumes)
\newbibmacro{volume}{%
  \iffieldundef{volume}
    {}
    {\printfield{volume}%
     \printfield{part}%
     \setunit{\addcomma\space}}%
}

% Macro for formatting multiple titles
\newbibmacro{multi:titles}{%
  \iffieldundef{maintitle}
    {\iffieldundef{booktitle}
      {\usebibmacro{titles}{}{emph}%
       \usebibmacro{volume}}
      {\usebibmacro{titles}{book}{emph}%
       \usebibmacro{volume}%
       \usebibmacro{titles}{}{}}}%
    {\usebibmacro{titles}{main}{emph}%
     \usebibmacro{volume}%
     \usebibmacro{titles}{}{}}%
}

% Macro for formatting multiple hierarchical titles
% (e.g. for inbook, incollection)
\newbibmacro{host:titles}{%
 \iffieldundef{maintitle}
   {\iffieldundef{booktitle}
      {}
      {\usebibmacro{titles}{book}{emph}}}
   {\usebibmacro{titles}{main}{emph}}%
}%

% Macro for formatting multiple titles in periodicals
\newbibmacro{periodical:titles}{%
  \usebibmacro{titles}{}{emph}%
  \newunit
  \iffieldundef{issuetitle}
    {\iffieldundef{journaltitle}
       {}
       {\usebibmacro{titles}{journal}{}}}
    {\usebibmacro{titles}{issue}{}}%
}



% MEDIUM TYPE MACROS

\newbibmacro*{medium-type}{%
  \iffieldundef{howpublished}
    {% Automatic printing of '[online]' type of medium when
     % a) 'urldate' is present AND
     % b) url is enabled (pkg option url=true) OR
     %    entry type is '@online'
      \ifboolexpr{
        not test {\iffieldundef{urlyear}}
        and (   test {\iftoggle{bbx:url}}
             or test {\ifentrytype{online}})
      }
        % Use a localisation string 'online' in the main document language
        {\midsentence\mainlangbibstring[\mkbibbrackets]{online}}%
        {}}% Don't print anything
    {% The only situation when we don't want to print
     % 'howpublished' field is when
     % a) url is disabled (pkg option url=false) AND
     % b) entry type is other than '@online' AND
     % c) 'howpublished' field is 'online'.
     % Please note that this field is not checked against
     % any possible literal value (e.g. electronic, online article)
     % that should be probably also hidden when a) AND b) hold.
      \ifboolexpr{
        test {\iffieldequalstr{howpublished}{online}}
        and not test {\iftoggle{bbx:url}}
        and not test {\ifentrytype{online}}
      }
        {}% Don't print 'howpublished' field
        {\printfield{howpublished}}}%
}



% EDITION INFO MACROS

% Refresh date
\newbibmacro{refreshdate}{%
  % the date is only supposed to be a refreshdate
  % if we have an origdate
  \iffieldundef{origyear}
    {}
    {\mainlangbibstring{refreshedon}\space\printdate}
}



% PUBLICATION INFO MACROS

% By default only year is used, but for some entries,
% we need full date (day or even time precision),
% (e.g. patents, TV shows, newspapers, online news)

% Macro for printing full date (full = YYYY-MM-DD)
\newbibmacro*{fulldate}{%
  \iffieldundef{year}
    {\iffieldundef{dateaddon}
      {\bibstring[\mkbibbrackets]{nodate}}%
      {\printfield{dateaddon}}}%
    {\iffieldundef{month}
       {\printdate}%            % en dash for ranges
       {\mkdaterangeiso{}}%     % keep ISO YYYY-MM-DD for full dates
     \setunit{\dateaddonpunct}%
     \printfield{dateaddon}}%
}

% a)
% If there is no date field in the bib entry,
% we should state there is no date by printing
% a localisation string, e.g. [n.d.].
% b)
% Order: <date> <dateaddon>
\renewbibmacro*{date}{%
  \iffieldundef{year}
    {\iffieldundef{dateaddon}
      {\bibstring[\mkbibbrackets]{nodate}}%
      {\printfield{dateaddon}}}%
    {\printdate%
     \setunit{\dateaddonpunct}%
     \printfield{dateaddon}}%
}

% Based on publisher+location+date macro (defined in standard.bbx)
% Differs only in punctuation, and printing the organization field
%
% Wrapper for printing normal or full date. 1st argument:
% a) <empty>: \usebibmacro{date}
% b) 'full' : \usebibmacro{fulldate}
\newbibmacro*{location+publisher+dateform}[1]{%
  \printlist{location}%
  \ifboolexpr{test {\iflistundef{publisher}} and
              test {\iflistundef{institution}} and
              test {\iflistundef{organization}}}
    {\setunit*{\addcomma\space}}
    {\setunit*{\subtitlepunct}}% <---- different punctuation
  \printlist{publisher}%
  \setunit*{\addcomma\space}%
  \printlist{institution}%
  \setunit*{\addcomma\space}%
  \printlist{organization}%
  \setunit*{\addcomma\space}%
  \usebibmacro{#1date}%
  \newunit}

\newbibmacro*{location+publisher+date}{%
  \usebibmacro{location+publisher+dateform}{}}

\newbibmacro*{location+publisher+fulldate}{%
  \usebibmacro{location+publisher+dateform}{full}}



% ADDITIONAL DATE MACROS FOR PATENTS

% Application date
\newbibmacro{applicationdate}{%
  \iffieldundef{origyear}
    {}
    {\mainlangbibstring{application}\addcolon\space\printorigdate}
}

% Publication date
\newbibmacro{publicationdate}{%
  \iffieldundef{year}
    {}
    {\mainlangbibstring{publication}\addcolon\space\usebibmacro{fulldate}}
}



% NUMERATION MACROS

\newbibmacro*{serial:numeration}{%
  \printfield{volume}%
  \iftoggle{bbx:shortnum}
    {}
    {\setunit*{\addcomma\space}}%
  \printfield{number}%
}

\newbibmacro*{book:numeration}{%
  \printfield{volume}%
  \setunit*{\addcomma\space}%
  \printfield{chapter}%
}



% SERIES TITLE AND NUMBER MACROS

% Based on series+number macro (defined in standard.bbx)
% Differs only in punctuation
\newbibmacro*{series+number}{%
  \printfield{series}%
  \setunit*{\addcomma\space}%
  \printfield{number}%
}%



% STANDARD IDENTIFIERS MACROS

% Bunch of standard identifiers
\newbibmacro*{identifier}{%
  \iftoggle{bbx:isbn}
    {\printfield{isan}%
     \newunit
     \printfield{eisbn}%
     \newunit
     \printfield{isbn}%
     \newunit
     \printfield{lccn}%
     \newunit
     \printfield{ismn}%
     \newunit
     \printfield{isrn}%
     \newunit
     \printfield{eissn}%
     \newunit
     \printfield{issn}%
     \newunit
     \printfield{iswc}%
     \newunit
     \printfield{din}%
     \newunit}
    {}%
}



% AVAILABILITY AND ACCESS MACROS

% Precedes DOI field with urlfrom localisation string
\newbibmacro*{from-doi}{%
  \ifentrytype{book}
    {\iffieldequalstr{type}{eBook}
      {\mainlangbibstringcolon{urlfrom}}
      {\mainlangbibstringcolon{urlalso}}}
    {\mainlangbibstringcolon{urlfrom}}%
  %\setunit{\addcolon\space}%
  % \addcolon\space%
  \printfield{doi}%
}


% Precedes eprint field with urlfrom localisation string
% Use default eprint formatting macro
\newbibmacro*{from-eprint}{%
  \mainlangbibstringcolon{urlfrom}
  % \setunit{\addcolon\space}%
  \usebibmacro{eprint}%
}

% Macro for availability and access information
% with order of importance: doi, eprint, url
\newbibmacro*{availability+access}{%
  \ifboolexpr{
    test {\iftoggle{bbx:doi}}
    and not test {\iffieldundef{doi}}
  }
    {\usebibmacro{from-doi}}%
    {%
      \ifboolexpr{
        test {\iftoggle{bbx:eprint}}
        and not test {\iffieldundef{eprint}}
      }
        {\usebibmacro{from-eprint}}%
        {\usebibmacro{url}}}%
}

% The url field of @online entries is always printed
\renewbibmacro*{url}{%
  \ifboolexpr{
    test {\iftoggle{bbx:url}}
    or test {\ifentrytype{online}}
  }
    {\printfield{url}}%
    {}%
}

\newbibmacro*{urldate-space}{%
  % if there is no publisher specified in the bib file, set unit to dot,
  % so there is a separation between previous block
  \ifboolexpr{%
    test {\iflistundef{publisher}}%
    and test {\iflistundef{location}}%
    and test {\iffieldundef{year}}%
    and test {\iffieldundef{version}}%
  }{\setunit{\adddot\addspace}}%
  {\setunit{\addspace}}%
}

% The url seen date of @online entries is always printed
\renewbibmacro*{urldate}{%
  \ifboolexpr{
    test {\iftoggle{bbx:url}}
    or test {\ifentrytype{online}}
  }
    {\printurldate}%
    {}%
}



% LOCATION MACROS

% Additional location information (e.g. library, repository)
\newbibmacro*{location}{%
  \iffieldundef{library}
    {}
    {\usebibmacro{at:}%
     \printfield{library}}%
}



% NOTES MACROS

% Event information
\newbibmacro*{event}{%
  \printfield{eventtitle}%
  \setunit{\addspace}%
  \printfield{eventtitleaddon}%
  \newunit
  \printfield{venue}%
  \setunit{\addcomma\addspace}%
  \printeventdate
}



% OTHER MACROS

% Redeclare in: bibmacro to use the main document language.
% There was discussion whether literal "In:" should be used,
% but that would look weird in non-latin languages.
% Context: https://github.com/michal-h21/biblatex-iso690/pull/33

% Force to use the main document language for 'in' localisation string
\renewbibmacro*{in:}{%
  \mainlangbibstring{in}%
  \printunit{\intitlepunct}%
}

% Based on 'in:' macro for 'at' localisation string
\newbibmacro*{at:}{%
  \mainlangbibstring{at}%
  \printunit{\intitlepunct}%
}




% BIBLATEX CORE ADJUSTMENTS

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Localisation strings in the main document language
%
% \mainlangbibstring in place of \bibstring
% \mainlangbiblstring in place of \biblstring
% \mainlangbibsstring in place of \bibsstring

% [<wrapper>]{<string>}
\newrobustcmd*{\blx@imc@mainlangbibstring}[2][\@firstofone]{%
  \blx@mainlangbibstring{#1}{\abx@str}{#2}}

\newrobustcmd*{\blx@imc@mainlangbiblstring}[2][\@firstofone]{%
  \blx@mainlangbibstring{#1}{abx@lstr}{#2}}

\newrobustcmd*{\blx@imc@mainlangbibsstring}[2][\@firstofone]{%
  \blx@mainlangbibstring{#1}{abx@sstr}{#2}}

\newrobustcmd*{\mainlangbibstringcolon}[1]{\textmainlang{\bibstring{#1}\addcolon\space}}


% We use Babel or Polyglossia main document language for some
% bibliography strings. With currentlang option, the currently
% selected language is used instead. It is useful in some classes
% that don't support selection of the main language.
% https://github.com/michal-h21/biblatex-iso690/issues/90
\newcommand\blx@selectlangmacro{%
  \ifboolexpr{%
        test {\iftoggle{bbx:currentlang}}%
        and test {\ifdef{\textouterlang}}%
      }%
      {\let\iso@mainlang\textouterlang}{\let\iso@mainlang\textmainlang}%
}

\protected\def\blx@mainlangbibstring#1#2#3{%
  \blx@begunit%
  \blx@hyphenreset%
  \blx@bibstringsimple%
  \blx@selectlangmacro%
  \lowercase{\edef\blx@tempa{#3}}%
  \ifcsundef{#2@\blx@tempa}%
    {\blx@warn@nostring\blx@tempa%
     \blx@endnounit}%
    {\blx@imc@ifcapital%
       {\iso@mainlang{#1{\MakeCapital{\csuse{#2@\blx@tempa}}}}}%
       {\iso@mainlang{#1{\csuse{#2@\blx@tempa}}}}%
     \blx@endunit}}

\blx@regimcs{%
  \mainlangbibstring \mainlangbiblstring \mainlangbibsstring
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Overriding bookpagination to use document main language
%
% Use new name 'mkpagetotal' over 'mkmlpagetotal'
% Use 'mainlangbibsstring' over 'bibstring'

\newrobustcmd*{\blx@imc@mkmlpagetotal}[1][bookpagination]{%
  \begingroup
  \def\blx@tempa{\blx@mkmlpagetotal{pagetotal}}%
  \iffieldundef{#1}
    {}
    {\iffieldequalstr{#1}{none}
       {\def\blx@tempa{\blx@mkmlpagetotal@i}}
       {\iffieldplusstringbibstring{#1}{total}
          {\edef\blx@tempa{\blx@mkmlpagetotal{\thefield{#1}total}}}
          {\blx@warning@entry{%
             Unknown pagination type '\strfield{#1}total'}}}}%
  \@ifnextchar[%]
    {\blx@tempa}
    {\blx@tempa[\@firstofone]}}

\protected\long\def\blx@mkmlpagetotal#1[#2]#3{%
  \ifnumeral{#3}
    {\setbox\@tempboxa=\hbox{%
       \blx@tempcnta0#3\relax
       \ifnum\blx@tempcnta=\@ne
         \aftergroup\@firstoftwo
       \else
         \aftergroup\@secondoftwo
       \fi}%
     {#2{#3}\ppspace\mainlangbibsstring{#1}}
     {#2{#3}\ppspace\mainlangbibsstring{#1s}}}
    {\def\pno{\mainlangbibsstring{#1}}%
     \def\ppno{\mainlangbibsstring{#1s}}%
     #2{#3}}%
  \endgroup}

\long\def\blx@mkmlpagetotal@i[#1]#2{#1{#2}\endgroup}

\blx@regimcs{\mkmlpagetotal}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Overriding pagination to use document main language
%
% Use new name 'mkmlpageprefix' over 'mkpageprefix'
% Use 'mainlangbibsstring' over 'bibstring'

\newrobustcmd*{\blx@imc@mkmlpageprefix}[1][pagination]{%
  \begingroup
  \def\blx@tempa{\blx@mkmlpageprefix{page}}%
  \iffieldundef{#1}
    {}
    {\iffieldequalstr{#1}{none}
       {\def\blx@tempa{\blx@mkmlpageprefix@i}}
       {\iffieldbibstring{#1}
          {\edef\blx@tempa{\blx@mkmlpageprefix{\thefield{#1}}}}
          {\blx@warning@entry{%
             Unknown pagination type '\strfield{#1}'}}}}%
  \@ifnextchar[%]
    {\blx@tempa}
    {\blx@tempa[\@firstofone]}}

\protected\long\def\blx@mkmlpageprefix#1[#2]#3{%
  \ifnumeral{#3}
    {\mainlangbibsstring{#1}\ppspace}
    {\ifnumerals{#3}
       {\mainlangbibsstring{#1s}\ppspace}
       {\def\pno{\mainlangbibsstring{#1}}%
        \def\ppno{\mainlangbibsstring{#1s}}}}%
  \blx@mkmlpageprefix@i[#2]{#3}}

\long\def\blx@mkmlpageprefix@i[#1]#2{#1{#2}\endgroup}

\blx@regimcs{\mkmlpageprefix}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use space punctuation, package option 'spacecolon',
% toggle 'bbx:spcolon', command '\addspcolon' / '\addspacecolon'

% See 'biblatex.sty' for these macros
%
% Let biblatex know the new macro
\blx@regimcs{\addspcolon}
% Define the new macro
\protected\def\blx@imc@addspcolon{\blx@addsppunct{colon}}
% Implement the new macro
\def\blx@addsppunct#1{% <---- new name for spaced punctuation
  %\unspace <----- commented out
  \ifnum\blx@spacefactor<\blx@sf@threshold@low
    \csuse{blx@qp@#1}\csuse{abx@#1}%
  \else%
    \ifnum\blx@spacefactor>\blx@sf@threshold@high
      \csuse{blx@qp@#1}\csuse{abx@#1}%
    \else%
      \ifcsdef{blx@pp@\the\csname blx@sf@#1\endcsname @\blx@spacefactor}%
        {\csuse{blx@qp@#1}\csuse{abx@#1}}%
        {\csuse{blx@qp@#1}}%%
    \fi%
  \fi%
  \csuse{blx@pq@#1}}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Adds non-breaking space after open date range, e.g. '1492-- '
%

\newcommand*{\mkopenendeddaterange}{\mbox{\bibdaterangesep\addnbspace}}% <---- added \addnbspace

% Used by '\printdate'
\xpatchcmd{\mkdaterangefull}{\mbox{\bibdaterangesep}}{\mkopenendeddaterange}%
{}{\PackageWarning{biblatex-iso690}{Patching Command '\mkdaterangefull' failed.}}
% Used by '\printlabeldateextra' in 'iso-authoryear.bbx'
\xpatchcmd{\mkdaterangefullextra}{\mbox{\bibdaterangesep}}{\mkopenendeddaterange}%
{}{\PackageWarning{biblatex-iso690}{Patching Command '\mkdaterangefullextra' failed.}}
% Other date formats for completeness
\xpatchcmd{\mkdaterangetrunc@i}{\mbox{\bibdaterangesep}}{\mkopenendeddaterange}%
{}{\PackageWarning{biblatex-iso690}{Patching Command '\mkdaterangetrunc@i' failed.}}
\xpatchcmd{\mkdaterangetruncextra@i}{\mbox{\bibdaterangesep}}{\mkopenendeddaterange}%
{}{\PackageWarning{biblatex-iso690}{Patching Command 'mkdaterangetruncextra@i' failed.}}
\xpatchcmd{\mkdaterangeymd}{\mbox{\bibdaterangesep}}{\mkopenendeddaterange}%
{}{\PackageWarning{biblatex-iso690}{Patching Command '\mkdaterangeymd' failed.}}
\xpatchcmd{\mkdaterangeymdextra}{\mbox{\bibdaterangesep}}{\mkopenendeddaterange}%
{}{\PackageWarning{biblatex-iso690}{Patching Command '\mkdaterangeymdextra' failed.}}




% BIBLIOGRAPHY DRIVERS

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{multi:titles}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \usebibmacro{refreshdate}%
  \newunit\newblock
  \usebibmacro{names:subsidiary}%
  \newunit\newblock
  \usebibmacro{location+publisher+date}%
  \newunit
  \printfield{version}%
  \usebibmacro{urldate-space}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{volumes}
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \newunit\newblock
  \usebibmacro{location}%
  \setunit{\addspace}%
  \iftoggle{bbx:totalpages}
    {\printfield{pagetotal}}
    {}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{periodical}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  % Names macro just because of author-year style
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{periodical:titles}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \usebibmacro{refreshdate}%
  \newunit\newblock
  \usebibmacro{location+publisher+date}%
  \setunit{\numerationpunct}%
  \usebibmacro{serial:numeration}%
  \setunit{\addspace}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \newunit\newblock
  \usebibmacro{location}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}%

\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{titles}{}{}%
  \newunit\newblock
  \usebibmacro{titles}{journal}{emph}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \usebibmacro{refreshdate}%
  \newunit\newblock
  \iftoggle{bbx:articlepubinfo}
    {\usebibmacro{location+publisher+date}}
    {\usebibmacro{date}}%
  \setunit{\numerationpunct}%
  \usebibmacro{serial:numeration}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \setunit{\addspace}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \newunit\newblock
  \usebibmacro{location}%
  \newunit\newblock
  \printfield{addendum}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}%

\DeclareBibliographyDriver{inbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{titles}{}{}%
  \newunit\newblock
  \usebibmacro{in:}%
  \printnames{bookauthor}%
  \newunit\newblock
  \usebibmacro{host:titles}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \usebibmacro{refreshdate}%
  \newunit\newblock
  \usebibmacro{names:subsidiary}%
  \newunit\newblock
  \usebibmacro{location+publisher+date}%
  \setunit{\addcomma\space}%
  \usebibmacro{book:numeration}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \printfield{version}%
  \setunit{\addspace}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \newunit\newblock
  \usebibmacro{location}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}%

\DeclareBibliographyDriver{incollection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{titles}{}{}%
  \newunit\newblock
  \usebibmacro{in:}%
  \usebibmacro{editor}%
  \newunit\newblock
  \usebibmacro{host:titles}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \usebibmacro{refreshdate}%
  \newunit\newblock
  \usebibmacro{names:subsidiary}%
  \newunit\newblock
  \usebibmacro{location+publisher+date}%
  % could number be even used in `incollection`?
  % It should be at some other place in this case
  \setunit{\numerationpunct}%
  \usebibmacro{book:numeration}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \printfield{version}%
  \setunit{\addspace}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \newunit\newblock
  \usebibmacro{location}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}%

\DeclareBibliographyDriver{inproceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{titles}{}{}%
  \newunit\newblock
  \usebibmacro{in:}%
  \usebibmacro{editor}%
  \newunit\newblock
  \usebibmacro{host:titles}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \usebibmacro{refreshdate}%
  \newunit\newblock
  \usebibmacro{names:subsidiary}%
  \newunit\newblock
  \usebibmacro{location+publisher+date}%
  % could number be even used in `inproceedings`?
  % It should be at some other place in this case
  \setunit{\numerationpunct}%
  \usebibmacro{book:numeration}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit
  \printfield{version}%
  \setunit{\addspace}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \newunit\newblock
  \usebibmacro{location}%
  \newunit\newblock
  \usebibmacro{event}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}%

\DeclareBibliographyDriver{misc}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \iffieldundef{maintitle}
    {\usebibmacro{multi:titles}}
    {\usebibmacro{titles}{}{}%
    \newunit\newblock
    \usebibmacro{in:}%
    \usebibmacro{editor}%
    \newunit\newblock
    \usebibmacro{host:titles}}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \usebibmacro{refreshdate}%
  \newunit\newblock
  \usebibmacro{names:subsidiary}%
  \newunit\newblock
  \printlist{institution}%
  \newunit\newblock
  \usebibmacro{location+publisher+date}%
  \newunit
  \printfield{version}%
  \usebibmacro{urldate-space}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{volumes}
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \newunit\newblock
  \usebibmacro{location}%
  \setunit{\addspace}%
  \iftoggle{bbx:totalpages}
    {\printfield{pagetotal}}
    {}%
  \newunit\newblock
  \usebibmacro{event}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{online}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{multi:titles}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \usebibmacro{refreshdate}%
  \newunit\newblock
  \usebibmacro{names:subsidiary}%
  \newunit\newblock
  \usebibmacro{location+publisher+fulldate}%
  \newunit
  \printfield{version}%
  \usebibmacro{urldate-space}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \setunit{\addspace}%
  \iftoggle{bbx:totalpages}
    {\printfield{pagetotal}}
    {}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}%

\DeclareBibliographyDriver{thesis}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{titles}{}{emph}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \printfield{type}%
  \newunit\newblock
  \usebibmacro{thesissupervisor}%
  \newunit\newblock
  \usebibmacro{location+publisher+date}%
  \newunit
  \printfield{version}%
  \usebibmacro{urldate-space}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \setunit{\addspace}%
  \iftoggle{bbx:totalpages}
    {\printfield{pagetotal}}
    {}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}%

\DeclareBibliographyDriver{report}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{titles}{}{emph}%
  \setunit{\addspace}%
  \usebibmacro{medium-type}%
  \newunit\newblock
  \usebibmacro{refreshdate}%
  \newunit\newblock
  \usebibmacro{location+publisher+fulldate}%
  \newunit
  \printfield{version}%
  \usebibmacro{urldate-space}%
  \usebibmacro{urldate}%
  \newunit\newblock
  \iffieldundef{type}
    {}
    {\printfield{type}%
     \setunit*{\addcomma\space}}%
  \printfield{number}%
  \newunit\newblock
  \printlist{institution}%
  \newunit\newblock
  \usebibmacro{identifier}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \setunit{\addspace}%
  \iftoggle{bbx:totalpages}
    {\printfield{pagetotal}}
    {}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{patent}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{names:primary}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{titles}{}{emph}%
  \newunit\newblock
  \usebibmacro{names:subsidiary}%
  \newunit\newblock
  \usebibmacro{patentinventor}%
  \newunit
  \usebibmacro{publicationdate}%
  \newunit
  \usebibmacro{applicationdate}%
  \newunit
  \printfield{note}%
  \newunit\newblock
  \printlist{location}%
  \newunit\newblock
  \iffieldundef{type}
    {}
    {\printfield{type}%
     \setunit*{\addspace}}%
  \printfield{number}%
  \newunit\newblock
  \usebibmacro{urldate}%
  \newunit\newblock
  \usebibmacro{availability+access}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}%

% BIBLIOGRAPHY ALIASES

\DeclareBibliographyAlias{mvbook}{book}
\DeclareBibliographyAlias{bookinbook}{inbook}
\DeclareBibliographyAlias{suppbook}{inbook}
\DeclareBibliographyAlias{booklet}{book}
\DeclareBibliographyAlias{collection}{book}
\DeclareBibliographyAlias{mvcollection}{collection}
\DeclareBibliographyAlias{suppcollection}{incollection}
\DeclareBibliographyAlias{manual}{book}
\DeclareBibliographyAlias{suppperiodical}{article}
\DeclareBibliographyAlias{proceedings}{collection}
\DeclareBibliographyAlias{reference}{collection}
\DeclareBibliographyAlias{inreference}{incollection}
\DeclareBibliographyAlias{unpublished}{misc}
\DeclareBibliographyAlias{movie}{book}
\DeclareBibliographyAlias{music}{book}
\DeclareBibliographyAlias{*}{misc}

\endinput

% vim: ft=tex
