% \iffalse meta-comment
%
% This bibliography style attempts to format bibliography according to
% GOST R 7.0.5-2008 with some modifications.
%
% Based on style gost71u.bst by Maksym Polyakov.
%
% For the Russian bibliographic entries you need to create field
%   language = {russian}.
%
% Default language is English.
% Field numpages for books must contain number of pages.
% Optional field url will format url (using hyperref, if loaded).
%
% Requires 8-bit bibtex with switch -H and csf file supporting cyrillic.
%
% bibtex8 -H -c <encoding>.csf <your_document>
%
% Copyright (C) Stanislav Kruchinin
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any later
% version. This version of this license is in
%    http://www.latex-project.org/lppl/lppl-1-3c.txt
% and the latest version of this license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% Current Maintainer of this work is Stanislav Kruchinin.
%
% This work consists of the main source file gost705.dtx
% and the derived files
%    gost705.bst, gost705s.bst, gost705.pdf.
%
% Distribution:
%    CTAN:macros/latex/contrib/disser/src/gost705.dtx
%
% Unpacking:
%   (a) If disser.ins present:
%         latex disser.ins
%   (b) Without disser.ins:
%         tex gost705.dtx
%
% Documentation:
%    latex gost705.dtx; ...
%
%    Programm calls to get the documentation (example):
%       pdflatex gost705.dtx
%       makeindex -r -s dtx.ist gost705
%       pdflatex gost705.dtx
%       pdflatex gost705.dtx
%
% Installation:
%    TDS:bibtex/bst/disser/
%    TDS:doc/latex/disser/
%    TDS:source/latex/disser/
%
%<*ignore>
\begingroup
  \catcode123=1 %
  \catcode125=2 %
  \def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
         \ifx\csname processbatchFile\endcsname\relax\else1\fi
         \ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
\Msg{* gost705: Format bibliography according to GOST R 7.0.5-2008}
\Msg{************************************************************************}

\keepsilent
\askforoverwritefalse

\let\MetaPrefix\relax
\preamble

This is a generated file.

This bibliography style attempts to format bibliography according to
GOST R 7.0.5-2008 with some conventional modifications.

Based on style gost71u.bst by Maksym Polyakov.

For the Russian or German bibliographic entries you need to create field
 language = {russian} or language = {german}.

Default language is English.
Field numpages for books must contain number of pages.
Optional field url will format url (using hyperref, if loaded).

Requires 8-bit bibtex with switch -H and csf file supporting cyrillic.

bibtex8 -H -c <encoding>.csf <your_document>

Copyright (C) Stanislav Kruchinin

This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3c of this license or (at your option) any later
version. This version of this license is in
   http://www.latex-project.org/lppl/lppl-1-3c.txt
and the latest version of this license is in
   http://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.

This work has the LPPL maintenance status "maintained".

Current Maintainer of this work is Stanislav Kruchinin.

This work consists of the main source file gost705.dtx
and the derived files
   gost705.bst gost705s.bst gost705.pdf.

\endpreamble
\let\MetaPrefix\DoubleperCent

\generate{%
  \nopostamble
  \usedir{bibtex/bst/disser}%
  \file{gost705.bst}{\from{gost705.dtx}{gost705}}%
  \file{gost705s.bst}{\from{gost705.dtx}{gost705s}}%
}

\catcode32=13\relax% active space
\let =\space%
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{*     gost705.bst gost705s.bst}
\Msg{*}
\Msg{* To produce the documentation run the file `gost705.dtx'}
\Msg{* through LaTeX or pdfLaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}

\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\ProvidesFile{gost705.drv}%
  [2016/06/18 1.4.0 Bibliography style for GOST R 7.0.5-2008]

\documentclass{ltxdoc}
\usepackage[a4paper,includeheadfoot,nohead,mag=1000,
            left=5.5cm,right=1cm,top=1.5cm,bottom=1.5cm]{geometry}
\usepackage{ifpdf,indentfirst,color,makeidx}
\definecolor{darkblue}{rgb}{0,0,.6}
\ifpdf
  \usepackage[pdftex,hyperindex,unicode]{hyperref}
  \usepackage{cmap}
\else
  \usepackage[hypertex]{hyperref}
\fi

\hypersetup{
  pdftitle           = {Documented source code of gost705 style},
  pdfauthor          = {Stanislav Kruchinin},
  pdfsubject         = {gost705},
  pdfstartview       = {FitH},
  pdfborder          = {0 0 0},
  bookmarksopen      = true,
  bookmarksnumbered  = true,
  bookmarksopenlevel = 2,
  colorlinks = true,     linkcolor  = darkblue,
  citecolor  = darkblue, filecolor  = darkblue,
  menucolor  = darkblue, urlcolor   = darkblue
}

\usepackage[T2A]{fontenc}
\usepackage[cp1251]{inputenc}
\usepackage[english,russian]{babel}

\MakeShortVerb{\|}

\def\file#1{\texttt{#1}}
\def\pkg#1{\textsf{#1}}
\def\cmd#1{\texttt{#1}}

\newcommand\DescribeFunction[1]{
  \DescribeMacro{#1}\index{\texttt{#1}}
}

\makeatletter
  \def\IndexParms{%
    \parindent \z@
    \columnsep 15pt
    \parskip 0pt plus 1pt
    \rightskip 15pt
    \mathsurround \z@
    \parfillskip=-15pt
    \small
    \def\@idxitem{\normalfont\par\hangindent 30pt\bfseries}%
    \def\subitem{\normalfont\par\hangindent 30pt}%
    \def\subsubitem{\normalfont\par\hangindent 30pt\hspace*{15pt}}%
    \def\indexspace{\par\vspace{10pt plus 2pt minus 3pt}}%
  }
  \def\theindex{\@restonecoltrue\if@twocolumn\@restonecolfalse\fi
    \columnseprule \z@  \columnsep 35\p@
    \twocolumn[\index@prologue]%
    \IndexParms \let\item\@idxitem \ignorespaces}
  \def\endtheindex{\if@restonecol\onecolumn\else\clearpage\fi}
\makeatother

\setlength\hfuzz{20pt}
\hbadness=10000

\makeindex

\begin{document}
  \sloppy
  \DocInput{gost705.dtx}
  \IndexPrologue{\section{Предметный указатель}}
  \printindex
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{gost705.drv}
%
% \title{\pkg{gost705} и \pkg{gost705s} "--- стили оформления библиографии
% в соответствии с ГОСТ Р 7.0.5-2008}
% \date{Версия \fileversion\\[6pt]\filedate}
% \author{Станислав Кручинин\\[6pt]
% \normalsize E-mail:
% \href{mailto:stanislav.kruchinin@gmail.com}
% {\texttt{stanislav.kruchinin@gmail.com}}}
%
% \maketitle
%
% \tableofcontents
%
%  \section{Исходный текст}\parindent=0pt
%    \begin{macrocode}

%<*gost705|gost705s>

%    \end{macrocode}
% \subsection{Поля, используемые в bib-файлах}
%    \begin{macrocode}
ENTRY
  { address
    annote
    author
    booktitle
    bookauthor
    chapter
    edition
    editor
    compiler
    howpublished
    institution
    journal
    key
    month
    note
    number
    organization
    pages
    numpages
    publisher
    school
    series
    title
    type
    volume
    year
    language
    booklanguage
    url
    urldate
    isbn
    doi
    archive
    archivePrefix
    primaryClass
    eprint
    authortype
    media
    location
    ipc
    holder
    credits
    reqnumber
    reqdate
    pubdate
    publication
    prdate
    prnumber
    prcountry
    pagetotal
  }
  {}
  { label }

%    \end{macrocode}
% \subsection{Объявление и инициализация переменных и констант}
%    \begin{macrocode}
INTEGERS { output.state before.all mid.sentence after.sentence after.block
after.dblslash after.slash after.colon after.semicolon }

%    \end{macrocode}
% \DescribeFunction{init.state.consts}
%    \begin{macrocode}
FUNCTION {init.state.consts}
{
  #0 'before.all :=
  #1 'mid.sentence :=
  #2 'after.sentence :=
  #3 'after.block :=
  #4 'after.dblslash :=
  #5 'after.slash :=
  #6 'after.colon :=
  #7 'after.semicolon :=
}

STRINGS { s t }

STRINGS { curlanguage }

%    \end{macrocode}
% \subsection{Переключение языка}
% \DescribeFunction{change.language}
%    \begin{macrocode}
FUNCTION {change.language}
{
  booklanguage empty$
    { "" }
    { booklanguage  'curlanguage :=
      "\selectlanguageifdefined{"
      curlanguage *
      "}" *
    }
  if$
}

%    \end{macrocode}
% \subsection{Вывод библиографической записи}
% \DescribeFunction{output.nonnull}
%    \begin{macrocode}
FUNCTION {output.nonnull}
{
  swap$
  output.state mid.sentence =
    { ", " * write$ }
    { output.state after.block =
        { add.period$ write$
          " \BibDash " write$
          newline$
          "\newblock " write$
        }
        { output.state before.all =
          'write$
            { output.state after.dblslash =
                { "~//" * change.language * " " * write$ }
                { output.state after.slash =
                    { "~/ " * write$ }
                    { output.state after.colon =
                        { ": " * write$ }
                        { output.state after.semicolon =
                            { "; " * write$ }
                            { add.period$ " " * write$ }
                          if$
                        }
                      if$
                    }
                  if$
                }
              if$
            }
          if$
        }
      if$
      mid.sentence 'output.state :=
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{output}
%    \begin{macrocode}
FUNCTION {output}
{
  duplicate$ empty$
    'pop$
    'output.nonnull
  if$
}

%    \end{macrocode}
% \DescribeFunction{output.check}
%    \begin{macrocode}
FUNCTION {output.check}
{
  't :=
  duplicate$ empty$
    { pop$ "empty " t * " in " * cite$ * warning$ }
    'output.nonnull
  if$
}

%    \end{macrocode}
% \subsection{Вывод блоков и ограничителей}
% \DescribeFunction{fin.entry}
%    \begin{macrocode}
FUNCTION {fin.entry}
{
  add.period$
  write$
  newline$
}

%    \end{macrocode}
% \DescribeFunction{new.block}
%    \begin{macrocode}
FUNCTION {new.block}
{
  output.state before.all =
    'skip$
    { after.block 'output.state := }
  if$
}

%    \end{macrocode}
% \DescribeFunction{new.dblslash}
%    \begin{macrocode}
FUNCTION {new.dblslash}
{
  output.state before.all =
    'skip$
    { after.dblslash 'output.state := }
  if$
}

%    \end{macrocode}
% \DescribeFunction{new.slash}
%    \begin{macrocode}
FUNCTION {new.slash}
{
  output.state before.all =
    'skip$
    { after.slash 'output.state := }
  if$
}

%    \end{macrocode}
% \DescribeFunction{new.colon}
%    \begin{macrocode}
FUNCTION {new.colon}
{
  output.state before.all =
    'skip$
    { after.colon 'output.state := }
  if$
}

%    \end{macrocode}
% \DescribeFunction{new.semicolon}
%    \begin{macrocode}
FUNCTION {new.semicolon}
{
  output.state before.all =
    'skip$
    { after.semicolon 'output.state := }
  if$
}

%    \end{macrocode}
% \DescribeFunction{new.sentence}
%    \begin{macrocode}
FUNCTION {new.sentence}
{
  output.state after.block =
    'skip$
    { output.state before.all =
        'skip$
        { after.sentence 'output.state := }
      if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{add.blank}
%    \begin{macrocode}
FUNCTION {add.blank} { " " * before.all 'output.state := }

%    \end{macrocode}
% \DescribeFunction{not}
%    \begin{macrocode}
FUNCTION {not}
{
    { #0 }
    { #1 }
  if$
}

%    \end{macrocode}
% \DescribeFunction{and}
%    \begin{macrocode}
FUNCTION {and}
{
    'skip$
    { pop$ #0 }
  if$
}

%    \end{macrocode}
% \DescribeFunction{or}
%    \begin{macrocode}
FUNCTION {or}
{
    { pop$ #1 }
    'skip$
  if$
}

%    \end{macrocode}
% \DescribeFunction{non.stop}
%    \begin{macrocode}
FUNCTION {non.stop}
{
  duplicate$
  "}" * add.period$
  #-1 #1 substring$ "." =
}

%    \end{macrocode}
% \DescribeFunction{new.block.checka}
%    \begin{macrocode}
FUNCTION {new.block.checka}
{
  empty$
    'skip$
    'new.block
  if$
}

%    \end{macrocode}
% \DescribeFunction{new.block.checkb}
%    \begin{macrocode}
FUNCTION {new.block.checkb}
{
  empty$
  swap$ empty$
  and
    'skip$
    'new.block
  if$
}

%    \end{macrocode}
% \DescribeFunction{new.sentence.checka}
%    \begin{macrocode}
FUNCTION {new.sentence.checka}
{
  empty$
    'skip$
    'new.sentence
  if$
}

%    \end{macrocode}
% \DescribeFunction{new.sentence.checkb}
%    \begin{macrocode}
FUNCTION {new.sentence.checkb}
{
  empty$
  swap$ empty$
  and
    'skip$
    'new.sentence
  if$
}

%    \end{macrocode}
% \DescribeFunction{field.or.null}
%    \begin{macrocode}
FUNCTION {field.or.null}
{
  duplicate$ empty$
    { pop$ "" }
    'skip$
  if$
}

%    \end{macrocode}
% \DescribeFunction{emphasize}
%    \begin{macrocode}
FUNCTION {emphasize}
{
  duplicate$ empty$
    { pop$ "" }
    { "\BibEmph{" swap$ * "}" * }
  if$
}

%    \end{macrocode}
% \DescribeFunction{space.word}
%    \begin{macrocode}
FUNCTION {space.word} { " " swap$ * " " * }

%    \end{macrocode}
% \subsection{Общепринятые сокращения}
%    \begin{macrocode}
FUNCTION {bbl.edby} % { "\bbledby{}" }
{
  curlanguage "english" =
  { "Ed. by " }
    { curlanguage "german" =
      { "ed. " }
        { curlanguage "russian" =
          { "{\cyr\CYRP\cyro\cyrd\ \cyrr\cyre\cyrd.\ }" }
          { "language is not defined: " language  "edited by" * *
           warning$ "edited by" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.cmplr}
%    \begin{macrocode}
FUNCTION {bbl.cmplr}
{
  curlanguage "english" =
  { "Compiler " }
    { curlanguage "german" =
      { "Hrsg. " }
        { curlanguage "russian" =
        { "{\cyr\CYRS\cyro\cyrs\cyrt.\ }" }
        { "language is not defined: " language  "compiler" * * warning$ "compiler" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.edition}
%    \begin{macrocode}
FUNCTION {bbl.edition} % { "\bbledition{}" }
{
  curlanguage "english" =
   { "edition" }
   { curlanguage "german" =
     { "Aufl." }
       { curlanguage "russian" =
         { "{\cyr\cyri\cyrz\cyrd.}" }
         { "language is not defined: " language  "edition" * * warning$ "edition" }
       if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.vvolume}
%    \begin{macrocode}
FUNCTION {bbl.vvolume} % { "\bblVolume{}" }
{
  curlanguage "english" =
    { "Volume" }
    { curlanguage "german" =
      { "Band" }
      { curlanguage "russian" =
        { "{\cyr\CYRT\cyro\cyrm}" }
        { "language is not defined: " language  "Volume" * * warning$ "Volume" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.vvol}
%    \begin{macrocode}
FUNCTION {bbl.vvol} % { "\bblVol{}" }
{
  curlanguage "english" =
    { "Vol." }
    { curlanguage "german" =
      { "Bd." }
      { curlanguage "russian" =
        { "{\cyr\CYRT.}" }
        { "language is not defined: " language  "Vol." * * warning$ "Vol." }
        if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.iissue}
%    \begin{macrocode}
FUNCTION {bbl.iissue} % { "\bblIssue{}" }
{
  curlanguage "english" =
    { "Issue" }
    { curlanguage "german" =
      { "Heft" }
      { curlanguage "russian" =
        { "{\cyr\CYRV\cyrery\cyrp\cyru\cyrs\cyrk}" }
        { "language is not defined: " language * warning$ "Issue" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.iiss}
%    \begin{macrocode}
FUNCTION {bbl.iiss} % { "\bblIss{}" }
{
  curlanguage "english" =
    { "Iss." }
    { curlanguage "german" =
      { "H." }
      { curlanguage "russian" =
        { "{\cyr\CYRV\cyrery\cyrp.}" }
        { "language is not defined: " language * warning$ "Iss." }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.of}
%    \begin{macrocode}
FUNCTION {bbl.of} % { "\bblof{}" }
{
  curlanguage "english" =
    { "of" }
    { curlanguage "german" =
      { "von" }
      { curlanguage "russian" =
        { "{\cyr\cyri\cyrz}" }
        { "language is not defined: " language * warning$ "of" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.etal}
%    \begin{macrocode}
FUNCTION {bbl.etal} % { "\bblof{}" }
{
  curlanguage "english" =
    { "et~al." }
    { curlanguage "german" =
      { "u.~a." }
      { curlanguage "russian" =
        { "{\cyr\cyri~\cyrd\cyrr.}" }
        { "language is not defined: " language * warning$ "etal" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.nnumber}
%    \begin{macrocode}
FUNCTION {bbl.nnumber} % { "\bblNumber{}" }
{
  curlanguage "english" =
    { "Number" }
    { curlanguage "german" =
      { "Heft" }
      { curlanguage "russian" =
        { "{\cyr\CYRN\cyro\cyrm\cyre\cyrr}" }
        { "language is not defined: " language * warning$ "Number" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.number}
%    \begin{macrocode}
FUNCTION {bbl.number} % { "\bblnumber{}" }
{
  curlanguage "english" =
    { "number" }
    { curlanguage "german" =
      { "Heft" }
      { curlanguage "russian" =
        { "{\cyr\cyrn\cyro\cyrm\cyre\cyrr}" }
        { "language is not defined: " language * warning$ "number" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.nr}
%    \begin{macrocode}
FUNCTION {bbl.nr} % { "\bblno{}" }
{
  curlanguage "english" =
    { "no." }
    { curlanguage "german" =
      { "H." }
      { curlanguage "russian" =
        { "{\cyr\textnumero}" }
        { "language is not defined: " language * warning$ "no" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.nnr}
%    \begin{macrocode}
FUNCTION {bbl.nnr} % { "\bblno{}" }
{
  curlanguage "english" =
    { "No." }
    { curlanguage "german" =
      { "H." }
      { curlanguage "russian" =
        { "{\cyr\textnumero}" }
        { "language is not defined: " language * warning$ "No" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.in}
%    \begin{macrocode}
FUNCTION {bbl.in} % { "\bblin{}" }
{
  curlanguage "english" =
    { "in" }
    { curlanguage "german" =
      { "in" }
    { curlanguage "russian" =
      { "{\cyr\cyrv}" }
      { "language is not defined: " language * warning$ "in" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.iin}
%    \begin{macrocode}
FUNCTION {bbl.iin} % { "\bblIn{}" }
{
  curlanguage "english" =
    { "In" }
    { curlanguage "german" =
      { "In" }
      { curlanguage "russian" =
        { "{\cyr\CYRV}" }
        { "language is not defined: " language * warning$ "In" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.pages}
%    \begin{macrocode}
FUNCTION {bbl.pages} % { "\bblpp." }
{
  curlanguage "english" =
    { "p." }
    { curlanguage "german" =
      { "S." }
      { curlanguage "russian" =
        { "{\cyr\cyrs.}" }
        { "language is not defined: " language * warning$ "p." }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.page}
%    \begin{macrocode}
FUNCTION {bbl.page} % { "\bblp." }
{
  curlanguage "english" =
    { "p." }
    { curlanguage "german" =
      { "S." }
      { curlanguage "russian" =
        { "{\cyr\cyrs.}"}
        { "language is not defined: " language * warning$ "p." }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.ppages}
%    \begin{macrocode}
FUNCTION {bbl.ppages} % { "\bblPp." }
{
  curlanguage "english" =
    { "P." }
    { curlanguage "german" =
      { "S." }
      { curlanguage "russian" =
        { "{\cyr\CYRS.}" }
        { "language is not defined: " language * warning$ "P." }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.ppage}
%    \begin{macrocode}
FUNCTION {bbl.ppage} % { "\bblP." }
{
  curlanguage "english" =
    { "P." }
    { curlanguage "german" =
      { "S." }
      { curlanguage "russian" =
        { "{\cyr\CYRS.}" }
        { "language is not defined: " language * warning$ "P." }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.techrep}
%    \begin{macrocode}
FUNCTION {bbl.techrep}
{
  curlanguage "english" =
    { "Tech.~Rep." }
    { curlanguage "german" =
      { "Tech.~Bericht" }
      { curlanguage "russian" =
        { "{\cyr\CYRT\cyre\cyrh.\ \cyrd\cyro\cyrk\cyrl\cyra\cyrd.}" }
        { "language is not defined: " language * warning$ "Tech Rep" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.mthesis}
%    \begin{macrocode}
FUNCTION {bbl.mthesis}
{
  curlanguage "english" =
    { "Master's thesis" }
    { curlanguage "german" =
      { "Diss.~Mag." }
      { curlanguage "russian" =
        { "{\cyr\CYRM\cyra\cyrg\cyri\cyrs\cyrt\cyre\cyrr\cyrs\cyrk\cyra\cyrya\ "
          "\cyrd\cyri\cyrs\cyrs\cyre\cyrr\cyrt\cyra\cyrc\cyri\cyrya}" * }
         { "language is not defined: " language * warning$ "Master thesis" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.phdthesis}
%    \begin{macrocode}
FUNCTION {bbl.phdthesis}
{
  curlanguage "english" =
    { "Ph.\,D. thesis" }
    { curlanguage "german" =
      { "Diss.~Ph.\,D." }
      { curlanguage "russian" =
        { "{\cyr\CYRK\cyra\cyrn\cyrd\cyri\cyrd\cyra\cyrt\cyrs\cyrk\cyra\cyrya\ "
          "\cyrd\cyri\cyrs\cyrs\cyre\cyrr\cyrt\cyra\cyrc\cyri\cyrya}" * }
        { "language is not defined: " language * warning$ "PhD thesis" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.dscithesis}
%    \begin{macrocode}
FUNCTION {bbl.dscithesis}
{
  curlanguage "english" =
    { "Dr.\,Sci. dissertation" }
    { curlanguage "german" =
      { "Diss.~Dr." }
      { curlanguage "russian" =
        { "{\cyr\CYRD\cyro\cyrk\cyrt\cyro\cyrr\cyrs\cyrk\cyra\cyrya\ "
          "\cyrd\cyri\cyrs\cyrs\cyre\cyrr\cyrt\cyra\cyrc\cyri\cyrya}" * }
        { "language is not defined: " language * warning$ "Dr. Sci. dissertation" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.req}
%    \begin{macrocode}
FUNCTION {bbl.req}
{
  curlanguage "english" =
    { "req." }
    { curlanguage "german" =
      { "ang." }
      { curlanguage "russian" =
        { "{\cyr\cyrz\cyra\cyrya\cyrv\cyrl.}" }
        { "language is not defined: " language * warning$ "req" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.publ}
%    \begin{macrocode}
FUNCTION {bbl.publ}
{
  curlanguage "english" =
    { "publ." }
    { curlanguage "german" =
      { "ausg." }
      { curlanguage "russian" =
        { "{\cyr\cyro\cyrp\cyru\cyrb\cyrl.}" }
        { "language is not defined: " language * warning$ "In" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bbl.prio}
%    \begin{macrocode}
FUNCTION {bbl.prio}
{
  curlanguage "english" =
    { "priority" }
    { curlanguage "german" =
      { "Prioritat" }
      { curlanguage "russian" =
        { "{\cyr\cyrp\cyrr\cyri\cyro\cyrr\cyri\cyrt\cyre\cyrt}" }
        { "language is not defined: " language * warning$ "In" }
      if$
      }
    if$
    }
  if$
}

%    \end{macrocode}
% \subsection{Формат элементов библиографических ссылок}
%    \begin{macrocode}
INTEGERS { nameptr namesleft numnames }

%    \end{macrocode}
% \DescribeFunction{format.names}
%    \begin{macrocode}
FUNCTION {format.names}
{
  's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr
      "{vv~}{ll}{~f.}{, jj}" format.name$ 't :=
      nameptr #1 >
        { nameptr #4 =
          numnames #4 > and
            { "others" 't :=
              #1 'namesleft := }
            'skip$
          if$
          namesleft #1 >
            { ", " * t * }
            { t "others" =
              t "~others" =
              or
                { " " * bbl.etal * }
                { ", " * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

%    \end{macrocode}
% \DescribeFunction{format.names.rev}
%    \begin{macrocode}
FUNCTION {format.names.rev}
{
  's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr
      "{f.}{~vv}{~ll}{, jj}" format.name$ 't :=
      nameptr #1 >
        { nameptr #4 =
          numnames #4 > and
            { "others" 't :=
              #1 'namesleft := }
            'skip$
          if$
          namesleft #1 >
            { ", " * t * }
            { t "others" =
              t "~others" =
              or
                { " " * bbl.etal * }
                { ", " * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

%    \end{macrocode}
% \DescribeFunction{format.authors}
%    \begin{macrocode}
FUNCTION {format.authors}
{
  author empty$
    { "" }
    { author format.names emphasize }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.bookauthors}
%    \begin{macrocode}
FUNCTION {format.bookauthors}
{
  bookauthor empty$
    { "" }
    { bookauthor format.names }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.authors.after}
%    \begin{macrocode}
FUNCTION {format.authors.after}
{
  author empty$
    { "" }
    { author format.names.rev }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.bookauthors.after}
%    \begin{macrocode}
FUNCTION {format.bookauthors.after}
{
  bookauthor empty$
    { "" }
    { bookauthor format.names.rev }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.editors.after}
%    \begin{macrocode}
FUNCTION {format.editors.after}
{
  editor empty$
    { "" }
    { bbl.edby editor format.names.rev * }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.compiler.after}
%    \begin{macrocode}
FUNCTION {format.compiler.after}
{
  compiler empty$
    { "" }
    { bbl.cmplr compiler format.names.rev * }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.title}
%    \begin{macrocode}
FUNCTION {format.title}
{
  title empty$
    { "" }
    { title }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.date}
%    \begin{macrocode}
FUNCTION {format.date}
{
  year empty$
    { month empty$
        { "" }
        { "there's a month but no year in " cite$ * warning$ month }
      if$
    }
    { month empty$
        'year
        { year ". " quote$ "--- " month * * * * }
      if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{output.address.publisher.date}
%    \begin{macrocode}
FUNCTION {output.address.publisher.date}
{
  address empty$
    'skip$
    { address output
      publisher empty$
        'skip$
        { new.colon }
      if$
    }
  if$
  publisher output
  format.date output
}

%    \end{macrocode}
% \DescribeFunction{output.bibitem}
%    \begin{macrocode}
FUNCTION {output.bibitem}
{
  newline$
  "\bibitem" "{" * write$
  cite$ write$
  "}" write$
  newline$
  language empty$
    { "english" 'curlanguage := }
    { language  'curlanguage := }
  if$
  "\selectlanguageifdefined{" write$
  curlanguage write$
  "}" write$ newline$
  ""
  before.all 'output.state :=
}

%    \end{macrocode}
% \DescribeFunction{n.dashify}
%    \begin{macrocode}
FUNCTION {n.dashify}
{
  't :=
  ""
    { t empty$ not }
    { t #1 #1 substring$ "-" =
        { t #1 #2 substring$ "--" = not
            { "--" *
              t #2 global.max$ substring$ 't :=
            }
            {   { t #1 #1 substring$ "-" = }
                { "-" *
                  t #2 global.max$ substring$ 't :=
                }
              while$
            }
          if$
        }
        { t #1 #1 substring$ *
          t #2 global.max$ substring$ 't :=
        }
      if$
    }
  while$
}

%    \end{macrocode}
% \DescribeFunction{word.in}
%    \begin{macrocode}
FUNCTION {word.in} { bbl.iin " " * }

%    \end{macrocode}
% \DescribeFunction{format.btitle}
%    \begin{macrocode}
FUNCTION {format.btitle} { title }

%    \end{macrocode}
% \DescribeFunction{tie.or.space.connect}
%    \begin{macrocode}
FUNCTION {tie.or.space.connect}
{
  duplicate$ text.length$ #3 <
    { "~" }
    { " " }
  if$
  swap$ * *
}

%    \end{macrocode}
% \DescribeFunction{tie.connect}
%    \begin{macrocode}
FUNCTION {tie.connect} { "~" swap$ * * }

%    \end{macrocode}
% \DescribeFunction{either.or.check}
%    \begin{macrocode}
FUNCTION {either.or.check}
{
  empty$
    'pop$
    { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.bvolume}
%    \begin{macrocode}
FUNCTION {format.bvolume}
{
  volume empty$
    { "" }
    { bbl.vvol volume tie.connect
      series empty$
        'skip$
        { bbl.of space.word * series emphasize * }
      if$
      "volume and number" number either.or.check
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.number.series}
%    \begin{macrocode}
FUNCTION {format.number.series}
{
  volume empty$
    { number empty$
        { series field.or.null }
        { series empty$
            { "there's a number but no series in " cite$ * warning$
              bbl.nnr
            }
            { new.sentence
              bbl.iiss series tie.or.space.connect
              ", " * bbl.nr
              tie.or.space.connect
            }
          if$
          number tie.or.space.connect
        }
      if$
    }
    { "" }
  if$
}

%    \end{macrocode}
% \DescribeFunction{is.num}
%    \begin{macrocode}
FUNCTION {is.num}
{
  chr.to.int$
  duplicate$ "0" chr.to.int$ < not
  swap$ "9" chr.to.int$ > not and
}

%    \end{macrocode}
% \DescribeFunction{extract.num}
%    \begin{macrocode}
FUNCTION {extract.num}
{
  duplicate$ 't :=
  "" 's :=
    { t empty$ not }
    { t #1 #1 substring$
      t #2 global.max$ substring$ 't :=
      duplicate$ is.num
        { s swap$ * 's := }
        { pop$ "" 't := }
      if$
    }
  while$
  s empty$
    'skip$
    { pop$ s }
  if$
}

%    \end{macrocode}
% \DescribeFunction{convert.edition}
%    \begin{macrocode}
FUNCTION {convert.edition} { edition }

%    \end{macrocode}
% \DescribeFunction{format.edition}
%    \begin{macrocode}
FUNCTION {format.edition}
{
  edition empty$
    { "" }
    { output.state mid.sentence =
        { convert.edition "l" change.case$ " " * bbl.edition * }
        { convert.edition "t" change.case$ " " * bbl.edition * }
      if$
    }
  if$
}

INTEGERS { multiresult }

%    \end{macrocode}
% \DescribeFunction{multi.page.check}
%    \begin{macrocode}
FUNCTION {multi.page.check}
{
  't :=
  #0 'multiresult :=
    { multiresult not
      t empty$ not
      and
    }
    { t #1 #1 substring$
      duplicate$ "-" =
      swap$ duplicate$ "," =
      swap$ "+" =
      or or
        { #1 'multiresult := }
        { t #2 global.max$ substring$ 't := }
      if$
    }
  while$
  multiresult
}

%    \end{macrocode}
% \DescribeFunction{format.pages}
%    \begin{macrocode}
FUNCTION {format.pages}
{
  pages empty$
    { "" }
    { pages multi.page.check
        { bbl.ppages pages n.dashify tie.connect }
        { bbl.ppage pages tie.connect }
      if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.pages.page}
%    \begin{macrocode}
FUNCTION {format.pages.page}
{
  pages empty$
    { numpages empty$
        { "" }
        { numpages bbl.pages tie.connect }
      if$
    }
    { format.pages }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.vol.num.pages}
%    \begin{macrocode}
FUNCTION {format.vol.num.pages}
{
  volume field.or.null
  number empty$
    'skip$
    { ", no." number tie.or.space.connect *
      volume empty$
        { "there's a number but no volume in " cite$ * warning$ }
        'skip$
      if$
    }
  if$
  pages empty$
    'skip$
    { duplicate$ empty$
        { pop$ format.pages }
        { ": " * pages n.dashify * }
      if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.volume}
%    \begin{macrocode}
FUNCTION {format.volume}
{
  volume empty$
    { "" }
    { bbl.vvol volume tie.or.space.connect }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.number}
%    \begin{macrocode}
FUNCTION {format.number}
{ number empty$
    { "" }
    { bbl.nr number tie.or.space.connect }
  if$
}

%    \end{macrocode}
% \DescribeFunction{empty.misc.check}
%    \begin{macrocode}
FUNCTION {empty.misc.check}
{
  author empty$ title empty$ howpublished empty$
  month empty$ year empty$ note empty$
  and and and and and
  key empty$ not and
    { "all relevant fields are empty in " cite$ * warning$ }
    'skip$
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.thesis.type}
%    \begin{macrocode}
FUNCTION {format.thesis.type}
{
  type empty$
    'skip$
    { pop$
      type "t" change.case$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.tr.number}
%    \begin{macrocode}
FUNCTION {format.tr.number}
{
  type empty$
    { bbl.techrep }
    'type
  if$
  number empty$
    { "t" change.case$ }
    { number tie.or.space.connect }
  if$
}

%    \end{macrocode}
% \DescribeFunction{author.before}
%    \begin{macrocode}
FUNCTION {author.before}
{
  author empty$
    'skip$
    { format.authors output
      new.sentence
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bookauthor.before}
%    \begin{macrocode}
FUNCTION {bookauthor.before}
{
  bookauthor empty$
    'skip$
    { format.bookauthors output
      new.sentence
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{author.after}
%    \begin{macrocode}
FUNCTION {author.after}
{
  author empty$
    'skip$
    { author num.names$ #3 >
      { format.authors.after output
        new.semicolon
      }
      'skip$
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{bookauthor.after}
%    \begin{macrocode}
FUNCTION {bookauthor.after}
{
  bookauthor empty$
    'skip$
    { bookauthor num.names$ #3 >
      { format.bookauthors.after output
        new.semicolon
      }
      'skip$
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{editor.organization.after}
%    \begin{macrocode}
FUNCTION {editor.organization.after}
{
  compiler empty$
    'skip$
    { format.compiler.after output
      new.semicolon
    }
  if$
  editor empty$
    'skip$
    { format.editors.after output
      new.semicolon
    }
  if$
  organization empty$
    'skip$
    { organization output
      new.semicolon
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.annote}
%    \begin{macrocode}
FUNCTION {format.annote}
{
  annote empty$
    { "" }
    { after.sentence 'output.state :=
      "\BibAnnote{" annote add.period$ * "}" *
    }
  if$
}

%    \end{macrocode}
% \subsection{Создание гиперссылок}
% \DescribeFunction{format.url}
%    \begin{macrocode}
FUNCTION {format.url}
{
  url empty$
    { "" }
    { "\BibUrl{" url * "}" * }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.urldate}
%    \begin{macrocode}
FUNCTION {format.urldate}
{
  urldate empty$
    { "" }
    { add.blank
      "\BibUrlDate{" urldate * "}" *
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{output.url}
%    \begin{macrocode}
FUNCTION {output.url}
{
  url empty$
    'skip$
    { format.url output
      format.urldate output
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.isbn}
%    \begin{macrocode}
FUNCTION {format.isbn}
{
  isbn empty$
    { "" }
    { "ISBN:~\href{http://isbndb.com/search-all.html?kw=" isbn *
      "}{" * isbn * "}" *
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{add.doi.url}
%    \begin{macrocode}
FUNCTION {add.doi.url}
{ duplicate$ empty$
    'skip$
    { doi empty$
      { url empty$
          'skip$
          { "\href{" url * "}{" * swap$ * "}" * }
        if$
      }
      { "\href{http://dx.doi.org/" doi * "}{" * swap$ * "}" * }
      if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.eprint}
%    \begin{macrocode}
FUNCTION {format.eprint}
{ eprint empty$
    { "" }
    { primaryClass empty$
    	  { " \href{http://arxiv.org/abs/" eprint * "}" *
    		  "{" * eprint * "}" *
        }
        { archivePrefix empty$
            { " \href{http://arxiv.org/abs/" eprint * "}" *
      	 	    "{" * primaryClass * "/" * eprint * "}" *
            }
            { " \href{http://arxiv.org/abs/" eprint * "}" *
      	 	  "{" * archivePrefix * ":" * primaryClass * "/" * eprint * "}" *
            }
          if$
        }
  	  if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{add.number}
%    \begin{macrocode}
FUNCTION {add.number}
{ duplicate$ empty$
    { "" }
    { bbl.nr swap$ tie.or.space.connect }
  if$
}

%    \end{macrocode}
% \DescribeFunction{in.square.brackets}
%    \begin{macrocode}
FUNCTION {in.square.brackets}
{
  duplicate$ empty$
    { pop$ "" }
    { "[" swap$ * "]" * }
  if$
}

%    \end{macrocode}
% \DescribeFunction{in.round.brackets}
%    \begin{macrocode}
FUNCTION {in.round.brackets}
{
  duplicate$ empty$
    { pop$ "" }
    { "(" swap$ * ")" * }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.type.number}
%    \begin{macrocode}
FUNCTION {format.type.number}
{
  type empty$
    { "" }
    {
      number empty$
      { "" }
      { type number tie.or.space.connect }
    if$
    }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.reqdate}
%    \begin{macrocode}
FUNCTION {format.reqdate}
{ reqdate empty$
    { "" }
    { bbl.req reqdate tie.or.space.connect }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.pubdate}
%    \begin{macrocode}
FUNCTION {format.pubdate}
{ pubdate empty$
    { "" }
    { bbl.publ pubdate tie.or.space.connect }
  if$
}

%    \end{macrocode}
% \DescribeFunction{format.prdate}
%    \begin{macrocode}
FUNCTION {format.prdate}
{ prdate empty$
    { "" }
    { bbl.prio prdate tie.or.space.connect }
  if$
}

%    \end{macrocode}
% \subsection{Описание типов библиографических ссылок}
% \DescribeFunction{article}
%    \begin{macrocode}
FUNCTION {article}
{
  output.bibitem
  author.before
  format.title "title" output.check
  new.dblslash
  journal emphasize add.doi.url "journal" output.check
  new.block
  format.date output
  new.block
  format.volume output
  format.number output
  new.block
  format.pages.page output
  new.block
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{book}
%    \begin{macrocode}
FUNCTION {book}
{
  output.bibitem
  author.before
  format.btitle add.doi.url "title" output.check
  new.slash
  editor.organization.after
  new.sentence
  format.number.series output
  new.block
  format.edition output
  new.block
  output.address.publisher.date
  new.block
  format.bvolume output
  new.block
  format.pages.page output
  new.block
  format.isbn output
  new.block
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{booklet}
%    \begin{macrocode}
FUNCTION {booklet}
{
  output.bibitem
  author.before
  format.title "title" output.check
  editor.organization.after
  new.block
  howpublished output
  address output
  format.date output
  new.block
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{inbook}
%    \begin{macrocode}
FUNCTION {inbook}
{
  output.bibitem
  author.before
  format.btitle add.doi.url "title" output.check
  new.dblslash
  bookauthor.before
  booktitle "booktitle" output.check
  editor.organization.after
  new.block
  format.edition output
  new.block
  format.number.series output
  new.sentence
  output.address.publisher.date
  new.block
  format.bvolume output
  new.block
  format.pages.page output
  new.block
  format.isbn output
  new.block
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{incollection}
%    \begin{macrocode}
FUNCTION {incollection}
{
  output.bibitem
  author.before
  new.sentence
  format.title add.doi.url "title" output.check
  new.dblslash
  booktitle "booktitle" output.check
  new.slash
  editor.organization.after
  new.block
  output.address.publisher.date
  new.block
  format.bvolume output
  format.number.series output
  new.block
  format.pages.page output
  new.block
  note output
  new.block
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{inproceedings}
%    \begin{macrocode}
FUNCTION {inproceedings}
{
  output.bibitem
  author.before
  new.sentence
  format.title add.doi.url "title" output.check
  new.dblslash
  booktitle "booktitle" output.check
  new.slash
  editor.organization.after
  new.block
  format.bvolume output
  format.number.series output
  new.block
  address empty$
    { publisher output
      format.date "year" output.check
    }
    { address output.nonnull
      new.colon
      publisher output
      format.date "year" output.check
    }
  if$
  new.block
  format.pages.page output
  new.block
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{conference}
%    \begin{macrocode}
FUNCTION {conference} { inproceedings }

%    \end{macrocode}
% \DescribeFunction{manual}
%    \begin{macrocode}
FUNCTION {manual}
{
  output.bibitem
  author empty$
    { organization empty$
        'skip$
        { organization output.nonnull
          address output
        }
      if$
    }
    { format.authors output.nonnull }
  if$
  new.block
  format.btitle "title" output.check
  author empty$
    { organization empty$
        { address new.block.checka
          address output
        }
        'skip$
      if$
    }
    { organization address new.block.checkb
      organization output
      address output
    }
  if$
  format.edition output
  format.date output
  new.block
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{mastersthesis}
%    \begin{macrocode}
FUNCTION {mastersthesis}
{
  output.bibitem
  format.authors "author" output.check
  new.block
  format.btitle add.doi.url "title" output.check
  new.block
  bbl.mthesis format.thesis.type output.nonnull
  school "school" output.check
  address output
  format.date "year" output.check
  new.block
  note output
  new.block
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{misc}
%    \begin{macrocode}
FUNCTION {misc}
{
  output.bibitem
  format.authors "author" output.check
  new.block
  format.title "title" output.check
  new.block
  howpublished output
  new.block
  format.date output
  new.block
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{phdthesis}
%    \begin{macrocode}
FUNCTION {phdthesis}
{
  output.bibitem
  format.authors "author" output.check
  new.sentence
  format.btitle add.doi.url "title" output.check
  new.colon
  bbl.phdthesis format.thesis.type output.nonnull
  new.slash
  school "school" output.check
  new.block
  output.address.publisher.date
  new.block
  format.pages.page output
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{dscithesis}
%    \begin{macrocode}
FUNCTION {dscithesis}
{
  output.bibitem
  format.authors "author" output.check
  new.sentence
  format.btitle add.doi.url "title" output.check
  new.colon
  bbl.dscithesis format.thesis.type output.nonnull
  new.slash
  school "school" output.check
  new.block
  output.address.publisher.date
  new.block
  format.pages.page output
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{proceedings}
%    \begin{macrocode}
FUNCTION {proceedings}
{
  output.bibitem
  format.btitle add.doi.url "title" output.check
  new.slash
  editor.organization.after
  new.block
  format.bvolume output
  format.number.series output
  address empty$
    { publisher output
      format.date "year" output.check
    }
    { address output.nonnull
      format.date "year" output.check
      new.sentence
      publisher output
    }
  if$
  new.block
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{techreport}
%    \begin{macrocode}
FUNCTION {techreport}
{
  output.bibitem
  author.before
  new.sentence
  format.title add.doi.url "title" output.check
  new.colon
  format.tr.number output.nonnull
  editor.organization.after
  new.block
  address output
  new.colon
  institution "institution" output.check
  format.date "year" output.check
  new.block
  note output
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{patent}
%    \begin{macrocode}
FUNCTION {patent}
{
  output.bibitem
  title output.nonnull
  add.blank
  media in.square.brackets output
  new.colon
  format.type.number output
  add.blank
  location output
  new.colon
  ipc output
  new.slash
  format.authors.after "author" output.check
  add.blank
  authortype in.round.brackets output.nonnull
  new.semicolon
  holder output.nonnull
  new.semicolon
  credits output.nonnull
  new.block
  reqnumber add.number output
  new.semicolon
  format.reqdate output
  new.semicolon
  format.pubdate output
  publication output
  new.semicolon
  format.prdate output
  prnumber output
  prcountry in.round.brackets output
  new.block
  note output
  new.sentence
  output.url
  format.annote output
  new.block
  pagetotal output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{unpublished}
%    \begin{macrocode}
FUNCTION {unpublished}
{
  output.bibitem
  author.before
  format.btitle add.doi.url "title" output.check
  editor.organization.after
  new.block
  note "note" output.check
  new.sentence
  format.eprint output
  new.block
  output.url
  format.annote output
  fin.entry
}

%    \end{macrocode}
% \DescribeFunction{default.type}
%    \begin{macrocode}
FUNCTION {default.type} { misc }

%    \end{macrocode}
% \subsection{Сокращения названий месяцев}
%    \begin{macrocode}
MACRO {jan} {"\bbljan{}"}
MACRO {feb} {"\bblfeb{}"}
MACRO {mar} {"\bblmar{}"}
MACRO {apr} {"\bblapr{}"}
MACRO {may} {"\bblmay{}"}
MACRO {jun} {"\bbljun{}"}
MACRO {jul} {"\bbljul{}"}
MACRO {aug} {"\bblaug{}"}
MACRO {sep} {"\bblsep{}"}
MACRO {oct} {"\bbloct{}"}
MACRO {nov} {"\bblnov{}"}
MACRO {dec} {"\bbldec{}"}

%    \end{macrocode}
% \subsection{Сокращения названий журналов}
% \subsubsection{Физика и астрономия}
% Код данной секции создан на основе файла \file{physjour.mbs} пакета
% \pkg{custom-bib}.
%    \begin{macrocode}
MACRO {aa}{"Astron. \& Astrophys."}
MACRO {aasup}{"Astron. \& Astrophys. Suppl. Ser."}
MACRO {aj} {"Astron. J."}
MACRO {aph} {"Acta Phys."}
MACRO {advp} {"Adv. Phys."}
MACRO {ajp} {"Amer. J. Phys."}
MACRO {ajm} {"Amer. J. Math."}
MACRO {amsci} {"Amer. Sci."}
MACRO {anofd} {"Ann. Fluid Dyn."}
MACRO {am} {"Ann. Math."}
MACRO {ap} {"Ann. Phys. (NY)"}
MACRO {adp} {"Ann. Phys. (Leipzig)"}
MACRO {ao} {"Appl. Opt."}
MACRO {apl} {"Appl. Phys. Lett."}
MACRO {app} {"Astroparticle Phys."}
MACRO {apj} {"Astrophys. J."}
MACRO {apjsup} {"Astrophys. J. Suppl."}
MACRO {apss} {"Astrophys. Space Sci."}
MACRO {araa} {"Ann. Rev. Astron. Astrophys."}
MACRO {baas} {"Bull. Amer. Astron. Soc."}
MACRO {baps} {"Bull. Amer. Phys. Soc."}
MACRO {cmp} {"Comm. Math. Phys."}
MACRO {cpam} {"Commun. Pure Appl. Math."}
MACRO {cppcf} {"Comm. Plasma Phys. \& Controlled Fusion"}
MACRO {cpc} {"Comp. Phys. Comm."}
MACRO {cqg} {"Class. Quant. Grav."}
MACRO {cra} {"C. R. Acad. Sci. A"}
MACRO {fed} {"Fusion Eng. \& Design"}
MACRO {ft} {"Fusion Tech."}
MACRO {grg} {"Gen. Relativ. Gravit."}
MACRO {ieeens} {"IEEE Trans. Nucl. Sci."}
MACRO {ieeeps} {"IEEE Trans. Plasma Sci."}
MACRO {ijimw} {"Interntl. J. Infrared \& Millimeter Waves"}
MACRO {ip} {"Infrared Phys."}
MACRO {irp} {"Infrared Phys."}
MACRO {jap} {"J. Appl. Phys."}
MACRO {jasa} {"J. Acoust. Soc. America"}
MACRO {jcp} {"J. Comp. Phys."}
MACRO {jchp} {"J. Chem. Phys."}
MACRO {jetp} {"Sov. Phys.--JETP"}
MACRO {jfe} {"J. Fusion Energy"}
MACRO {jfm} {"J. Fluid Mech."}
MACRO {jmp} {"J. Math. Phys."}
MACRO {jne} {"J. Nucl. Energy"}
MACRO {jnec} {"J. Nucl. Energy, C: Plasma Phys., Accelerators, Thermonucl. Res."}
MACRO {jnm} {"J. Nucl. Mat."}
MACRO {jpc} {"J. Phys. Chem."}
MACRO {jpp} {"J. Plasma Phys."}
MACRO {jpsj} {"J. Phys. Soc. Japan"}
MACRO {jsi} {"J. Sci. Instrum."}
MACRO {jvst} {"J. Vac. Sci. \& Tech."}
MACRO {nat} {"Nature"}
MACRO {nature} {"Nature"}
MACRO {nedf} {"Nucl. Eng. \& Design/Fusion"}
MACRO {nf} {"Nucl. Fusion"}
MACRO {nim} {"Nucl. Inst. \& Meth."}
MACRO {nimpr} {"Nucl. Inst. \& Meth. in Phys. Res."}
MACRO {np} {"Nucl. Phys."}
MACRO {npb} {"Nucl. Phys. B"}
MACRO {nt/f} {"Nucl. Tech./Fusion"}
MACRO {npbpc} {"Nucl. Phys. B (Proc. Suppl.)"}
MACRO {inc} {"Nuovo Cimento"}
MACRO {nc} {"Nuovo Cimento"}
MACRO {pf} {"Phys. Fluids"}
MACRO {pfa} {"Phys. Fluids A: Fluid Dyn."}
MACRO {pfb} {"Phys. Fluids B: Plasma Phys."}
MACRO {pl} {"Phys. Lett."}
MACRO {pla} {"Phys. Lett. A"}
MACRO {plb} {"Phys. Lett. B"}
MACRO {prep} {"Phys. Rep."}
MACRO {pnas} {"Proc. Nat. Acad. Sci. USA"}
MACRO {pp} {"Phys. Plasmas"}
MACRO {ppcf} {"Plasma Phys. \& Controlled Fusion"}
MACRO {phitrsl} {"Philos. Trans. Roy. Soc. London"}
MACRO {prl} {"Phys. Rev. Lett."}
MACRO {pr} {"Phys. Rev."}
MACRO {physrev} {"Phys. Rev."}
MACRO {pra} {"Phys. Rev. A"}
MACRO {prb} {"Phys. Rev. B"}
MACRO {prc} {"Phys. Rev. C"}
MACRO {prd} {"Phys. Rev. D"}
MACRO {pre} {"Phys. Rev. E"}
MACRO {ps} {"Phys. Scripta"}
MACRO {procrsl} {"Proc. Roy. Soc. London"}
MACRO {rmp} {"Rev. Mod. Phys."}
MACRO {rsi} {"Rev. Sci. Inst."}
MACRO {science} {"Science"}
MACRO {sciam} {"Sci. Am."}
MACRO {sam} {"Stud. Appl. Math."}
MACRO {sjpp} {"Sov. J. Plasma Phys."}
MACRO {spd} {"Sov. Phys.--Doklady"}
MACRO {sptp} {"Sov. Phys.--Tech. Phys."}
MACRO {spu} {"Sov. Phys.--Uspekhi"}
MACRO {st} {"Sky and Telesc."}

%    \end{macrocode}
% \subsubsection{Оптика}
% Из файла~\file{photjour.mbs}.
%    \begin{macrocode}
MACRO {appopt} {"Appl. Opt."}
MACRO {bell} {"Bell Syst. Tech. J."}
MACRO {ell} {"Electron. Lett."}
MACRO {jasp} {"J. Appl. Spectr."}
MACRO {jqe} {"IEEE J. Quantum Electron."}
MACRO {jlwt} {"J. Lightwave Technol."}
MACRO {jmo} {"J. Mod. Opt."}
MACRO {josa} {"J. Opt. Soc. America"}
MACRO {josaa} {"J. Opt. Soc. Amer.~A"}
MACRO {josab} {"J. Opt. Soc. Amer.~B"}
MACRO {jdp} {"J. Phys. (Paris)"}
MACRO {oc} {"Opt. Commun."}
MACRO {ol} {"Opt. Lett."}
MACRO {os} {"Opt. Spectrosc."}
MACRO {phtl} {"IEEE Photon. Technol. Lett."}
MACRO {pspie} {"Proc. Soc. Photo-Opt. Instrum. Eng."}
MACRO {sjot} {"Sov. J. Opt. Technol."}
MACRO {sjqe} {"Sov. J. Quantum Electron."}
MACRO {sleb} {"Sov. Phys.--Leb. Inst. Rep."}
MACRO {stph} {"Sov. Phys.--Techn. Phys."}
MACRO {stphl} {"Sov. Techn. Phys. Lett."}
MACRO {vr} {"Vision Res."}
MACRO {zph} {"Z. f. Physik"}
MACRO {zphb} {"Z. f. Physik~B"}
MACRO {zphd} {"Z. f. Physik~D"}

%    \end{macrocode}
% \subsubsection{Физика конденсированного состояния}
%    \begin{macrocode}
MACRO {sse} {"Solid-State Electron."}
MACRO {pss} {"Phys. Sol. State"}
MACRO {sst} {"Semicond. Sci. Tech."}
MACRO {nl} {"Nano Lett."}

READ

%    \end{macrocode}
% \subsection{Сортировка списка литературы по именам авторов и названиям}
%    \begin{macrocode}
%<*gost705s>
%    \end{macrocode}
% \DescribeFunction{sortify}
%    \begin{macrocode}
FUNCTION {sortify}
{
  purify$
  "l" change.case$
}

INTEGERS { len }

%    \end{macrocode}
% \DescribeFunction{chop.word}
%    \begin{macrocode}
FUNCTION {chop.word}
{
  's :=
  'len :=
  s #1 len substring$ =
    { s len #1 + global.max$ substring$ }
    's
  if$
}

%    \end{macrocode}
% \DescribeFunction{sort.format.names}
%    \begin{macrocode}
FUNCTION {sort.format.names}
{
  's :=
  #1 'nameptr :=
  ""
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { nameptr #1 >
        { "   " * }
        'skip$
      if$
      s nameptr
      "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}"
      format.name$ 't :=
      nameptr numnames = t "others" = and
        { "et al" * }
        { t sortify * }
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

%    \end{macrocode}
% \DescribeFunction{sort.format.title}
%    \begin{macrocode}
FUNCTION {sort.format.title}
{
  't :=
  "A " #2
    "An " #3
      "The " #4 t chop.word
    chop.word
  chop.word
  sortify
  #1 global.max$ substring$
}

%    \end{macrocode}
% \DescribeFunction{author.sort}
%    \begin{macrocode}
FUNCTION {author.sort}
{
  author empty$
    { key empty$
        { "to sort, need author or key in " cite$ * warning$ "" }
        { key sortify }
      if$
    }
    { author sort.format.names }
  if$
}

%    \end{macrocode}
% \DescribeFunction{author.title.sort}
%    \begin{macrocode}
FUNCTION {author.title.sort}
{
  author empty$
    { title empty$
      { key empty$
        { "to sort, need author, title, or key in " cite$ * warning$ "" }
        { key sortify }
      if$
      }
      { title sort.format.title }
    if$
    }
    { author sort.format.names }
  if$
}

%    \end{macrocode}
% \DescribeFunction{presort}
%    \begin{macrocode}
FUNCTION {presort}
{
  author.title.sort
  "   "
  *
  year field.or.null sortify
  *
  "   "
  *
  title field.or.null
  sort.format.title
  *
  #1 entry.max$ substring$
  'sort.key$ :=
}

ITERATE {presort}

SORT

%</gost705s>

%    \end{macrocode}
% \subsection{Вычисление длины табуляции между номером и текстом}
%    \begin{macrocode}
STRINGS { longest.label }

INTEGERS { number.label longest.label.width }

%    \end{macrocode}
% \DescribeFunction{initialize.longest.label}
%    \begin{macrocode}
FUNCTION {initialize.longest.label}
{
  "" 'longest.label :=
  #1 'number.label :=
  #0 'longest.label.width :=
}

%    \end{macrocode}
% \DescribeFunction{longest.label.pass}
%    \begin{macrocode}
FUNCTION {longest.label.pass}
{
  number.label int.to.str$ 'label :=
  number.label #1 + 'number.label :=
  label width$ longest.label.width >
    { label 'longest.label :=
      label width$ 'longest.label.width :=
    }
    'skip$
  if$
}

EXECUTE {initialize.longest.label}

ITERATE {longest.label.pass}

%    \end{macrocode}
% \subsection{Формирование окружения thebibliography}
% \subsubsection{Преамбула}
% \DescribeFunction{begin.bib}
%    \begin{macrocode}
FUNCTION {begin.bib}
{
  preamble$ empty$
    'skip$
    { preamble$ write$ newline$ }
  if$
  "\providecommand*\BibEmph[1]{#1}" write$ newline$
  "\providecommand*\BibDash{}" write$ newline$
  "\providecommand*\href[2]{#2}" write$ newline$
  "\providecommand*\url[1]{\texttt{#1}}" write$ newline$
  "\providecommand*\urlprefix{URL: }" write$ newline$
  "\providecommand*\BibUrl[1]{\urlprefix\url{#1}}" write$ newline$
  "\providecommand*\BibUrlDate[1]{({%" write$ newline$
    "\cyr\cyrd\cyra\cyrt\cyra\ %" write$ newline$
    "\cyro\cyrb\cyrr\cyra\cyrshch\cyre\cyrn\cyri\cyrya}: #1)}" write$ newline$
  "\providecommand*\BibAnnote[1]{#1}" write$ newline$
  "\begin{thebibliography}{" longest.label  * "}" * write$ newline$
  "\def\selectlanguageifdefined#1{" write$ newline$
    "\expandafter\ifx\csname date#1\endcsname\relax" write$ newline$
    "\else\language\csname l@#1\endcsname\fi}" write$ newline$
}

%    \end{macrocode}
% \subsubsection{Начало окружения}
%    \begin{macrocode}
EXECUTE {begin.bib}

EXECUTE {init.state.consts}

ITERATE {call.type$}

%    \end{macrocode}
% \subsubsection{Конец окружения}
% \DescribeFunction{end.bib}
%    \begin{macrocode}
FUNCTION {end.bib}
{
  newline$
  "\end{thebibliography}" write$ newline$
}

EXECUTE {end.bib}

%</gost705|gost705s>
%    \end{macrocode}
