\definecolor{TitleColor}{rgb}{0,0,0}
\definecolor{InnerLinkColor}{rgb}{0,0,0}
\definecolor{OuterLinkColor}{rgb}{1.0,0.5,0.0}

\newenvironment{underscoresplit}{\let\underscore\_
  \renewcommand{\_}{\discretionary{\underscore}{}{\underscore}}}{}

\let\oldtabulary\tabulary
\let\endoldtabulary\endtabulary

\renewenvironment{tabulary}{\underscoresplit\oldtabulary}{\endoldtabulary\endunderscoresplit}

\let\oldprintindex\printindex

\renewenvironment{printindex}{\underscoresplit\oldprintindex}

\usepackage{minted}
\fvset{
breaklines=true,
breakanywhere=true,
linenos,
numbersep=5pt,
gobble=0,
}

\renewcommand{\maketitle}{%
  \let\spx@tempa\relax
  \ifHy@pageanchor\def\spx@tempa{\Hy@pageanchortrue}\fi
  \hypersetup{pageanchor=false}% avoid duplicate destination warnings
  \begin{titlepage}%
    \let\footnotesize\small
    \let\footnoterule\relax
    \par
      \begingroup % for PDF information dictionary
       \def\endgraf{ }\def\and{\& }%
       \pdfstringdefDisableCommands{\def\\{, }}% overwrite hyperref setup
       \hypersetup{pdfauthor={\@author}, pdftitle={\@title}}%
      \endgroup
    \begin{center}{%
      \vspace*{3cm}
      \includegraphics{logo.pdf}
      \vspace{3cm}
      \par
      {\rm\Huge \@title \par}%
      {\em\LARGE \py@release\releaseinfo \par}
      {\large
       \copyright Copyright \rtemscopyright \par
       \py@authoraddress \par
      }%
    }%
    \end{center}%\par
    \@thanks
  \end{titlepage}%
  \setcounter{footnote}{0}%
  \let\thanks\relax\let\maketitle\relax
  %\gdef\@thanks{}\gdef\@author{}\gdef\@title{}
  \if@openright\cleardoublepage\else\clearpage\fi
  \spx@tempa
}

\fancypagestyle{normal}{
  \fancyhf{}
  \fancyfoot[LE,RO]{{\thepage}}
  \fancyfoot[LO]{{\ifnum\value{chapter}>0{\nouppercase{\rightmark}}\fi}}
  \fancyfoot[RE]{{\nouppercase{\leftmark}}}
  \fancyhead[LE,RO]{{\@title, \py@release}}
  \fancyhead[RE,LO]{{\ifnum\value{chapter}>0{\chaptername\:\thechapter\:Section\:\thesection}\fi}}
  \renewcommand{\headrulewidth}{0.4pt}
  \renewcommand{\footrulewidth}{0.4pt}
}

\fancypagestyle{plain}{
  \fancyhf{}
  \fancyfoot[LE,RO]{{\thepage}}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0.4pt}
}

\titleformat{\section}{\Large}%
            {\py@TitleColor\thesection}{0.5em}{\py@TitleColor}{\py@NormalColor}
\titleformat{\subsection}{\large}%
            {\py@TitleColor\thesubsection}{0.5em}{\py@TitleColor}{\py@NormalColor}
\titleformat{\subsubsection}{}%
            {\py@TitleColor\thesubsubsection}{0.5em}{\py@TitleColor}{\py@NormalColor}
\titleformat{\paragraph}{\large}%
            {\py@TitleColor}{0em}{\py@TitleColor}{\py@NormalColor}

\ChNameVar{\raggedleft\normalsize}
\ChNumVar{\raggedleft \bfseries\Large}
\ChTitleVar{\raggedleft \rm\Huge}

\usepackage{enumitem}
\setlist[description]{style=nextline,leftmargin=10pt}

\let\oldsection\section
\renewcommand\section{\clearpage\oldsection}

\usepackage{titlesec}
\setcounter{secnumdepth}{8}

\renewcommand\thepart{\@Roman\c@part}
\renewcommand\part{%
   \pagestyle{normal}
   \if@noskipsec \leavevmode \fi
   \cleardoublepage
   \vspace*{6cm}%
   \@afterindentfalse
   \secdef\@part\@spart}

% fonts
\usepackage{charter}
\usepackage{rtemsextrafonts}
