\ProvidesFile{gost-standard.bbx}
[2015/05/02\space v1.3\space biblatex-gost styles]

\def\bbx@gost@date{2015/05/02}
\def\bbx@gost@version{1.3}

\@ifpackagelater{biblatex}{2013/11/21}
  {}
  {\PackageError{biblatex}
    {Outdated 'biblatex' package}
    {This version of 'biblatex-gost' requires biblatex v2.8a or later.\MessageBreak
     You are using: '\csuse{ver@biblatex.sty}'.\MessageBreak
     This is a fatal error. I'm aborting now.}%
    \endinput}

\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

\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:gostbibliography}
\togglefalse{bbx:gostbibliography}

\protected\def\blx@imc@printupdate{\csuse{mkbibrangeshort}{up}}
\protected\def\blx@imc@printpubldate{\csuse{mkbibrangeshort}{publ}}
\protected\def\blx@imc@printprdate{\csuse{mkbibrangeshort}{pr}}
\blx@regimcs{%
  \printupdate \printpubldate \printprdate}

%  OPTIONS

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

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

\ExecuteBibliographyOptions{
  useeditor=false,
  usetranslator=false,
  maxnames=3,
  minnames=1,
  dashed=false,
  singletitle=false,
  movenames=true,
  firstinits,
  volsorder=vbpi,
  related=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}
\DeclareFieldFormat*{volume}{%
  \iffieldnum{volume}
    {\ifbibstring{volume}
      {\bibstring{volume}\addabbrvspace#1}
      {}}
    {\ifcapital{\MakeCapital{#1}}{#1}\isdot}}
\DeclareFieldFormat[article,periodical]{volume}{%
  \ifbibstring{volume}
    {\bibstring{jourvol}\addabbrvspace#1}
    {}}
\DeclareFieldFormat*{book}{%
  \iffieldnum{book}
    {\ifbibstring{book}
      {\bibstring{book}\addabbrvspace#1}
      {}}
    {\ifcapital{\MakeCapital{#1}}{#1}\isdot}}
\DeclareFieldFormat*{part}{%
  \iffieldnum{part}
    {\ifbibstring{part}
      {\bibstring{part}\addabbrvspace#1}
      {}}
    {\ifcapital{\MakeCapital{#1}}{#1}\isdot}}
\DeclareFieldFormat{seriesnumber}{#1}%
\DeclareFieldFormat*{number}{%
  \iffieldnum{number}
    {\ifbibstring{number}
      {\bibsstring{number}\addabbrvspace#1}
      {\unspace\adddot#1}}%
    {\ifcapital{\MakeCapital{#1}}{#1}\isdot}}
\DeclareFieldFormat[patent]{number}{#1}%
\DeclareFieldFormat{reqnumber}{%
  \ifbibstring{number}
    {\bibsstring{number}\addnbspace#1}
    {#1}}%
\newbibmacro*{volumes/parts/books/issues}[2]{%
  \iffieldnum{#1}
    {\ifbibstring{#1}
      {#2~\bibsstring{#1}}
      {}}
    {\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~\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}}
\DeclareFieldFormat{issue}{%
  \iffieldnum{issue}
    {\ifbibstring{issue}
      {\bibstring{issue}\addabbrvspace#1}
      {}}
    {\ifcapital{\MakeCapital{#1}}{#1}\isdot}}
\DeclareFieldFormat[article,periodical]{issue}{%
  \ifinteger{#1}
    {\ifbibstring{issue}%
     {\bibstring{issue}\addabbrvspace#1}%
     {\unspace\adddot#1}}%
    {\ifcapital{\MakeCapital{#1}}{#1}\isdot}}
\DeclareFieldFormat{date}{%
 \iffieldundef{endyear}
   {#1}
   {\iffieldequalstr{endyear}{}
      {#1\mbox{~~~~}}
      {#1}}}
\DeclareFieldFormat{update}{%
  \ifbibstring{updated}
    {\bibstring{updated}\addcolon\space#1}
    {Updated\addcolon\space#1}}
\DeclareFieldFormat{publdate}{%
  \ifbibstring{published}
    {\bibstring{published}\addspace#1}
    {#1}}
\DeclareFieldFormat{reqdate}{%
  \ifbibstring{requested}
    {\bibstring{requested}\addspace#1}
    {#1}}
\DeclareFieldFormat{prdate}{%
  \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}{%
  \ifinteger{#1}
    {\mkbibordedition{#1}~\bibstring{edition}}
    {\ifcapital{\MakeCapital{#1}}{#1}\isdot}}
\DeclareFieldFormat[thesis]{type}{\ifbibstring{#1}{\bibsentence\biblstring{#1}}{#1}}
\DeclareFieldFormat{prcountry}{%
  \ifbibxstring{\thefield{prcountry}}
    {\bibcpstring{\thefield{prcountry}}}
    {#1}}

\DeclareNameAlias{sortname}{last-first}

\DefineBibliographyExtras{french}{\restorecommand\mkbibnamelast}

% format for author is defined separately, because \mkbibnamelast, etc. cannot be
% used, since they affect all names, not only headings
\DeclareNameFormat{author}{%
  \iftoggle{bbx:gostbibliography}
    {\ifnumequal{\value{listcount}}{1}
      {\iffirstinits
        {\usebibmacro{authorname:last-first}{#1}{#4}{#5}{#7}}
        {\usebibmacro{authorname:last-first}{#1}{#3}{#5}{#7}}}
      {}}
    {\iffirstinits
      {\usebibmacro{authorname:last-first}{#1}{#4}{#5}{#7}}
      {\usebibmacro{authorname:last-first}{#1}{#3}{#5}{#7}}%
     \usebibmacro{name:andothers}}}
\newcommand*{\mkgostheading}[1]{\mkbibemph{#1}}%\nocorr}}
\DeclareFieldFormat{heading}{%
  \mkgostheading{#1}\addperiod\space}
\newcommand*{\mkbibhdnamelast}[1]{\mkgostheading{#1}}
\newcommand*{\mkbibhdnamefirst}[1]{\mkbibhdnamelast{#1}}
\newcommand*{\mkbibhdnameprefix}[1]{\mkbibhdnamelast{#1}}
\newcommand*{\mkbibhdnameaffix}[1]{\mkbibhdnamelast{#1}}
\newbibmacro*{authorname:last-first}[4]{%
  \ifuseprefix
    {\usebibmacro{name:delim}{#3#1}%
     \usebibmacro{name:hook}{#3#1}%
     \ifblank{#3}{}{%
       \ifcapital
         {\mkbibhdnameprefix{\MakeCapital{#3}}\isdot}
	 {\mkbibhdnameprefix{#3}\isdot}%
       \ifpunctmark{'}{}{\bibnamedelimc}}%
     \mkbibhdnamelast{#1}\isdot
     \ifblank{#4}{}{\bibnamedelimd\mkbibhdnameaffix{#4}\isdot}%
     \ifblank{#2}{}{\revsdnamepunct\bibnamedelimd\mkbibhdnamefirst{#2}\isdot}}
    {\usebibmacro{name:delim}{#1}%
     \usebibmacro{name:hook}{#1}%
     \mkbibhdnamelast{#1}\isdot
     \ifblank{#4}{}{\bibnamedelimd\mkbibhdnameaffix{#4}\isdot}%
     \ifblank{#2#3}{}{\revsdnamepunct}%
     \ifblank{#2}{}{\bibnamedelimd\mkbibhdnamefirst{#2}\isdot}%
     \ifblank{#3}{}{\bibnamedelimd\mkbibhdnameprefix{#3}\isdot}}}
\DeclareNameAlias{editor}{author}
\DeclareNameAlias{editora}{editor}
\DeclareNameAlias{editorb}{editor}
\DeclareNameAlias{editorc}{editor}
\DeclareNameAlias{translator}{author}

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

\DeclareNameFormat{last-first:full}{%
  \begingroup%
  \renewcommand*{\revsdnamepunct}{\addspace}%
  \usebibmacro{name:last-first}{#1}{#3}{#5}{#7}%
  \endgroup}

% FORMATTING COMMANDS

\newbibmacro*{//}{%
  \nopunct\printtext{\addnbspace\mbox{//}\addspace}}
\renewcommand*{\labelnamepunct}{\addspace}
\renewcommand*{\intitlepunct}{\addspace}
\renewcommand*{\finalnamedelim}{\addcomma\space}
\renewcommand*{\finallistdelim}{\addcomma\space}
\renewcommand*{\bibpagespunct}{\addperiod\space}
\renewcommand*{\subtitlepunct}{\addcolon\space}
\renewcommand*{\newblockpunct}{%
  \addperiod\addnbspace\textemdash\space\bibsentence}%block punct.,\bibsentence is for vol,etc.
\newcommand*{\respdelim}{\addnbspace/\space}% delimiter before "credits"
\newcommand*{\resppunct}{\addsemicolondelim}% punctuation between "credits" items

% 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

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

\newbibmacro*{begentry}{}
\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
   {\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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{authortype}
        {}
        {\setunit*{\addspace}%
         \printfield[parens]{authortype}}%
      \setunit*{\addsemicolondelim}}%
  \ifnameundef{holder}
    {}
    {\setrespdelim%
      \usebibmacro{byholder}%
      \setunit*{\addsemicolondelim}}%
  \usebibmacro{credits}%
  \newunit\newblock
  \printfield{reqnumber}%
  \ifboolexpr{
      test {\iffieldundef{year}}
      and test {\iffieldundef{month}}
      and test {\iffieldundef{day}}
      }
      {}
      {\setunit*{\addsemicolondelim}%
       \printtext[reqdate]{\mkbibdateshort{year}{month}{day}}}%
  \setunit*{\addsemicolondelim}%
  \printpubldate%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{thesis}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{heading}%
  \newunit
  \usebibmacro{author}%
  \setunit*{\labelnamepunct}%
  \usebibmacro{thesistitle}%
  \setunit{\respdelim}%
  \printnames[last-first:full]{author}%
  \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{related:init}%
  \usebibmacro{related}%
  \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{related:init}%
  \usebibmacro{related}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{shorthands}{%
  \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{credits}
    {}
    {\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}%
     \printfield{issuetitle}}}%

\newbibmacro*{jour:date}{%
  \usebibmacro{year}%
  \newunit\newblock
  \iffieldundef{month}
    {}
    {\printtext{\mkbibdatelong{}{month}{day}}}%
  \iffieldundef{endyear}
    {}
    {\bibdatedash%
     \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}}

\newbibmacro*{year}{%
  \printfield{year}}

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

\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}}%
       \ifbibxstring{\thefield{type}}
          {\bibstring{\thefield{type}}}
          {\printfield{type}}%
       \setunit*{\addspace}%
       \printfield{major}%
       \setunit*{\addcolondelim}%
       \printfield{majorcode}}%
  \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}
       {\printnames{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{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{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}{%
  \printprdate%
  \setunit{\addcomma\space}%
  \printfield{prnumber}%
  \setunit{\addspace}%
  \iffieldundef{prcountry}
    {}
    {\printtext[parens]{\printfield{prcountry}}}}

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

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

\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 {\ifcitation}
      and
      not togl {bbx:related:cite}
    )
    or
    ( not test {\ifcitation}
      and
      not togl {bbx:related:bib}
    )
    or
    test {\iffieldundef{related}}
    or
    test {\ifrelatedloop}
  }
    {}
    {\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}
         {\printtext{\relateddelim}}
         {}}%
     \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{begrelated}%
       \iffieldundef{relatedstring}
         {\ifboolexpr{
            test {\ifnumgreater{\value{bbx:relatedtotal}}{1}}
            and
            test {\ifbibxstring{\thefield{relatedtype}s}}
          }
            {\printtext[\bbx@tempb]{%
               \bibstring[\mkrelatedstring]{\thefield{relatedtype}s}}}
            {\iffieldbibstring{relatedtype}
               {\printtext[\bbx@tempb]{%
                     \bibstring[\mkrelatedstring]{\thefield{relatedtype}}}}
               {}}}
         {\iffieldbibstring{relatedstring}
            {\printtext[\bbx@tempb]{%
                  \bibstring[\mkrelatedstring]{\thefield{relatedstring}}}}
            {\printfield[\bbx@tempb]{relatedstring}}}%
       \docsvfield{related}%
          \usebibmacro{endrelated}}}%
       {}}}

\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{pagetotal}%
  \clearfield{titleaddon}%
  \clearfield{booktitleaddon}%
  \clearfield{maintitleaddon}%
  \clearfield{addendum}%
  \clearfield{pubstate}%
  \clearname{holder}%
  \clearfield{publyear}%
  \clearfield{publmonth}%
  \clearfield{publday}%
  \clearfield{reqnumber}%
  \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