<% set footnote_lut = dict() %>
<% set footnotes = namespace(i=1) %>
<%- from 'reporting/tex/fragments/macros.tex' import create_evidence_linklist with context -%>
<%- from 'reporting/tex/fragments/evidence.tex' import create_evidence with context -%>
<%- from 'reporting/tex/fragments/place.tex' import create_place with context -%>
<%- from 'reporting/tex/fragments/religion.tex' import create_religion with context -%>
<%- from 'reporting/tex/fragments/person.tex' import create_person with context -%>
<%- from 'reporting/tex/fragments/timeline.tex' import create_timeline with context -%>
<%- from 'reporting/tex/fragments/metadata.tex' import creation_metadata, filter_description with context -%>

\documentclass[fontsize=10pt,toc=chapterentrywithdots]{scrreprt}
\usepackage{scrtime}
\usepackage{scrlayer-scrpage}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{csquotes}
\PassOptionsToPackage{hyphens}{url}\usepackage[hidelinks]{hyperref}
\usepackage{graphicx}
\usepackage{float}
\usepackage{lastpage}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{array}
\usepackage{longtable}
\usepackage{amssymb}


\usepackage{fontspec}
\newfontfamily{\defaultfont}{FreeSerif}
\newfontfamily\syriacfont[Script=Syriac]{Estrangelo Talada}
\newfontfamily\arabicfont[Script=Arabic]{Noto Naskh Arabic}
\newfontfamily\hebrewfont[Script=Hebrew]{FreeSerif}
\setmainfont{FreeSerif}
\setsansfont{FreeSans}
\setmonofont{FreeMono}

\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguages{arabic,armenian,coptic,georgian,greek,hebrew,hindi,kurdish,latin,macedonian,persian,russian,sanskrit,syriac,turkish,urdu}

\setlength\parindent{0pt}
\setlength\parsep{7pt}

\begin{document}

\title{Report \texttt{\href{<<report_url|texsafe>>}{<<report_id|texsafe>>}}}
\subtitle{\textsc{Damast} \texttt{<<server_version|texsafe>>}}
\date{<<metadata.current_time>>}
\author{Provisioned by \texttt{<<metadata.current_user>>}}
\publishers{Generated with \textsc{Damast} \\ \small{\url{https://github.com/UniStuttgart-VISUS/damast}}}

\maketitle

\automark*{chapter}
\pagestyle{scrheadings}
\setkomafont{pageheadfoot}{\scriptsize}
\ofoot*{\texttt{\href{<<report_url|texsafe>>}{<<report_id|texsafe>>}}}
\cfoot*{}
\ifoot*{\textsc{Damast} \texttt{<<server_version|texsafe>>}}
\ohead*{Page \thepage{} of \pageref{LastPage}}
\chead*{}
\ihead*{\textsc{\rightmark}}

\tableofcontents

<% if dbversiondata %>
\clearpage
\chapter*{Version Disclaimer}
\label{chapter:version-disclaimer}
\addcontentsline{toc}{chapter}{\nameref{chapter:version-disclaimer}}
\markboth{Version Disclaimer}{Version Disclaimer}

The instance of \textsc{Damast} this report was generated on has \emph{report eviction} turned on.
That means that the contents of reports that have not been accessed for a while are deleted to save storage space.
The reports in question can still be accessed, but will be re-created on demand from the database.
On systems with report eviction, the assumption is that there are no major changes to the underlying data in the database, to ensure that the report content overall does not change.
However, in some cases smaller updates to the data might still happen.
This report was originally created with a different version of the underlying data, but was evicted and now re-created with a newer version.
Some changes to its contents might be present.

This is the chronological history to the data in this \textsc{Damast} instance.
The last entry is the version of the database this report was created with.
The version the report was originally created with is marked with an arrow:

\begin{center}
\renewcommand{\arraystretch}{1.3}
\footnotesize
\begin{longtable}{@{}p{1cm}p{1.5cm}p{6cm}p{5.8cm}@{}}
  \textbf{Version} & \textbf{Date} & \textbf{URL} & \textbf{Description} \\
  \hline
  \endhead
    <% for ver in dbversiondata.versions %>
      <%- if ver.version == dbversiondata.original_version -%>
      $\blacktriangleright$
      <%- endif -%>
      \hfill << ver.version >>
      &
      << ver.date >>
      &
      <%- if ver.url -%>
      \scriptsize{\url{<< ver.url | texsafe >>}}
      <%- else -%>
      ---
      <%- endif -%>
      &
      << ver.description >>
      \\
    <% endfor %>
\end{longtable}
\end{center}
<% endif %>

\chapter{Query Description}
\label{sec:filters}

<< creation_metadata(metadata) >>

<< filter_description(filter_desc) >>

This report contains:
\textbf{<< evidences | length >>} distinct pieces of evidence,
\textbf{<< places | length >>} distinct places,
\textbf{<< religions | length >>} distinct religions,
<% if persons|length %>
\textbf{<< persons | length >>} distinct persons,
<% endif %>
based on \textbf{<< sources | length >>} distinct sources.


\clearpage
\chapter{Pieces of Evidence}
\label{sec:evidences}

<% for evidence in evidences %>
  << create_evidence(evidence) >>
<% endfor %>


\clearpage
\chapter{Places}
\label{sec:places}

\begin{figure}[H]
  \includegraphics[width=\textwidth]{map.pdf}
  \caption{Made with Natural Earth (\url{https://www.naturalearthdata.com/}).}
\end{figure}

<% for place in places %>
<< create_place(place) >>
<% endfor %>


\clearpage
\chapter{Religions}
\label{sec:religions}

<% for religion in religions %>
  << create_religion(religion) >>
<% endfor %>


<% if persons|length %>
\clearpage
\chapter{Persons}
\label{sec:persons}

<% for person in persons %>
  << create_person(person) >>
<% endfor %>
<% endif %>


\clearpage
\chapter{Timeline}
\label{sec:timeline}

<< create_timeline(time_data) >>


<% if sources %>
\clearpage
\chapter{Sources}
\label{sec:sources}

\begin{description}
    <% for i, source in sources %>
  \item[\textsc{<< source.short | texsafe >>}]
      \hypertarget{source<<source.id>>}{<< source.name | texsafe >>
        \emph{<< source.source_type | texsafe >>}}

      << create_evidence_linklist(source_evidence[source.id], before='', middle=' based on this source: ', after='') >>
    <% endfor %>
\end{description}
<% endif %>

\clearpage
\chapter*{How to Cite}
\ihead*{\textsc{How to Cite}}
\label{sec:how-to-cite}
\addcontentsline{toc}{chapter}{\nameref{sec:how-to-cite}}

We suggest to cite this report in the following way:

\begingroup
\small
\begin{quote}
  Damast report \texttt{<< report_id >>},
  based on data by Ralph Barczok and Bernd A. Vest, and the visualization of
  \emph{Damast --- A Research System to Analyze Multi-Religious Constellations in the Islamicate World,}
  edited by Dorothea Weltecke, Steffen Koch, Ralph Barczok, Max Franke, Florian Jäckel, and Bernd A. Vest.
  April 2022.
  Created << metadata.current_time_short >>.
  \url{<< report_url >>}, data deposited at DaRUS:
  \url{https://doi.org/10.18419/darus-2318}.
\end{quote}
\endgroup


\clearpage
\chapter*{License}
\label{sec:license}
\ihead*{\textsc{License}}
\addcontentsline{toc}{chapter}{\nameref{sec:license}}

\begingroup
\small
\begin{verbatim}
<% include "reporting/license.txt" %>
\end{verbatim}
\endgroup

\end{document}
