% Copyright 2019 Ekaitz Zarraga <ekaitz@elenq.tech>
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
%     http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ElenQ Article template
% -----------------------------------------------------------------------------
%
% Expects some metadata to be set:
%
%   polyglossia-lang:
%       name: english | spanish | basque | ...
%   lang: en-US | es-ES | ...
%   title: The title of the document
%   subtitle: The subtitle of the article
%   author: Author's name
%   license: License of the document
%
% It also accepts some optional metadata:
%
%   toc: true | false  # Activate table of contents (defaults to false)
%   abstract: "Content of the abstract"
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[a4paper,11pt
$if(lang)$
  $babel-lang$,
$endif$]{$documentclass$}
\usepackage{tikz}
\newcommand{\logo}[1]{
  \begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-{#1}, xscale={#1}, inner sep=0pt, outer sep=0pt]
\begin{scope}[shift={(3.54331,-984.39026)}]
  \begin{scope}[shift={(-161.98599,807.24042)}]
    \begin{scope}[shift={(-13.57143,-11.78571)},fill=black,line join=miter,line cap=butt,line width=0.800pt]
      \path[fill] (175.5574,234.4789) -- (203.0824,234.4789) -- (203.0824,231.7789) --
        (178.7824,231.7789) -- (178.7824,214.5289) -- (199.3324,214.5289) --
        (199.3324,211.8289) -- (178.7824,211.8289) -- (178.7824,195.9289) --
        (203.0824,195.9289) -- (203.0824,193.2289) -- (175.5574,193.2289) --
        (175.5574,234.4789) -- cycle;
      \path[fill] (208.2234,234.4789) -- (211.4484,234.4789) -- (211.4484,193.2289) --
        (208.2234,193.2289) -- (208.2234,234.4789) -- cycle;
      \path[fill] (216.6375,219.7039) .. controls (216.6375,230.9539) and
        (225.3375,235.3039) .. (233.1375,235.3039) .. controls (244.9875,235.3039) and
        (248.4375,230.5789) .. (249.1875,226.0789) -- (245.5875,226.0789) .. controls
        (244.8375,227.9539) and (243.4125,232.0789) .. (233.1375,232.0789) .. controls
        (227.2125,232.0789) and (220.6875,228.4789) .. (220.1625,221.0539) --
        (249.1875,221.0539) -- (249.1875,217.8289) .. controls (248.4375,207.4039) and
        (242.7375,202.0789) .. (233.1375,202.0789) .. controls (223.5375,202.0789) and
        (216.6375,209.2789) .. (216.6375,219.7039) -- cycle(220.3125,217.8289) ..
        controls (221.3625,209.9539) and (225.4875,205.2289) .. (233.4375,205.2289) ..
        controls (241.3875,205.2289) and (244.8375,210.3289) .. (245.5875,217.8289) --
        (220.3125,217.8289) -- cycle;
      \path[fill] (254.5875,234.4789) -- (257.8125,234.4789) -- (257.8125,208.6039) ..
        controls (259.3875,206.5789) and (262.8375,205.3789) .. (268.0125,205.3789) ..
        controls (271.6125,205.3789) and (276.1125,206.7289) .. (276.1125,213.0289) --
        (276.1125,234.4789) -- (279.5625,234.4789) -- (279.5625,213.0289) .. controls
        (279.5625,204.7789) and (273.4125,202.0789) .. (268.0125,202.0789) .. controls
        (262.4625,202.0789) and (258.9375,203.4289) .. (257.8125,206.1289) --
        (257.8125,202.9039) -- (254.5875,202.9039) -- (254.5875,234.4789) -- cycle;
      \path[fill] (284.5312,213.8539) .. controls (284.5312,225.0289) and
        (293.8313,235.3039) .. (305.1562,235.3039) .. controls (309.9563,235.3039) and
        (314.3062,233.4289) .. (317.8313,230.5039) -- (322.6313,234.4789) --
        (326.3813,234.4789) -- (319.7812,228.7039) .. controls (323.4563,224.7289) and
        (325.7812,219.4039) .. (325.7812,213.8539) .. controls (325.7812,202.7539) and
        (316.5562,192.4789) .. (305.1562,192.4789) .. controls (293.7563,192.4789) and
        (284.5312,202.6789) .. (284.5312,213.8539) -- cycle(287.8313,213.8539) ..
        controls (287.8313,204.7039) and (295.4062,195.5539) .. (305.1562,195.5539) ..
        controls (314.9062,195.5539) and (322.4812,204.7039) .. (322.4812,213.8539) ..
        controls (322.4812,223.0039) and (314.9062,232.2289) .. (305.1562,232.2289) ..
        controls (295.4062,232.2289) and (287.8313,223.0039) .. (287.8313,213.8539) --
        cycle;
    \end{scope}
    \begin{scope}[fill=black,line join=miter,line cap=butt,line width=0.800pt]
      \path[fill] (176.4077,232.6768) -- (180.4452,232.6768) -- (180.4452,244.8605) --
        (181.4665,244.8605) -- (181.4665,232.6768) -- (185.5277,232.6768) --
        (185.5277,231.7980) -- (176.4077,231.7980) -- (176.4077,232.6768) -- cycle;
      \path[fill] (187.0132,244.8605) -- (195.7295,244.8605) -- (195.7295,244.0055) --
        (188.0345,244.0055) -- (188.0345,238.5430) -- (194.5420,238.5430) --
        (194.5420,237.6880) -- (188.0345,237.6880) -- (188.0345,232.6530) --
        (195.7295,232.6530) -- (195.7295,231.7980) -- (187.0132,231.7980) --
        (187.0132,244.8605) -- cycle;
      \path[fill] (197.2387,238.3293) .. controls (197.2387,242.6043) and
        (199.2099,245.1218) .. (202.8674,245.1218) .. controls (205.6699,245.1218) and
        (208.0212,243.6255) .. (208.0212,241.4880) -- (206.8812,241.4880) .. controls
        (206.8812,242.7943) and (205.3137,244.1005) .. (202.8674,244.1005) .. controls
        (199.7087,244.1005) and (198.3549,241.0368) .. (198.3549,238.3293) .. controls
        (198.3549,235.2180) and (200.1837,232.5580) .. (202.9624,232.5580) .. controls
        (205.3849,232.5580) and (206.8812,233.8168) .. (206.8812,235.2418) --
        (208.0212,235.2418) .. controls (208.0212,232.8905) and (205.6699,231.5605) ..
        (202.8674,231.5605) .. controls (198.9724,231.5605) and (197.2387,235.0280) ..
        (197.2387,238.3293) -- cycle;
      \path[fill] (209.6499,244.8605) -- (210.6712,244.8605) -- (210.6712,238.5430) --
        (217.1787,238.5430) -- (217.1787,244.8605) -- (218.1999,244.8605) --
        (218.1999,231.7980) -- (217.1787,231.7980) -- (217.1787,237.6880) --
        (210.6712,237.6880) -- (210.6712,231.7980) -- (209.6499,231.7980) --
        (209.6499,244.8605) -- cycle;
      \path[fill] (219.9942,244.8605) -- (221.0392,244.8605) -- (221.0392,233.7455) --
        (228.2354,244.8605) -- (229.2567,244.8605) -- (229.2567,231.7980) --
        (228.2354,231.7980) -- (228.2354,243.0318) -- (221.0392,231.7980) --
        (219.9942,231.7980) -- (219.9942,244.8605) -- cycle;
      \path[fill] (230.8917,238.3293) .. controls (230.8917,241.8680) and
        (233.8367,245.1218) .. (237.4229,245.1218) .. controls (241.0092,245.1218) and
        (243.9542,241.8680) .. (243.9542,238.3293) .. controls (243.9542,234.8143) and
        (241.0329,231.5605) .. (237.4229,231.5605) .. controls (233.8129,231.5605) and
        (230.8917,234.7905) .. (230.8917,238.3293) -- cycle(231.9367,238.3293) ..
        controls (231.9367,235.4318) and (234.3354,232.5343) .. (237.4229,232.5343) ..
        controls (240.5104,232.5343) and (242.9092,235.4318) .. (242.9092,238.3293) ..
        controls (242.9092,241.2268) and (240.5104,244.1480) .. (237.4229,244.1480) ..
        controls (234.3354,244.1480) and (231.9367,241.2268) .. (231.9367,238.3293) --
        cycle;
      \path[fill] (245.5521,244.8605) -- (253.4609,244.8605) -- (253.4609,243.8393) --
        (246.5734,243.8393) -- (246.5734,231.7980) -- (245.5521,231.7980) --
        (245.5521,244.8605) -- cycle;
      \path[fill] (254.9200,238.3293) .. controls (254.9200,241.8680) and
        (257.8650,245.1218) .. (261.4513,245.1218) .. controls (265.0375,245.1218) and
        (267.9825,241.8680) .. (267.9825,238.3293) .. controls (267.9825,234.8143) and
        (265.0613,231.5605) .. (261.4513,231.5605) .. controls (257.8413,231.5605) and
        (254.9200,234.7905) .. (254.9200,238.3293) -- cycle(255.9650,238.3293) ..
        controls (255.9650,235.4318) and (258.3638,232.5343) .. (261.4513,232.5343) ..
        controls (264.5388,232.5343) and (266.9375,235.4318) .. (266.9375,238.3293) ..
        controls (266.9375,241.2268) and (264.5388,244.1480) .. (261.4513,244.1480) ..
        controls (258.3638,244.1480) and (255.9650,241.2268) .. (255.9650,238.3293) --
        cycle;
      \path[fill] (269.5092,238.3293) .. controls (269.5092,242.6043) and
        (271.4805,245.1218) .. (275.1380,245.1218) .. controls (276.7767,245.1218) and
        (278.2255,244.5993) .. (279.1517,243.7443) -- (279.1517,244.8605) --
        (280.1730,244.8605) -- (280.1730,238.4480) -- (274.9480,238.4480) --
        (274.9480,239.4693) -- (279.1517,239.4693) -- (279.1517,241.4880) .. controls
        (279.1517,242.7943) and (277.5842,244.1005) .. (275.1380,244.1005) .. controls
        (271.9792,244.1005) and (270.6255,241.0368) .. (270.6255,238.3293) .. controls
        (270.6255,235.2180) and (272.4542,232.5580) .. (275.2330,232.5580) .. controls
        (277.6555,232.5580) and (279.1517,233.8168) .. (279.1517,235.2418) --
        (280.1730,235.2418) .. controls (280.1730,232.8905) and (277.9405,231.5605) ..
        (275.1380,231.5605) .. controls (271.2430,231.5605) and (269.5092,235.0280) ..
        (269.5092,238.3293) -- cycle;
      \path[fill] (281.6818,231.7980) -- (286.4318,239.4218) -- (286.4318,244.8605) --
        (287.4531,244.8605) -- (287.4531,239.4218) -- (292.2268,231.7980) --
        (291.0868,231.7980) -- (286.9543,238.4480) -- (282.8456,231.7980) --
        (281.6818,231.7980) -- cycle;
    \end{scope}
  \end{scope}
\end{scope}
\end{tikzpicture}
}

$if(lang)$
  % Load polyglossia as late as possible: uses bidi with RTL langages (e.g. Hebrew, Arabic)
  \usepackage{polyglossia}
  \setmainlanguage[$polyglossia-lang.options$]{$polyglossia-lang.name$}
  $for(polyglossia-otherlangs)$
    \setotherlanguage[$polyglossia-otherlangs.options$]{$polyglossia-otherlangs.name$}
  $endfor$
$endif$

% No indent
\usepackage{parskip}

% Margins
\usepackage[top=2.5cm,
            bottom=2.5cm,
            left=3.25cm,
            right=2.5cm,
            headheight=30pt,
            includeheadfoot=true]{geometry}

% Spacing
\usepackage{setspace}

% Font
\usepackage{anyfontsize} % para seleccionar tamaño de fuente
\usepackage{fontspec}
\setmainfont[
  BoldFont        = Lato-Bold.ttf,
  ItalicFont      = Lato-Italic.ttf,
  BoldItalicFont  = Lato-BoldItalic.ttf
]{Lato-Regular.ttf}

\newfontfamily\code{B612 Mono}[
  NFSSFamily      = b612,
  Scale           = 0.90,
]
\newcommand{\euro}{€}

% Pretty hyperlinks
\usepackage{hyperref}
$if(colorlinks)$
\PassOptionsToPackage{usenames,dvipsnames}{color} % color is loaded by hyperref
$endif$
\hypersetup{unicode=true,
$if(title-meta)$
            pdftitle={$title-meta$},
$endif$
$if(author-meta)$
            pdfauthor={$author-meta$},
$endif$
$if(lang)$
            pdflang={$lang$},
$endif$
$if(keywords)$
            pdfkeywords={$for(keywords)$$keywords$$sep$; $endfor$},
$endif$
$if(colorlinks)$
            colorlinks=true,
            linkcolor=$if(linkcolor)$$linkcolor$$else$Maroon$endif$,
            citecolor=$if(citecolor)$$citecolor$$else$Blue$endif$,
            urlcolor=$if(urlcolor)$$urlcolor$$else$Blue$endif$,
$else$
            pdfborder={0 0 0},
$endif$
            breaklinks=true}

% Hyperlinks as footnotes control from Metadata
$if(links-as-notes)$
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$

% Verbatim in footnotes control from Metadata
$if(verbatim-in-note)$
\usepackage{fancyvrb}
\VerbatimFootnotes
$endif$

% Syntax highlight
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{
  commandchars=\\\{\},
  fontsize=\footnotesize,
  fontfamily=b612}
\newenvironment{Shaded}{}{}
\newcommand{\AlertTok}[1]{\textbf{#1}}
\newcommand{\AnnotationTok}[1]{\textit{#1}}
\newcommand{\AttributeTok}[1]{#1}
\newcommand{\BaseNTok}[1]{#1}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{#1}
\newcommand{\CommentTok}[1]{\textit{#1}}
\newcommand{\CommentVarTok}[1]{\textit{#1}}
\newcommand{\ConstantTok}[1]{#1}
\newcommand{\ControlFlowTok}[1]{\textbf{#1}}
\newcommand{\DataTypeTok}[1]{\underline{#1}}
\newcommand{\DecValTok}[1]{#1}
\newcommand{\DocumentationTok}[1]{\textit{#1}}
\newcommand{\ErrorTok}[1]{\textbf{#1}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{#1}
\newcommand{\FunctionTok}[1]{#1}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textit{#1}}
\newcommand{\KeywordTok}[1]{\textbf{#1}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{#1}
\newcommand{\OtherTok}[1]{#1}
\newcommand{\PreprocessorTok}[1]{\textbf{#1}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{#1}
\newcommand{\SpecialStringTok}[1]{#1}
\newcommand{\StringTok}[1]{#1}
\newcommand{\VariableTok}[1]{#1}
\newcommand{\VerbatimStringTok}[1]{#1}
\newcommand{\WarningTok}[1]{\textit{#1}}


% Multiple page tables if needed
$if(tables)$
\usepackage{longtable,booktabs}
$endif$

% Strikeout text if needed
$if(strikeout)$
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$

% Custom header
\usepackage{fancyhdr} % man http://osl.ugr.es/CTAN/macros/latex/contrib/fancyhdr/fancyhdr.pdf

% No 'chapter' word
%\addto\captionsenglish{\renewcommand\chaptername{}}

% Scale images to avoid overflow by default
\usepackage{textcomp}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}

% Copyleft symbol
\newcommand{\copyleft}{\reflectbox{\copyright}}

% Prevent overfull lines
\setlength{\emergencystretch}{3em}
\providecommand{\tightlist}{
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}

% Redefine (sub)paragraphs to behave more like sections
$if(subparagraph)$
$else$
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
$endif$

\pagestyle{fancy}
% Header
\fancyhead{} % clear header
\fancyhead[RO]{\slshape \rightmark}
\fancyhead[LE]{\slshape \leftmark}

% Footer
\fancyfoot{} % clear footer
\renewcommand{\footrulewidth}{0.4pt}
\fancyfoot[RO, LE]{\thepage}
\fancyfoot[LO, RE]{$if(license)$\textcopyleft $endif$ $author$}

% Header on CHAPTER PAGE TODO
\fancypagestyle{chapter}{%
  \fancyhead[L]{\logo{0.5}}
  \fancyhead[R]{\LARGE{$title$}}
}

% Footer on cover
\fancypagestyle{titlepage}{%
  \fancyhead{} % clear header
  \renewcommand{\headrulewidth}{0pt}
  \fancyfoot[R]{$author$}
  \fancyfoot[L]{$if(license)$\textcopyleft $license$ $endif$}
}

% Article titlepage, similar to book chapter
\fancypagestyle{articletitle}{%
  \fancyhead{} % clear header
  \fancyhead[L]{\logo{0.5}}
  \fancyhead[R]{\LARGE{$title$}}
  \fancyfoot[R]{$author$}
  \fancyfoot[L]{$if(license)$\textcopyleft $license$ $endif$}
}

% Beautiful quotes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{framed}

% Use custom leftbar
\renewenvironment{leftbar}[1][\hsize]
  { \color{gray}
      \def\FrameCommand
      {{\color{lightgray}\vrule width 3pt}}
      \MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
  }
  {\endMakeFramed}
% Put leftbar on quote
\let\oldquote=\quote
\let\oldendquote=\endquote
\renewenvironment{quote}
    {\vspace{10pt}\leftbar\vspace*{-6pt}\oldquote}
    {\oldendquote\endleftbar\vspace{10pt}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

$for(header-includes)$
$header-includes$
$endfor$

% Metathings for title, author and date
$if(title)$
\title{$title$$if(thanks)$\thanks{$thanks$}$endif$}
$endif$
$if(subtitle)$
\providecommand{\subtitle}[1]{}
\subtitle{$subtitle$}
$endif$
$if(author)$
\author{$for(author)$$author$$sep$ \and $endfor$}
$endif$
\date{$date$}

\begin{document}

% Define cover
% Make Title act similarly to book chapter
\thispagestyle{articletitle}
\begin{center}
\vspace*{0.3cm}
\begin{doublespace}
$if(title)$
{\Huge\bfseries $title$}\\
$endif$
$if(subtitle)$
{\LARGE $subtitle$}
$endif$
\end{doublespace}
\end{center}

$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$

$for(include-before)$
$include-before$
$endfor$

$if(toc)$
{
$if(colorlinks)$
\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$black$endif$}
$endif$
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
}
$endif$

$if(lot)$
\listoftables
$endif$
$if(lof)$
\listoffigures
$endif$
$body$

$for(include-after)$
$include-after$
$endfor$

\end{document}
