%% Chapter Index / Table of Contents Generation Template
%% Auto-generated by ggen from RDF ontology

% Main table of contents (generated automatically by \tableofcontents)
% This template provides custom TOC formatting and chapter navigation

{% raw %}{% if custom_toc %}
% Custom table of contents formatting
\renewcommand{\contentsname}{{{ toc_title | default(value="Contents") }}}

\setcounter{tocdepth}{{{ toc_depth | default(value="3") }}}

% Chapter entries in TOC
\renewcommand{\cftchapterfont}{\bfseries\large}
\renewcommand{\cftchapterpagefont}{\bfseries\large}
\setlength{\cftbeforechapterskip}{1em}

% Section entries in TOC
\renewcommand{\cftsectionfont}{\normalfont}
\renewcommand{\cftsectionpagefont}{\normalfont}
\setlength{\cftbeforesectionskip}{0.3em}

% Subsection entries in TOC
\renewcommand{\cftsubsectionfont}{\small}
\renewcommand{\cftsubsectionpagefont}{\small}
\setlength{\cftbeforesubsectionskip}{0.2em}
{% endif %}{% endraw %}

{% raw %}{% if mini_toc %}
% Mini table of contents at start of each chapter
\usepackage{minitoc}
\setcounter{minitocdepth}{2}
\mtcsetrules{minitoc}{off}
{% endif %}{% endraw %}

{% raw %}{% if chapter_overview %}
% Chapter overview generation
\newcommand{\chapteroverview}[1]{
  \begin{quote}
  \textit{#1}
  \end{quote}
  {% if mini_toc %}
  \minitoc
  {% endif %}
}
{% endif %}{% endraw %}

{% raw %}{% if chapter_roadmap %}
% Chapter roadmap (navigation between chapters)
\newcommand{\chapterroadmap}{
  \vspace{1cm}
  \noindent\textbf{Chapter Roadmap:}
  \begin{itemize}
  {% for chapter in chapters %}
  \item \cref{ch:{{ chapter.id }}}: {{ chapter.title }}
  {% if chapter.sections %}
    \begin{itemize}
    {% for section in chapter.sections %}
    \item \cref{sec:{{ section.id }}}: {{ section.title }}
    {% endfor %}
    \end{itemize}
  {% endif %}
  {% endfor %}
  \end{itemize}
}
{% endif %}{% endraw %}

{% raw %}{% if chapter_dependencies %}
% Chapter dependency graph
\newcommand{\chapterdependencies}[2]{
  % #1: current chapter ID
  % #2: list of prerequisite chapter IDs
  \noindent\textbf{Prerequisites:}
  {% for prereq in chapter_dependencies %}
  {% if prereq.chapter_id == "#1" %}
  {% if prereq.prerequisites %}
  {% for dep in prereq.prerequisites %}
  \cref{ch:{{ dep }}}{% if not loop.last %}, {% endif %}
  {% endfor %}
  {% else %}
  None (foundational chapter)
  {% endif %}
  {% endif %}
  {% endfor %}
}
{% endif %}{% endraw %}

{% raw %}{% if list_of_definitions %}
% List of definitions
\newcommand{\printofdefinitions}{
  \chapter*{List of Definitions}
  \addcontentsline{toc}{chapter}{List of Definitions}
  \begin{enumerate}
  {% for definition in definitions %}
  \item \textbf{{{ definition.name }}} (\cpageref{thm:{{ definition.id }}}): {{ definition.short_description }}
  {% endfor %}
  \end{enumerate}
}
{% endif %}{% endraw %}

{% raw %}{% if list_of_theorems %}
% List of theorems
\newcommand{\printoftheorems}{
  \chapter*{List of Theorems}
  \addcontentsline{toc}{chapter}{List of Theorems}
  \begin{enumerate}
  {% for theorem in theorems %}
  \item \textbf{{{ theorem.name }}} (\cpageref{thm:{{ theorem.id }}}): {{ theorem.short_statement }}
  {% endfor %}
  \end{enumerate}
}
{% endif %}{% endraw %}

{% raw %}{% if list_of_algorithms %}
% List of algorithms (already provided by algorithm2e)
% This enhances the default list
\renewcommand{\listofalgorithms}{
  \chapter*{List of Algorithms}
  \addcontentsline{toc}{chapter}{List of Algorithms}
  \@starttoc{loa}
}
{% endif %}{% endraw %}

{% raw %}{% if cross_chapter_index %}
% Cross-chapter concept index
\newcommand{\conceptindex}{
  \chapter*{Concept Index}
  \addcontentsline{toc}{chapter}{Concept Index}
  \begin{multicols}{2}
  \printindex
  \end{multicols}
}
{% endif %}{% endraw %}

{% raw %}{% if reading_guide %}
% Reading guide for different audiences
\newcommand{\readingguide}{
  \chapter*{Reading Guide}
  \addcontentsline{toc}{chapter}{Reading Guide}

  {% for guide in reading_guides %}
  \section*{{{ guide.audience }}}
  \noindent\textbf{Recommended path:}
  \begin{enumerate}
  {% for step in guide.path %}
  \item {{ step.description }} (\cref{ch:{{ step.chapter_id }}})
  {% endfor %}
  \end{enumerate}
  {% if guide.optional_chapters %}
  \noindent\textbf{Optional chapters:}
  {% for opt in guide.optional_chapters %}
  \cref{ch:{{ opt }}}{% if not loop.last %}, {% endif %}
  {% endfor %}
  {% endif %}
  {% endfor %}
}
{% endif %}{% endraw %}
