% ****************************************************************************************************
% classicthesis-config.tex 
% formerly known as loadpackages.sty, classicthesis-ldpkg.sty, and classicthesis-preamble.sty 
% Use it at the beginning of your ClassicThesis.tex, or as a LaTeX Preamble 
% in your ClassicThesis.{tex,lyx} with \input{classicthesis-config}
% ****************************************************************************************************  
% If you like the classicthesis, then I would appreciate a postcard. 
% My address can be found in the file ClassicThesis.pdf. A collection 
% of the postcards I received so far is available online at 
% http://postcards.miede.de
% ****************************************************************************************************

% ****************************************************************************************************
% 1. Configure classicthesis for your needs here, e.g., remove "drafting" below 
% in order to deactivate the time-stamp on the pages
% ****************************************************************************************************
\PassOptionsToPackage{
                    eulerchapternumbers,
                    % drafting, % comentar para remover a linha com a versão
                    pdfspacing,
                    %floatperchapter,
                    %linedheaders,%
                    subfig,beramono,
                    eulermath,
                    parts
                    }{classicthesis}
% Available options for classicthesis.sty 
% (see ClassicThesis.pdf for more information):
% drafting
% parts nochapters linedheaders
% eulerchapternumbers beramono eulermath pdfspacing minionprospacing
% tocaligned dottedtoc manychapters
% listings floatperchapter subfig
% ********************************************************************

% ********************************************************************
% Triggers for this config
% ******************************************************************** 
\usepackage{ifthen}
\newboolean{enable-backrefs} % enable backrefs in the bibliography
\setboolean{enable-backrefs}{false} % true false
% ****************************************************************************************************


% ********************************************************************
% Setup, finetuning, and useful commands
% ********************************************************************
\newcounter{dummy} % necessary for correct hyperlinks (to index, bib, etc.)
\newlength{\abcd} % for ab..z string length calculation
\providecommand{\mLyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}
\newcommand{\ie}{\textit{i.\,e.}\xspace}
\newcommand{\Ie}{\textit{I.\,e.}\xspace}
\newcommand{\eg}{\textit{e.\,g.}\xspace}
\newcommand{\Eg}{\textit{E.\,g.}\xspace} 
\newcommand{\etc}{\textit{etc}\xspace} 


% ****************************************************************************************************
% \DeclareTextFontCommand{\code}{\fontfamily{pcr}\scriptsize}


% ****************************************************************************************************
% 3. Loading some handy packages
% ****************************************************************************************************
% ******************************************************************** 
% Packages with options that might require adjustments
% ******************************************************************** 

\PassOptionsToPackage{main=english}{babel}
\usepackage{babel}
\usepackage{dirtytalk}

\renewcommand{\figurename}{Figure}
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Bibliografia
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% package recomendada para usar com o biblatex
\usepackage{csquotes}

% carrega a package biblatex
\usepackage[
    backend=biber,    % usar o biber para processar
    style=authoryear, % estilo de citação
    sortcites=true,
    maxcitenames=2,   % a partir de 2 escreve "et al."
]{biblatex} 

% para adicionar uma vírgula antes do ano: (Dirac, 1981)
\renewcommand*{\nameyeardelim}{\addcomma\space}

%  dica: configurar o kile para reconhecer os comandos:
%    \parencite{bibkey}
%    \textcite{bibkey}
%    \citeauthor{bibkey}
%    \citetitle{bibkey}
%    
%    Settingis -> Configure Kile -> Latex/General -> Commands/Configure -> Commands/Citation -> add
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
\usepackage{float}

\PassOptionsToPackage{fleqn}{amsmath}		% math environments and more by the AMS 
\usepackage{amsmath}

\usepackage{multirow}
 
%******************************************************************** 
% General useful packages
%******************************************************************** 
\PassOptionsToPackage{T1}{fontenc} % T2A for cyrillics
\usepackage{fontenc}

\usepackage{textcomp} % fix warning with missing font shapes
\usepackage{scrhack} % fix warnings when using KOMA with listings package          
\usepackage{xspace} % to get the spacing after macros right  
\usepackage{mparhack} % get marginpar right
% \usepackage{fixltx2e} % fixes some LaTeX stuff 

\PassOptionsToPackage{printonlyused,smaller}{acronym}
\usepackage{acronym} % nice macros for handling all acronyms in the thesis

%\renewcommand*{\acsfont}[1]{\textssc{#1}} % for MinionPro
\newcommand{\bflabel}[1]{{#1}\hfill} % fix the list of acronyms
%****************************************************************************************************


%****************************************************************************************************
% 4. Setup floats: tables, (sub)figures, and captions
%****************************************************************************************************

\usepackage[flushleft]{threeparttable}

\usepackage{tabularx} % better tables
    \setlength{\extrarowheight}{3pt} % increase table row height
\newcommand{\tableheadline}[1]{\multicolumn{1}{c}{\spacedlowsmallcaps{#1}}}
\newcommand{\tableheadlineR}[1]{\multicolumn{1}{r}{\spacedlowsmallcaps{#1}}}
\newcommand{\myfloatalign}{\centering} % to be used with each float for alignment
\usepackage{caption}
\captionsetup{format=hang,font=small}
\usepackage{subfig}  
% ****************************************************************************************************


%----------------------------------------------------------
% Filipius's famous "issue" command (Patricio, 2016-08-03)
%----------------------------------------------------------
\newcommand{\issue}[1] { {\footnotesize\textbf{
    \begin{center}
      \begin{tabular}{|c|}
        \hline
	\parbox[c]{\textwidth}{
          \medskip
          #1
          \medskip} \\
        \hline
      \end{tabular}
    \end{center}
  }
 }
}


% ****************************************************************************************************
% 6. PDFLaTeX, hyperreferences and citation backreferences
% ****************************************************************************************************
% ********************************************************************
% Using PDFLaTeX
% ********************************************************************
\PassOptionsToPackage{pdftex,hyperfootnotes=false,pdfpagelabels}{hyperref}
	\usepackage{hyperref}  % backref linktocpage pagebackref
\pdfcompresslevel=9
\pdfadjustspacing=1 
\PassOptionsToPackage{pdftex}{graphicx}
	\usepackage{graphicx} 

% ********************************************************************
% Setup the style of the backrefs from the bibliography
% (translate the options to any language you use)
% ********************************************************************
\newcommand{\backrefnotcitedstring}{\relax}%(Not cited.)
\newcommand{\backrefcitedsinglestring}[1]{(Cited on page~#1.)}
\newcommand{\backrefcitedmultistring}[1]{(Cited on pages~#1.)}
\ifthenelse{\boolean{enable-backrefs}}%
{%
		\PassOptionsToPackage{hyperpageref}{backref}
		\usepackage{backref} % to be loaded after hyperref package 
		   \renewcommand{\backreftwosep}{ and~} % separate 2 pages
		   \renewcommand{\backreflastsep}{, and~} % separate last of longer list
		   \renewcommand*{\backref}[1]{}  % disable standard
		   \renewcommand*{\backrefalt}[4]{% detailed backref
		      \ifcase #1 %
		         \backrefnotcitedstring%
		      \or%
		         \backrefcitedsinglestring{#2}%
		      \else%
		         \backrefcitedmultistring{#2}%
		      \fi}%
}{\relax}    

% ********************************************************************
% Hyperreferences
% ********************************************************************
\hypersetup{%
    %draft,	% = no hyperlinking at all (useful in b/w printouts)
    colorlinks=true, linktocpage=true, pdfstartpage=3, pdfstartview=FitV,%
    % uncomment the following line if you want to have black links (e.g., for printing)
    %colorlinks=false, linktocpage=false, pdfborder={0 0 0}, pdfstartpage=3, pdfstartview=FitV,% 
    breaklinks=true, pdfpagemode=UseNone, pageanchor=true, pdfpagemode=UseOutlines,%
    plainpages=false, bookmarksnumbered, bookmarksopen=true, bookmarksopenlevel=1,%
    hypertexnames=true, pdfhighlight=/O,%nesting=true,%frenchlinks,%
    urlcolor=RoyalBlue, linkcolor=RoyalBlue, citecolor=RoyalBlue, %pagecolor=RoyalBlue,%
    %urlcolor=Black, linkcolor=Black, citecolor=Black, %pagecolor=Black,%
    pdftitle={\myTitle},%
    pdfauthor={\textcopyright\ \myNameOne, \myNameTwo, \myDegree, \myDepartment, \mySchool, \myFaculty},%
    pdfsubject={},%
    pdfkeywords={}
}   

% ********************************************************************
% Setup autoreferences
% ********************************************************************
% There are some issues regarding autorefnames
% http://www.ureader.de/msg/136221647.aspx
% http://www.tex.ac.uk/cgi-bin/texfaq2html?label=latexwords
% you have to redefine the makros for the 
% language you use, e.g., american, ngerman
% (as chosen when loading babel/AtBeginDocument)
% ********************************************************************
\makeatletter
\@ifpackageloaded{babel}%
    {%
       \addto\extrasamerican{%
					\renewcommand*{\figureautorefname}{Figure}%
					\renewcommand*{\tableautorefname}{Table}%
					\renewcommand*{\partautorefname}{Part}%
					\renewcommand*{\chapterautorefname}{Chapter}%
					\renewcommand*{\sectionautorefname}{Section}%
					\renewcommand*{\subsectionautorefname}{Section}%
					\renewcommand*{\subsubsectionautorefname}{Section}% 	
				}%
			% Fix to getting autorefs for subfigures right (thanks to Belinda Vogt for changing the definition)
			\providecommand{\subfigureautorefname}{\figureautorefname}%  			
    }{\relax}
\makeatother

% ****************************************************************************************************
% 7. Last calls before the bar closes
% ****************************************************************************************************
% ********************************************************************
% Development Stuff
% ********************************************************************
\listfiles
%\PassOptionsToPackage{l2tabu,orthodox,abort}{nag}
%	\usepackage{nag}
%\PassOptionsToPackage{warning, all}{onlyamsmath}
%	\usepackage{onlyamsmath}


% ********************************************************************
% Last, but not least...
% ********************************************************************
\usepackage{classicthesis} 
% ****************************************************************************************************


\clearscrheadfoot
\ohead[]{\headmark}
\ofoot[\pagemark]{\pagemark}

% incluir PDFs
\usepackage{pdfpages}

% ****************************************************************************************************
% 8. Further adjustments (experimental)
% ****************************************************************************************************

\usepackage{setspace}

% recomendado por ser o mais próximo do word
\spacing{1.3}

% text justification
\usepackage[document]{ragged2e}


% ********************************************************************
% Changing the text area
% ********************************************************************
%\linespread{1.05} % a bit more for Palatino
%\areaset[current]{312pt}{761pt} % 686 (factor 2.2) + 33 head + 42 head \the\footskip
%\setlength{\marginparwidth}{7em}%
%\setlength{\marginparsep}{2em}%

% ********************************************************************
% Using different fonts
% ********************************************************************
%\usepackage[oldstylenums]{kpfonts} % oldstyle notextcomp
%\usepackage[osf]{libertine}
%\usepackage{hfoldsty} % Computer Modern with osf
%\usepackage[light,condensed,math]{iwona}
%\renewcommand{\sfdefault}{iwona}
\usepackage{lmodern} % <-- no osf support :-(
%\usepackage[urw-garamond]{mathdesign} <-- no osf support :-(
% ****************************************************************************************************

% \usepackage{inconsolata}

% \usepackage{caption,setspace}
% \captionsetup[lstlisting]{belowskip=0pt}
% \captionsetup[lstlisting]{belowcaptionskip=0pt}
% \captionsetup[lstinputlisting]{belowcaptionskip=0pt}
% \captionsetup[listing]{font={stretch=0.8}}


% o mint dá erro se pedirmos para imprimir o @
\newcommand{\at}{\makeatletter @\makeatother}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INÍCIO minted --- colorir código fonte
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[newfloat]{minted}	% package responsável pelo processamento

\SetupFloatingEnvironment{listing}{name={Listing}, within=none}
\captionsetup[listing]{position=above,skip=-3pt} % remover espaço vertical demasiado grande

% criar ambiente para listagem de código que ocupa mais de uma página.
\newenvironment{longlisting}{
        \bigskip\medskip
        \captionsetup{type=listing}
    }{
        \bigbreak
        \medskip
    }


% estilo pré-definido, fazer: pygmentize -L style para ver mais estilos
\usemintedstyle{autumn} 

% definir estilos
% 
% NOTA:
% 	para o kile reconhecer este estilo, tive de editar o ficheiro
% 	sudo vim /usr/share/kde4/apps/katepart/syntax/latex.xml
% 	e acrescentar: 
% 	<!-- mfrade -->
%         <StringDetect String="bashcode" attribute="Environment" context="MintedEnvParam"/>
% 
% 	e depois adicionar "|bashcode" sempre que aparecia "minted" no ficheiro, ex.
% 	<RegExpr String="\\end\s*\{(lstlisting|minted|bashcode)\*?\}"

\newmint{bash}{
  fontsize=\scriptsize,
  fontfamily=courier,
  linenos=false
}

\newminted{python}{
  frame=lines,
  framesep=2mm,
  fontsize=\scriptsize,
  fontfamily=courier,
  linenos=true,
  breaklines=true,
  breakanywhere=true,
}

\newminted{text}{
  frame=lines,
  framesep=2mm,
  fontsize=\scriptsize,
  fontfamily=courier,
  linenos=true,
  breaklines=true,
  breakanywhere=true,
}

\newminted{sql}{
  frame=lines,
  framesep=2mm,
  fontsize=\scriptsize,
  fontfamily=courier,
  linenos=true,
  breaklines=true,
  breakanywhere=true,
}

\newminted{html}{
  frame=lines,
  framesep=2mm,
  fontsize=\scriptsize,
  fontfamily=courier,
  linenos=true,
  breaklines=true,
  breakanywhere=true,
}

\newminted{json}{
  frame=lines,
  framesep=2mm,
  fontsize=\scriptsize,
  fontfamily=courier,
  linenos=true,
  breaklines=true,
  breakanywhere=true,
}

\newmintedfile[codefilec]{c}{
  frame=lines,
  framesep=2mm,
  fontsize=\scriptsize,
  fontfamily=courier,
  linenos=true,
  breaklines=true,
  breakanywhere=true,
}

\newmintedfile[codefilebash]{bash}{
  frame=lines,
  framesep=2mm,
  fontsize=\scriptsize,
  fontfamily=courier,
  linenos=true,
  breaklines=true,
  breakanywhere=true,
}

\newminted{yaml}{
  frame=lines,
  framesep=2mm,
  fontsize=\scriptsize,
  fontfamily=courier,
  linenos=true,
  breaklines=true,
  breakanywhere=true,
}

% \newmintinline[code]{text}{fontsize=\footnotesize,fontfamily=courier}
\newmintinline[code]{text}{fontsize=\footnotesize,fontfamily=tt}

% mudar o aspeto da numeração
\renewcommand{\theFancyVerbLine}{\tiny\ttfamily%
  \textcolor[rgb]{0.7,0.7,0.7}{\arabic{FancyVerbLine}}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FIM --- minted
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% controlar o tamanho das margens
% \usepackage{showframe}
\marginparwidth=0pt
\marginparsep=5pt
\addtolength{\evensidemargin}{-15mm}
\addtolength{\textwidth}{20mm}

% espaçamento entre parágrafos
\setlength{\parskip}{0.5em}

% obter o símbolo do Euro
\usepackage{eurosym}
\DeclareUnicodeCharacter{20AC}{\euro} % aceita o símbolo do teclado
% usar a vírgula como separador decimal
\usepackage{icomma}

% 
% tem de ser carregada depois do hyperref
% 
\PassOptionsToPackage{xindy,style=super,nolist}{glossaries}
\PassOptionsToPackage{acronym}{glossaries}
\PassOptionsToPackage{nonumberlist}{glossaries}
\usepackage{glossaries}


% avoid numbering empty pages
\usepackage{emptypage}


% permite quebrar a 1ª coluna
\newglossarystyle{clong}{%
 \renewenvironment{theglossary}%
%      {\begin{longtable}{p{.2\linewidth}p{\glsdescwidth}}}%
     {\begin{longtable}{p{.18\linewidth}p{.78\linewidth}}}%
     {\end{longtable}}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupheading}[1]{}%
  \renewcommand*{\glossaryentryfield}[5]{%
    \glstarget{##1}{##2} & ##3\glspostdescription\space ##5\\}%
  \renewcommand*{\glossarysubentryfield}[6]{%
     & \glstarget{##2}{\strut}##4\glspostdescription\space ##6\\}%
  %\renewcommand*{\glsgroupskip}{ & \\}%
}
