\ProvidesPackage{tugraz_defaults}
%\usepackage[hyphens]{url}
\PassOptionsToPackage{bookmarks,hidelinks}{hyperref}
\usepackage{hyperref}
\hypersetup{breaklinks=true}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{collcell}
\usepackage{comment}
\usepackage{float}
\usepackage{adjustbox}
\usepackage{paralist}
\usepackage[binary-units=true,per-mode=symbol]{siunitx}
\sisetup{detect-weight=true,unit-mode=text,group-minimum-digits=4} 
\usepackage{xspace}
\usepackage{placeins}
\usepackage{xcolor}

\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{shapes.arrows}
\usetikzlibrary{shapes.geometric,shapes.misc}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat=newest}

\usepackage{caption}
\usepackage{subcaption}
\captionsetup{compatibility=false}
\captionsetup[figure]{aboveskip=0.5em, belowskip=0.5em,labelfont={small},font={small}} 
%\captionsetup[subfigure]{skip=10pt,labelfont={bf,normal},font={bf,normal}}
\captionsetup[table]{aboveskip=0.5em, belowskip=0.5em,labelfont={small},font={small}}
\captionsetup[lstlisting]{labelformat=simple,skip=5pt,labelfont={small},font={small}}
\captionsetup[subfloat]{font={small}}
% ------------------------------

\definecolor{lukasred}{HTML}{950000}
\definecolor{andreasgreen}{HTML}{e9f5db}
\definecolor{vsblack}{cmyk}{0,0,0,1}             
\definecolor{vswhite}{HTML}{24292e}
\definecolor{vsbackground}{HTML}{ffffff}    %background in Visual Studio
\definecolor{vscomment}{HTML}{047f04}       %comments in Visual Studio
\definecolor{vskeyword}{HTML}{0024fe}       %keywords in Visual Studio
\definecolor{vsstring}{cmyk}{0,0.26,0.38,0} %strings in Visual Studio
\definecolor{vsctrlflow}{HTML}{ad1eda}      %if/else,switch/case etc. in Visual Studio
\definecolor{vslocalvar}{HTML}{001780}      %local variables in Visual Studio
\definecolor{vsclass}{HTML}{1d809d}         %class types in Visual Studio
\definecolor{vsfunctions}{HTML}{7a5d27}     %enumerations and methods in Visual Studio

% ------------------------------
% Fancy notes
\usepackage{letltxmacro}

\usepackage{xparse}
\setdefaultleftmargin{1.5em}{}{}{}{.5em}{.5em}
\NewDocumentEnvironment{figureA}{omo}{\begin{figure}[#1]\tikzsetnextfilename{#2}\centering}{\IfNoValueTF {#3}{}{\caption{#3}}\label{fig:#2}\end{figure}}
\NewDocumentEnvironment{subfigureA}{ommo}{\begin{subfigure}[#1]{#2}\tikzsetnextfilename{#3}\centering}{\IfNoValueTF {#4}{}{\caption{#4}}\label{fig:#3}\end{subfigure}}
\NewDocumentEnvironment{figureA*}{omo}{\begin{figure*}[#1]\tikzsetnextfilename{#2}\centering}{\IfNoValueTF {#3}{}{\caption{#3}}\label{fig:#2}\end{figure*}}
\NewDocumentEnvironment{subfigureA*}{ommo}{\begin{subfigure*}[#1]{#2}\tikzsetnextfilename{#3}\centering}{\IfNoValueTF {#4}{}{\caption{#4}}\label{fig:#3}\end{subfigure*}}

\usepackage{algorithmic}
\usepackage[ruled]{algorithm2e}
\usepackage{listings}
\newfloat{listing}{tbhp}{lst}%[section]
\floatname{listing}{Listing}
\lstset{ %
  backgroundcolor=\color{vsbackground},
  basicstyle=\scriptsize\bf\ttfamily\upshape\color{vswhite},
  belowcaptionskip=1\baselineskip,
  breakatwhitespace=true,
  breakautoindent=false,
  breakindent=0pt,
  breaklines=true,                 % sets automatic line breaking
  captionpos=b,                    % sets the caption-position to bottom
  columns=fixed,
  commentstyle=\color{vscomment},
  emphstyle={[2]\color{vslocalvar}},
  emphstyle={[3]\color{vsclass}},
  emphstyle={[4]\color{vsfunctions}},
  emphstyle=\color{vsctrlflow},
  escapeinside={(*@}{@*)},
  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
  frame=single,                    % adds a frame around the code
  %framesep=5pt,
  framexleftmargin=13pt,
  framexrightmargin=-20.5pt,
  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
  keywordstyle=\color{vskeyword},
  language=C,                      % the language of the code
  %linewidth=\listingwidth,
  morecomment=[s][\color{vscomment}]{/*-}{*/},
  morecomment=[s][\color{vscomment}]{/*+}{*/},
  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)
  numbersep=4pt,                   % how far the line-numbers are from the code
  numberstyle=\tiny\bf\color{vsblack}, 
  postbreak=\mbox{\textcolor{red}{->}\space},
  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
  rulecolor=\color{vsbackground},
  rulesep=0pt,
  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
  showstringspaces=false,          % underline spaces within strings only
  showtabs=false,                  % show tabs within strings adding particular underscores
  stringstyle=\color{vsstring},
  tabsize=2,                       % sets default tabsize to 2 spaces
  xleftmargin=10pt,
  xrightmargin=10pt
}
\lstdefinelanguage
   [x64]{Assembler}     % add a "x64" dialect of Assembler
   [x86masm]{Assembler} % based on the "x86masm" dialect
   % with these extra keywords:
   {morekeywords={CDQE,CQO,CMPSQ,CMPXCHG16B,JRCXZ,LODSQ,MOVSXD, %
                  POPFQ,PUSHFQ,SCASQ,STOSQ,IRETQ,RDTSCP,SWAPGS, %
                  rax,rdx,rcx,rbx,rsi,rdi,rsp,rbp, %
                  r8,r8d,r8w,r8b,r9,r9d,r9w,r9b}} % etc.

\lstdefinestyle{cpp}
{
  language=c++,
  % syntax higlights
  morekeywords={partial, var, value, get, set, uint64\_t, func},
  % control flow 
  emph={if, else, return, throw, switch, case, for, repeat},
  % local vars
  emph={[2]start, end, samples, N, L, cache\_line, victim_cache_line,KEY_FLAG_REVOKED,keyring,ns},
  % class and structs
  emph={[3]SomeOwnClassType, Measurement, Sample, key},
  % functions
  emph={[4]measure,fill,ioctl,measure_power,record_sample,diff,access,find\_keyring\_by\_name,list\_for\_each\_entry,test\_bit,kuid_has_mapping,keyctl_join_session_keyring,KEYCTL_JOIN_SESSION_KEYRING},
}
\usepackage{fancyvrb}


\lstdefinestyle{asm}
{
  language={[x64]Assembler},
  % syntax higlights
  morekeywords={ud2,syscall,movq,prefetcht0},
  % control flow 
  emph={},
  % local vars
  emph={[2]victim\_cache\_line,MSR\_PKG\_POWER\_LIMIT},
  % class and structs
  emph={[3]rip,rax,rdx,eax,rsp},
  % functions
  emph={[4]module\_ioctl,misspeculation,retpoline,retpoline\_end},
}

\newcommand\Highlight[1]{\underline{\textcolor{red}{#1}}}
\newcommand\HighlightB[1]{\textbf{\textcolor{blue}{#1}}}

\newcommand\HighlightD[1]{{\textcolor{green!80!black}{#1}}}

\newenvironment{Plain}[1][]
  { \VerbatimEnvironment%
    \begin{Verbatim}[#1]}
  { \end{Verbatim}  } 

\newcommand{\gbr}[1]{\left\{#1\right\}}
\newcommand{\SIx}[1]{\num{#1}\relax}
\newcommand{\xor}{\oplus}
\newcommand{\etal}{et~al.\ } % typography nerd
\newcommand{\ie}{\textit{i.e.},\ } % typography nerd
\newcommand{\eg}{e.g.,\ } % typography nerd
\newcommand{\cf}{cf.\ } % typography nerd
\newcommand{\KeyDrown}{\emph{KeyDrown}\xspace}
\newcommand{\FlushOnly}{Flush+Flush\xspace}
\newcommand{\clflush}{\texttt{clflush}\xspace}
\newcommand{\FlushReload}{Flush+\allowbreak Reload\xspace}
\newcommand{\EvictReload}{Evict+\allowbreak Reload\xspace}
\newcommand{\EvictTime}{Evict+\allowbreak Time\xspace}
\newcommand{\PrimeProbe}{Prime+\allowbreak Probe\xspace}
\newcommand{\MultiPrimeProbe}{Multi-\allowbreak Prime+\allowbreak Probe\xspace}
\newcommand{\FlushFlush}{Flush+\allowbreak Flush\xspace}
\newcommand{\GTKplus}{\emph{GTK+}\xspace}
\newcommand{\libgdk}{\emph{libgdk}\xspace}
\newcommand{\OnePlus}{OnePlus 3t\xspace}
\newcommand{\FScore}{F-score\xspace}

\newcommand{\ReqOne}{\emph{R1}\xspace}
\newcommand{\ReqTwo}{\emph{R2}\xspace}
\newcommand{\ReqThree}{\emph{R3}\xspace}

\usepackage{pifont}
\newcommand{\xmark}{\leavevmode{\color{red}\ding{55}}}%
\newcommand{\cmark}{\leavevmode{\color{TolDarkGreen}\ding{51}}}%
\newcommand{\tmark}{\leavevmode{\color{orange!90!red}\large $\mathbf{\thicksim}$}}%
\mathchardef\mhyphen="2D
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\newcommand*\circledb[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt,fill=black,text=white] (char) {#1};}}
\newcommand*\circleds[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=1pt] (char) {\footnotesize #1};}}
\newcommand*\circledsb[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=0.7pt,fill=black,text=white] (char) {\footnotesize #1};}}
% ------------------------------


\newcommand{\FakeMarker}{{\color{red}$\blacktriangle$}}
\newcommand{\RealMarker}{{\color{green}$\bullet$}}

\newfloat{lstfloat}{htbp}{lop}
\floatname{lstfloat}{Listing}

\usepackage{epsdice}
\usepackage{soul}
\usepackage[noabbrev,capitalize]{cleveref}

\widowpenalty10000
\clubpenalty10000

% plot default colors
\definecolor{TolDarkPurple}{HTML}{332288}
\definecolor{TolDarkBlue}{HTML}{6699CC}
\definecolor{TolLightBlue}{HTML}{88CCEE}
\definecolor{TolLightGreen}{HTML}{44AA99}
\definecolor{TolDarkGreen}{HTML}{117733}
\definecolor{TolDarkBrown}{HTML}{999933}
\definecolor{TolLightBrown}{HTML}{DDCC77}
\definecolor{TolDarkRed}{HTML}{661100}
\definecolor{TolLightRed}{HTML}{CC6677}
\definecolor{TolLightPink}{HTML}{AA4466}
\definecolor{TolDarkPink}{HTML}{882255}
\definecolor{TolLightPurple}{HTML}{AA4499}

% plot
\definecolor{PlotColorBlue}{HTML}{2C7FB8}
\definecolor{PlotColorRed}{HTML}{F03B20}
\definecolor{PlotColorGreen}{HTML}{31A354}

% colors
\definecolor{red}{HTML}{F03B20}
\definecolor{yellow}{HTML}{F5EE9A}
\definecolor{green}{HTML}{BEDB39}
\definecolor{blue}{HTML}{2C7FB8}


\pgfplotscreateplotcyclelist{mbarplot cycle}{%
  {draw=TolDarkBlue,    fill=TolDarkBlue!70},
  {draw=TolLightBrown,  fill=TolLightBrown!70},
  {draw=TolLightGreen,  fill=TolLightGreen!70},
  {draw=TolDarkPink,    fill=TolDarkPink!70},
  {draw=TolDarkPurple,  fill=TolDarkPurple!70},
  {draw=TolDarkRed,     fill=TolDarkRed!70},
  {draw=TolDarkBrown,   fill=TolDarkBrown!70},
  {draw=TolLightRed,    fill=TolLightRed!70},
  {draw=TolLightPink,   fill=TolLightPink!70},
  {draw=TolLightPurple, fill=TolLightPurple!70},
  {draw=TolLightBlue,   fill=TolLightBlue!70},
  {draw=TolDarkGreen,   fill=TolDarkGreen!70},
}

\pgfplotscreateplotcyclelist{mlineplot cycle}{%
  {TolDarkBlue, mark=*, mark size=1.5pt},
  {TolLightBrown, mark=square*, mark size=1.3pt},
  {TolLightGreen, mark=triangle*, mark size=1.5pt},
  {TolDarkBrown, mark=diamond*, mark size=1.5pt},
}

\usepackage{diagbox}
\usepackage{oplotsymbl}

\LetLtxMacro{\oldcircletfill}{\circletfill}
\LetLtxMacro{\oldcirclet}{\circlet}
\LetLtxMacro{\oldcircletfillhl}{\circletfillhl}
\renewcommand{\circletfill}{\raisebox{-0.9pt}{\tikzsetnextfilename{circletfill}\oldcircletfill}}
\renewcommand{\circlet}{\raisebox{-0.9pt}{\tikzsetnextfilename{circlet}\oldcirclet}}
\renewcommand{\circletfillhl}{\raisebox{-0.9pt}{\tikzsetnextfilename{circletfillhl}\oldcircletfillhl}}
  
\newcommand{\cmarkfull}{\multicolumn{1}{c} {\circletfill \phantom{*}}}
\newcommand{\cmarkempty}{\multicolumn{1}{c} {\circlet \phantom{*}}}
\newcommand{\cmarkhalf}{\multicolumn{1}{c} {\circletfillhl \phantom{*}}}

\newcommand{\cstarletfill}{\multicolumn{1}{c} {\starletfill \phantom{*}}}
\newcommand{\cstarlet}{\multicolumn{1}{c} {\starlet \phantom{*}}}

\newcommand{\cmarkfulls}{\multicolumn{1}{c} {\circletfill *}}
\newcommand{\cmarkemptys}{\multicolumn{1}{c} {\circlet *}}
\newcommand{\cmarkhalfs}{\multicolumn{1}{c} {\circletfillhl *}}

\newcommand{\cmarkfulld}{\multicolumn{1}{c} {\circletfill $^\dagger$}}
\newcommand{\cmarkemptyd}{\multicolumn{1}{c} {\circlet $^\dagger$}}
\newcommand{\cmarkhalfd}{\multicolumn{1}{c} {\circletfillhl $^\dagger$}}

\newcommand{\muop}{$\mu$OP\xspace}
\newcommand{\muops}{$\mu$OPs\xspace}

\lstdefinestyle{python}{
  language=python,
  % syntax higlights
  morekeywords={False, True},
  % control flow 
  emph={if, else, return, throw, switch, case, for, repeat, import},
  % local vars
  emph={[2]cpu, self, stable_periode, STABLE, PWRSAVE, POWERSAVE},
  % class and structs
  emph={[3]SUIT_DOWN_simple, PowerState},
  % functions
  emph={[4]__init__, disabled_instruction_ex_handler, timer_interrupt_handler},
}


\lstdefinestyle{cppinline}{
  style = cpp,
  basicstyle=\small\bf\ttfamily\upshape\color{vswhite},
}

\lstdefinestyle{asminline}{
  style = asm,
  basicstyle=\small\bf\ttfamily\upshape\color{vswhite},
}

\lstdefinestyle{pythoninline}{
  style = python,
  basicstyle=\small\bf\ttfamily\upshape\color{vswhite},
}
\newcommand{\asm}[1]{\lstinline[style=asm]{#1}\xspace}
\newcommand{\cpp}[1]{\lstinline[style=cpp]{#1}\xspace}
\newcommand{\py}[1]{\lstinline[style=python]{#1}\xspace}
\usepackage{moresize}
\usepackage{pdfpages}
\usepackage{enumitem}
\usepackage{mdframed}
\usepackage{import}
\usepackage{microtype}
\usepackage[breakable, theorems, skins]{tcolorbox}
\usepackage[backend=biber,
            url=true,
            style=numeric,
            giveninits=false,
            maxnames=32,
            minnames=32,
            maxcitenames=2,
            mincitenames=1,
            backref=true, %
           ]{biblatex}

\DeclareFieldFormat*{title}{#1} 
\DeclareFieldFormat*{booktitle}{#1}  
\DeclareFieldFormat*{journaltitle}{#1}  
\newcommand{\itemcite}[1]{\begin{itemize}\item \fullcite{#1}\end{itemize}}

\newcommand{\bf}{\bfseries}
\newcommand{\tt}{\ttfamily}
\renewcommand{\and}{,\xspace}
\newcommand{\CopyrightYear}{}
\newcommand{\setcopyright}{}
\newcommand{\conferenceinfo}{}
\newcommand{\isbn}{}
\newcommand{\doi}{}
\newcommand{\printccsdesc}{}
\newcommand{\numberofauthors}{}
\newcommand{\alignauthor}{}
\newcommand{\affaddr}{}
\newcommand{\ccsdesc}[1]{}
\newcommand{\acmPrice}{}
\newcommand{\keywords}[1]{Keywords:\ #1.}

\usepackage{graphicx}
\usepackage[openbib,NoDate]{currvita}
\preto\fullcite{\AtNextCite{\defcounter{maxnames}{99}}}


\usepackage{quotchap} %

\DefineBibliographyStrings{english}{%
  backrefpage = {p.},%
  backrefpages = {pp.},%
}

\usepackage[titles]{tocloft}
\renewcommand\cftchapaftersnum{.}
\setlength{\cftchapnumwidth}{2em}

\usepackage{verbatim}

\makeatletter
\frenchspacing
\widowpenalty=10000
\clubpenalty=10000
\setcounter{tocdepth}{1}
\renewenvironment{table}
               {\setlength\abovecaptionskip{0\p@}%
                \setlength\belowcaptionskip{10\p@}%
                \@float{table}}
               {\end@float}
\newenvironment{CCSXML}
               {\comment}
               {\endcomment}
\makeatother

\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{} \vspace*{\fill}
\begin{center}
\end{center}
\vspace{\fill} \thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother

\makeatletter
\newcommand\declarecommand{\@star@or@long\@declarecommand}
\newcommand\@declarecommand[1]{%
  \provide@command{#1}{}%
  \renew@command{#1}%
}
\def\declareenvironment{\@star@or@long\declare@environment}
\def\declare@environment#1{%
        \@ifundefined{#1}%
                {\def\reserved@a{\newenvironment{#1}}}%
                {\def\reserved@a{\renewenvironment{dummy@environ}}}%
        \reserved@a
}
\def\dummy@environ{}
\makeatother

\makeatletter
\DeclareRobustCommand{\rvdots}{%
  \vbox{
    \baselineskip4\p@\lineskiplimit\z@
    \kern-\p@
    \hbox{.}\hbox{.}\hbox{.}
  }}
\makeatother

\usepackage{titling}
\usepackage[english]{babel}
\addto{\captionsenglish}{\renewcommand*{\appendixname}{Appendix}}
\renewcommand{\algorithmautorefname}{Algorithm}
\renewcommand\itemautorefname{Step}
\renewcommand\chapterautorefname{Chapter}
\renewcommand\sectionautorefname{Section}
\renewcommand\subsectionautorefname{Section}
\renewcommand\subsubsectionautorefname{Section}

\usepgfplotslibrary{dateplot}
\usepgfplotslibrary{fillbetween}

\hyphenation{}
\usepackage{chngcntr}
\addtokomafont{disposition}{\rmfamily}

\usepackage{mypreamble}
\usepackage{scrhack}


