%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%                                                                      %%%
%%%    INSTITUTE FOR CONDENSED MATTER PHYSICS                            %%%
%%%                                                                      %%%
%%%    Style file for preparing an article for publication               %%%
%%%    in the Computer Tools in Education journal <info@ipo.spb.ru>,     %%%
%%%    http://cte.eltech.ru/ojs                                          %%%
%%%    using LaTeX2e                                                     %%%
%%%                                                                      %%%
%%%    Copyright (C) 2019 by the center for informatization of Education %%%
%%%                      "KIO", all rights reserved.                     %%%
%%%                                                                      %%%
%%%    This file can be redistributed and/or modified under the terms    %%%
%%%    of the LaTeX Project Public License (lppl).                       %%%
%%%                                                                      %%%
%%%    The work is based on the Style for the journal Condensed          %%%
%%%    Matter Physics (https://ctan.org/pkg/cmpj)                        %%%
%%%                                                                      %%%
%%%    Please report errors to: Ilya Posov                               %%%
%%%                             iposov@gmail.com                         %%%
%%%                                                                      %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}

% А. Б. Иванов1,  должность, orcid (если есть)
% Б. П. Петров1,2,  должность, orcid (если есть)
% 1. Полное наименование организации, адрес, город, индекс, страна
% 2. Полное наименование организации, адрес, город, индекс, страна
% Цифры 1 и 2 - это верхние индексы, как у нас и было. Если автор один, индекс также нужен.
%
% TODO В английской части добавляется Reference.
% TODO разобраться в конфликте, какой пакет добавляет \iint (это txfont, не надо ли его обновить до заменяющего пакета)
% TODO можно ли убрать линии перед переведенной частью, если она начинается в начале страницы
% TODO переписать работу с двумя языками.

\ProvidesPackage{kioj4}[2020/04/15 v0.4 The KIO and CAM journals package]
\def\filename{kioj4.sty}
\def\fileversion{4.00}
\def\filedate{2020/04/15}
\immediate\write32{This is '\filename' v\fileversion \space <\filedate> ^^J%
     the KIO and CTE journals package}

\if\@ptsize1
   \else
   \PackageWarning{kioj4.sty}{Bad \noexpand\documentclass option, use 11pt}
\fi

%do not forget to install droid, fourier, and txfonts fonts before usage

\RequirePackage{cmap} % pdf copy\paste + search package

% ========== Options ==============

%eqsecnum: new numbering of formulae in each section
\def\eqsecnum{%
        \@addtoreset{equation}{section} %
        \def\theequation{\ifnum \c@section>\z@ \thesection.\fi \@arabic\c@equation}%
}

\DeclareOption{eqsecnum}{\eqsecnum}

\DeclareOption{noimages}{\def\@noimages{}}

% font options

\def\kio@sf{cmss}

\def\lat@sf{\kio@sf}
\def\cyr@sf{\kio@sf}
\def\Hv@scale{0.889}
\def\Pr@scale{0.889}
\def\cmpj@sf{}

\def\cmpj@sf@helvet{
  %P%\IfFileExists{t1phv.fd}{
  \IfFileExists{t2aphv.fd}{
    \def\lat@sf{phv}
  }{
    \def\lat@sf{\kio@sf}
  }
  \IfFileExists{t2appr.fd}{
    \def\cyr@sf{ppr}
  }{
    \def\cyr@sf{\kio@sf}
  }
}

\def\cmpj@sf@droid{
%  \IfFileExists{t2afds.fd}{
%    \IfFileExists{omltxmi.fd}{\RequirePackage{txfonts}}{}
%    \IfFileExists{fmlfutm.fd}{\RequirePackage{fourier}}{}
\RequirePackage{txfonts}
\RequirePackage{fourier}
\IfFileExists{omltxmi.fd}{\re@DeclareMathSymbol{\varkappa}{\mathord}{AMSb}{123}}{}
\RequirePackage[default,scale=0.86]{droidserif}
\RequirePackage[defaultsans,scale=0.86]{droidsans}
\RequirePackage[defaultmono,scale=0.86]{droidsansmono}
\def\lat@sf{droidsans}
\def\cyr@sf{droidsans}
%  }{\PackageWarning{kioj4.sty}{Failed to use droid fonts}\cmpj@sf@helvet}
}

\DeclareOption{droid}{\let\cmpj@sf\cmpj@sf@droid}

\DeclareOption{helvet}{\let\cmpj@sf\cmpj@sf@helvet}

\DeclareOption{cm}{\def\cmpj@sf{}}

%Two languages

\newcommand\@lang[2]{\@ifundefined{@english}{#1}{#2}}
\newcommand\@langrev[2]{\@ifundefined{@reverse@lang}{\@lang{#1}{#2}}{\@lang{#2}{#1}}}
\newcommand\@unreverselang[1]{%
\let\@reverse@lang@temp\@reverse@lang%
\let\@reverse@lang\undefined%
#1%
\let\@reverse@lang\@reverse@lang@temp%
}

\DeclareOption{english}{
	\def\@english{}
}
\DeclareOption{authorsinfo}{
    \def\need@authors@info{}
}

% nocopyright option

\def\@@copyright{\copyright}
\def\copyright@size{\small}
\def\copyright@author{\@author\cp@issue@year}
\def\copyright@journal{\@unreverselang{\copyright\space\MakeTextUppercase{\journal@type}. \textnumero\issue@number, \issue@year}\@lang{ \space г.}{}}
\def\authorcopyright{\@ifnextchar[
        \iauthorcopyright{\iauthorcopyright[\small]}}
\def\iauthorcopyright[#1]#2{\gdef\copyright@size{#1}
        \gdef\copyright@author{#2}}

\DeclareOption{nocopyright}{\def\@@copyright{}\authorcopyright{}}

\ExecuteOptions{droid}

\ProcessOptions\relax

\RequirePackage[T2A]{fontenc}
\@lang{
  \RequirePackage[english,russian]{babel}
}{
  \RequirePackage[russian,english]{babel}
}
\RequirePackage{fancyhdr}
\RequirePackage{graphicx}
\@ifundefined{@noimages}{}{\renewcommand{\includegraphics}[2][]{\fbox{\detokenize{#2}}}}  % TODO use width, height from graphics specification
\RequirePackage[square,comma,numbers,sort&compress]{natbib}
\RequirePackage{ifthen}
\RequirePackage{textcase}
\RequirePackage{setspace}
\RequirePackage[pdfstartview=FitH,colorlinks=true,urlcolor=Blue,citecolor=Green,linkcolor=BrickRed]{hyperref}
\RequirePackage{url}
%\RequirePackage{doi}
\RequirePackage[dvipsnames]{xcolor}
\RequirePackage{float}
\RequirePackage[tableposition=top,labelfont={bf,sf,small},font=small,skip=4mm,labelsep=period]{caption}
\RequirePackage{subcaption}
%\RequirePackage[misc]{ifsym}  % TODO needed only for the \Letter symbol, don't load this package if it is not installed
\RequirePackage{microtype}

\@lang{
  \renewcommand\thesubfigure{\asbuk{subfigure}}
}{
  \renewcommand\thesubfigure{\alph{subfigure}}
}

\newcommand\kioabstractname{\@langrev{Аннотация}{Abstract}}
\newcommand\keywordsname{\@langrev{Ключевые слова}{Keywords}}
\newcommand\citationname{\@langrev{Цитирование}{Citation}}
\newcommand\acknowledgementsname{\@langrev{Благодарности}{Acknowledgements}}

\urlstyle{same}

\cmpj@sf

\def\hv@sf{\sffamily\upshape}

% remove lists spacing

\def\remove@lists@spacings{
  \let\oldenumerate\enumerate
  \renewcommand{\enumerate}{
    \oldenumerate
    \setlength{\itemsep}{0pt}
    \setlength{\parskip}{0pt}
    \setlength{\parsep}{0pt}
    \setlength{\topsep}{0pt}
    \setlength{\partopsep}{0pt}
  }

  \let\olditemize\itemize
  \renewcommand{\itemize}{
    \olditemize
    \setlength{\topsep}{0pt}
    \setlength{\itemsep}{0pt}
    \setlength{\parskip}{0pt}
    \setlength{\parsep}{0pt}
    \setlength{\partopsep}{0pt}
  }
}
\remove@lists@spacings

%%  Sectioning  %%

%%TODO make command to uppercase all sections

\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\large\hv@sf\bfseries\mathversion{bold}\centering}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\large\hv@sf\bfseries\mathversion{bold}}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\normalsize\hv@sf\bfseries\mathversion{bold}}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1em}%
                                    {\normalfont\normalsize\hv@sf\bfseries\mathversion{bold}}}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\parindent}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1em}%
                                      {\normalfont\normalsize\hv@sf\bfseries\mathversion{bold}}}

\def\@seccntformat#1{\csname the#1\endcsname.\hspace{0.5em}}

%% penalties

\widowpenalty=300
\clubpenalty=300
\emergencystretch=3em

%% Affiliations
%\def\affil#1{\@for\@fnt:=#1\do{\textsuperscript{\@fnt}}}%TODO separate by comma
\def\relax@with@arg#1{\relax}
\def\@affil#1{\textsuperscript{#1}}%TODO separate by comma
\let\affil\@affil
\def\affiliation@footnotes{}
\def\affiliation#1#2{\g@addto@macro\affiliation@footnotes{
\textsuperscript{#1}#2\par
}}

%% Authors splitted by ,

\def\authorI@short@cont{\@ifundefined{authorII@short}{}{, \authorII@short\authorII@short@cont}}
\def\authorII@short@cont{\@ifundefined{authorIII@short}{}{, \authorIII@short\authorIII@short@cont}}
\def\authorIII@short@cont{\@ifundefined{authorIV@short}{}{, \authorIV@short\authorIV@short@cont}}
\def\authorIV@short@cont{\@ifundefined{authorV@short}{}{, \authorV@short\authorV@short@cont}}
\def\authorV@short@cont{\@ifundefined{authorVI@short}{}{, \authorVI@short\authorVI@short@cont}}
\def\authorVI@short@cont{\@ifundefined{authorVII@short}{}{, \authorVII@short\authorVII@short@cont}}
\def\authorVII@short@cont{\@ifundefined{authorVIII@short}{}{, \authorVIII@short\authorVIII@short@cont}}
\def\authorVIII@short@cont{\@ifundefined{authorIX@short}{}{, \authorIX@short\authorIX@short@cont}}
\def\authorIX@short@cont{\@ifundefined{authorX@short}{}{, \authorX@short}}

\def\authors@short@split@by@comma{\authorI@short\authorI@short@cont}

\def\authorI@short@first@lang@cont{\@ifundefined{authorII@short@first@lang}{}{, \authorII@short@first@lang\authorII@short@first@lang@cont}}
\def\authorII@short@first@lang@cont{\@ifundefined{authorIII@short@first@lang}{}{, \authorIII@short@first@lang\authorIII@short@first@lang@cont}}
\def\authorIII@short@first@lang@cont{\@ifundefined{authorIV@short@first@lang}{}{, \authorIV@short@first@lang\authorIV@short@first@lang@cont}}
\def\authorIV@short@first@lang@cont{\@ifundefined{authorV@short@first@lang}{}{, \authorV@short@first@lang\authorV@short@first@lang@cont}}
\def\authorV@short@first@lang@cont{\@ifundefined{authorVI@short@first@lang}{}{, \authorVI@short@first@lang\authorVI@short@first@lang@cont}}
\def\authorVI@short@first@lang@cont{\@ifundefined{authorVII@short@first@lang}{}{, \authorVII@short@first@lang\authorVII@short@first@lang@cont}}
\def\authorVII@short@first@lang@cont{\@ifundefined{authorVIII@short@first@lang}{}{, \authorVIII@short@first@lang\authorVIII@short@first@lang@cont}}
\def\authorVIII@short@first@lang@cont{\@ifundefined{authorIX@short@first@lang}{}{, \authorIX@short@first@lang\authorIX@short@first@lang@cont}}
\def\authorIX@short@first@lang@cont{\@ifundefined{authorX@short@first@lang}{}{, \authorX@short@first@lang}}

\def\authors@short@first@lang@split@by@comma{\authorI@short@first@lang\authorI@short@first@lang@cont}
\def\authors@short@first@lang@split@by@comma@remove@affil{%
\global\let\@@affil\affil%
\global\let\affil\relax@with@arg%
\authors@short@first@lang@split@by@comma%
\global\let\affil\@@affil%
}

%\def\@Letter{{\footnotesize \Letter}}  % TODO symbol should depend on whether ifsym package is loaded

%% Authors information
\def\authors@all@info{%
    \def\authorinfo##1{
        \setstretch{0.9}
        \csname author##1@short\endcsname, \csname author##1@pos\endcsname%
        \ifcsname author##1@email\endcsname, \ifcsname author##1@email@recepient\endcsname\fi~\href{mailto:\csname author##1@email\endcsname}{\csname author##1@email\endcsname}\fi
        \ifcsname author##1@orcid\endcsname, \href{http://\csname author##1@orcid\endcsname}{\csname author##1@orcid\endcsname}\fi
    }
    \ifcsname authorI@short\endcsname\authorinfo{I}\par\fi
    \ifcsname authorII@short\endcsname\authorinfo{II}\par\fi
    \ifcsname authorIII@short\endcsname\authorinfo{III}\par\fi
    \ifcsname authorIV@short\endcsname\authorinfo{IV}\par\fi
    \ifcsname authorV@short\endcsname\authorinfo{V}\par\fi
    \ifcsname authorVI@short\endcsname\authorinfo{VI}\par\fi
    \ifcsname authorVII@short\endcsname\authorinfo{VII}\par\fi
    \ifcsname authorVIII@short\endcsname\authorinfo{VIII}\par\fi
    \ifcsname authorIX@short\endcsname\authorinfo{IX}\par\fi
    \ifcsname authorX@short\endcsname\authorinfo{X}\par\fi
}

%%  Title  %%

\renewcommand\maketitle{\par
  \author{\mbox\authors@short@split@by@comma}
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \newpage
    \global\@topnum\z@   % Prevents figures from going at top of page.
    \@maketitle

    \thispagestyle{plain}
    \@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\affil\relax@with@arg
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \firstpage
  \renewcommand\refname{\@langrev{Список литературы}{References}} % TODO почему нельзя написать это вместе с другими \@langrev?
}

\def\@title{}
\def\@author{}
\def\@address{}
\def\fancy@header@title{FANCY@HEADER@TITLE}
\def\journal@type{}
\def\issue@year{????}%
\def\issue@number{?}%
\def\journal@section@img{kio-logo-col.png}
\def\journal@section@name{????}
\def\cp@issue@year{}
%\def\doi@number{10.XXXX/CMPJ.XX.XXXXX}
\def\authorI@short{???}
\def\authorI@full{????}
\def\authorI@addr{??????}
\def\authorI@email{???@???}

\def\issue#1#2#3{
    \def\issue@year{#1}%
    \def\cp@issue@year{,\space#1}%
    \def\issue@number{#2}%
    \def\@section@image@path@prefix{}
    \ifthenelse{\equal{edu}{#3}}{%
      \def\journal@type{\@langrev{Компьютерные инструменты в образовании}{Computer tools in education}}%
    }{%
      \ifthenelse{\equal{cam}{#3}}{%
        \def\journal@type{\@langrev{Компьютерная математика}{Computer assisted mathematics}}%
        \def\@section@image@path@prefix{cam-}%
      }{%
        \def\journal@type{\@langrev{Компьютерные инструменты в школе}{Computer tools at schools}}%
      }%
    }%
    \ifthenelse{\equal{cam}{#3}}{%
        \definecolor{rulercolor}{RGB}{32,63,153}
    }{%
        \definecolor{rulercolor}{RGB}{145,56,40}
    }%
}
\def\article@type{}
\def\articletype#1{\def\article@type{#1}}
\def\kio@page{\bf \arabic{page}}
\def\doinumber#1{\def\doi@number{#1}}
\def\udknumber#1{\def\udk@number{#1}}
%\def\bibdoi#1{\href{http://dx.doi.org/#1}{doi:#1}}
\def\bibdoi{\doi}
\def\arxiv#1{\href{http://arxiv.org/abs/#1}{arXiv:#1}}

%TODO make more modern, use etex primitives for cases
\def\journalsection#1{%
    \def\journal@section@id{#1}
    \ifthenelse{\equal{informatics}{#1}}{%
        \def\journal@section@name{\@lang{ИНФОРМАТИКА}{COMPUTER SCIENCE}}%
    }{%
    \ifthenelse{\equal{information-systems}{#1}}{%
        \def\journal@section@name{\@lang{ИНФОРМАЦИОННЫЕ СИСТЕМЫ}{INFORMATION SYSTEMS}}%
    }{%
    \ifthenelse{\equal{software-engineering}{#1}}{%
    	\def\journal@section@name{\@lang{ИНЖЕНЕРИЯ ПРОГРАММНОГО ОБЕСПЕЧЕНИЯ}{SOFTWARE ENGINEERING}}%
    }{%
    \ifthenelse{\equal{computer-in-education}{#1}}{%
    	\def\journal@section@name{\@lang{КОМПЬЮТЕР В УЧЕБНОМ ПРОЦЕССЕ}{COMPUTER IN EDUCATION}}%
    }{%
    \ifthenelse{\equal{popular-science-articles}{#1}}{%
    	\def\journal@section@name{\@lang{НАУЧНО-ПОЛУЛЯРНЫЕ СТАТЬИ}{POPULAR-SCIENCE ARTICLES}}%
    }{%
    \ifthenelse{\equal{programming-practice}{#1}}{%
    	\def\journal@section@name{\@lang{ПРАКТИКА ПРОГРАММИРОВАНИЯ}{PROGRAMMING PRACTICE}}%
    }{%
    \ifthenelse{\equal{editorial-column}{#1}}{%
    	\def\journal@section@name{\@lang{КОЛОНКА РЕДАКТОРА}{EDITORIAL COLUMN}}%
    }{%
    \ifthenelse{\equal{specialists-training-new-teaching-methods}{#1}}{%
    	\def\journal@section@name{\@lang{ПОДГОТОВКА СПЕЦИАЛИСТОВ: новые методы обучения}{SPECIALISTS TRAINING: new teaching methods}}%
    }{%
    \ifthenelse{\equal{specialists-training-training-programs}{#1}}{%
    	\def\journal@section@name{\@lang{ПОДГОТОВКА СПЕЦИАЛИСТОВ: программы обучения}{SPECIALISTS TRAINING: training programs}}%
    }{%
    \ifthenelse{\equal{specialists-training-professional-standards}{#1}}{%
    	\def\journal@section@name{\@lang{ПОДГОТОВКА СПЕЦИАЛИСТОВ: профессиональные стандарты}{SPECIALISTS TRAINING: professional standards}}%
    }{%
    \ifthenelse{\equal{algorithmic-mathematics}{#1}}{%
    	\def\journal@section@name{\@lang{АЛГОРИТМИЧЕСКАЯ МАТЕМАТИКА}{ALGORITHMIC MATHEMATICS}}%
    }{%
    \ifthenelse{\equal{mathematical-modeling}{#1}}{%
        \def\journal@section@name{\@lang{МАТЕМАТИЧЕСКОЕ МОДЕЛИРОВАНИЕ}{MATHEMATICAL MODELING}}%
    }{%
    \ifthenelse{\equal{open-problems-for-young-scientists}{#1}}{%
    	\def\journal@section@name{\@lang{НЕРЕШЕННЫЕ ЗАДАЧИ ДЛЯ МОЛОДЫХ УЧЕНЫХ}{OPEN PROBLEMS FOR YOUNG SCIENTISTS}}%
    }{%
    \ifthenelse{\equal{empty}{#1}}{%
        \def\journal@section@name{}%
        \def\journal@section@img{}%

        \chead[]{}\cfoot[]{}\lhead[]{}\rhead[]{}
        \lfoot[\issue@page@even\normalsize\sf@phv\kio@page]{}
        \rfoot[]{\normalsize\sf@phv\kio@page\issue@page@odd}
        \renewcommand{\headrule}{}
        \renewcommand{\footrule}{}
    }{%
        \def\journal@section@name{\@lang{раздел не указан или неизвестен}{section not specified or unknown} #1}%
    }%
    }%
    }%
    }%
    }%
    }%
    }%
    }%
    }%
    }%
    }%
    }%
    }%
    }%
}%
\def\journalsectionnoimage#1{%
  \journalsection{#1}%
  \def\no@section@image{}%
}%

\def\print@title{{\LARGE \hv@sf\bfseries\mathversion{bold} \@title \par}}
\def\print@author{%
    \vskip 1.5em%
    {\hv@sf
      \lineskip .5em%
        \large\upshape\authors@all@info\par}
  }
\def\print@address{\vskip 0.5em
        \small\hv@sf\upshape\@address\par
        }

% title

\def\pages@span{%
\ifthenelse{\equal{\pageref*{first@page}}{\pageref*{last@page}}}%
        {\pageref*{last@page}}%
        {\pageref*{first@page}--\pageref*{last@page}}%
}

\newcommand\print@doi{\href{http://dx.doi.org/\doi@number}{doi:\doi@number}}
\newcommand\print@doi@full{\url{http://dx.doi.org/\doi@number}}

\def\title@full@article@info{%
    \begin{minipage}{0.5\linewidth}% TODO make this linewidth - 7cm
      \small\hv@sf \journal@type, \issue@year\\ [0.6ex]%
      №~\issue@number:\space
      \pages@span%
      \@langrev{%no UDC in english
        \@ifundefined{udk@number}{}{\\[0.6ex]\@langrev{УДК}{UDC}:\space\udk@number}%
      }{}
      \\[0.6ex]\href{http://cte.eltech.ru}{http://cte.eltech.ru}%
      \@ifundefined{doi@number}{}{\\[0.6ex]\print@doi}%
    \end{minipage}%
  }
\def\title@section@image{%
  \begin{minipage}{7cm}
     \@ifundefined{no@section@image}{%
       \includegraphics[width=7cm]{\@section@image@path@prefix\journal@section@id\@lang{}{-en}.png}%
     }{%
       \hskip 7cm%
     }
  \end{minipage}%
}%

\def\@maketitle{%
%----------------------------
  \newpage%
  \ifthenelse{\isodd{\pageref{first@page}}}{%
      \noindent\title@full@article@info\hfill\title@section@image%
  }{%
      \noindent\title@section@image\hfill\title@full@article@info%
  }%
  %
%----------------------------  
  %ruler below title
  %\par\vskip3pt\noindent\textcolor{rulercolor}{\hrulefill}
  \par\vskip 1ex\noindent\textsf{\bfseries\slshape\article@type}\par\vskip 2em
  \noindent\null%\hspace{\@titleindent}\parbox{\@titlewidth}
  {%\raggedright%
  \centering
  \let \footnote \thanks
  \@ifundefined{@title}{}{\print@title}%
  \@ifundefined{@author}{}{\print@author}%
  \@ifundefined{@address}{}{\print@address}%
  \affiliation@footnotes
  }%
  \par
  \vskip 1.5em%
}

\renewenvironment{abstract}{%
%%%    \setcounter{page}{\start@page}\label{first@page}
%    \setcounter{page}{1}\label{first@page}
    \if@twocolumn
      %\section*{Аннотация}%
    \else
      \everypar{\parskip 3pt plus1pt minus2pt
      \parindent=0pt%\hangindent=\@titleindent
      \hangafter=0%
      \leftskip=\@titleindent%
      \rightskip=\@titleindent}
      \noindent\small\hv@sf\upshape\ignorespaces
    \fi
    {\centering\textbf{\kioabstractname}\par}}
    {\if@twocolumn\else\vskip 1.5em plus 0.2em \fi\upshape}

\newcommand\abstract@section[2]{\par\vskip 1ex
        \noindent%
        \raggedright%
        \leftskip=\@titleindent%
        \rightskip=\@titleindent%
        \upshape{\hv@sf\bfseries #1:}#2\space}

\newcommand\keywords{\abstract@section{\keywordsname}{\slshape}}
\newcommand\citationexample{\abstract@section{\citationname}{}}
\newcommand\acknowledgements{\abstract@section{\acknowledgementsname}{\slshape}}

\newcommand\autocitationexample{\citationexample\@langrev{
  \authors@short@split@by@comma\space\fancy@title\space//
  \journal@type. \issue@year. № \issue@number. С. \pages@span.
  \@ifundefined{doi@number}{}{\print@doi}
}{
  \authors@short@split@by@comma. \fancy@title. \journal@type, \issue@year.
  № \issue@number. P. \pages@span. \@ifundefined{doi@number}{}{\print@doi}.
}}

\newcommand\pacs{\par\vskip 1ex
        \noindent\raggedright\upshape{\hv@sf\bfseries PACS:}\slshape\space}

\def\author{\@dblarg{\make@author}}
\long\def\make@author[#1]#2{\gdef\@author{#2}\gdef\@copyright{\@@copyright}}

\def\title{\@dblarg{\make@title}}
\long\def\make@title[#1]#2{\gdef\fancy@title{#1}\gdef\fancy@header@title{#1}\gdef\@title{#2}}

\def\authorI{\@dblarg{\def@authorI}}
\def\authorII{\@dblarg{\def@authorII}}
\def\authorIII{\@dblarg{\def@authorIII}}
\def\authorIV{\@dblarg{\def@authorIV}}
\def\authorV{\@dblarg{\def@authorV}}
\def\authorVI{\@dblarg{\def@authorVI}}
\def\authorVII{\@dblarg{\def@authorVII}}
\def\authorVIII{\@dblarg{\def@authorVIII}}
\def\authorIX{\@dblarg{\def@authorIX}}
\def\authorX{\@dblarg{\def@authorX}}
\def\def@authorI[#1]#2{\gdef\authorI@short{#1}\providecommand\authorI@short@first@lang{#1}\gdef\authorI@full{#2}\providecommand\authorI@full@first@lang{#2}}
\def\def@authorII[#1]#2{\gdef\authorII@short{#1}\providecommand\authorII@short@first@lang{#1}\gdef\authorII@full{#2}\providecommand\authorII@full@first@lang{#2}}
\def\def@authorIII[#1]#2{\gdef\authorIII@short{#1}\providecommand\authorIII@short@first@lang{#1}\gdef\authorIII@full{#2}\providecommand\authorIII@full@first@lang{#2}}
\def\def@authorIV[#1]#2{\gdef\authorIV@short{#1}\providecommand\authorIV@short@first@lang{#1}\gdef\authorIV@full{#2}\providecommand\authorIV@full@first@lang{#2}}
\def\def@authorV[#1]#2{\gdef\authorV@short{#1}\providecommand\authorV@short@first@lang{#1}\gdef\authorV@full{#2}\providecommand\authorV@full@first@lang{#2}}
\def\def@authorVI[#1]#2{\gdef\authorVI@short{#1}\providecommand\authorVI@short@first@lang{#1}\gdef\authorVI@full{#2}\providecommand\authorVI@full@first@lang{#2}}
\def\def@authorVII[#1]#2{\gdef\authorVII@short{#1}\providecommand\authorVII@short@first@lang{#1}\gdef\authorVII@full{#2}\providecommand\authorVII@full@first@lang{#2}}
\def\def@authorVIII[#1]#2{\gdef\authorVIII@short{#1}\providecommand\authorVIII@short@first@lang{#1}\gdef\authorVIII@full{#2}\providecommand\authorVIII@full@first@lang{#2}}
\def\def@authorIX[#1]#2{\gdef\authorIX@short{#1}\providecommand\authorIX@short@first@lang{#1}\gdef\authorIX@full{#2}\providecommand\authorIX@full@first@lang{#2}}
\def\def@authorX[#1]#2{\gdef\authorX@short{#1}\providecommand\authorX@short@first@lang{#1}\gdef\authorX@full{#2}\providecommand\authorX@full@first@lang{#2}}

\def\authorIpos#1{\def\authorI@pos{#1}}
\def\authorIIpos#1{\def\authorII@pos{#1}}
\def\authorIIIpos#1{\def\authorIII@pos{#1}}
\def\authorIVpos#1{\def\authorIV@pos{#1}}
\def\authorVpos#1{\def\authorV@pos{#1}}
\def\authorVIpos#1{\def\authorVI@pos{#1}}
\def\authorVIIpos#1{\def\authorVII@pos{#1}}
\def\authorVIIIpos#1{\def\authorVIII@pos{#1}}
\def\authorIXpos#1{\def\authorIX@pos{#1}}
\def\authorXpos#1{\def\authorX@pos{#1}}

\def\authorIinfo#1{\gdef\authorI@info{#1}\providecommand\authorI@info@first@lang{#1}}
\def\authorIIinfo#1{\gdef\authorII@info{#1}\providecommand\authorII@info@first@lang{#1}}
\def\authorIIIinfo#1{\gdef\authorIII@info{#1}\providecommand\authorIII@info@first@lang{#1}}
\def\authorIVinfo#1{\gdef\authorIV@info{#1}\providecommand\authorIV@info@first@lang{#1}}
\def\authorVinfo#1{\gdef\authorV@info{#1}\providecommand\authorV@info@first@lang{#1}}
\def\authorVIinfo#1{\gdef\authorVI@info{#1}\providecommand\authorVI@info@first@lang{#1}}
\def\authorVIIinfo#1{\gdef\authorVII@info{#1}\providecommand\authorVII@info@first@lang{#1}}
\def\authorVIIIinfo#1{\gdef\authorVIII@info{#1}\providecommand\authorVIII@info@first@lang{#1}}
\def\authorIXinfo#1{\gdef\authorIX@info{#1}\providecommand\authorIX@info@first@lang{#1}}
\def\authorXinfo#1{\gdef\authorX@info{#1}\providecommand\authorX@info@first@lang{#1}}

\def\authorIemail#1{\def\authorI@email{#1}}
\def\authorIIemail#1{\def\authorII@email{#1}}
\def\authorIIIemail#1{\def\authorIII@email{#1}}
\def\authorIVemail#1{\def\authorIV@email{#1}}
\def\authorVemail#1{\def\authorV@email{#1}}
\def\authorVIemail#1{\def\authorVI@email{#1}}
\def\authorVIIemail#1{\def\authorVII@email{#1}}
\def\authorVIIIemail#1{\def\authorVIII@email{#1}}
\def\authorIXemail#1{\def\authorIX@email{#1}}
\def\authorXemail#1{\def\authorX@email{#1}}

\def\authorIemailEnvelope#1{\authorIemail{#1}\def\authorI@email@recepient{}}
\def\authorIIemailEnvelope#1{\authorIIemail{#1}\def\authorII@email@recepient{}}
\def\authorIIIemailEnvelope#1{\authorIIIemail{#1}\def\authorIII@email@recepient{}}
\def\authorIVemailEnvelope#1{\authorIVemail{#1}\def\authorIV@email@recepient{}}
\def\authorVemailEnvelope#1{\authorVemail{#1}\def\authorV@email@recepient{}}
\def\authorVIemailEnvelope#1{\authorVIemail{#1}\def\authorVI@email@recepient{}}
\def\authorVIIemailEnvelope#1{\authorVIIemail{#1}\def\authorVII@email@recepient{}}
\def\authorVIIIemailEnvelope#1{\authorVIIIemail{#1}\def\authorVIII@email@recepient{}}
\def\authorIXemailEnvelope#1{\authorIXemail{#1}\def\authorIX@email@recepient{}}
\def\authorXemailEnvelope#1{\authorXemail{#1}\def\authorX@email@recepient{}}

\def\authorIorcid#1{\def\authorI@orcid{#1}}
\def\authorIIorcid#1{\def\authorII@orcid{#1}}
\def\authorIIIorcid#1{\def\authorIII@orcid{#1}}
\def\authorIVorcid#1{\def\authorIV@orcid{#1}}
\def\authorVorcid#1{\def\authorV@orcid{#1}}
\def\authorVIorcid#1{\def\authorVI@orcid{#1}}
\def\authorVIIorcid#1{\def\authorVII@orcid{#1}}
\def\authorVIIIorcid#1{\def\authorVIII@orcid{#1}}
\def\authorIXorcid#1{\def\authorIX@orcid{#1}}
\def\authorXorcid#1{\def\authorX@orcid{#1}}

\def\address#1{\gdef\@address{#1}}
\def\addresses#1{\gdef\@address{%
    \renewcommand{\labelenumi}{$^{\textsf{\footnotesize\arabic{enumi}}}$}
    \setlength{\leftmargini}{0mm}
    \setlength{\topsep}{0mm}
    \setlength{\partopsep}{0mm}
    \setlength{\parskip}{0mm}
    \begin{enumerate}
    \setlength{\itemsep}{0mm}
    \setlength{\itemindent}{0em}
    \setlength{\labelsep}{2pt}
    #1
    \end{enumerate}}}
\newcommand{\addr}[1]{\item\label{#1}}

\newcommand{\refaddr}[1]{$^{\textsf{\footnotesize\@refad{#1}}}$}

\DeclareRobustCommand\@refad{\@@refadx}
\def\@@refadx#1{%
  \let\@@refada\@empty
  \@@refad{\@for\@@refadb:=#1\do
    {\@@refada\def\@@refada{,\penalty\@m}%
     \edef\@@refadb{\expandafter\@firstofone\@@refadb\@empty}%
     \@ifundefined{r@\@@refadb}{\mbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue
       \@latex@warning
         {Address reference `\@@refadb' undefined}}%
       {\hbox{\ref{\@@refadb}}}}}}
\def\@@refad#1{{#1}}

%%  Floats  %%

\bibsep=0pt
\renewcommand{\bibnumfmt}[1]{#1.}
\@ifundefined{bibfont}{\newcommand{\bibfont}{\small}}{\renewcommand{\bibfont}{\small}}

%%  Second Language Part  %%

\newcommand\maketranslatedtitle{
  \begingroup
      \global\@botnum\z@   % Prevents figures from going at bottom of page.
      \@makeukrtitle
    \@thanks
  \endgroup
  \global\let\thanks\relax
  \global\let\makeukrtitle\relax
  \global\let\@makeukrtitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
\def\print@ukrtitle{{\Large \hv@sf\bfseries\mathversion{bold} \@title \par}}

\def\@makeukrtitle{%
\par
\vskip 10pt
\noindent\null
\ifthenelse{\isodd{\value{page}}}{%
    \noindent\title@full@article@info\hfill%
}{%
    \noindent\hfill\title@full@article@info%
}
\vskip 1.5em
\noindent\null
%\hspace{\@titleindent}\parbox{\@titlewidth}{
\raggedright%
  \centering
  \let \footnote \thanks
  \@ifundefined{@title}{}{\print@ukrtitle}%
  \global\let\affil\@affil%
  \@ifundefined{@author}{}{\print@author}%
  \@ifundefined{@address}{}{\print@address}%
  \affiliation@footnotes
  \global\let\affil\relax@with@arg%
%  {\Large \hv@sf \bfseries\upshape \@title \par}%
%    \vskip 1em%
%    {\normalsize\hv@sf\upshape \@date}%
  %}%end of \parbox
  \par
  \vskip 1.5em%
}

\newenvironment{translatedpart}{%
  \def\@has@translated@part{}
  \print@authors@info%
  \ifx\l@ukrainian\@undefined
  \@nopatterns{Ukrainian}
  \adddialect\l@ukrainian0
  \fi
  \language\l@ukrainian
  \lefthyphenmin=2 \righthyphenmin=2 % disallow x- or -x breaks; -xx OK
  \lccode`\'=`\'
  \renewcommand{\addr}[1]{\item\label{##1}}
  \long\gdef\make@title[##1]##2{\gdef\fancy@title{##1}\gdef\@title{##2}} % redefine with no-changing header title
  \def\@reverse@lang{}
  \def\affiliation@footnotes{}
%%
%%
%http://tex.stackexchange.com/questions/173304/can-newpage-take-an-argument-like-pagebreak
\vspace{0pt plus \textheight}\pagebreak[3]\vspace{0pt plus -\textheight}
%TODO don't draw ruler if after page break
\vskip 1cm
\hrule width\headwidth height\headrulewidth
\vskip 1pt
\hrule width\headwidth height\headrulewidth
}{}

\newcommand\additionalinfo[1]{
\begin{center}
{\noindent\small\hv@sf\upshape\ignorespaces #1}
\end{center}
}

%%  General  %%

%\voffset -1in
%\hoffset -1in
\textwidth 150mm
%\textheight 227mm
\textheight 646pt    % = 227.0430331mm
\topmargin 30mm
\headheight 15pt
\headsep 6mm
\addtolength{\topmargin}{-\headheight}
\addtolength{\topmargin}{-\headsep}
\addtolength{\topmargin}{-1in}
\oddsidemargin 25mm
\setlength{\evensidemargin}{210mm}
\addtolength{\evensidemargin}{-\textwidth}
\addtolength{\evensidemargin}{-\oddsidemargin}
\addtolength{\oddsidemargin}{-1in}
\addtolength{\evensidemargin}{-1in}
\baselineskip 15pt
\newlength{\@titlewidth}
\newlength{\@titleindent}
\setlength{\@titlewidth}{\textwidth}
\setlength{\@titleindent}{15mm}
\addtolength{\@titlewidth}{-\@titleindent}
\newlength{\@captionwidth}
%\setlength{\@captionwidth}{\hsize}
%\addtolength{\@captionwidth}{-2\parindent}
%P%\renewcommand{\encodingdefault}{T1}
%\renewcommand{\sfdefault}{phv}
\renewcommand{\sfdefault}{\lat@sf}
\frenchspacing
\let\@afterindentfalse\@afterindenttrue

\renewcommand\footnoterule{%
  \kern-3\p@
  \hrule height 0.4pt\@width.2\columnwidth
  \kern2.6\p@}

%%  Headings  %%

%\def\sf@phv{\fontencoding{T1}\fontfamily{phv}\selectfont\upshape}
%P1%\def\sf@phv{\fontencoding{T1}\fontfamily{\lat@sf}\selectfont\upshape}
\def\sf@phv{\fontfamily{\lat@sf}\selectfont\upshape}
\newcounter{isspage}
\def\issue@page@odd{}
\def\issue@page@even{}
\def\issuepage#1{%
      \oddsidemargin 20mm%
      \setlength{\evensidemargin}{210mm}%
      \addtolength{\evensidemargin}{-\textwidth}%
      \addtolength{\evensidemargin}{-\oddsidemargin}%
      \addtolength{\oddsidemargin}{-1in}
      \addtolength{\evensidemargin}{-1in}
                 \setcounter{isspage}{#1}%
                 \addtocounter{isspage}{-1}%
                 \def\issue@page@odd{%
                     \stepcounter{isspage}%
                     {\unitlength1mm%
                     \begin{picture}(0,0)%
%                     \put(30,10){\makebox(0,0)[l]{\vrule height 20pt}}%
                     \put(30.5,10){\makebox(0,0)[l]{\rotatebox{90}{\textsf{\theisspage}}}}%
                     \end{picture}}%
                     }%
                 \def\issue@page@even{%
                     \stepcounter{isspage}%
                     {\unitlength1mm%
                     \begin{picture}(0,0)%
%                     \put(-30,10){\makebox(0,0)[l]{\vrule height 20pt}}%
                     \put(-30,10){\makebox(0,0)[r]{\rotatebox{90}{\textsf{\theisspage}}}}%
                     \end{picture}}%
                     }%
}

%----- begin headers footers

\def\@curlang{%here we can debug language inside a header
%\@langrev{*RU*}{*EN*}
}

\chead[\@curlang]{\@curlang}
\cfoot[\@curlang]{\@curlang}

\lhead[\fancyplain{}{\small\sf@phv\def\refaddr##1{}\textcolor{rulercolor}{\mbox\authors@short@first@lang@split@by@comma@remove@affil}}]{}

\rhead[]{\fancyplain{}{\small\sf@phv\textcolor{rulercolor}{\fancy@header@title}}} % \fancy@header@title это всегда название на основном языке

\lfoot[\issue@page@even\normalsize\sf@phv\kio@page]{
   \copyright@size\sf@phv\textcolor{rulercolor}{\journal@section@name}
}

\rfoot[
  \copyright@size\sf@phv\textcolor{rulercolor}{\copyright@journal}%
]{\normalsize\sf@phv\kio@page\issue@page@odd}

%------ end headers footers      

%colorize rulers: http://ctan.uni-altai.ru/macros/latex/contrib/fancyhdr/fancyhdr.pdf

\renewcommand{\headrule}{\fancyplain{}{{\color{rulercolor}%
    \hrule width\headwidth height\headrulewidth \vskip-\headrulewidth}}}

\renewcommand{\footrule}{{\color{rulercolor}%
    \vskip-\footruleskip\vskip-\headrulewidth%
    \hrule width\headwidth height\headrulewidth\vskip\footruleskip}}

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\renewcommand{\plainheadrulewidth}{0pt}
\renewcommand{\plainfootrulewidth}{0.4pt}

\pagestyle{fancyplain}

\newcommand\firstpage{\label{first@page}}
\newcommand\lastpage{\label{last@page}}
\lefthyphenmin=2
\righthyphenmin=3

\def\print@authors@info{
    \@ifundefined{need@authors@info}{}{
        \vspace*{0.5cm}%
        \noindent
        \begin{minipage}[b]{\textwidth}%
        \bfseries
        \sf@phv

        \def\authorlonginfo##1{
            \setstretch{0.9}
            \noindent
            \csname author##1@full\endcsname,
            \ifcsname author##1@info\endcsname \csname author##1@info\endcsname\fi,
            \ifcsname author##1@email\endcsname\ifcsname author##1@email@recepient\endcsname~\fi\href{mailto:\csname author##1@email\endcsname}{\csname author##1@email\endcsname}\fi
        }

        \def\allauthorslonginfo{
            \ifcsname authorI@short\endcsname\authorlonginfo{I}\par\fi
            \ifcsname authorII@short\endcsname\vskip 2mm\authorlonginfo{II}\par\fi
            \ifcsname authorIII@short\endcsname\vskip 2mm\authorlonginfo{III}\par\fi
            \ifcsname authorIV@short\endcsname\v