%% LaTeX Preamble Template
%% Auto-generated by ggen from RDF ontology

% Document class options already set in main document

% Encoding and fonts
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}

% Mathematics packages
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{thmtools}

% Graphics and figures
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{subcaption}

% Tables
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{colortbl}

% Algorithms
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}

% Code listings
\usepackage{listings}
\usepackage{xcolor}

% Bibliography and references
\usepackage[backend=biber,style=alphabetic,sorting=nyt]{biblatex}
\usepackage{hyperref}
\usepackage{cleveref}  % MUST be loaded AFTER hyperref (ADR-007)

% Hyperlinks configuration
\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  citecolor=blue,
  urlcolor=blue,
  bookmarks=true,
  bookmarksopen=true,
  pdfauthor={% raw %}{{{ author }}}{% endraw %},
  pdftitle={% raw %}{{{ title }}}{% endraw %},
  pdfsubject={% raw %}{{{ subject | default(value="PhD Thesis") }}}{% endraw %},
  pdfkeywords={% raw %}{{{ keywords | default(value="") }}}{% endraw %}
}

% Cleveref configuration
\crefname{chapter}{Chapter}{Chapters}
\crefname{section}{Section}{Sections}
\crefname{subsection}{Subsection}{Subsections}
\crefname{figure}{Figure}{Figures}
\crefname{table}{Table}{Tables}
\crefname{equation}{Equation}{Equations}
\crefname{theorem}{Theorem}{Theorems}
\crefname{lemma}{Lemma}{Lemmas}
\crefname{definition}{Definition}{Definitions}
\crefname{algorithm}{Algorithm}{Algorithms}
\crefname{listing}{Listing}{Listings}

% Memoir class customization
\setsecnumdepth{subsubsection}
\maxtocdepth{subsubsection}

% Chapter style
\chapterstyle{% raw %}{{ chapter_style | default(value="default") }}{% endraw %}

% Page style
\pagestyle{% raw %}{{{ page_style | default(value="ruled") }}}{% endraw %}

% Theorem environments
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{note}[theorem]{Note}

% Custom commands
{% raw %}{% if custom_commands %}
{% for cmd in custom_commands %}
\newcommand{\{{ cmd.name }}}{% if cmd.num_args %}[{{ cmd.num_args }}]{% endif %}{{{ cmd.definition }}}
{% endfor %}
{% endif %}{% endraw %}

% Custom operators
{% raw %}{% if custom_operators %}
{% for op in custom_operators %}
\DeclareMathOperator{\{{ op.name }}}{{{ op.symbol }}}
{% endfor %}
{% endif %}{% endraw %}

% Code listing styles
\lstdefinestyle{default}{
  basicstyle=\ttfamily\footnotesize,
  commentstyle=\color{gray}\itshape,
  keywordstyle=\color{blue}\bfseries,
  stringstyle=\color{red},
  showstringspaces=false,
  frame=single,
  breaklines=true,
  numbers=left,
  numberstyle=\tiny\color{gray},
  tabsize=4
}

{% raw %}{% if additional_packages %}
% Additional packages
{% for pkg in additional_packages %}
\usepackage{% if pkg.options %}[{{ pkg.options }}]{% endif %}{{{ pkg.name }}}
{% endfor %}
{% endif %}{% endraw %}

% TikZ libraries
\usetikzlibrary{arrows.meta,positioning,shapes,calc,patterns}

% PGFPlots settings
\pgfplotsset{
  width=0.8\textwidth,
  height=0.5\textwidth,
  compat=newest,
  legend pos=north west
}

% Spacing and layout
\setlength{\parindent}{{% raw %}{{ parindent | default(value="1.5em") }}{% endraw %}}
\setlength{\parskip}{{% raw %}{{ parskip | default(value="0pt") }}{% endraw %}}

% Index generation
\usepackage{makeidx}
\makeindex
