{{=<< >>=}} % Use <<&foo>> to include (non HTML-escape) variable foo instead of {{{foo}}}
\documentclass<<#has_tex_size>>[<<&tex_size>>pt]<</has_tex_size>>{<<&class>>}

%% Pacake inclusion
<<#xelatex>>
% Unicode support if xelatex is used
\usepackage{fontspec}
\usepackage{xunicode}
<</xelatex>>
<<^xelatex>>
% Unicode support if xelatex is not used
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

% Even with inputenc, not all unicode chars are recognized when not using xelatex. This a
% listof some I stumbled upon and manually added to fix
\usepackage{newunicodechar}
\newunicodechar{ }{ } % thin non breaking space
\newunicodechar{°}{$^{\circ}$}
% Force LaTeX not to overflow page e.g. when there is long words
% (e.g. filenames, urls, ...). The result is not necesarily very
% beautiful, though, but at least it's readable.
\setlength\emergencystretch{.5\textwidth}
<</xelatex>>

\usepackage[<<&tex_lang>>]{babel} % Language support
\usepackage{fancyhdr} % Headers

% Allows hyphenatations in \texttt
\usepackage[htt]{hyphenat}

<<#use_strikethrough>>
% Only included if strikethrough is used in the document
\usepackage[normalem]{ulem}
<</use_strikethrough>>
<<#use_taskitem>>
\usepackage{amssymb}
<</use_taskitem>>
% Set hyperlinks and metadata 
\usepackage[colorlinks=true,breaklinks=true,hypertexnames=false]{hyperref}
\hypersetup{pdfauthor={<<&author>>},
  pdftitle={<<&title>>},
  pdfsubject={<<&description>>}
}
<<^xelatex>>
\usepackage[anythingbreaks]{breakurl}
<</xelatex>>


<<#initials>>
% Only included if use_initials is set to true
\usepackage{lettrine}
<</initials>>

<<#stdpage>>
% Only included if the stdpage option is set to true
\usepackage[<<&papersize>>]{geometry}
\usepackage[hyphen=false, parskip]{stdpage}
<</stdpage>>
<<^stdpage>>
% Included if the stdpage option if set to false
\usepackage[<<&papersize>>, top=<<&margin_top>>, bottom=<<&margin_bottom>>,
  left=<<&margin_left>>,right=<<&margin_right>>]{geometry} % Set dimensions/margins of the parge
<</stdpage>>


\makeatletter
\date{<<&date>>}

<<^stdpage>>
<<#book>>
% Redefine the \maketitle command, only for book class (not used if stdpage option is set to true)
\renewcommand{\maketitle}{
  % First page with only the title
  \thispagestyle{empty}
  \vspace*{\stretch{1}}
  
  \begin{center}
    {\Huge \@title   \\[5mm]}
  \end{center}
  \vspace*{\stretch{2}}
  
  \newpage
  % Empty left page
  \thispagestyle{empty}
  \cleardoublepage

  % Main title page, with author, title, subtitle, date
  \begin{center}  
    \thispagestyle{empty}
    \vspace*{\baselineskip}
    \rule{\textwidth}{1.6pt}\vspace*{-\baselineskip}\vspace*{2pt}
    \rule{\textwidth}{0.4pt}\\[\baselineskip]
    
    {\Huge\scshape \@title   \\[5mm]}
    {\Large <<&subtitle>>}
    
    \rule{\textwidth}{0.4pt}\vspace*{-\baselineskip}\vspace{3.2pt}
    \rule{\textwidth}{1.6pt}\\[\baselineskip]

    \vspace*{4\baselineskip}

    {\Large \@author}
    <<#has_autograph>>
    
    \vspace*{10\baselineskip}
    
    <<&autograph>>
    <</has_autograph>>
    \vfill
    <<#has_date>>\@date<</has_date>>
  \end{center}
  
  \pagebreak
  \newpage
  % Copyright page with author, version, and license
  \thispagestyle{empty}
  \null\vfill
  \noindent
  \begin{center}
    {\emph{\@title}<<#has_version>>{, <<&version>>}<</has_version>><<#has_author>>, © \@author<</has_author>>.\\[5mm]}
    <<#has_license>>{<<&license>>\\[5mm]}<</has_license>>
  \end{center}
  \pagebreak
  \newpage
}
<</book>>


% Redefine headers
\pagestyle{fancy}
\fancyhead{}
\fancyhead[CO,CE]{\thepage}
\fancyfoot{}


<</stdpage>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Command and environment definitions
%
% Here, commands are defined for all Markdown element (even if some
% of them do nothing in this template).
%
% If you want to change the rendering of some elements, this is probably
% what you should modify.
%
% Note that elements that already have a LaTeX semantic equivalent aren't redefined
% : if you want to redefine headers, you'll have to renew \chapter, \section, \subsection,
% ..., commands. If you want to change how emphasis is displayed, you'll have to renew
% the \emph command, for list the itemize one, for ordered list the enumerate one,
% for super/subscript the \textsuper/subscript ones.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Strong
\newcommand\mdstrong[1]{\textbf{#1}}

% Code
\newcommand\mdcode[1]{\texttt{#1}}

% Rule
% Default impl : (displays centered asterisks)
\newcommand\mdrule{
  \nopagebreak
  {\vskip 1em}
  \nopagebreak
  \begin{center}
    ***
  \end{center}
  \nopagebreak
 {\vskip 1em}
 \nopagebreak
}

% Hardbreak
\newcommand\mdhardbreak{\\}

% Block quote$
\newenvironment{mdblockquote}{%
  \begin{quotation}
    \itshape
}{%
  \end{quotation}
}


% Code block
%
% Only used if syntect is used for syntax highlighting is used, else
% the spverbatim environment is preferred.
<<#use_codeblocks>> % This part is only included if document contains code blocks
\usepackage{spverbatim}
\usepackage{color}
\usepackage[
  topline=false,
  rightline=false,
  bottomline=false]{mdframed}

\newenvironment{mdcodeblock}{%
  \begin{mdframed}
}{%
  \end{mdframed}
} 
<</use_codeblocks>>

<<#use_images>>
% Only included if document contains images
\usepackage{graphicx}

% Standalone image
% (an image alone in its paragraph)
\newcommand\mdstandaloneimage[1]{
  \begin{center}
    \includegraphics[width=0.8\linewidth]{#1}
  \end{center}
}

% Image
% (an image embedded in a pagraph or other element)
\newcommand\mdimage[1]{\includegraphics{#1}}
<</use_images>>

<<#use_tables>>
% Only included if document contains tables
\usepackage{tabularx}

% Table environment
% Crowbook currently always insert \hline at beginning and end of the table


\newenvironment{mdtable}[1]{%
  \center
  \tabularx{\textwidth}{#1}
  \hline
}{%
  \endtabularx
  \endcenter
}
<</use_tables>>

<<&additional_code>>

\makeatother

\title{<<&title>>}
\author{<<&author>>}

\begin{document}

% Redefine chapter and part names if they needs to be
% Needs to be after \begin{document} because babel
<<#chapter_name>>
\makeatletter
\renewcommand{\@chapapp}{<<&chapter_name>>}
\makeatother
<</chapter_name>>

<<#part_name>>
\renewcommand{\partname}{<<&part_name>>}
<</part_name>>


<<#tex_title>>
\maketitle
<</tex_title>>

<<&content>>

\end{document}
