% Page 
% = setup 
\documentclass[a4paper]{article}
\usepackage[14pt]{extsizes}
\usepackage[T2A]{fontenc}
\usepackage{ dsfont }
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
% = margins
\usepackage[left=3cm,right=1.5cm,top=2cm,bottom=2cm]{geometry}
% = indents
\usepackage{indentfirst}
\setlength{\parindent}{1.25cm}
% = spacing
\usepackage{setspace}
\onehalfspacing

% Fonts
% = family
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setmonofont{Courier New}

% Text
% = parindent
\setlength{\parindent}{1.25cm}
% = strikethrough
\usepackage{ulem}
\let\st\sout
% = italic
\renewcommand{\emph}[1]{\textit{#1}}

% Title 
% = space after title
\usepackage{titlesec}
\titleformat{\section}
  {\normalfont\normalsize\bfseries\sloppy}{\hspace{1.25cm}\thesection}{1em}{}
\titleformat{\subsection}
  {\normalfont\normalsize\bfseries\sloppy}{\hspace{1.25cm}\thesubsection}{1em}{}
\titleformat{\subsubsection}
  {\normalfont\normalsize\bfseries\sloppy}{\hspace{1.25cm}\thesubsubsection}{1em}{}
% = Adjust spacing
\titlespacing*{\section}{0pt}{0.3\baselineskip}{0.3\baselineskip}
\titlespacing*{\subsection}{0pt}{0.3\baselineskip}{0.3\baselineskip}
\titlespacing*{\subsubsection}{0pt}{0.3\baselineskip}{0.3\baselineskip}
% = breaks
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}
% = special title
\newcommand{\centertitle}[1]{
  \titleformat*{\section}{\centering\normalsize\bfseries}
  \section*{#1}
  \titleformat*{\section}{\normalfont\normalsize\bfseries\sloppy}
  \addcontentsline{toc}{section}{#1}
}

% List
% = indents
\usepackage{enumitem}
\setlist[itemize,enumerate,1]{label=\textbullet, topsep=0.25pt, partopsep=0.25pt, parsep=0pt, itemsep=0pt, labelindent=\parindent, align=left, leftmargin=*}
\setlist[itemize,enumerate,2]{label=\textbullet, topsep=0.25pt, partopsep=0.25pt, parsep=0pt, itemsep=0pt, labelindent=\parindent, align=left, leftmargin=*}
\setlist[itemize,enumerate,3]{label=\textbullet, topsep=0.25pt, partopsep=0.25pt, parsep=0pt, itemsep=0pt, labelindent=\parindent, align=left, leftmargin=*}
\setlist[itemize,enumerate,4]{label=\textbullet, topsep=0.25pt, partopsep=0.25pt, parsep=0pt, itemsep=0pt, labelindent=\parindent, align=left, leftmargin=*}
% = tightlist fix
\def\tightlist{}

% Сode
\usepackage{xcolor}
\definecolor{lightgray}{rgb}{0.95, 0.95, 0.95}
\usepackage{listings}
\lstset{
  basicstyle=\small,
  numbers=left,                    
  stepnumber=1,                   
  numbersep=10pt,                  
  tabsize=2,                      
  showspaces=false,                
  showstringspaces=false,
  breaklines=true,                
  escapeinside={\%*}{*)},         
  numbersep=15pt,                 
  xleftmargin=25pt,              
  backgroundcolor=\color{lightgray}
}
% = inline code
\usepackage{fontspec}
\newfontfamily{\codefont}[SizeFeatures={Size=14}]{Courier New}
\newcommand{\passthrough}[1]{{\codefont #1}}
% = fix russian sybmols
\makeatletter % see https://tex.stackexchange.com/a/320345
\lst@InputCatcodes
\def\lst@DefEC{%
 \lst@CCECUse \lst@ProcessLetter
  ^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f%
  ^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f%
  ^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af%
  ^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf%
  ^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf%
  ^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df%
  ^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef%
  ^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff%
  ^^^^20ac^^^^0153^^^^0152%
  % Basic Cyrillic alphabet coverage
  ^^^^0410^^^^0411^^^^0412^^^^0413^^^^0414^^^^0415^^^^0416^^^^0417%
  ^^^^0418^^^^0419^^^^041a^^^^041b^^^^041c^^^^041d^^^^041e^^^^041f%
  ^^^^0420^^^^0421^^^^0422^^^^0423^^^^0424^^^^0425^^^^0426^^^^0427%
  ^^^^0428^^^^0429^^^^042a^^^^042b^^^^042c^^^^042d^^^^042e^^^^042f%
  ^^^^0430^^^^0431^^^^0432^^^^0433^^^^0434^^^^0435^^^^0436^^^^0437%
  ^^^^0438^^^^0439^^^^043a^^^^043b^^^^043c^^^^043d^^^^043e^^^^043f%
  ^^^^0440^^^^0441^^^^0442^^^^0443^^^^0444^^^^0445^^^^0446^^^^0447%
  ^^^^0448^^^^0449^^^^044a^^^^044b^^^^044c^^^^044d^^^^044e^^^^044f%
  ^^^^0401^^^^0451%
  %%%
  ^^00}
\lst@RestoreCatcodes
\makeatother

% Hyperlinks
\usepackage[hidelinks]{hyperref}
\let\oldhref\href
% = URI
\renewcommand{\href}[2]{\oldhref{#1}{#2} (URI - \url{#1})}

% Images
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{caption}
\usepackage{float}

\DeclareCaptionLabelSeparator{mysep}{ - }
\captionsetup[figure]{name=Рисунок, labelsep=mysep}
\renewcommand{\thefigure}{\arabic{figure}}

\newcommand{\image}[3]{
    % fix floating
    \begin{figure}[H]
        \centering
        \begin{adjustbox}{width=#3\textwidth,center}
            \includegraphics[keepaspectratio]{\detokenize{#1}}
        \end{adjustbox}
        \caption{\detokenize{#2}}
        \label{fig:#2}
    \end{figure}
}

% Table
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{array}
% = simple creation
\captionsetup[table]{
  name=Таблица, 
  labelsep=mysep,
  justification=raggedleft,
  singlelinecheck=false
}
% = csv read
\usepackage{pgfplotstable}
\newcommand{\sucsvtable}[2]{
\begin{table}[h]
\caption{#2}
\centering
\renewcommand{\arraystretch}{1.5} 
\pgfplotstabletypeset[
  col sep=semicolon,
  string type,
  every head row/.style={before row=\hline,after row=\hline},
  every column/.style={column type={|c}},
  every last column/.style={column type={|c|}},
  after row=\hline
]{#1}
\label{tab:#2}
\end{table}
}
% = label 
\let\oldcaption\caption
\renewcommand{\caption}[1]{\oldcaption{#1}\label{tab:#1}}

\newcommand{\sutable}[2]{
\begin{table}[h!]
    \centering
    \caption{#1}
    \label{table:#1}
    \bgroup
      \def\arraystretch{1.3}
      {#2}
    \egroup
  \end{table}
}

% = Equation
\usepackage{amsmath}
\usepackage{amssymb}

% Table of content
\usepackage{titlesec}
\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\hfill\normalsize\bfseries\MakeUppercase}
\renewcommand{\cftaftertoctitle}{\hfill\mbox{}}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}

\usepackage{pdfpages}
\begin{document}
$if(suaidocintropath)$
  \includepdf[pages={1}, fitpaper=true]{\detokenize{$suaidocintropath$}}
$endif$
\sloppy
\tableofcontents
$body$
\end{document}

