\usepackage[english,british,italian]{babel}
\hyphenation{pa-ra-me-tri-ze re-pa-ra-me-tri-zed re-pa-ra-me-tri-ze a-lu-mi-nium pro-duct pro-ducts cros-sing}
%\usepackage{kpfonts}
\usepackage{charter}
%\usepackage{libertine}
\usepackage{microtype} % makes pdf look better
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%\usepackage{geometry}
%\geometry{a4paper,tmargin=30mm,bmargin=30mm,lmargin=30mm,rmargin=30mm}
\usepackage[norules,nouppercase]{frontespizio}
\usepackage{graphicx}
\usepackage[footnotesize,bf]{subfigure}
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage{booktabs,longtable,rotating}
\usepackage{array,warpcol} % Alignment on decimal point entries in tables
\usepackage{multirow,hhline} % muli rows (merge) in tables
\usepackage[titletoc]{appendix}
\usepackage{minitoc}
\usepackage{listings}
\usepackage[ruled,vlined,nofillcomment]{algorithm2e}
%\usepackage{sectsty} % Changing section headinds
\usepackage{ifthen,varioref}
\vrefwarning					% TO BE REMOVED FOR FINAL VERSION!!!
\usepackage{verbatim, amsmath, amsfonts, amssymb, amsthm}
%\usepackage{bm}
\usepackage{numprint,relsize,siunitx,nicefrac,slashed}
\usepackage{setspace}
\usepackage{float}
\usepackage{url}
\usepackage{fancyhdr} % Change caption style; changes headers and page styles etc.
\usepackage{emptypage}
\usepackage[style=numeric-comp,firstinits=true]{biblatex}
\renewbibmacro{in:}{%
  \ifentrytype{article}{}{%
  \printtext{\bibstring{in}\intitlepunct}}}
%\renewbibmacro{in:}{}
\DeclareFieldFormat[article,incollection]{title}{#1}%No quotes for article titles
\DeclareFieldFormat[thesis]{title}{\mkbibemph{#1}} % Theses like book titles
\bibliography{Parts/bibliog}

% THEOREM ENVIRONMENT
\newtheorem*{pttheo}{Ptolemy's Theorem}

% C++
\def\ifmonospace{\ifdim\fontdimen3\font=0pt }
\def\C++{%
\ifmonospace{C++}%
\else{C\kern-.1667em\raise.50ex\hbox{\textbf{\tiny{++}}}}%
\fi%
\spacefactor1000 }

% LOGICAL OPERATORS
\newcommand{\AND}{\wedge}
\newcommand{\OR}{\vee}
\newcommand{\XOR}{\otimes}

% SISTEMA IL SIMBOLO d (DIFFERENZIALE O DERIVATA)
\newcommand{\diff}{\mathop{}\!\mathrm{d}}

% RESTYLES CHAPTER TITLE FORMAT
\usepackage[Bjornstrup]{fncychap}
%\usepackage[Lenny]{fncychap}
% adjustment for the "charter" font
\ChTitleVar{\raggedleft\Large\bfseries}

% DEFINES THE CENTIGRADE DEGREES SYMBOL
\newcommand{\degree}{\ensuremath{^\circ}}

% SISTEMA L'INTERLINEA DI ELENCHI PUNT. E NUMERATI
\usepackage{enumitem}
\setlist{noitemsep}

%% DEFINES THE "ABSTRACT" ENVIRONMENT
%\usepackage{fancyhdr}	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newcommand{\fncyblank}{\fancyhf{}}
%\newenvironment{abstract}%
%{\cleardoublepage\fncyblank\null\vfill\begin{center}%
%\bfseries\abstractname\end{center}}%
%{\vfill\null}
%
%% DEFINES THE "AKNOWLEDGEMENTS" ENVIRONMENT
%\newenvironment{acknowledgements}%
%{\cleardoublepage\fncyblank\null\vfill\begin{center}%
%\bfseries Aknowledgements \end{center}}%
%{\vfill\null}

% DEFINES THE "ABSTRACT" ENVIRONMENT
\usepackage{fancyhdr}	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newenvironment{abstract}%
{\cleardoublepage\null\vfill\begin{center}%
\bfseries\abstractname\end{center}}%
{\vfill\null}
%\usepackage{fancyhdr}	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newenvironment{abstract}%
%{\cleardoublepage\null%\vfill%
%Titolo: \textbf{A GPU-based real time trigger for rare decays at NA62}\\Candidato: \textbf{Elena Graverini}\\Relatore: \textbf{Prof. Marco Sozzi}\\\centerline{\textbf{Sommario\B\B}}}%
%{\vfill\null}

% DEFINES THE "AKNOWLEDGEMENTS" ENVIRONMENT
\newenvironment{acknowledgements}%
{\cleardoublepage\null\vfill\begin{center}%
\bfseries Acknowledgements \end{center}}%
{\vfill\null}

% DEFINES SUBSCRIPTS AND SUPERSCRIPTS OUTSIDE MATH MODE
\newcommand{\superscript}[1]{\ensuremath{^{\textrm{#1}}}}
\newcommand{\subscript}[1]{\ensuremath{_{\textrm{#1}}}}

% This redefines \@xobeysp, to which the space character is \let in verbatim text, to a normal space instead of an unbreakable space.
\makeatletter
\def\@xobeysp{ }
\makeatother

% SETS SPACES VISIBLE IN LSTLISTINGS
\makeatletter
\def\lst@visiblespace{\phantom{\lst@ttfamily{\char32}\textvisiblespace}}
\makeatother
% SETUP LISTINGS
\lstdefinestyle{customcpp}{
  belowcaptionskip=1\baselineskip,
  breaklines=true,
  frame=L,
  xleftmargin=\parindent,
  language=C++,
  showstringspaces=false,
  basicstyle=\footnotesize\ttfamily,
  keywordstyle=\bfseries\color{green!40!black},
  commentstyle=\itshape\color{purple!40!black},
  identifierstyle=\color{blue},
  stringstyle=\color{orange},
}
%\lstset{language=C++, basicstyle=\footnotesize, breaklines=true, frame=single, caption=\lstname, captionpos=t}
\lstset{breaklines=true, style=customcpp}

% SETS CLEARDOUBLEPAGE HEADERS EMPTY
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\vspace{\fill}
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother

\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\renewcommand\Re{\operatorname{\mathfrak{Re}}}
\renewcommand\Im{\operatorname{\mathfrak{Im}}}
\newcommand\T{\rule{0pt}{2.6ex}}       % Top strut
\newcommand\B{\rule[-1.2ex]{0pt}{0pt}} % Bottom strut

% Fuzz
\hfuzz2pt % Don't bother to report over-full boxes if over-edge is < 2pt

\interfootnotelinepenalty=10000		% TO BE REMOVED FOR FINAL VERSION - footnotes to be checked!

% LOWERCASE HEADINGS
%\usepackage{regexpatch}% http://ctan.org/pkg/regexpatch
%\makeatletter
%% \*patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
%\xpatchcmd{\chaptermark}{\MakeUppercase}{}{}{}%
%\xpatchcmd{\sectionmark}{\MakeUppercase}{}{}{}%
%\xpatchcmd*{\tableofcontents}{\MakeUppercase}{}{}{}%
%\makeatother

% colored blocks
\newsavebox{\selvestebox}
\newenvironment{colbox}[1]
  {\newcommand\colboxcolor{#1}%
   \begin{lrbox}{\selvestebox}%
   \begin{minipage}{\dimexpr\columnwidth-2\fboxsep\relax}}
  {\end{minipage}\end{lrbox}%
   \begin{center}
   \colorbox[HTML]{\colboxcolor}{\usebox{\selvestebox}}
   \end{center}}

% VREF 2 REFERENCES
%\newcommand\vrefV2[2]{%
%\vrefpagenum\firstnum{#1}%
%\vrefpagenum\secondnum{#2}%
%\ifthenelse{\equal\firstnum\secondnum}%
%{\ref{#1} and \ref{#2} \vpageref{#1}}%
%{\ref{#1} \vpageref{#1} and \ref{#2} \vpageref{#2}}%
%}


% with this we ensure that the chapter and section
% headings are in lowercase.
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{} % delete current setting for header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt} % make space for the rule
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers on plain pages
\renewcommand{\headrulewidth}{0pt} % and the line
}

\usepackage[final]{feynmp}
\DeclareGraphicsRule{*}{mps}{*}{}
\makeatletter
\def\endfmffile{%
	\fmfcmd{\p@rcent\space the end.^^J%
			end.^^J%
			endinput;}%
	\if@fmfio
		\immediate\closeout\@outfmf
	\fi
	\ifnum\pdfshellescape=\@ne
		\immediate\write18{mpost \thefmffile}%
	\fi}


\usepackage[usenames,dvipsnames,svgnames,x11names,table]{xcolor}

%\input{bjornstrup_setup} BOH NON FUNZIONA

\usepackage[colorlinks,linkcolor=Blue3]{hyperref}				% TO BE REMOVED FOR FINAL VERSION!!!
\usepackage{bookmark}

% problems with \bm in titles
%\pdfstringdefDisableCommands{%
%    \renewcommand*{\bm}[1]{#1}%
%    % any other necessary redefinitions 
%}