\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{kinote}[2019/10/16 Kinote clean style template]

\RequirePackage{lmodern}

\newif\ifshowlogos
\DeclareOption{logos}{\showlogostrue}
\DeclareOption{nologos}{\showlogosfalse}

\ExecuteOptions{logos}

\newif\ifshowconfidential
\DeclareOption{confidential}{\showconfidentialtrue}
\DeclareOption{noconfidential}{\showconfidentialfalse}

\ExecuteOptions{noconfidential}

\newif\ifshowsectionbreak
\DeclareOption{sectionbreak}{\showsectionbreaktrue}
\DeclareOption{nosectionbreak}{\showsectionbreakfalse}

\ExecuteOptions{nosectionbreak}

\DeclareOption*{%
  \PackageWarning{\@currname}{Unknown option: \CurrentOption}%
}

\ProcessOptions\relax

%\usepackage{pygments-docutilsroles}
\usepackage{pdftexcmds}
%\usepackage{boolexpr}
\usepackage{indentfirst}
\@ifpackageloaded{xcolor}{
  \PassOptionsToPackage{usenames,dvipsnames,svgnames,table,x11names}{xcolor}
}{
  \usepackage[usenames,dvipsnames,svgnames,table,x11names]{xcolor}
}
%\PassOptionsToPackage{nobottomtitles*}{titlesec}
\usepackage[nobottomtitles*]{titlesec}

\titleformat{\paragraph}[hang]{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{0pt}

\usepackage[a4paper]{geometry}
\geometry{
  %top=0cm,
  bottom=3cm,
  left=2cm,
  right=2cm,
  headheight=2cm,
  %includehead,
  %includefoot,
  %heightrounded, % to avoid spurious underfull messages
}
%\usepackage{parskip}
\usepackage{graphicx,grffile}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{changepage}

\usepackage[open=true]{bookmark}

\usepackage[shortlabels]{enumitem}
\PassOptionsToPackage{shortlabels}{enumitem}
\setlist{nosep}

%\usepackage[no-sscript]{xltxtra} % loads fixltx2e, metalogo, xunicode, fontspec
%\setmainfont{Linux Libertine O}
%\setsansfont{Linux Biolinum O}
%\setmonofont[HyphenChar=None,Scale=MatchLowercase]{DejaVu Sans Mono}

\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  %\usepackage{tgpagella}
  \usepackage[sfdefault]{AlegreyaSans}
  %\usepackage[default]{cantarell}
  %\usepackage[sfdefault]{overlock}
  \usepackage{inconsolata}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
  \else
    \usepackage{fontspec}
  \fi
  \setmainfont{Alegreya Sans}
  \setmonofont{Inconsolata}
\fi

%\long\def\isequal#1#2{\pdfstrcmp{#1}{#2}}
%
%\newcommand\DUrole[2]{%
%  \switch%
%  \case{\isequal{#1}{error}}\DUroleerr{#2}%
%  \case{\isequal{#1}{tag}}\DUrolent{#2}%
%  \case{\isequal{#1}{operator}}\DUroleo{#2}%
%  \case{\isequal{#1}{comment}}\DUrolec{#2}%
%  \case{\isequal{#1}{preproc}}\DUrolecp{#2}%
%  \case{\isequal{#1}{keyword}}\DUrolek{#2}%
%  \case{\isequal{#1}{class}}\DUrolenc{#2}%
%  \case{\isequal{#1}{function}}\DUrolenf{#2}%
%  \case{\isequal{#1}{pseudo}}\DUrolebp{#2}%
%  \case{\isequal{#1}{number}}\DUrolem{#2}%
%  \case{\isequal{#1}{string}}\DUroles{#2}%
%  \otherwise\footnotesize #2%
%  \endswitch%
%}


% for adjustwidth environment
%\usepackage[strict]{changepage}

\usepackage{kinote-frames}

%\usepackage{fancyhdr}
%\fancyhead[L]{Test}%\DUheader}
%\fancyfoot{} % reset
%\fancyfoot[L]{Test2}%\DUfooter}
%\pagestyle{fancy}

\setcounter{secnumdepth}{2}

\setlength{\parindent}{0pt}
\setlength{\parskip}{0.5em}

% Evitar que se corten demasiado las palabras.
\hyphenpenalty=5000
\tolerance=1000

\let\origdescription\description
\renewenvironment{description}{
  \setlength{\labelsep}{\textwidth}
  \origdescription
}
{\endlist}

\let\oldtitle\title
\renewcommand{\title}[1]{\oldtitle{#1}\def\titletext{#1}}
\def\titletext{}

\let\olddate\date
\renewcommand{\date}[1]{\olddate{#1}\def\datetext{#1}}
\def\datetext{}

\let\oldauthor\author
\renewcommand{\author}[1]{\oldauthor{#1}\def\authortext{#1}}
\def\authortext{}

%\renewcommand{\maketitle}{
%  %\thispagestyle{empty}
%  %\begin{titlepage}
%  %  \thispagestyle{fancy}
%  %  \vspace*{\fill}
%  %  \begin{center}
%  %    \huge{\textbf{\titletext}}\\
%  %  \end{center}
%  %  \vspace*{\fill}
%  %\end{titlepage}
%  \begin{center}
%    \huge{\textbf{\titletext}}
%    %\vspace{1em}
%  \end{center}

\renewcommand{\maketitle}{
  %\thispagestyle{empty}
  %\begin{titlepage}
  %  \thispagestyle{fancy}
  %  \vspace*{\fill}
  %  \begin{center}
  %    \huge{\textbf{\titletext}}\\
  %  \end{center}
  %  \vspace*{\fill}
  %\end{titlepage}
  \begin{center}
    {
      \LARGE
      \vspace*{1em}
      \@title\\
      \vspace{1em}
    }
    \ifx\authortext\@empty%
    \else%
    {%
      \large
      \lineskip .75em%
      \begin{tabular}[t]{c}%
        \authortext
      \end{tabular}\par%
    }%
    \fi
    {\large\datetext}
    \vspace*{2em}
  \end{center}
}

\newcommand{\project}[1]{\def\projecttext{#1}}
\def\projecttext{\@empty}

\newcommand{\revision}[1]{\def\revisiontext{#1}}
\def\revisiontext{\@empty}

\newcommand{\file}[1]{\def\filetext{#1}}
\def\filetext{\@empty}

\newcommand{\approved}[1]{\def\approvedtext{#1}}
\def\approvedtext{\@empty}

\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{}
\ifshowlogos
  \rhead{%
    % fix org-mode subtitle style
    \renewcommand{\large}{\mdseries}%
    \renewcommand{\medskip}{}%
    % show title
    {\bfseries\titletext}%
  }
\else
  \rhead{}
\fi
%%%\rhead{%
%%%  \parbox[b][30mm][t]{0.85\textwidth}{
%%%    \vspace*{7mm}
%%%    \fontsize{7pt}{8pt}
%%%    \sffamily
%%%    \begin{flushright}CONFIDENTIAL\\\textbf{DOCUMENTACIÓN DE PROYECTO}\end{flushright}%
%%%    \renewcommand{\arraystretch}{1.2}
%%%    \newcolumntype{Y}{>{\raggedright\arraybackslash}X}
%%%    \noindent\begin{tabularx}{0.85\textwidth}{| l | l | l | Y |}
%%%    \hline
%%%    \emph{Preparado por / Prepared by} & \multicolumn{2}{l|}{\emph{No. / Num.}}    & \emph{Pág. Page}\\
%%%    \textbf{\authortext}               & \multicolumn{2}{l}{\textbf{\projecttext}} & \textbf{\thepage ~/ \pageref*{LastPage}}\\
%%%    \hline
%%%    \emph{Aprobado por / Approved by} & \emph{Fecha / Date}                    & \emph{Rev. / Rev.}               & \emph{Archivo / File}\\
%%%    \textbf{\approvedtext}            & \multicolumn{1}{c}{\textbf{\datetext}} & \multicolumn{1}{c}{\textbf{\revisiontext}} & \textbf{\filetext} \\
%%%    \hline
%%%    \end{tabularx}
%%%  }
%%%}
\ifshowconfidential
  \lfoot{\small STRICTLY CONFIDENTIAL}
\else
  \lfoot{}
\fi
\cfoot{\small\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

%\definecolor{linkcolor}{RGB}{6,59,153}
%\definecolor{linkcolor}{HTML}{009534}
\colorlet{linkcolor}{kinote}
\hypersetup{
  colorlinks=true,
  linkcolor=linkcolor,
  urlcolor=linkcolor,
  filecolor=linkcolor,
  linkbordercolor=linkcolor,
  filebordercolor=linkcolor,
  urlbordercolor=linkcolor
}

%\makeatletter
%\Hy@AtBeginDocument{%
%  \def\@pdfborder{0 0 1}% Overrides border definition set with colorlinks=true
%  \def\@pdfborderstyle{/S/U/W 1}% Overrides border style set with colorlinks=true
%                                % Hyperlink border style will be underline of width 1pt
%}
%\makeatother

\setcounter{tocdepth}{1}

% Remove color from links in table of contents
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
  \begingroup%
  \hypersetup{hidelinks}%
  \oldtableofcontents%
  \endgroup%
}

\usepackage{caption}
\captionsetup[figure]{name=,labelformat=empty}

\usepackage{makeidx}
\makeindex

\ifshowsectionbreak
  \newcommand{\sectionbreak}{\clearpage}
\fi

\usepackage[section]{placeins}
\makeatletter
\AtBeginDocument{%
  %\expandafter\renewcommand\expandafter\section\expandafter
  %  {\expandafter\@fb@secFB\ubsection}%
  %\newcommand\@fb@secFB{\FloatBarrier
  %  \gdef\@fb@afterHHook{\@fb@topbarrier \gdef\@fb@afterHHook{}}}%
  %\g@addto@macro\@afterheading{\@fb@afterHHook}%
  %\gdef\@fb@afterHHook{}%

  \expandafter\renewcommand\expandafter\subsection\expandafter{%
    \expandafter\@fb@secFB\subsection
  }%

  %\expandafter\renewcommand\expandafter\subsection\expandafter
  %  {\expandafter\@fb@secFB\subsection}%
  %\newcommand\@fb@secFB{\FloatBarrier
  %  \gdef\@fb@afterHHook{\@fb@topbarrier \gdef\@fb@afterHHook{}}}%
  %\g@addto@macro\@afterheading{\@fb@afterHHook}%
  %\gdef\@fb@afterHHook{}%
}
\makeatother

%\usepackage{needspace}
%\usepackage{xpatch}
%\xpretocmd{\section}{\needspace{6\baselineskip}}{}{}

\endinput
