% SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
% SPDX-License-Identifier: MIT

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{lecture-notes}[00.00.0000 0.0.0 Useful commands for my lecture notes]

\RequirePackage{pgfopts}
\pgfkeys{
  /ln/.cd,
  russian/.store in=\ln@russian,
}
\ProcessPgfPackageOptions{/ln}

\RequirePackage[utf8]{inputenc}

\ifdefined\ln@russian
  \RequirePackage{fontspec}
  \RequirePackage{polyglossia}
    \setmainlanguage{russian}
    \setotherlanguage{english}
    \setmainfont{Noto Serif}
    \setsansfont{Noto Sans}
    \setmonofont{Roboto Mono}
    \newfontfamily\cyrillicfont{Noto Serif}
    \newfontfamily\cyrillicfontsf{Noto Sans}
    \newfontfamily\cyrillicfonttt{Roboto Mono}
\else
  \RequirePackage[T1]{fontenc}
  \RequirePackage[tt=false]{libertine}
\fi

\RequirePackage{paralist}
\RequirePackage{calc}
\@ifpackageloaded{crumbs}{}{\RequirePackage[dry,increment]{crumbs}}
\@ifpackageloaded{clicks}{}{\RequirePackage[static]{clicks}}
\@ifpackageloaded{ppt-slides}{}{\RequirePackage[template,scheme=light]{ppt-slides}}
\RequirePackage[nocn,novert]{ffcode}
\RequirePackage{underscore}
\RequirePackage{to-be-determined}
\RequirePackage{setspace}
\RequirePackage{fancyvrb}
\RequirePackage{xstring}
\RequirePackage{xparse}
\RequirePackage{biblatex}
  \setlength{\bibitemsep}{0.2em}
  \IfFileExists
    {bibliography/main.bib}
    {\addbibresource{bibliography/main.bib}}
    {\IfFileExists{../bibliography/main.bib}
      {\addbibresource{../bibliography/main.bib}}
      {
        \IfFileExists{../../bibliography/main.bib}
        {\addbibresource{../../bibliography/main.bib}}
        {\PackageError{notes}{The main.bib file is not found}{}}}}
\RequirePackage{tocbibind} % to render Bibliography as chapter
\RequirePackage{doi}
\RequirePackage{booktabs}
\RequirePackage{tikz}
  \usetikzlibrary{positioning}
  \usetikzlibrary{calc}
  \usetikzlibrary{arrows}
  \usetikzlibrary{arrows.meta}
\RequirePackage{soul}
  \renewcommand\emph[1]{\textit{#1}}

\tikzstyle{graph} = [
  node distance=0,
  every node/.style={draw=black,circle,minimum width=2.2em,line width=.08em,outer sep=.2em,font={\ttfamily}},
  every edge/.append style={draw=black,line width=.08em,-{Latex[length=2.5mm,width=2mm]},every node/.style={above}},
  every loop/.append style={draw=black,line width=.08em,-{Latex[length=2.5mm,width=2mm]},every node/.style={above}},
]

\newcommand\lnDisclaimer{{%
  \color{grey}\rmfamily\scriptsize
  All visual and text materials presented in this slidedeck are
  either originally made by the author or taken from public Internet
  sources, such as web sites. Copyright belongs to their
  respected authors.\par
}}

\newcommand\lnTitlePage[3]{%
  \lnPitch{%
    \begin{pptMiddle}%
      \ifdef{\thesubtitle}{%
        \pptTitle{\thetitle}{\thesubtitle}%
      }{%
        \pptTitle{\thetitle}{}%
      }\par
      {\scshape Yegor Bugayenko}\par
      Lecture \##1 out of #2\newline
      80 minutes\par
      \def\param{#3}%
      \ifx\param\empty\else%
        The slidedeck was presented by the author in this
        \textcolor{red}{\href{https://www.youtube.com/watch?v=#3}{YouTube Video}}\par
      \fi%
      \lnDisclaimer{}%
    \end{pptMiddle}%
  }%
}

\newcounter{thght}
\NewDocumentCommand{\lnThought}{s m}{
  \plush{%
    \pptThought{%
      \raggedright%
      \IfBooleanTF{#1}{}{%
        \addtocounter{thght}{1}%
        \textcolor{orange}{\Huge\thethght.}%
      }%
      #2%
    }%
  }%
}

\newcommand\nospell[1]{#1}

\newcommand\lnPitch[1]{%
  \plush{%
    \begin{pptMiddle}%
    #1%
    \end{pptMiddle}%
  }%
}

\newcommand\lnQuote[4][]{%
  \def\bib{#4}%
  \def\cover{}
  \lnPitch{%
    \IfFileExists{../bibliography/book-covers/#4.jpg}{%
      \pptPin[left]{\tikz \node[rotate=5, draw=gray, line width=1pt, inner sep=0pt]{\includegraphics[height=7em]{../bibliography/book-covers/#4.jpg}};}%
    }{%
      \IfFileExists{../../bibliography/book-covers/#4.jpg}{%
        \pptPin[left]{\tikz \node[rotate=5, draw=gray, line width=1pt, inner sep=0pt]{\includegraphics[height=7em]{../../bibliography/book-covers/#4.jpg}};}%
    }{}%
    }%
    \IfFileExists{../faces/#2.jpg}
      {
        \pptQuote
          [\scriptsize\scshape\color{gray}{#1}]
          {../faces/#2.jpg}
          {#3}
          {\color{gray}\rmfamily\scriptsize\fullcite{#4}
        }%
      }
      {
        \IfFileExists{#2}
        {
          \pptQuote
            [\scriptsize\scshape\color{gray}{#1}]
            {#2}
            {#3}
            {\ifx\bib\empty\else\color{gray}\rmfamily\scriptsize\fullcite{#4}\fi}%
        }
        {
          \pptQuote
            [\scriptsize\scshape\color{gray}{#1}]
            {#2.jpg}
            {#3}
            {\ifx\bib\empty\else\color{gray}\rmfamily\scriptsize\fullcite{#4}\fi}%
        }
      }%
  }%
}

\newenvironment{lnSnippet}[1][lncode.txt]
  {\VerbatimEnvironment\begin{VerbatimOut}{#1}}
  {\end{VerbatimOut}}

\newcommand\lnSource[1]{%
  \par
  {\scriptsize\color{gray} Source: \fullcite{#1}\par}%
}

\AtBeginDocument{%
  \ifdef{\thesubtitle}{%
    \pptLeft{\thetitle~\thesubtitle}%
  }{%
    \pptLeft{\thetitle}%
  }%
  \pptRight{@yegor256}%
  % \bibliographystyle{plainnat}
}

\AtEndDocument{%
  \begin{pptWide}{3}
  % \setlength{\bibsep}{.2em}
  \renewcommand{\bibfont}{\tiny}
  \printbibliography
  \end{pptWide}
}

\endinput
