% Systematic Review Report
% Generated by Papercutter Factory
%
% Template variables:
% - title: Report title
% - author: Author name
% - date: Report date
% - abstract: Abstract text
% - paper_count: Number of papers
% - papers: List of paper objects
% - fields: Schema field definitions
% - matrix: 2D array of evidence matrix data
% - include_summaries: Whether to include paper summaries
% - include_matrix: Whether to include evidence matrix
% - include_appendix: Whether to include appendix

\documentclass[12pt,a4paper]{article}

% Packages
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage{parskip}
\usepackage{xcolor}
\usepackage{graphicx}

% Page setup
\geometry{
    left=1in,
    right=1in,
    top=1in,
    bottom=1in
}

% Hyperlink setup
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    urlcolor=blue,
    citecolor=blue
}

% Title
\title{<< title | latex_escape >>}
\author{<< author | latex_escape >>}
\date{<< date >>}

\begin{document}

\maketitle

<% if abstract %>
\begin{abstract}
<< abstract | latex_escape >>
\end{abstract}
<% endif %>

\tableofcontents
\newpage

% =============================================================================
\section{Introduction}
% =============================================================================

This systematic review synthesizes evidence from << paper_count >> papers.

<% if fields %>
The following data points were extracted from each paper:
\begin{itemize}
<% for field in fields %>
    \item \textbf{<< field.key | latex_escape >>}: << field.description | latex_escape >>
<% endfor %>
\end{itemize}
<% endif %>

<% if include_matrix and matrix %>
% =============================================================================
\section{Evidence Matrix}
% =============================================================================

The following table summarizes the key evidence extracted from each paper.

\begin{longtable}{<% for _ in matrix[0] %>p{2cm}<% endfor %>}
\toprule
<% for cell in matrix[0] %>\textbf{<< cell | latex_escape >>}<% if not loop.last %> & <% endif %><% endfor %> \\
\midrule
\endhead
\bottomrule
\endfoot
<% for row in matrix[1:] %>
<% for cell in row %><< cell | latex_escape | truncate_chars(40) >><% if not loop.last %> & <% endif %><% endfor %> \\
<% if not loop.last %>\midrule<% endif %>
<% endfor %>
\end{longtable}
<% endif %>

<% if include_summaries %>
% =============================================================================
\section{Paper Summaries}
% =============================================================================

<% for paper in papers %>
\subsection{<< paper.title | latex_escape | truncate_chars(80) >>}
<% if paper.bibtex_key %>
\label{sec:<< paper.bibtex_key >>}
<% endif %>

<% if paper.one_pager %>
<< paper.one_pager | latex_escape >>
<% else %>
\textit{Summary not available.}
<% endif %>

<% if paper.extractions %>
\paragraph{Key Data Points}
\begin{description}
<% for key, data in paper.extractions.items() %>
    \item[<< key | latex_escape >>] << data.value | latex_escape if data.value else 'N/A' >>
    <% if data.quote %>
    \\\textit{``<< data.quote | latex_escape | truncate_chars(150) >>''}<% if data.page %> (p. << data.page >>)<% endif %>
    <% endif %>
<% endfor %>
\end{description}
<% endif %>

<% endfor %>
<% endif %>

<% if include_appendix %>
% =============================================================================
\appendix
\section{Paper Contribution Statements}
% =============================================================================

Brief contribution statements for each paper included in the review:

\begin{enumerate}
<% for paper in papers %>
    \item \textbf{<< paper.title | latex_escape | truncate_chars(50) >>}:
    <% if paper.appendix_row %>
    << paper.appendix_row | latex_escape >>
    <% else %>
    \textit{Contribution statement not available.}
    <% endif %>
<% endfor %>
\end{enumerate}
<% endif %>

% =============================================================================
% Bibliography would go here if using BibTeX
% \bibliographystyle{apalike}
% \bibliography{references}
% =============================================================================

\end{document}
