\documentclass{$latex.properties.documentClass}
\usepackage{standalone}

## Commands that can be overridden by users in a custom Preamble
\newcommand{\xwikidate}[1]{
  ${SP}${SP}\date{\DTMdate{#1}}}
\newcommand{\xwikititle}[1]{
  ${SP}${SP}\title{#1}}
\newcommand{\xwikiauthor}[1]{
  ${SP}${SP}\author{#1}}

$latex.processor.render('Preamble')

## Needs to be put after the babel package
#if ("$!latex.properties.date" != '' && $latex.properties.coverPage)
  % Used to format the date for the cover page
  \usepackage[useregional]{datetime2}

#end
\begin{document}

#set ($shouldClearPage = false)
## Display numbers in TOC and list of tables/figures using the roman style
#if ($latex.properties.pageNumbering && $latex.properties.coverPage && $latex.properties.toc || $latex.properties.listOfFigures || $latex.properties.listOfTables)
  \pagenumbering{Roman}
#elseif (!$latex.properties.pageNumbering)
  \pagenumbering{gobble}
#end
#if ($latex.properties.coverPage && "$!latex.properties.title" != '')
  \xwikititle{%
    #if ("$!latex.properties.coverPageImage" != '')
      ${SP}${SP}\includegraphics{$latex.tool.escape($latex.resourceConverter.convert($latex.properties.coverPageImage, true).reference)}\\\vspace{1cm}
    #end
    ${SP}${SP}$latex.tool.escape($latex.properties.title)##
    #if ("$!latex.properties.subtitle" != '')
      \\
      ${SP}${SP}\large $latex.tool.escape($latex.properties.subtitle)}
    #else
      }
    #end
  #if ("$!latex.properties.author" != '')
    \xwikiauthor{$latex.tool.escape($latex.properties.author)}
  #end
  #if ("$!latex.properties.date" != '')
    \xwikidate{$latex.tool.escape($datetool.format('yyyy-MM-dd', $latex.properties.date))}
  #end
  \maketitle
#end
#if ($latex.properties.toc)
  \setcounter{tocdepth}{3}
  #if ($latex.properties.coverPage && "$!latex.properties.title" != '')
    \clearpage
  #end
  \tableofcontents
  ## Make sure no page numbers are printed in the TOC
  #if (!$latex.properties.pageNumbering)
    \addtocontents{toc}{\protect\thispagestyle{empty}}
  #end
  #set ($shouldClearPage = true)
#end
#if ($latex.properties.listOfFigures)
  \listoffigures
  #set ($shouldClearPage = true)
#end
#if ($latex.properties.listOfTables)
  \listoftables
  #set ($shouldClearPage = true)
#end
#if ($shouldClearPage)
  \clearpage
#end
## Reset page counter so that first page of the doc starts at 1
#if ($latex.properties.pageNumbering && $latex.properties.coverPage && $latex.properties.toc || $latex.properties.listOfFigures || $latex.properties.listOfTables)
  \setcounter{page}{0}
  ## Display numbers on pages using the arabic style
  \pagenumbering{arabic}
#end
#if ("$!latex.includes" != '')

  #foreach ($latexPageInclude in $latex.includes)
    ## Don't escape the page since LaTeX doesn't support escapes in paths and the path has already been cleaned.
    \include{$latexPageInclude}
  #end
#end

\end{document}