\usepackage{graphicx}
\usepackage{verbatim}
\usepackage{latexsym}
\usepackage{setspace}
\usepackage{todonotes} %this is used for TODO notes, see https://www.overleaf.com/help/41-can-i-add-inline-or-margin-comments-to-the-pdf
\usepackage[toc,page]{appendix} % this is for appendices, see  https://tex.stackexchange.com/questions/49643/making-appendix-for-thesis#49647
\usepackage{listings} % for adding source code, see https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings
\usepackage{textcomp} % for arrows in text mode. Usage: \textleftarrow
\usepackage{hyperref} % for clickable url links
\usepackage[T1]{fontenc} % better fonts without weird issues
\usepackage{lmodern}
\parindent0pt

\input{icrobotum_report.sty}

\usepackage{xcolor}
\hypersetup{
    colorlinks,
    linkcolor={red!30!black},
    citecolor={blue!50!black},
    urlcolor={blue!80!black}
}

% Funky symbols for footnotes
\newcommand{\symbolfootnote}{\renewcommand{\thefootnote}{\fnsymbol{footnote}}}
% now add \symbolfootnote to the beginning of the document...

\usepackage{float} %for putting images exactly where you want them, use 

\newtheorem{definition}{Definition}[chapter]
\newtheorem{theorem}{Theorem}[chapter]

% this adds another layer of depth to the sectioning numbers (chapter (0) > section (1) > subsection(2) > subsubsection(3) > paragraph(4) > subparagraph(5)). We only number up till subsubsection with depth 3
\setcounter{secnumdepth}{3} %the depth of numbering
\setcounter{tocdepth}{3}  %what's included in the Table Of Contents (ToC)

% %from https://tex.stackexchange.com/questions/53338/reducing-spacing-after-headings
% % spacing: how to read \titlespacing{command}{left spacing}{before spacing}{after spacing}[right]

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}
\titleformat{\paragraph}[runin]
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titleformat{\subparagraph}[runin]
{\normalfont\normalsize\bfseries}{\thesubparagraph}{1em}{}
\titlespacing*{\chapter} {0pt}{50pt}{40pt}
\titlespacing*{\section} {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection} {0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\paragraph} {0pt}{3.25ex plus 1ex minus .2ex}{1em}
\titlespacing*{\subparagraph} {\parindent}{3.25ex plus 1ex minus .2ex}{1em}


% % commands for easy referencing
\newcommand{\fref}[1]{Figure~\ref{#1}}
\newcommand{\tref}[1]{Table~\ref{#1}}
\newcommand{\eref}[1]{Equation~\ref{#1}}
\newcommand{\cref}[1]{Chapter~\ref{#1}}
\newcommand{\sref}[1]{Section~\ref{#1}}
\newcommand{\aref}[1]{Appendix~\ref{#1}}

%% line spacing etc (from the ShareLatex Thesis template)
\makeatletter  %to avoid error messages generated by "\@". Makes Latex treat "@" like a letter

\usepackage{setspace}
\setstretch{0.1}
%\setlength{\parindent}{0pt}
%\setlength{\parskip}{0ex plus0.3ex minus0.2ex}


\usepackage{vmargin}
\setmarginsrb           { 1.0in}  % left margin
                        { 0.5in}  % top margin
                        { 1.0in}  % right margin
                        { 0.7in}  % bottom margin
                        {  10pt}  % head height
                        {0.25in}  % head sep
                        {   9pt}  % foot height
                        { 0.3in}  % foot sep
% \raggedbottom
\hyphenpenalty=5000
% \doublehyphendemerits=1000       % No consecutive line hyphens.
% \brokenpenalty=1000           % No broken words across columns/pages.
% \widowpenalty=1000               % Almost no widows at bottom of page.
% \clubpenalty=1000                 % Almost no orphans at top of page.
% \interfootnotelinepenalty=1000   % Almost never break footnotes.
\widowpenalties 1 10000
\raggedbottom

\usepackage{fancyhdr}
\lhead[\rm\thepage]{\fancyplain{}{\sl{\rightmark}}}
\rhead[\fancyplain{}{\sl{\leftmark}}]{\rm\thepage}
\chead{}\lfoot{}\rfoot{}\cfoot{}
\pagestyle{fancy}
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}

\makeatother  %to avoid error messages generated by "\@". Makes Latex treat "@" like a letter

% fancy source code listings: http://stackoverflow.com/questions/741985/latex-source-code-listing-like-in-professional-books
% usage: \lstinputlisting[label=samplecode,caption=A sample]{sourceCode/HelloWorld.java}
\definecolor{light-gray}{gray}{0.95}
\usepackage{listings}
\usepackage{courier}
\lstset{
         basicstyle=\footnotesize\ttfamily, % Standardschrift
         numbers=left,               % Ort der Zeilennummern
         numberstyle=\tiny,          % Stil der Zeilennummern
         stepnumber=0,               % Abstand zwischen den Zeilennummern
         numbersep=5pt,              % Abstand der Nummern zum Text
         tabsize=2,                  % Groesse von Tabs
         extendedchars=true,         %
         breaklines=true,            % Zeilen werden Umgebrochen
         keywordstyle=\color{red},
         stringstyle=\color{white}\ttfamily, % Farbe der String
         showspaces=false,           % Leerzeichen anzeigen ?
         showtabs=false,             % Tabs anzeigen ?
         xleftmargin=0pt,
         framexleftmargin=10pt,
         framexrightmargin=10pt,
         framexbottommargin=0pt,
         backgroundcolor=\color{light-gray},
         showstringspaces=false      % Leerzeichen in Strings anzeigen ?        
}

\lstdefinestyle{customc}{
  	belowcaptionskip=1\baselineskip,
  	breaklines=true,
  	%frame=L,
  	language=C,
  	showstringspaces=false,
 	basicstyle=\footnotesize\ttfamily\color{blue!40!black},
 	keywordstyle=\bfseries\color{green!40!black},
  	commentstyle=\itshape\color{purple!40!black},
  	%identifierstyle=\color{blue}, %color of actual code
 	stringstyle=\color{orange},
    numbers=left,               % Ort der Zeilennummern
    numberstyle=\tiny,          % Stil der Zeilennummern
    stepnumber=2,               % Abstand zwischen den Zeilennummern
    numbersep=5pt,              % Abstand der Nummern zum Text
    tabsize=2,                  % Groesse von Tabs
    extendedchars=true,         %
    showspaces=false,           % Leerzeichen anzeigen ?
    showtabs=false,             % Tabs anzeigen ?
  	xleftmargin=\parindent,
    framexleftmargin=10pt,
    framexrightmargin=10pt,
    framexbottommargin=0pt,
    backgroundcolor=\color{light-gray},
}

\lstset{escapechar=@,style=customc}


\usepackage{underscore} % no need to use '\' before underscore


% easiest way to add a figure: 

%\begin{figure}[h!]
%\centering
%\includegraphics[width=50mm]{method.eps}
%\captionsource{caption}{source}
%\label{fig:method}
%\end{figure}


\newcommand*{\captionsource}[2]{%
  \caption[{#1}]{%
    #1%
    \\\hspace{\linewidth}%
    \textbf{Source:} #2%
  }%
}
