\ProvidesFile{gost-standard.bbx}
[2023/04/25\space v1.24\space biblatex-gost styles]

\def\bbx@gost@date{2023/04/25}
\def\bbx@gost@version{1.24}

\@ifpackagelater{biblatex}{2019/09/01}
  {}
  {\PackageError{biblatex}
    {Outdated 'biblatex' package}
    {This version of 'biblatex-gost' requires biblatex v3.14 or
    later.\MessageBreak You are using: '\csuse{ver@biblatex.sty}'.\MessageBreak
     This is a fatal error. I'm aborting now.}%
    \endinput}

\ifpdftex
\@ifpackagelater{biblatex}{2020/08/23}  % v3.15a+
  {}
  {\PackageWarningNoLine{biblatex-gost}{Applying temporary patch for 
    Unicode symbols.\MessageBreak For details see biblatex issue \protect#960}
  \AtEndPreamble{\DefineBibliographyStrings{russian}{number={\textnumero}}}}
\fi

\AtEndOfPackage{%
\ifboolexpr{
      test {\ifdefstring{\blx@opt@movenames}{true}}
      and
      ( not test {\ifnumequal{\blx@maxbibnames}{3}}
        or
        not test {\ifnumequal{\blx@maxcitenames}{3}}
      )
      }
  {\PackageWarningNoLine{biblatex-gost}{You set maxbibnames or maxcitenames\MessageBreak
    different from their default value 3.\MessageBreak
    Make sure that sorting works as expected}}
  {}}

\RequireBiber[3]  % strictly required

% workaround for the \mkrelatedstring deprecation.
% https://github.com/odomanov/biblatex-gost/issues/27
\providecommand*{\mkrelatedstringtext}[1]{{{\mainlang #1}}}

\blx@inputonce{biblatex-gost.def}{biblatex-gost generic definitions}{}{}{}{}

\newtoggle{bbx:isbn}
\newtoggle{bbx:url}
\newtoggle{bbx:doi}
\newtoggle{bbx:eprint}
\newtoggle{cbx:isbn}
\newtoggle{cbx:url}
\newtoggle{cbx:doi}
\newtoggle{cbx:eprint}
\newtoggle{bbx:related:bib}
\newtoggle{bbx:related:cite}
\newtoggle{bbx:gost:otherlangs}
\newtoggle{bbx:gostbibliography}
\togglefalse{bbx:gostbibliography}

%  OPTIONS

\DeclareBibliographyOption{otherlangs}[true]{%
  \ifstrequal{#1}{true}
    {\toggletrue{bbx:gost:otherlangs}}
    {\togglefalse{bbx:gost:otherlangs}}
  }

\newbibmacro*{bbx:savehash}{%
  \savefield{fullhash}{\bbx@lasthash}}
\DeclareBibliographyOption{dashed}[true]{%
  \ifstrequal{#1}{true}
    {\ExecuteBibliographyOptions{pagetracker}%
     \renewbibmacro*{bbx:savehash}{\savefield{fullhash}{\bbx@lasthash}}}
    {\renewbibmacro*{bbx:savehash}{}}}

% block punctuation = emdash / space
% \bibsentence is for vol,etc.
\DeclareBibliographyOption{blockpunct}[emdash]{%
  \ifstrequal{#1}{emdash}
    {\renewcommand*{\newblockpunct}{\addperiod\addnbspace\textemdash\space\bibsentence}}
    {\renewcommand*{\newblockpunct}{\addperiod\space\bibsentence}}
}

\DeclareBibliographyOption{isbn}[true]{%
  \global\settoggle{bbx:isbn}{#1}%
  \global\settoggle{cbx:isbn}{#1}}
\DeclareBibliographyOption{url}[true]{%
  \global\settoggle{bbx:url}{#1}%
  \global\settoggle{cbx:url}{#1}}
\DeclareBibliographyOption{doi}[true]{%
  \global\settoggle{bbx:doi}{#1}%
  \global\settoggle{cbx:doi}{#1}}
\DeclareBibliographyOption{eprint}[true]{%
  \global\settoggle{bbx:eprint}{#1}%
  \global\settoggle{cbx:eprint}{#1}}
\DeclareBibliographyOption{bibisbn}[true]{%
  \global\settoggle{bbx:isbn}{#1}}
\DeclareBibliographyOption{biburl}[true]{%
  \global\settoggle{bbx:url}{#1}}
\DeclareBibliographyOption{bibdoi}[true]{%
  \global\settoggle{bbx:doi}{#1}}
\DeclareBibliographyOption{bibeprint}[true]{%
  \global\settoggle{bbx:eprint}{#1}}
\DeclareBibliographyOption{citeisbn}[true]{%
  \global\settoggle{cbx:isbn}{#1}}
\DeclareBibliographyOption{citeurl}[true]{%
  \global\settoggle{cbx:url}{#1}}
\DeclareBibliographyOption{citedoi}[true]{%
  \global\settoggle{cbx:doi}{#1}}
\DeclareBibliographyOption{citeeprint}[true]{%
  \global\settoggle{cbx:eprint}{#1}}
\DeclareBibliographyOption{related}[true]{%
  \ifcsdef{bbx@opt@related@#1}
    {\csuse{bbx@opt@related@#1}}
    {\PackageError{biblatex}
       {Invalid option 'related=#1'}
       {Valid values are 'true', 'false', 'bib', and 'cite'.}}}

\def\bbx@opt@related@true{%
  \toggletrue{bbx:related:bib}%
  \toggletrue{bbx:related:cite}}

\def\bbx@opt@related@false{%
  \togglefalse{bbx:related:bib}%
  \togglefalse{bbx:related:cite}}

\def\bbx@opt@related@bib{%
  \toggletrue{bbx:related:bib}%
  \togglefalse{bbx:related:cite}}

\def\bbx@opt@related@cite{%
  \togglefalse{bbx:related:bib}%
  \toggletrue{bbx:related:cite}}

\newcommand*{\blx@gost@defaultorder}{vbpi}
\DeclareBibliographyOption{volsorder}[vbpi]{%
  \renewcommand*{\blx@gost@defaultorder}{#1}}

\DeclareBibliographyOption{movenames}[true]{%
  \gdef\blx@opt@movenames{#1}}

\newtoggle{bbx:gost:doublevols}
\DeclareBibliographyOption{doublevols}[true]{%
  \ifstrequal{#1}{true}
    {\toggletrue{bbx:gost:doublevols}}
    {\togglefalse{bbx:gost:doublevols}}}

\AtEndOfPackage{%
  \ifdefstring{\blx@opt@movenames}{true}
    {\DeclareStyleSourcemap{
      \maps[datatype=bibtex]{
        \map[overwrite]{
          \step[fieldsource=author,
            match=\regexp{(.+\s+and\s+){3,}|and\s+others\s*$},
            final]
          \step[fieldsource=options,
            match=\regexp{(.+)},
            replace=\regexp{useauthor=false,$1}]
          \step[fieldsource=options,
            match=\regexp{^$},
            replace=\regexp{useauthor=false}]
        }
        \map{
          \step[fieldsource=author,
            match=\regexp{(.+\s+and\s+){3,}|and\s+others\s*$},
            final]
          \step[fieldset=options, fieldvalue={useauthor=false}]
        }
        \map[overwrite]{
          \step[fieldsource=editor,
            match=\regexp{(.+\s+and\s+){3,}|and\s+others\s*$},
            final]
          \step[fieldsource=options,
            match=\regexp{(.+)},
            replace=\regexp{useeditor=false,$1}]
          \step[fieldsource=options,
            match=\regexp{^$},
            replace=\regexp{useeditor=false}]
        }
        \map{
          \step[fieldsource=editor,
            match=\regexp{(.+\s+and\s+){3,}|and\s+others\s*$},
            final]
          \step[fieldset=options, fieldvalue={useeditor=false}]
        }
        \map[overwrite, foreach={volume,book,part,issue}]{
          \step[fieldsource=\regexp{$MAPLOOP}, final]
          \step[fieldset=\regexp{internalsort$MAPLOOP}, origfieldval]
          \step[fieldsource=\regexp{internalsort$MAPLOOP},
            match=\regexp{(\d+).*},
            replace=\regexp{$1}]
        }
        \map{
          \step[typesource=candthesis,typetarget=thesis, final]
          \step[fieldset=type,        fieldvalue=phdthesis]
        }
        \map{
          \step[typesource=docthesis, typetarget=thesis, final]
          \step[fieldset=type,        fieldvalue=docthesis]
        }
        \map[overwrite]{
          \pertype{patent}
          \step[fieldsource=options, final]
          \step[fieldset=options, fieldvalue={useauthor=false,}]
          \step[fieldset=options, origfieldval, append]
        }
        \map{
          \pertype{patent}
          \step[fieldset=options, fieldvalue={useauthor=false}]
          \step[fieldsource=authortype, fieldtarget=authorcountry]
          \step[fieldsource=reqnumber,  fieldtarget=requestnumber]
          \step[fieldsource=publdate,   fieldtarget=publicationdate]
          \step[fieldsource=prdate,     fieldtarget=prioritydate]
          \step[fieldsource=prnumber,   fieldtarget=prioritynumber]
          \step[fieldsource=prcountry,  fieldtarget=prioritycountry]
        }
        \map{
          \pertype{thesis}
          \pertype{masterthesis}
          \pertype{phdthesis}
          \pertype{candthesis}
          \pertype{docthesis}
          \step[fieldsource=major,     fieldtarget=science]
          \step[fieldsource=majorcode, fieldtarget=specialitycode]
          \step[fieldsource=number,    fieldtarget=specialitycode]
        }
      }
     }
    }
   {\DeclareStyleSourcemap{
      \maps[datatype=bibtex]{
        \map[overwrite, foreach={volume,book,part,issue}]{
          \step[fieldsource=\regexp{$MAPLOOP}, final]
          \step[fieldset=\regexp{internalsort$MAPLOOP}, origfieldval]
          \step[fieldsource=\regexp{internalsort$MAPLOOP},
            match=\regexp{(\d+).*},
            replace=\regexp{$1}]
        }
        \map{
          \step[typesource=candthesis,typetarget=thesis, final]
          \step[fieldset=type,        fieldvalue=phdthesis]
        }
        \map{
          \step[typesource=docthesis, typetarget=thesis, final]
          \step[fieldset=type,        fieldvalue=docthesis]
        }
        \map[overwrite]{
          \pertype{patent}
          \step[fieldsource=options, final]
          \step[fieldset=options, fieldvalue={useauthor=false,}]
          \step[fieldset=options, origfieldval, append]
        }
        \map{
          \pertype{patent}
          \step[fieldset=options, fieldvalue={useauthor=false}]
          \step[fieldsource=authortype, fieldtarget=authorcountry]
          \step[fieldsource=reqnumber,  fieldtarget=requestnumber]
          \step[fieldsource=publdate,   fieldtarget=publicationdate]
          \step[fieldsource=prdate,     fieldtarget=prioritydate]
          \step[fieldsource=prnumber,   fieldtarget=prioritynumber]
          \step[fieldsource=prcountry,  fieldtarget=prioritycountry]
        }
        \map{
          \pertype{thesis}
          \pertype{masterthesis}
          \pertype{phdthesis}
          \pertype{candthesis}
          \pertype{docthesis}
          \step[fieldsource=major,     fieldtarget=science]
          \step[fieldsource=majorcode, fieldtarget=specialitycode]
          \step[fieldsource=number,    fieldtarget=specialitycode]
        }
      }
    }
   }
 }
 
\ExecuteBibliographyOptions{
  useeditor=false,
  usetranslator=false,
  maxnames=3,
  minnames=1,
  dashed=false,
  movenames=true,
  giveninits=true,
  volsorder=vbpi,
  related=true,
  alldates=short,
  eventdate=comp,
  blockpunct=emdash,
  doublevols=true,
  otherlangs=true,
}

\newbibmacro*{cbx:bookibid:check}[2]{#2}

%  FORMATS

\renewcommand*{\mkbibacro}[1]{\MakeUppercase{#1}}
\DeclareFieldFormat{isbn}{\mkbibacro{ISBN} #1}
\DeclareFieldFormat{isrn}{\mkbibacro{ISRN} #1}
\DeclareFieldFormat{issn}{\mkbibacro{ISSN} #1}
\DeclareFieldFormat*{title}{#1}
\DeclareFieldFormat{booktitle}{#1}
\DeclareFieldFormat{journaltitle}{#1}
\DeclareFieldFormat{issuetitle}{#1}
\DeclareFieldFormat{maintitle}{#1}

% volume etc
%
% helper for printing volume/book/number/part/issue
% [prefix] <value> <volume-string>
\newcommand{\printvol}[3][]{%
  \ifnumcomp{\rangelen{#3}}{=}{2}
    {\iftoggle{bbx:gost:doublevols}{\def\bibrangedash{\doublevolsdelim}}{}}
    {}%
  \iffieldnums{#3}
    {\ifbibstring{#3}
      {\bibstring{#3}\addabbrvspace#2}
      {#1#2}}
    {\ifcapital{\MakeCapital{#2}}{#2}\isdot}}
\DeclareFieldFormat*{volume}{\printvol{#1}{volume}}
\DeclareFieldFormat[article,periodical]{volume}{%
  \ifnumcomp{\rangelen{volume}}{=}{2}{%
    \iftoggle{bbx:gost:doublevols}{\def\bibrangedash{\doublevolsdelim}}{}%
  }{}%
  \ifbibstring{volume}
    {\bibstring{jourvol}\addabbrvspace#1}
    {#1}}
\DeclareFieldFormat*{book}{\printvol{#1}{book}}
\DeclareFieldFormat*{part}{\printvol{#1}{part}}
\DeclareFieldFormat*{issue}{\printvol{#1}{issue}}
\DeclareFieldFormat[article,periodical]{issue}{\printvol[\unspace\adddot]{#1}{issue}}
\DeclareFieldFormat*{number}{\printvol[\unspace\adddot]{#1}{number}}
% \DeclareFieldFormat*{number}{\printvol{#1}{number}}
\DeclareFieldFormat[patent]{number}{#1}%
\DeclareFieldFormat{requestnumber}{%
  \ifbibstring{number}
    {\bibsstring{number}\addnbspace#1}
    {#1}}%
\DeclareFieldFormat{seriesnumber}{#1}%

% volumes etc, involumes etc
%  
\newbibmacro*{volumes/parts/books/issues}[2]{%
  \iffieldnum{#1}
    {\ifbibstring{#1}
      {#2\addnbspace\bibsstring{#1}}
      {#2}}
    {\ifcapital{\MakeCapital{#2}}{#2}}}
\DeclareFieldFormat{volumes}{\usebibmacro{volumes/parts/books/issues}{volumes}{#1}}
\DeclareFieldFormat{parts}{\usebibmacro{volumes/parts/books/issues}{parts}{#1}}
\DeclareFieldFormat{books}{\usebibmacro{volumes/parts/books/issues}{books}{#1}}
\DeclareFieldFormat{issues}{\usebibmacro{volumes/parts/books/issues}{issues}{#1}}
\newbibmacro*{in+}[2]{%
  \iffieldnum{#1}
    {\ifbibstring{involumes}
      {\bibstring{involumes}\addabbrvspace}
      {}%
      #2\addnbspace\bibsstring{#1}}
    {\ifcapital{\MakeCapital{#2}}{#2}}}
\DeclareFieldFormat{involumes}{\usebibmacro{in+}{volumes}{#1}}
\DeclareFieldFormat{inbooks}{\usebibmacro{in+}{books}{#1}}
\DeclareFieldFormat{inparts}{\usebibmacro{in+}{parts}{#1}}
\DeclareFieldFormat{inissues}{\usebibmacro{in+}{issues}{#1}}

% dates
%
\DeclareFieldFormat{date}{%
 \iffieldundef{endyear}
   {#1}
   {\iffieldequalstr{endyear}{}
      {#1\mbox{~~~~}}
      {#1}}}
\DeclareFieldFormat{update}{%
  \ifbibstring{updated}
    {\bibstring{updated}\addcolon\space#1}
    {Updated\addcolon\space#1}}
\DeclareFieldFormat{publicationdate}{%
  \ifbibstring{published}
    {\bibstring{published}\addspace#1}
    {#1}}
\DeclareFieldFormat{requestdate}{%  = date (in @patent)
  \ifbibstring{requested}
    {\bibstring{requested}\addspace#1}
    {#1}}
\DeclareFieldFormat{prioritydate}{%
  \ifbibstring{priority}
    {\bibstring{priority}\addspace#1}
    {#1}}
\DeclareFieldFormat{systemreq}{%
  \ifbibstring{systemreq}
    {\bibstring{systemreq}\addcolon\space#1}
    {Sys. requirements\addcolon\space#1}}
\DeclareListFormat{semicolondelim}{%
  \ifnumgreater{\value{listcount}}{\value{liststart}}
    {\ifnumless{\value{listcount}}{\value{liststop}}
      {\addsemicolondelim}
      {\ifnumequal{\value{listcount}}{\value{liststop}}
        {\addsemicolondelim}
        {}}}
    {}%
    #1\isdot}
\DeclareFieldFormat{edition}{%
  \iffieldnum{edition}
    {\mkbibordedition{#1}\addnbspace\bibstring{edition}}
    {\ifcapital{\MakeCapital{#1}}{#1}\isdot}}
\DeclareFieldFormat[thesis]{type}{%
  \ifbibstring{#1}{\biblstring{#1}%
    \setunit*{\addspace}%
    \printfield{science}}%
  {#1}}
\DeclareFieldFormat{prioritycountry}{%
  \ifbibxstring{\thefield{prioritycountry}}
    {\bibcpstring{\thefield{prioritycountry}}}
    {#1}}
\DeclareFieldFormat{bracketsalways}{[#1]}
  
\DeclareNameAlias{default}{given-family}

\DefineBibliographyExtras{french}{\restorecommand\mkbibnamefamily}

% Format for names (authors, editors, translators) used as headings.
% It is defined separately, because \mkbibnamefamily, etc. cannot be
% used, since they affect all names, not only headings
\DeclareNameFormat{heading}{%
  \nameparts{#1}%
  \ifgiveninits
    {\usebibmacro{headingname:family-given}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartprefix}
      {\namepartsuffix}}
    {\usebibmacro{headingname:family-given}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}}%
    \iftoggle{bbx:gostbibliography}
      {}
      {\usebibmacro{name:andothers}}} 
\newbibmacro*{headingname:family-given}[4]{%
  \ifuseprefix
    {\usebibmacro{name:delim}{#3#1}%
     \usebibmacro{name:hook}{#3#1}%
     \ifdefvoid{#3}{}{%
       \ifcapital
         {\mkbibhdnameprefix{\MakeCapital{#3}}\isdot}
         {\mkbibhdnameprefix{#3}\isdot}%
       \ifprefchar{}{\bibnamedelimc}}%
     \mkbibhdnamefamily{#1}\isdot
     \ifdefvoid{#4}{}{\bibnamedelimd\mkbibhdnamesuffix{#4}\isdot}%
     \ifdefvoid{#2}{}{\revsdnamepunct\bibnamedelimd\mkbibhdnamegiven{#2}\isdot}}
    {\usebibmacro{name:delim}{#1}%
     \usebibmacro{name:hook}{#1}%
     \mkbibhdnamefamily{#1}\isdot
     \ifdefvoid{#4}{}{\bibnamedelimd\mkbibhdnamesuffix{#4}\isdot}%
     \ifboolexpe{%
       test {\ifdefvoid{#2}}
       and
       test {\ifdefvoid{#3}}}
       {}
       {\revsdnamepunct}%
     \ifdefvoid{#2}{}{\bibnamedelimd\mkbibhdnamegiven{#2}\isdot}%
     \ifdefvoid{#3}{}{\bibnamedelimd\mkbibhdnameprefix{#3}\isdot}}}
\newcommand*{\mkgostheading}[1]{\mkbibemph{#1}}%\nocorr}}
\DeclareFieldFormat{heading}{%
  \mkgostheading{#1}\addperiod\space}
\newcommand*{\mkbibhdnamefamily}[1]{\mkgostheading{#1}}
\newcommand*{\mkbibhdnamegiven}[1]{\mkbibhdnamefamily{#1}}
\newcommand*{\mkbibhdnameprefix}[1]{\mkbibhdnamefamily{#1}}
\newcommand*{\mkbibhdnamesuffix}[1]{\mkbibhdnamefamily{#1}}

\renewcommand*{\revsdnamepunct}{\addspace}%

\DeclareNameFormat{family-given:full}{%
  \begingroup%
  \renewcommand*{\revsdnamepunct}{\addspace}%
  \nameparts{#1}%
  \usebibmacro{name:family-given}
      {\namepartprefix}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartsuffix}
  \endgroup}

% FORMATTING COMMANDS

\newcommand*{\blxgostdblslash}{\nopunct\printtext{\addnbspace\mbox{//}\addspace}}
\newbibmacro*{//}{\blxgostdblslash}
\renewcommand*{\labelnamepunct}{\addperiod\space}
\renewcommand*{\intitlepunct}{\addspace}
\renewcommand*{\finalnamedelim}{\addcomma\space}
\renewcommand*{\finallistdelim}{\addcomma\space}
\renewcommand*{\bibpagespunct}{\addperiod\space}
\renewcommand*{\subtitlepunct}{\addcolondelim}
\newcommand*{\respdelim}{\addnbspace/\space}% delimiter before "credits"
\newcommand*{\resppunct}{\addsemicolondelim}% between "credits" items
\newcommand*{\specialitydelim}{\addnbspace\textemdash\space}% between specialitycode and speciality
\newcommand{\doublevolsdelim}{\slash}% between double volumes/numbers/...

% auxillary macros for volsorder handling
\newcounter{blx@gost@pointer}%
\newcommand*{\blx@gost@endofstring}{\@\@\@\@\@}  % end of string = \\\
\newcommand*{\blx@gost@setunit}{\newunit}

\ifboolexpr{%
    test {\@ifpackageloaded{babel}}
    or
    test {\@ifpackageloaded{polyglossia}}
  }
  {\edef\gostmedialanguage{\csname bbl@main@language\endcsname}%
   \newcommand*{\select@medialanguage}{\select@language{\gostmedialanguage}}}
  {\edef\gostmedialanguage{russian}%
   \newcommand*{\select@medialanguage}{}}

% macros and formats for printing origlanguage and bookoriglanguage.
% made special to simplify making them lists

\@ifpackagelater{biblatex}{2016/12/06} %biblatex 3.8+
{
% \DeclareListFormat{origlanguage}{%
%   \bibstring{from#1}}

% used for printing origlanguage and bookoriglanguage
\newcommand*{\lbx@gost@lfromlang}[1]{%
  \iflistundef{#1}
    {\unspace}
    {\printlist[lfromoriglanguage]{#1}}}
\newcommand*{\lbx@gost@sfromlang}[1]{%
  \iflistundef{#1}
    {\unspace}
    {\printlist[sfromoriglanguage]{#1}}}
% \renewcommand*{\lbx@lfromlang}{\lbx@gost@lfromlang{origlanguage}}
% \renewcommand*{\lbx@sfromlang}{\lbx@gost@sfromlang{origlanguage}}
\newcommand*{\blx@gost@iflangundef}[3]{\iflistundef{#1}{#2}{#3}}
\newcommand*{\blx@gost@iflangsequal}[4]{\iflistsequal{#1}{#2}{#3}{#4}}}
{
\DeclareFieldFormat{origlanguage}{%
  \bibstring{from#1}}

\newcommand*{\lbx@gost@lfromlang}[1]{%
  \iffieldundef{#1}
    {\unspace}
    {\printfield[origlanguage]{#1}}}
\newcommand*{\lbx@gost@sfromlang}[1]{%
  \iffieldundef{#1}
    {\unspace}
    {\printfield[origlanguage]{#1}}}
% \renewcommand*{\lbx@lfromlang}{\lbx@gost@lfromlang{origlanguage}}
% \renewcommand*{\lbx@sfromlang}{\lbx@gost@sfromlang{origlanguage}}
\newcommand*{\blx@gost@iflangundef}[3]{\iffieldundef{#1}{#2}{#3}}
\newcommand*{\blx@gost@iflangsequal}[4]{\iffieldsequal{#1}{#2}{#3}{#4}}
}

% clear \newblock in citations, not in biblists
\AtUsedriver*{%
  \delimcontext{bib}%
  \ifcitation{\let\newblock\relax}{}%
  \let\finentry\blx@finentry@usedrv
  \let\abx@macro@bibindex\@empty
  \let\abx@macro@pageref\@empty}

\newbibmacro*{begentry}{%
  \csundef{savedclearedcredits}%
  \csundef{savedclearededitor}%
  \csundef{savedclearedtranslator}}
\newbibmacro*{finentry}{\finentry}
%
%-----------  Drivers  ----------------
%
\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author/translator+others}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{bytranslator+others}%
  \setunit{\space}%
  \iffieldundef{journaltitle}  % no journaltitle means electronic publication
  {\newunit\newblock
   \printlist[semicolondelim]{specdata}%
   \newunit\newblock
   \usebibmacro{jour:date}%
   \newunit\newblock
   \usebibmacro{doi+eprint+url+note}}
   {\usebibmacro{//}%
    \usebibmacro{cbx:bookibid:check}
     {\bibsentence\printtext{%
        \bibhyperlink{\csuse{%
            cbx@\iffootnote{f}{t}@bookref@%
              \iffieldundef{crossref}
                {\iffieldundef{xref}
                  {}
                  {\thefield{xref}}}
                {\thefield{crossref}}}}
            {\bibstring[\mkibid]{ibidem}}}%
        \newunit\newblock
        \usebibmacro{chapter+pages}}
     {\usebibmacro{journal}%
      \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
      \usebibmacro{jour:credits}%
      \setunit*{\resppunct}%
      \usebibmacro{byeditor}%
      \newunit\newblock
      \printlist[semicolondelim]{specdata}%
      \newunit\newblock
      \printlist{location}%              ???
      \setunit*{\addcomma\space}%
      \usebibmacro{jour:date}%
      \newunit\newblock
      \usebibmacro{jour:volume+parts+issuetitle}%
      \newunit\newblock
      \printfield{pages}%
      \newunit\newblock
      \iffieldundef{series}
        {}
        {\printtext{(\printfield{series})}}%
      \newunit\newblock
      \usebibmacro{issn}%
      \newunit\newblock}%
      \usebibmacro{doi+eprint+url+note}}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author/editor+others/translator+others}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{maintitle+volumes+parts+title}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{byeditor}%
  \setunit*{\resppunct}%
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{edition}%
  \setunit*{\respdelim}%
  \printlist[semicolondelim]{editioncredits}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \usebibmacro{isbn}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{booklet}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author/editor}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\subtitlepunct}%
  \printfield{type}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{byeditor}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \usebibmacro{location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit
  \printfield{howpublished}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{collection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{editor+others}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{maintitle+volumes+parts+title}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{byeditor}%
  \setunit*{\resppunct}%
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{edition}%
  \setunit*{\respdelim}%
  \printlist[semicolondelim]{editioncredits}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \usebibmacro{isbn}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{inbook}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author/translator+others}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{bytranslator+others}%
  \setunit{\space}%
  \usebibmacro{//}%
  \usebibmacro{cbx:bookibid:check}
     {\bibsentence\printtext{%
        \bibhyperlink{\csuse{%
            cbx@\iffootnote{f}{t}@bookref@%
              \iffieldundef{crossref}
                {\iffieldundef{xref}
                  {}
                  {\thefield{xref}}}
                {\thefield{crossref}}}}
            {\bibstring[\mkibid]{ibidem}}}%
        \newunit\newblock
        \usebibmacro{chapter+pages}}
     {\usebibmacro{maintitle+volumes+parts+booktitle}%
      \setunit{\addcolondelim}%
      \usebibmacro{book:translation}%
      \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
      \usebibmacro{book:byauthor}%
      \setunit*{\resppunct}%
      \usebibmacro{book:credits}%
      \setunit*{\resppunct}%
      \usebibmacro{book:byeditor}%
      \setunit*{\resppunct}%
      \usebibmacro{book:bytranslator+others}%
      \newunit\newblock
      \printfield{edition}%
      \setunit*{\respdelim}%
      \printlist[semicolondelim]{editioncredits}%
      \newunit\newblock
      \printlist[semicolondelim]{specdata}%
      \newunit\newblock
      \usebibmacro{publisher+location+date}%
      \newunit\newblock
      \usebibmacro{chapter+pages}%
      \newunit\newblock
      \usebibmacro{series+number}%
      \newunit\newblock
      \usebibmacro{isbn}%
      \newunit\newblock
      \usebibmacro{doi+eprint+url+note}%
      \newunit\newblock
      \usebibmacro{addendum+pubstate}%
      \setunit{\bibpagerefpunct}\newblock
      \usebibmacro{pageref}}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{incollection}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author/translator+others}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{bytranslator+others}%
  \setunit{\space}%
  \usebibmacro{//}%
  \usebibmacro{cbx:bookibid:check}
     {\bibsentence\printtext{%
        \bibhyperlink{\csuse{%
            cbx@\iffootnote{f}{t}@bookref@%
              \iffieldundef{crossref}
                {\iffieldundef{xref}
                  {}
                  {\thefield{xref}}}
                {\thefield{crossref}}}}
            {\bibstring[\mkibid]{ibidem}}}%
        \newunit\newblock
        \usebibmacro{chapter+pages}}
     {\usebibmacro{maintitle+volumes+parts+booktitle}%
      \setunit{\addcolondelim}%
      \usebibmacro{book:translation}%
      \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
      \usebibmacro{book:credits}%
      \setunit*{\resppunct}%
      \usebibmacro{book:byeditor}%
      \setunit*{\resppunct}%
      \usebibmacro{book:bytranslator+others}%
      \newunit\newblock
      \printfield{edition}%
      \setunit*{\respdelim}%
      \printlist[semicolondelim]{editioncredits}%
      \newunit\newblock
      \printlist[semicolondelim]{specdata}%
      \newunit\newblock
      \usebibmacro{publisher+location+date}%
      \newunit\newblock
      \usebibmacro{chapter+pages}%
      \newunit\newblock
      \usebibmacro{series+number}%
      \newunit\newblock
      \usebibmacro{isbn}%
      \newunit\newblock
      \usebibmacro{doi+eprint+url+note}%
      \newunit\newblock
      \usebibmacro{addendum+pubstate}%
      \setunit{\bibpagerefpunct}\newblock
      \usebibmacro{pageref}}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{inproceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author/translator+others}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{bytranslator+others}%
  \setunit{\space}%
  \usebibmacro{//}%
  \usebibmacro{cbx:bookibid:check}
     {\bibsentence\printtext{%
        \bibhyperlink{\csuse{%
            cbx@\iffootnote{f}{t}@bookref@%
              \iffieldundef{crossref}
                {\iffieldundef{xref}
                  {}
                  {\thefield{xref}}}
                {\thefield{crossref}}}}
            {\bibstring[\mkibid]{ibidem}}}%
        \newunit\newblock
        \usebibmacro{chapter+pages}}
     {\usebibmacro{maintitle+volumes+parts+booktitle}%
      \newunit
      \usebibmacro{event+venue+date}%
      \setunit{\addcolondelim}%
      \usebibmacro{book:translation}%
      \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
      \usebibmacro{book:credits}%
      \setunit*{\resppunct}%
      \usebibmacro{book:byeditor}%
      \setunit*{\resppunct}%
      \usebibmacro{book:bytranslator+others}%
      \newunit\newblock
      \printlist[semicolondelim]{specdata}%
      \newunit\newblock
      \printlist{organization}%
      \newunit
      \usebibmacro{publisher+location+date}%
      \newunit\newblock
      \usebibmacro{chapter+pages}%
      \newunit\newblock
      \usebibmacro{series+number}%
      \newunit\newblock
      \usebibmacro{isbn}%
      \newunit\newblock
      \usebibmacro{doi+eprint+url+note}%
      \newunit\newblock
      \usebibmacro{addendum+pubstate}%
      \setunit{\bibpagerefpunct}\newblock
      \usebibmacro{pageref}}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{manual}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author/editor}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\subtitlepunct}%
  \printfield{type}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \iflistundef{organization}
    {}
    {\setrespdelim%
     \printlist{organization}%
     \setunit*{\resppunct}}%
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{byeditor}%
  \setunit*{\resppunct}%
  \newunit\newblock
  \printfield{edition}%
  \setunit*{\respdelim}%
  \printlist[semicolondelim]{editioncredits}%
  \newunit
  \printfield{version}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \usebibmacro{isbn}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{misc}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author/editor}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\subtitlepunct}%
  \printfield{type}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \usebibmacro{credits}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \usebibmacro{organization+location+date}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit
  \printfield{howpublished}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{online}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author/editor}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \iflistundef{organization}
    {}
    {\setrespdelim%
     \printlist{organization}%
     \setunit*{\resppunct}}%
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{byeditor}%
  \setunit*{\resppunct}%
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \usebibmacro{date}%
  \newunit\newblock
  \printupdate%
  \newunit\newblock
  \printfield{systemreq}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{patent}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{title}%
  \setunit*{\subtitlepunct}%
  \printfield{type}%
  \setunit*{\addspace}%
  \printfield{number}%
  \iflistundef{location}
    {}
    {\setunit*{\addspace}%
     \printlist[][-\value{listtotal}]{location}}%
  \setunit{\addcolondelim}%
  \printfield{ipc}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \ifnameundef{author}
    {}
    {\setrespdelim%
      \printnames[byauthor]{author}%
      \iffieldundef{authorcountry}
        {}
        {\setunit*{\addspace}%
         \printfield[parens]{authorcountry}}%
      \setunit*{\addsemicolondelim}}%
  \ifnameundef{holder}
    {}
    {\setrespdelim%
      \usebibmacro{byholder}%
      \setunit*{\addsemicolondelim}}%
  \usebibmacro{credits}%
  \newunit\newblock
  \printfield{requestnumber}%
  \ifboolexpr{
      test {\iffieldundef{year}}
      and test {\iffieldundef{month}}
      and test {\iffieldundef{day}}
      }
      {}
      {\setunit*{\addsemicolondelim}%
       \printtext[requestdate]{\mkbibdateshort{year}{month}{day}}}%
  \setunit*{\addsemicolondelim}%
  \printpublicationdate%
  \setunit*{\addcomma\space}%
  \printfield{publication}%
  \setunit*{\addsemicolondelim}%
  \printlist[semicolondelim]{specdata}%
  \setunit*{\addsemicolondelim}%
  \usebibmacro{priority}%
  \newunit\newblock
  \printfield{pagetotal}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{periodical}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{editor}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{byeditor}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \printlist{location}%              ???
  \setunit*{\addcomma\space}%
  \usebibmacro{jour:date}%
  \newunit\newblock
  \usebibmacro{jour:volume+parts+issuetitle}%
  \newunit\newblock
  \iffieldundef{series}
    {}
    {\printtext{(\printfield{series})}}%
  \newunit\newblock
  \usebibmacro{issn}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{proceedings}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{editor+others}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{maintitle+volumes+parts+title}%
  \newunit
  \usebibmacro{event+venue+date}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{credits}%
  \setunit*{\resppunct}%
  \usebibmacro{byeditor}%
  \setunit*{\resppunct}%
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \printlist{organization}%
  \newunit
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \usebibmacro{isbn}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{report}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit{\subtitlepunct}%
  \printfield{type}%
  \setunit{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \iflistundef{institution}
    {}
    {\setrespdelim%
     \printlist[semicolondelim]{institution}%
     \setunit*{\resppunct}}%
  \usebibmacro{credits}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \usebibmacro{location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \usebibmacro{isrn}
  \setunit*{\addspace}%
  \printfield{number}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{thesis}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{thesistitle}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \setrespdelim%
  \printnames[family-given:full]{author}%
  \setunit*{\resppunct}%
  \usebibmacro{credits}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit
  \usebibmacro{institution+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url+note}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{unpublished}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{title}%
  \setunit*{\addcolondelim}%
  \usebibmacro{translation}%
  \def\bbx@gost@respdelim{\setunit{\respdelim}}% ----- Resp starts -----
  \usebibmacro{byauthor}%
  \setunit*{\resppunct}%
  \usebibmacro{credits}%
  \newunit\newblock
  \printlist[semicolondelim]{specdata}%
  \newunit\newblock
  \usebibmacro{location+date}%
  \newunit\newblock
  \usebibmacro{isbn}%
  \newunit\newblock
  \usebibmacro{url+urldate+note}%
  \newunit
  \printfield{howpublished}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{relatedblock}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{shorthand}{%
  \usedriver
    {\DeclareNameAlias{sortname}{default}}
    {\thefield{entrytype}}%
  \finentry}

\DeclareBibliographyAlias{mvbook}{book}
\DeclareBibliographyAlias{bookinbook}{inbook}
\DeclareBibliographyAlias{suppbook}{inbook}
\DeclareBibliographyAlias{mvcollection}{collection}
\DeclareBibliographyAlias{suppcollection}{incollection}
\DeclareBibliographyAlias{mvproceedings}{proceedings}
\DeclareBibliographyAlias{reference}{collection}
\DeclareBibliographyAlias{mvreference}{reference}
\DeclareBibliographyAlias{inreference}{incollection}
\DeclareBibliographyAlias{suppperiodical}{article}
\DeclareBibliographyAlias{review}{article}
\DeclareBibliographyAlias{*}{misc}

% (RE)DEFINING BIBMACROS

\newbibmacro*{maintitle+volumes+parts+}[1]{%
  \iffieldsequal{maintitle}{#1}
    {\clearfield{maintitle}%
     \clearfield{mainsubtitle}%
     \clearfield{maintitleaddon}}
    {\iffieldundef{maintitle}
       {\usebibmacro{#1}%
        \setunit{\addcolondelim}%
        \usebibmacro{involumes+otherparts}{\setunit*{\addcomma\space}}%
        \newunit
        \usebibmacro{volume+parts}{\newunit}}
       {\usebibmacro{maintitle}%
        \newunit
        \usebibmacro{involumes+otherparts}{\setunit*{\addcomma\space}}%
        \newunit
        \usebibmacro{volume+parts}{\newunit}%
        \newunit
        \usebibmacro{#1}}}%
  \newunit}

\newbibmacro*{maintitle+volumes+parts+title}{%
  \usebibmacro{maintitle+volumes+parts+}{title}}

\newbibmacro*{maintitle+volumes+parts+booktitle}{%
  \usebibmacro{maintitle+volumes+parts+}{booktitle}}

\newbibmacro*{event+venue+date}{%
    \ifboolexpr{
      test {\iffieldundef{eventtitle}}
      and
      test {\iffieldundef{venue}}
      and
      test {\iffieldundef{eventyear}}
    }
      {}
      {\setunit{\addspace}%
       \printtext[parens]{%
         \printfield{eventtitle}%
         \setunit{\addcolondelim}%
         \printfield{eventtitleaddon}%
         \setunit{\addcomma\space}%
         \printfield{venue}%
         \setunit*{\addcomma\space}%
         \printeventdate}}%
  \newunit}

\newbibmacro*{series+number}{%
  \iffieldundef{series}
    {}
    {\printtext{(%
      \printfield{series}%
      \setunit*{\addsemicolondelim}%
      \printfield[seriesnumber]{number})}}}

\newbibmacro*{publisher+location+date}{%
  \usebibmacro{publisher+location}%
  \setunit*{\addcomma\space}%
  \usebibmacro{date}}

\newbibmacro*{publisher+location}{%
  \printlist{location}%
  \iflistundef{publisher}
    {\setunit*{\addcomma\space}}
    {\setunit*{\addcolondelim}}%
  \printlist{publisher}}

\newbibmacro*{institution+location+date}{%
  \printlist{location}%
  \iflistundef{institution}
    {\setunit*{\addcomma\space}}
    {\setunit*{\addcolondelim}}%
  \printlist{institution}%
  \setunit*{\addcomma\space}%
  \usebibmacro{date}%
  \newunit}

\newbibmacro*{organization+location+date}{%
  \printlist{location}%
  \iflistundef{organization}
    {\setunit*{\addcomma\space}}
    {\setunit*{\addcolondelim}}%
  \printlist{organization}%
  \setunit*{\addcomma\space}%
  \usebibmacro{date}%
  \newunit}

\newbibmacro*{location+date}{%
  \printlist{location}%
  \setunit*{\addcomma\space}%
  \usebibmacro{date}%
  \newunit}

\newbibmacro*{chapter+pages}{%
  \printfield{chapter}%
  \setunit*{\bibpagespunct}%
  \printfield{pages}%
  \newunit}

\newbibmacro*{note+pages}{%
  \printfield{note}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit}

\newbibmacro*{isbn}{%
  \ifcitation
    {\iftoggle{cbx:isbn}
      {\printfield{isbn}}
      {}}
    {\iftoggle{bbx:isbn}
      {\printfield{isbn}}
      {}}}

\newbibmacro*{issn}{%
  \ifcitation
    {\iftoggle{cbx:isbn}
      {\printfield{issn}}
      {}}
    {\iftoggle{bbx:isbn}
      {\printfield{issn}}
      {}}}

\newbibmacro*{isrn}{%
  \ifcitation
    {\iftoggle{cbx:isbn}
      {\printfield{isrn}}
      {}}
    {\iftoggle{bbx:isbn}
      {\printfield{isrn}}
      {}}}

\newbibmacro*{doi+eprint+url+note}{%
  \ifcitation
    {\iftoggle{cbx:doi}
      {\printfield{doi}}
      {}}
    {\iftoggle{bbx:doi}
      {\printfield{doi}}
      {}}%
  \newunit\newblock
  \ifcitation
    {\iftoggle{cbx:eprint}
      {\usebibmacro{eprint}}
      {}}
    {\iftoggle{bbx:eprint}
      {\usebibmacro{eprint}}
      {}}%
  \newunit\newblock
  \usebibmacro{url+urldate+note}}

\newbibmacro*{addendum+pubstate}{%
  \printfield{addendum}%
  \newunit\newblock
  \printfield{pubstate}}

\renewbibmacro*{byeditorx}{%
  \ifnameundef{editora}
    {}
    {\usebibmacro{byeditor+othersstrg}{editora}%
     \setunit{\addspace}%
     \printnames[byeditora]{editora}%
     \setunit*{\resppunct}}%
  \ifnameundef{editorb}
    {}
    {\usebibmacro{byeditor+othersstrg}{editorb}%
     \setunit{\addspace}%
     \printnames[byeditorb]{editorb}%
     \setunit*{\resppunct}}%
  \ifnameundef{editorc}
    {}
    {\usebibmacro{byeditor+othersstrg}{editorc}%
     \setunit{\addspace}%
     \printnames[byeditorc]{editorc}%
     \setunit*{\resppunct}}}

\newbibmacro*{book:byeditorx}{%
  \ifnameundef{editora}
    {}
    {\usebibmacro{book:byeditor+othersstrg}{editora}%
     \setunit{\addspace}%
     \printnames[byeditora]{editora}%
     \setunit*{\resppunct}}%
  \ifnameundef{editorb}
    {}
    {\usebibmacro{book:byeditor+othersstrg}{editorb}%
     \setunit{\addspace}%
     \printnames[byeditorb]{editorb}%
     \setunit*{\resppunct}}%
  \ifnameundef{editorc}
    {}
    {\usebibmacro{book:byeditor+othersstrg}{editorc}%
     \setunit{\addspace}%
     \printnames[byeditorc]{editorc}%
     \setunit*{\resppunct}}}

% <field><true><false>
% checks if book<field> doesn't exist nor is equal to <field>,
% so that <field> should be printed
\newbibmacro*{checkbookfield}[3]{%
  \ifboolexpr{
    test {\iffieldundef{book#1}}
    or
    not test {\iffieldsequal{#1}{book#1}}
  }
  {#2}
  {#3}}

% <name><true><false>
% similar check for names
\newbibmacro*{checkbookname}[3]{%
  \ifboolexpr{
    test {\ifnameundef{book#1}}
    or
    ( not test {\ifnamesequal{#1}{book#1}}
      or
      togl {bbx:gostbibliography}
    )
  }
  {#2}
  {#3}}

% <list><true><false>
% similar check for lists
\newbibmacro*{checkbooklist}[3]{%
  \ifboolexpr{
    test {\iflistundef{book#1}}
    or
    not test {\iflistsequal{#1}{book#1}}
  }
  {#2}
  {#3}}

\newbibmacro*{credits}{%
  \iflistundef{credits}
    {}
    {\usebibmacro{checkbooklist}{credits}
      {\setrespdelim%
       \printlist[semicolondelim]{credits}%
       \savelist{credits}{\savedclearedcredits}%
       \clearlist{credits}%
      }
      {}}}

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

\renewbibmacro*{byeditor}{%
  \ifnameundef{editor}
    {}
    {\setrespdelim%
     \usebibmacro{byeditor+othersstrg}{editor}%
     \setunit{\addspace}%
     \printnames[byeditor]{editor}%
     \savename{editor}{\savedclearededitor}%
     \clearname{editor}%
     \setunit*{\resppunct}%
     \usebibmacro{byeditorx}}}

\renewbibmacro*{bytranslator+others}{%
  \ifnameundef{translator}
    {}
    {\ifboolexpr{
      test {\ifnameundef{booktranslator}}
      or
      not test {\ifnamesequal{translator}{booktranslator}}
      or
      ( not test {\blx@gost@iflangundef{origlanguage}}
        and
        test {\blx@gost@iflangundef{bookoriglanguage}}
      )
      or
      ( test {\blx@gost@iflangundef{origlanguage}}
        and
        not test {\blx@gost@iflangundef{bookoriglanguage}}
      )
      or
      ( not test {\blx@gost@iflangundef{origlanguage}}
        and
        not test {\blx@gost@iflangundef{bookoriglanguage}}
        and
        not test {\blx@gost@iflangsequal{origlanguage}{bookoriglanguage}}
      )
      }
        {\setrespdelim%
         \usebibmacro{bytranslator+othersstrg}%
         \setunit*{\addspace}%
         \printnames[bytranslator]{translator}%
         \savename{translator}{\savedclearedtranslator}%
         \clearname{translator}%
         \setunit*{\resppunct}}
        {}}%
  \usebibmacro{withothers}}

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

\renewbibmacro*{withothers}{%
  \usebibmacro{checkbookname}{commentator}
    {\usebibmacro{withcommentator}%
     \clearname{commentator}%
     \setunit*{\resppunct}}
    {}%
  \usebibmacro{checkbookname}{annotator}
    {\usebibmacro{withannotator}%
     \clearname{annotator}%
     \setunit*{\resppunct}}
    {}%
  \usebibmacro{checkbookname}{introduction}
    {\usebibmacro{withintroduction}%
     \clearname{introduction}%
     \setunit*{\resppunct}}
    {}%
  \usebibmacro{checkbookname}{foreword}
    {\usebibmacro{withforeword}%
     \clearname{foreword}%
     \setunit*{\resppunct}}
    {}%
  \usebibmacro{checkbookname}{afterword}
    {\usebibmacro{withafterword}%
     \clearname{afterword}}
    {}}

\newbibmacro*{with+}[1]{%
  \ifnameundef{#1}
    {}
    {\setrespdelim%
     \bibstring{with#1}%
     \setunit{\addspace}%
     \printnames[with#1]{#1}}}

\renewbibmacro*{withcommentator}{%
  \usebibmacro{with+}{commentator}}

\renewbibmacro*{withannotator}{%
  \usebibmacro{with+}{annotator}}

\renewbibmacro*{withintroduction}{%
  \usebibmacro{with+}{introduction}}

\renewbibmacro*{withforeword}{%
  \usebibmacro{with+}{foreword}}

\renewbibmacro*{withafterword}{%
  \usebibmacro{with+}{afterword}}

%  book:...  macros

\newbibmacro*{book:credits}{%
  \iflistundef{bookcredits}
    {}
    {\setrespdelim%
     \printlist[semicolondelim]{bookcredits}%
     \clearlist{bookcredits}}%
}

\newbibmacro*{book:byeditor+othersstrg}[1]{%
  \iffieldundef{#1type}
    {\def\abx@tempa{byeditor}}
    {\edef\abx@tempa{by\thefield{#1type}}}%
  \let\abx@tempb=\empty
  \ifnamesequal{#1}{booktranslator}
    {\appto\abx@tempa{tr}%
     \appto\abx@tempb{\clearname{booktranslator}}}
    {}%
  \ifnamesequal{#1}{bookcommentator}
    {\appto\abx@tempa{co}%
     \appto\abx@tempb{\clearname{bookcommentator}}}
    {\ifnamesequal{#1}{bookannotator}
       {\appto\abx@tempa{an}%
        \appto\abx@tempb{\clearname{bookannotator}}}
       {}}%
  \ifnamesequal{#1}{bookintroduction}
    {\appto\abx@tempa{in}%
     \appto\abx@tempb{\clearname{bookintroduction}}}
    {\ifnamesequal{#1}{bookforeword}
       {\appto\abx@tempa{fo}%
        \appto\abx@tempb{\clearname{bookforeword}}}
       {\ifnamesequal{#1}{bookafterword}
          {\appto\abx@tempa{af}%
           \appto\abx@tempb{\clearname{bookafterword}}}
          {}}}%
  \ifbibxstring{\abx@tempa}
    {\printtext{\bibstring{\abx@tempa}}\abx@tempb}
    {\usebibmacro{bytypestrg}{#1}{editor}}}

\newbibmacro*{book:byeditor}{%
  \ifnameundef{editor}
    {}
    {\setrespdelim%
     \usebibmacro{book:byeditor+othersstrg}{editor}%
     \setunit{\addspace}%
     \printnames[byeditor]{editor}%
     \savename{editor}{\savedclearededitor}%
     \clearname{editor}%
     \setunit*{\resppunct}%
     \usebibmacro{book:byeditorx}}}

\newbibmacro*{book:bytranslator+others}{%
  \ifnameundef{booktranslator}
    {}
    {\setrespdelim%
     \usebibmacro{book:bytranslator+othersstrg}%
     \setunit{\addspace}%
     \printnames[bytranslator]{booktranslator}%
     \clearname{booktranslator}%
     \setunit*{\resppunct}}%
  \usebibmacro{book:withothers}}

\newbibmacro*{book:bytranslator+othersstrg}{%
  \def\abx@tempa{bytranslator}%
  \ifnamesequal{booktranslator}{bookcommentator}
    {\appto\abx@tempa{co}%
     \clearname{bookcommentator}}
    {\ifnamesequal{booktranslator}{bookannotator}
       {\appto\abx@tempa{an}%
        \clearname{bookannotator}}
       {}}%
  \ifnamesequal{booktranslator}{bookintroduction}
    {\appto\abx@tempa{in}%
     \clearname{bookintroduction}}
    {\ifnamesequal{booktranslator}{bookforeword}
       {\appto\abx@tempa{fo}%
        \clearname{bookforeword}}
       {\ifnamesequal{booktranslator}{bookafterword}
          {\appto\abx@tempa{af}%
           \clearname{bookafterword}}
          {}}}%
  % temporarily redefining commands used in the bibstring
  \savecommand\lbx@lfromlang%
  \savecommand\lbx@sfromlang%
  \renewcommand*{\lbx@lfromlang}{\lbx@gost@lfromlang{bookoriglanguage}}%
  \renewcommand*{\lbx@sfromlang}{\lbx@gost@sfromlang{bookoriglanguage}}%
  \bibstring{\abx@tempa}%
  \restorecommand\lbx@lfromlang%
  \restorecommand\lbx@sfromlang%
}

\newbibmacro*{book:withothers}{%
  \usebibmacro{book:withcommentator}%
  \clearname{bookcommentator}%
  \setunit*{\resppunct}%
  \usebibmacro{book:withannotator}%
  \clearname{bookannotator}%
  \setunit*{\resppunct}%
  \usebibmacro{book:withintroduction}%
  \clearname{bookintroduction}%
  \setunit*{\resppunct}%
  \usebibmacro{book:withforeword}%
  \clearname{bookforeword}%
  \setunit*{\resppunct}%
  \usebibmacro{book:withafterword}%
  \clearname{bookafterword}%
}

\newbibmacro*{book:with+}[1]{%
  \ifnameundef{book#1}
    {}
    {\setrespdelim%
     \bibstring{with#1}%
     \setunit{\addspace}%
     \printnames[with#1]{book#1}}}

\newbibmacro*{book:withcommentator}{%
  \usebibmacro{book:with+}{commentator}}

\newbibmacro*{book:withannotator}{%
  \usebibmacro{book:with+}{annotator}}

\newbibmacro*{book:withintroduction}{%
  \usebibmacro{book:with+}{introduction}}

\newbibmacro*{book:withforeword}{%
  \usebibmacro{book:with+}{foreword}}

\newbibmacro*{book:withafterword}{%
  \usebibmacro{book:with+}{afterword}}

%  jour:..  macros

\newbibmacro*{jour:volume+parts+issuetitle}{%
  \printfield{volume}%
  \setunit*{\addcomma\space}%
  \printfield{issue}%
  \setunit*{\addcomma\space}%
  \printfield{number}%
  \iffieldundef{issuetitle}
    {}
    {\setunit{\addcolon\space}%
     \printtext[issuetitle]{\printfield[titlecase]{issuetitle}}}}%

\newbibmacro*{jour:date}{%
  \usebibmacro{year}%
  \newunit\newblock
  \iffieldundef{month}
    {}
    {\printtext{\mkbibdatelong{}{month}{day}}}%
  \iffieldundef{endyear}
    {}
    {\bibdaterangesep%
     \iffieldequalstr{endyear}{}
      {\mbox{~~~~}}
      {\printfield{endyear}%
       \newunit\newblock
       \iffieldundef{endmonth}
         {}
         {\printtext{\mkbibdatelong{}{endmonth}{endday}}}}}%
}

\newbibmacro*{jour:credits}{%
  \iflistundef{credits}
    {}
    {\setrespdelim%
     \printlist[semicolondelim]{journalcredits}%
     \clearlist{journalcredits}}%
}

% processing volumes, books, parts, issues in the specified order

\def\blx@gost@volsinorder#1#2{%
  \ifstrequal{#1}{v}
    {\printfield{volume}%
     \iffieldundef{volume}{}{\blx@gost@setunit}}
    {\ifstrequal{#1}{b}
      {\printfield{book}%
       \iffieldundef{book}{}{\blx@gost@setunit}}
      {\ifstrequal{#1}{p}
        {\printfield{part}%
         \iffieldundef{part}{}{\blx@gost@setunit}}
        {\ifstrequal{#1}{i}
          {\printfield{issue}%
           \iffieldundef{issue}{}{\blx@gost@setunit}}
          {}}}}%
  \ifthenelse{\equal{#2}{\blx@gost@endofstring}}% end of string ?
    {}%
    {\stepcounter{blx@gost@pointer}%
     \blx@gost@volsinorder#2}}

\newbibmacro*{volume+parts}[1]{%
  \iffieldundef{volsorder}
     {\edef\gost@tempa{\blx@gost@defaultorder}}
     {\edef\gost@tempa{\thefield{volsorder}}}%
  \ifdefvoid{\gost@tempa}
     {}
     {\renewcommand*{\blx@gost@setunit}{#1}%
      \setcounter{blx@gost@pointer}{1}%
      \expandafter\blx@gost@volsinorder\gost@tempa\blx@gost@endofstring}}

\renewbibmacro*{date}{%
  \usebibmacro{printdate}{}}

\newbibmacro*{year}{%
  \usebibmacro{printyear}{}}

\renewbibmacro*{title}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext[title]{%
       \printfield[titlecase]{title}%
       \iffieldundef{media}
          {\setunit*{\subtitlepunct}}
          {\setunit*{\addspace}%
           \usebibmacro{media}%
           \setunit*{\addcolondelim}}%
       \printfield[titlecase]{subtitle}}%
     \newunit}%
  \setunit*{\addcolondelim}%
  \printfield{titleaddon}%
  \clearfield{media}}

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

\@ifpackagelater{biblatex}{2016/12/06} %biblatex 3.8+
{\newbibmacro*{translation}{%
  \ifnameundef{translator}
    {\ifnameundef{booktranslator}
      {\iflistundef{origlanguage}
        {}
        {\bibstring{bytranslator}%
         \clearlist{origlanguage}}}
      {}}%
    {}}

\newbibmacro*{book:translation}{%
  \ifnameundef{booktranslator}
    {\iflistundef{bookoriglanguage}
      {}
      {% temporarily redefining commands used in the bibstring
        \savecommand\lbx@lfromlang%
        \savecommand\lbx@sfromlang%
        \renewcommand*{\lbx@lfromlang}{\lbx@gost@lfromlang{bookoriglanguage}}%
        \renewcommand*{\lbx@sfromlang}{\lbx@gost@sfromlang{bookoriglanguage}}%
        \bibstring{bytranslator}%
        \restorecommand\lbx@lfromlang%
        \restorecommand\lbx@sfromlang%
        \clearlist{bookoriglanguage}}}
    {}}
}
{
\newbibmacro*{translation}{%
  \ifnameundef{translator}
    {\ifnameundef{booktranslator}
      {\iffieldundef{origlanguage}
        {}
        {\bibstring{bytranslator}%
         \clearfield{origlanguage}}}
      {}}%
    {}}

\newbibmacro*{book:translation}{%
  \ifnameundef{booktranslator}
    {\iffieldundef{bookoriglanguage}
      {}
      {% temporarily redefining commands used in the bibstring
        \savecommand\lbx@lfromlang%
        \savecommand\lbx@sfromlang%
        \renewcommand*{\lbx@lfromlang}{\lbx@gost@lfromlang{bookoriglanguage}}%
        \renewcommand*{\lbx@sfromlang}{\lbx@gost@sfromlang{bookoriglanguage}}%
        \bibstring{bytranslator}%
        \restorecommand\lbx@lfromlang%
        \restorecommand\lbx@sfromlang%
        \clearfield{bookoriglanguage}}}
    {}}
}




\renewbibmacro*{maintitle}{%
  \ifboolexpr{
    test {\iffieldundef{maintitle}}
    and
    test {\iffieldundef{mainsubtitle}}
  }
    {}
    {\printtext[maintitle]{%
       \printfield[titlecase]{maintitle}%
       \iffieldundef{media}
          {\setunit*{\subtitlepunct}}
          {\setunit*{\addspace}%
           \usebibmacro{media}%
           \setunit*{\addcolondelim}}%
       \printfield[titlecase]{mainsubtitle}}%
     \newunit}%
  \setunit{\addcolondelim}%
  \printfield{maintitleaddon}%
  \clearfield{media}}

\newbibmacro*{thesistitle}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext[title]{%
       \printfield[titlecase]{title}%
       \iffieldundef{media}
          {\setunit*{\subtitlepunct}}
          {\setunit*{\addspace}%
           \usebibmacro{media}%
           \setunit*{\addcolondelim}}%
         \printfield[titlecase]{subtitle}}%
       \midsentence
       \setunit*{\addcolondelim}%
       \printfield{type}%
       \midsentence
       \setunit*{\addcolondelim}%
       \printfield{specialitycode}%
       \setunit*{\specialitydelim}%
       \printfield{speciality}}%
  \setunit{\addcolondelim}%
  \printfield{titleaddon}%
  \clearfield{media}}

\newcommand*{\addcolondelim}{%
  \begingroup%
  \def\abx@colon{%
    \ifdim\lastkern>\z@\unkern\fi%
    \addnbspace\abx@puncthook{:}\space}%
  \addcolon%
  \endgroup}

\newcommand*{\addsemicolondelim}{%
  \begingroup%
  \def\abx@semicolon{%
    \ifdim\lastkern>\z@\unkern\fi%
    \addnbspace\abx@puncthook{;}\space}%
  \addsemicolon%
  \endgroup}

\def\blx@gost@involsinorder#1#2{%
  \ifstrequal{#1}{v}
    {\printfield{volumes}%
     \blx@gost@setunit}
    {\ifstrequal{#1}{b}
      {\printfield{books}%
       \blx@gost@setunit}
      {\ifstrequal{#1}{p}
        {\printfield{parts}%
         \blx@gost@setunit}
        {\ifstrequal{#1}{i}
          {\printfield{issues}%
           \blx@gost@setunit}
          {}}}}%
  \ifthenelse{\equal{#2}{\blx@gost@endofstring}}% end of string ?
    {}%
    {\stepcounter{blx@gost@pointer}%
     \blx@gost@involsinorder#2}}

\newbibmacro*{involumes+otherparts}[1]{%
  \ifboolexpr{
              test {\iffieldundef{volumes}}
              and
              test {\iffieldundef{parts}}
              and
              test {\iffieldundef{books}}
              and
              test {\iffieldundef{issues}}
  }
    {}
    {\iffieldundef{volsorder}
         {\edef\gost@tempa{\blx@gost@defaultorder}}
         {\edef\gost@tempa{\thefield{volsorder}}}%
     \ifdefvoid{\gost@tempa}
         {}
         {\renewcommand*{\blx@gost@setunit}{#1}%
          \setcounter{blx@gost@pointer}{1}%
          \bibstring{involumes}%
          \addabbrvspace%
          \expandafter\blx@gost@involsinorder\gost@tempa\blx@gost@endofstring}}}

\renewbibmacro*{byauthor}{%
  \ifboolexpr{
    ( test \ifuseauthor
      and
      not togl {bbx:gostbibliography}
    )
    or
    test {\ifnameundef{author}}
  }
    {}
    {\setrespdelim%
     \printnames[byauthor]{author}}}

\newbibmacro*{book:byauthor}{%
  \ifboolexpr{
    test {\ifnameundef{bookauthor}}
    or
    ( test {\ifnamesequal{author}{bookauthor}}
      and
      not togl {bbx:gostbibliography}
    )
  }
    {}
    {\setrespdelim%
     \printnames[byauthor]{bookauthor}}}

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

\InitializeBibliographyStyle{%
  \global\undef\bbx@lasthash}

\newbool{bbx@inset}
\DeclareBibliographyDriver{set}{%
  \booltrue{bbx@inset}%
  \entryset{}{}%
  \newunit\newblock
  \usebibmacro{setpageref}%
  \finentry}

\renewbibmacro*{author}{%
  \ifboolexpr{
    test \ifuseauthor
    and
    not test {\ifnameundef{author}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\iftoggle{bbx:gostbibliography}
         {\printnames[heading][1-1]{author}}
         {\printnames[heading]{author}}%
     \setunit{\addcomma\space}%
     \usebibmacro{bbx:savehash}}%
     \usebibmacro{authorstrg}}
    {\global\undef\bbx@lasthash}}

\renewbibmacro*{editor}{%
  \usebibmacro{bbx:editor}{editorstrg}}
\renewbibmacro*{editor+others}{%
  \usebibmacro{bbx:editor}{editor+othersstrg}}
\newbibmacro*{bbx:editor}[1]{%
  \ifboolexpr{
    test \ifuseeditor
    and
    not test {\ifnameundef{editor}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\printnames[heading]{editor}%
     \setunit{\addcomma\space}%
     \usebibmacro{bbx:savehash}}%
     \usebibmacro{#1}%
     \savename{editor}{\savedclearededitor}%
     \iftoggle{bbx:gostbibliography}
      {}
      {\clearname{editor}}}
    {\global\undef\bbx@lasthash}}

\renewbibmacro*{translator}{%
  \usebibmacro{bbx:translator}{translatorstrg}}
\renewbibmacro*{translator+others}{%
  \usebibmacro{bbx:translator}{translator+othersstrg}}
\newbibmacro*{bbx:translator}[1]{%
  \ifboolexpr{
    test \ifusetranslator
    and
    not test {\ifnameundef{translator}}
  }
    {\usebibmacro{bbx:dashcheck}
       {\bibnamedash}
       {\printnames[heading]{translator}%
     \setunit{\addcomma\space}%
     \usebibmacro{bbx:savehash}}%
     \usebibmacro{#1}%
     \savename{translator}{\savedclearedtranslator}%
     \iftoggle{bbx:gostbibliography}
      {}
      {\clearname{translator}}}
    {\global\undef\bbx@lasthash}}

\newbibmacro*{bbx:dashcheck}[2]{%
  \ifboolexpr{
    test {\iffieldequals{fullhash}{\bbx@lasthash}}
    and
    not test \iffirstonpage
    and
    (
       not bool {bbx@inset}
       or
       test {\iffieldequalstr{entrysetcount}{1}}
    )
  }
    {#1}
    {#2}}

\newbibmacro*{url+urldate+note}{%
  \ifboolexpr{
    test {\ifentrytype{online}}
    or
    ( test \ifcitation
      and
      togl {cbx:url}
    )
    or
    ( not test \ifcitation
      and
      togl {bbx:url}
    )
  }
    {\usebibmacro{url+urldate}}
    {}%
  \setunit*{\addsemicolondelim}%
  \printfield{note}}

% do I need this?

\gdef\ifmulticitation{%
  \ifnum\c@multicitetotal>0
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}

\newbibmacro*{media}{%
  \iffieldundef{media}
    {}
    {{\ifdefvoid{\gostmedialanguage}
        {}
        {\select@medialanguage}% first switch language, then \ifbibxstring
      \ifbibxstring{media\thefield{media}}
        {\printtext[brackets]{\bibcpstring{media\thefield{media}}}}
        {}}}}

\newbibmacro*{priority}{%
  \printprioritydate%
  \setunit{\addcomma\space}%
  \printfield{prioritynumber}%
  \setunit{\addspace}%
  \iffieldundef{prioritycountry}
    {}
    {\printtext[parens]{\printfield{prioritycountry}}}}

\newbibmacro*{heading}{%
  \printfield{heading}}

% whether date needs brackets.
% labeldate needs special account
\newcommand*{\blx@gost@ifdateuncertain}[3]{%
  \ifboolexpr{
    test {\csuse{if#1datecirca}}
    or
    test {\csuse{if#1dateuncertain}}
    or
    test {\csuse{if#1enddatecirca}}
    or
    test {\csuse{if#1enddateuncertain}}
    or
    not test {\iffieldundef{#1dateunspecified}}
    or (
       test {\ifstrequal{#1}{label}}
       and
       not test {\iffieldundef{\thefield{labeldatesource}dateunspecified}}
       )
  }
  {#2}
  {#3}}

% Adds brackets is necessary
\newbibmacro*{printdate}[1]{%
  \blx@gost@ifdateuncertain{#1}
  {\printtext[bracketsalways]{\midsentence*%
      \ifstrequal{#1}{label}
        {\iffieldequalstr{\thefield{labeldatesource}dateunspecified}{yearincentury}
          {\number\numexpr\thefield{\thefield{labeldatesource}year}/100\relax%
            \bibrangedash\addnbspace\bibrangedash}
          {\iffieldequalstr{\thefield{labeldatesource}dateunspecified}{yearindecade}
            {\number\numexpr\thefield{\thefield{labeldatesource}year}/10\relax\bibrangedash}%
          {\csuse{print#1date}}}}
        {\iffieldequalstr{#1dateunspecified}{yearincentury}
          {\number\numexpr\thefield{#1year}/100\relax%
            \bibrangedash\addnbspace\bibrangedash}
          {\iffieldequalstr{#1dateunspecified}{yearindecade}
            {\number\numexpr\thefield{#1year}/10\relax\bibrangedash}%
          {\csuse{print#1date}}}}}}
  {\csuse{print#1date}}}

\newbibmacro*{printyear}[1]{%
  \blx@gost@ifdateuncertain{#1}
  {\printtext[bracketsalways]{\midsentence*%
     \ifstrequal{#1}{label}
      {\iffieldequalstr{\thefield{labeldatesource}dateunspecified}{yearincentury}
        {\number\numexpr\thefield{\thefield{labeldatesource}year}/100\relax%
          \bibrangedash\addnbspace\bibrangedash}
        {\iffieldequalstr{\thefield{labeldatesource}dateunspecified}{yearindecade}
          {\number\numexpr\thefield{\thefield{labeldatesource}year}/10\relax\bibrangedash}
          {\usebibmacro{printyear+}{#1}}}}
      {\iffieldequalstr{#1dateunspecified}{yearincentury}
        {\number\numexpr\thefield{#1year}/100\relax%
          \bibrangedash\addnbspace\bibrangedash}
        {\iffieldequalstr{#1dateunspecified}{yearindecade}
          {\number\numexpr\thefield{#1year}/10\relax\bibrangedash}
          {\usebibmacro{printyear+}{#1}}}}}}
  {\usebibmacro{printyear+}{#1}}}

\newbibmacro*{printyear+}[1]{%
  \printtext{%
    \iffieldundef{#1year}
      {}
      {\ifdefstring\blx@dateformat@labeldate{edtf}
         {}
         {\datecircaprint}%
       \dateeraprintpre{#1year}%
       \mkyearzeros{\thefield{#1year}}%
       % \printfield{extradate}%
       \iffieldsequal{#1dateera}{#1enddateera}
         {}
         {\dateeraprint{#1year}}%
       \dateuncertainprint%
       \ifdefstring\blx@dateformat@labeldate{edtf}
         {\datecircaprintedtf}
         {}%
       \iffieldundef{#1endyear}
         {}
         {\iffieldsequal{#1year}{#1endyear}
           {}
           {\ifdefstring\blx@dateformat@labeldate{edtf}
             {\slash}% strict EDTF
             {\bibdaterangesep%
              \enddatecircaprint}%
            \dateeraprintpre{#1endyear}%
            \mkyearzeros{\thefield{#1endyear}}%
            \enddateuncertainprint%
            \ifdefstring\blx@dateformat@labeldate{edtf}
              {\enddatecircaprintedtf}
              {}%
            \dateeraprint{#1endyear}}}}}}

\newcommand*{\setrespdelim}{\bbx@gost@respdelim\def\bbx@gost@respdelim{}}

%  Related field

\newcounter{bbx:relatedcount}
\newcounter{bbx:relatedtotal}

\newbibmacro*{related:init}{%
  \csundef{bbx:relatedloop}}

\newbibmacro*{begrelated}{}
\newbibmacro*{endrelated}{}
\newbibmacro*{begrelatedloop}{}
\newbibmacro*{endrelatedloop}{}

\def\ifrelatedloop{%
  \ifboolexpr{ test {\xifinlistcs{\strfield{entrykey}}{bbx:relatedloop}}
    or test {\xifinlistcs{\strfield{clonesourcekey}}{bbx:relatedloop}} }}

\newbibmacro*{related}{%
  \restorelist{credits}{\savedclearedcredits}%
  \restorename{editor}{\savedclearededitor}%
  \restorename{translator}{\savedclearedtranslator}%
  \iffieldequalstr{relatedtype}{multivolume}
    {\finentry}
    {}%
  \ifboolexpr{ test {\iffieldundef{related}} or test {\ifrelatedloop} }
    {}
    {\usebibmacro{begrelated}%
     \def\bbx@tempa{}%
     \setcounter{bbx:relatedtotal}{0}%
     \def\do##1{%
       \entrydata{##1}{%
         \ifrelatedloop
           {}
           {\stepcounter{bbx:relatedtotal}%
            \gappto{\bbx@tempa}{##1,}}}}%
     \docsvfield{related}%
     \restorefield{related}{\bbx@tempa}%
     \ifnumgreater{\value{bbx:relatedtotal}}{0}
       {\listcsxadd{bbx:relatedloop}{\strfield{entrykey}}%
        \iffieldundef{clonesourcekey}
          {}
          {\listcsxadd{bbx:relatedloop}{\strfield{clonesourcekey}}}%
        \setcounter{bbx:relatedcount}{0}%
     \def\do{%
       \stepcounter{bbx:relatedcount}%
       \ifnumgreater{\value{bbx:relatedcount}}{1}
            {\ifcsundef{relateddelim\strfield{relatedtype}}
              {\printtext{\relateddelim}}
              {\printtext{\csuse{relateddelim\strfield{relatedtype}}}}}
         {}}%
     \ifbibmacroundef{related:\strfield{relatedtype}}
       {\appto{\do}{\usebibmacro{related:default}}}
       {\appto{\do}{\usebibmacro*{related:\strfield{relatedtype}}}}%
     \iffieldformatundef{related:\strfield{relatedtype}}
       {\def\bbx@tempa{related}}
       {\def\bbx@tempa{related:\strfield{relatedtype}}}%
     \iffieldformatundef{relatedstring:\strfield{relatedtype}}
       {\def\bbx@tempb{relatedstring:default}}
       {\def\bbx@tempb{relatedstring:\strfield{relatedtype}}}%
     \printtext[\bbx@tempa]{%
          \usebibmacro{begrelatedloop}%
       \iffieldundef{relatedstring}
         {\ifboolexpr{
            test {\ifnumgreater{\value{bbx:relatedtotal}}{1}}
            and
            test {\ifbibxstring{\thefield{relatedtype}s}}
          }
            {\printtext[\bbx@tempb]{%
               \bibstring[\mkrelatedstringtext]{\thefield{relatedtype}s}}}
            {\iffieldbibstring{relatedtype}
               {\printtext[\bbx@tempb]{%
                     \bibstring[\mkrelatedstringtext]{\thefield{relatedtype}}}}
               {}}}
         {\iffieldbibstring{relatedstring}
            {\printtext[\bbx@tempb]{%
                  \bibstring[\mkrelatedstringtext]{\thefield{relatedstring}}}}
            {\printfield[\bbx@tempb]{relatedstring}}}%
       \docsvfield{related}%
          \usebibmacro{endrelatedloop}}}%
       {}%
     \usebibmacro{endrelated}}}

\newbibmacro*{relatedblock}{%
  \ifboolexpr{
    ( test {\ifcitation} and togl {bbx:related:cite})
    or
    ( not test {\ifcitation} and togl {bbx:related:bib})
   }
   {\usebibmacro{related:init}%
    \usebibmacro{related}}
   {}}

\newbibmacro*{setup:min}{%
  \renewbibmacro*{series+number}{}%
  \renewbibmacro*{credits}{}%
  \renewbibmacro*{book:credits}{}%
  \renewbibmacro*{byeditor}{}%
  \renewbibmacro*{book:byeditor}{}%
  \renewbibmacro*{bytranslator+others}{}%
  \renewbibmacro*{book:bytranslator+others}{}%
  \renewbibmacro*{media}{}%
  \renewbibmacro*{priority}{}%
  \clearfield{series}%
  \clearfield{edition}%
  \clearlist{credits}%
  \clearlist{editioncredits}%
  \clearlist{specdata}%
  \clearfield{media}%
  \clearfield{titleaddon}%
  \clearfield{booktitleaddon}%
  \clearfield{maintitleaddon}%
  \clearfield{addendum}%
  \clearfield{pubstate}%
  \clearname{holder}%
  \clearfield{publicationyear}%
  \clearfield{publicationmonth}%
  \clearfield{publicationday}%
  \clearfield{requestnumber}%
  \clearfield{publication}%
  \clearfield{upyear}%
  \clearfield{upmonth}%
  \clearfield{upday}%
  \clearfield{systemreq}%
}

\DeclareAutoCiteCommand{footnote}{\smartcite}{\smartcites}
\DeclareAutoCiteCommand{superscript}{\supercite}{\supercites}

\defbibenvironment{gostbibliography}
  {\list
     {}
     {\toggletrue{bbx:gostbibliography}%
      \renewcommand*{\revsdnamepunct}{\addcomma}%
      \renewcommand*{\labelnamepunct}{\addperiod\space}%
      \setlength{\bibitemsep}{0pt}%
      \setlength{\leftmargin}{\bibhang}%
      \setlength{\itemindent}{-\leftmargin}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}}
  {\endlist}
  {\item}

\endinput