%% bmstu_title.sty
%% Copyright 2023 Mikael Novikov
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% 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'.
%
% The Current Maintainer of this work is Mikael Novikov.
%
% This work consists of all files listed in manifest.txt.

% ������������������ ��������-������������ ������������������ ����������
\newcommand{\documentmeta}[4]
{
	\hypersetup{
		pdftitle={#1 #2 #3},
		pdfsubject={#4},
		pdfauthor={#2}
	}
}

% C�������������� ����������
\RequirePackage[normalem]{ulem}
\RequirePackage{stackengine}
\newcommand{\longunderline}[1]
{
	\uline{#1\hfill\mbox{}}
}
\newcommand{\fixunderline}[3]
{
	$\underset{\text{#3}}{\text{\uline{\stackengine{0pt}{\hspace{#2}}{\text{#1}}{O}{c}{F}{F}{L}}}}$
}

% ���������������� ���������������������������� ����������
\makeatletter
\newcommand{\vhrulefill}[1]
{
	\leavevmode\leaders\hrule\@height#1\hfill \kern\z@
}
\makeatother

% ���������������� ���������� ������������������ ����������������
\newcommand{\titlepageheader}[2]
{
	\begin{wrapfigure}[7]{l}{0.14\linewidth}
		\vspace{3.4mm}
		\hspace{-8mm}
		\includegraphics[width=0.89\linewidth]{bmstu-logo}
	\end{wrapfigure}

	{
		\singlespacing \small
		������������������������ ���������� �� �������������� ���������������������� �������������������� ������������������ \\
		���������������������� ������������������������������ ������������������ ������������������������������ �������������������� \\
		�������������� ���������������������� \\
		<<�������������������� ������������������������������ ���������������������� ���������������������� \\
		���������� ��.~��.~�������������� \\
		(������������������������ ���������������������������������� ����������������������)>> \\
		(�������� ����. ��.~��.~��������������) \\
	}

	\vspace{-4.2mm}
	\vhrulefill{0.9mm} \\
	\vspace{-7mm}
	\vhrulefill{0.2mm} \\
	\vspace{2.8mm}

	{
		\small
		������������������ \longunderline{<<#1>>} \\
		\vspace{3.3mm}
		�������������� \longunderline{<<#2>>} \\
	}
}

% ������������������ �������������������� ������������ ���� ������
\newcommand{\titlepageresearchtitle}[1]
{
	{
		\LARGE \bfseries
		����������������-�������������������������� �������������� \\
	}
	\vspace{5mm}
	{
		\Large \itshape
		�� ������������-���������������������������������� ������������ \\
		\vspace{5mm}
		���� ��������: \\
		<<#1>> \\
	}
}

% ������������������ �������������������� ������
\newcommand{\titlepagenotetitle}[2]
{
	{
		\LARGE \bfseries
		����������������-�������������������������� �������������� \\
	}
	\vspace{5mm}
	{
		\Large \itshape
		#1 \\
		\vspace{5mm}
		���� ��������: \\
		<<#2>> \\
	}
}

% ������������������ �������������������� ������������
\newcommand{\titlepagereporttitle}[4]
{
	\textbf{����������} \\
	���� #1 \\
	\ifthenelse{\isempty{#2}}{}{���� ���������� <<#2>> \\}
	\ifthenelse{\isempty{#3}}{}{���� ��������: <<#3>> \\}
	\ifthenelse{\isempty{#4}}{}{�������������� ���~#4 \\}
}

% ���������������� �������� ����������������
\RequirePackage{pgffor}

\newcommand*\titlepagestudentscontent{}

\newcommand{\maketitlepagestudent}[1]
{
	\foreach \s/\g in {#1} {
		\gappto\titlepagestudentscontent{�������������� \fixunderline}
		\xappto\titlepagestudentscontent{{\g}}
		\gappto\titlepagestudentscontent{{25mm}{(������������)} &}
		\gappto\titlepagestudentscontent{\fixunderline{}{40mm}{(��������������, ��������)} \vspace{1.3mm} &}
		\gappto\titlepagestudentscontent{\fixunderline}
		\xappto\titlepagestudentscontent{{\s}}
		\gappto\titlepagestudentscontent{{40mm}{(��.~��.~��������������)} \\}
	}
}

% ���������������� ������������ ����������
\newcommand*\titlepageotherscontent{}

\newcommand{\maketitlepageothers}[2]
{
	\foreach \c in {#2} {
		\gappto\titlepagestudentscontent{#1 &}
		\gappto\titlepagestudentscontent{\fixunderline{}{40mm}{(��������������, ��������)} \vspace{1.3mm} &}
		\gappto\titlepagestudentscontent{\fixunderline}
		\xappto\titlepagestudentscontent{{\c}}
		\gappto\titlepagestudentscontent{{40mm}{(��.~��.~��������������)} \\}
	}
}

% ������������������ ������������������������ ������������
\newcommand{\titlepageauthors}[5]
{
	{
		\renewcommand{\titlepagestudentscontent}{}
		\maketitlepagestudent{#1}

		\renewcommand{\titlepageotherscontent}{}
		\maketitlepageothers{#2}{#3}
		\maketitlepageothers{����������������������}{#4}
		\maketitlepageothers{����������������������������}{#5}

		\small
		\begin{tabularx}{\textwidth}{@{}>{\hsize=.5\hsize}X>{\hsize=.25\hsize}X>{\hsize=.25\hsize}X@{}}
			\titlepagestudentscontent

			\titlepageotherscontent
		\end{tabularx}
	}
}

% ���������������� ������������������ ���������������� ������ �� ������
\newcommand{\makethesistitle}[7]
{
	\documentmeta{������ �� ������}{#4}{}{#3}

	\begin{titlepage}
		\centering

		\titlepageheader{#1}{#2}
		\vspace{15.8mm}

		\titlepagenotetitle{�� ������������������ �������������������������������� ������������}{#3}
		\vfill

		\titlepageauthors{#4}{������������������������ ������}{#5}{#6}{#7}
		\vspace{14mm}

		\textit{{\the\year} ��.}
	\end{titlepage}

	\setcounter{page}{2}
}

% ���������������� ������������������ ���������������� ������������ ���� ������
\newcommand{\makeresearchtitle}[6]
{
	\documentmeta{���������� ���� ������}{#4}{}{#3}

	\begin{titlepage}
		\centering

		\titlepageheader{#1}{#2}
		\vspace{15.8mm}

		\titlepageresearchtitle{#3}
		\vfill

		\titlepageauthors{#4}{������������������������ ������}{#5}{#6}{}
		\vspace{14mm}

		\textit{{\the\year} ��.}
	\end{titlepage}

	\setcounter{page}{2}
}

% ���������������� ������������������ ���������������� ������ �� ����
\newcommand{\makecourseworktitle}[6]
{
	\documentmeta{������ �� ����}{#4}{}{#3}

	\begin{titlepage}
		\centering

		\titlepageheader{#1}{#2}
		\vspace{15.8mm}

		\titlepagenotetitle{�� ���������������� ������������}{#3}
		\vfill

		\titlepageauthors{#4}{������������������������ ���������������� ������������}{#5}{#6}{}
		\vspace{14mm}

		\textit{{\the\year} ��.}
	\end{titlepage}

	\setcounter{page}{2}
}

% ���������������� ������������������ ���������������� ������������
\newcommand{\makereporttitle}[8]
{
	\documentmeta{����������}{#7}{���� #3 ���� ���������� #4}{#5}

	\begin{titlepage}
		\centering

		\titlepageheader{#1}{#2}
		\vspace{15.8mm}

		\titlepagereporttitle{#3}{#4}{#5}{#6}
		\vfill

		\titlepageauthors{#7}{��������������������������}{#8}{}{}
		\vspace{14mm}

		\textit{{\the\year} ��.}
	\end{titlepage}

	\setcounter{page}{2}
}