% Layout and Pagraph Format for Unified Process Methodology
%
% Copyright (c) 2006-2009, 2012-2025 Stephane GALLAND <galland@arakhne.org>
% 
% This program is free library; you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as
% published by the Free Software Foundation; either version 3 of the
% License, or any later version.
%
% This library is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this library; see the file COPYING.  If not,
% write to the Free Software Foundation, Inc., 59 Temple Place - Suite
% 330, Boston, MA 02111-1307, USA.

\global\edef\upm@package@fmt@ver{2025/03/23}

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{upmethodology-fmt}[\upm@package@fmt@ver]

\RequirePackage{upmethodology-p-common}

\gdef\upm@fmt@force@single@spacing#1{{\begin{singlespace}#1\end{singlespace}}}
\gdef\upm@date@head#1/#2\@nil{#1}
\gdef\upm@date@tail#1/#2\@nil{#2}
\gdef\upm@date@first#1{{\expandafter\upm@date@head#1\expandafter\@nil}}
\gdef\upm@date@second#1{{\expandafter\expandafter\expandafter\upm@date@head\expandafter\upm@date@tail#1\expandafter\@nil\expandafter\expandafter\expandafter\@nil}}
\gdef\upm@date@third#1{{\expandafter\expandafter\expandafter\upm@date@tail\expandafter\upm@date@tail#1\expandafter\@nil\expandafter\expandafter\expandafter\@nil}}

\newif\ifupm@use@override@standard@lists
\global\upm@use@override@standard@liststrue

%----------------------------------------
% LOCALES
%----------------------------------------
\global\let\upm@format@lang@extractyear\upm@date@first%
\def\upm@format@lang@english{%
  \gdef\upm@lang@@{\message{**** upmethodology-fmt is using English language ****}}%
  \global\renewcommand{\upm@format@lang@makedate}[3]{##3\string/\two@digits{##2}\string/\two@digits{##1}}%
  \global\let\upm@format@lang@extractyear\upm@date@first%
  \global\let\upm@format@lang@extractmonth\upm@date@second%
  \gdef\upm@format@lang@professor{Pr.}%
  \gdef\upm@format@lang@doctor{Dr.}%
  \gdef\upm@format@lang@phdoctor{Ph.D.}%
  \gdef\upm@format@lang@scdoctor{Sc.D.}%
  \gdef\upm@format@lang@mdoctor{M.D.}%
  \gdef\upm@format@lang@professionalengineer{CEng.}%
  \gdef\upm@format@lang@incorporatedengineer{IEng.}%
  \gdef\upm@format@lang@listofalgorithms{List of Algorithms}%
  \gdef\upm@format@lang@listoffigures{List of Figures}%
  \gdef\upm@format@lang@sourcename{Source}%
  \gdef\upm@format@lang@colonchar{:\xspace}%
}
\def\upm@format@lang@french{%
  \gdef\upm@lang@@{\message{**** upmethodology-fmt is using French language ****}}%
  \global\renewcommand{\upm@format@lang@makedate}[3]{\two@digits{##1}\string/\two@digits{##2}\string/##3}%
  \global\let\upm@format@lang@extractyear\upm@date@third%
  \global\let\upm@format@lang@extractmonth\upm@date@second%
  \global\let\upm@format@lang@extractday\upm@date@first%
  \gdef\upm@format@lang@professor{Pr.}%
  \gdef\upm@format@lang@doctor{Dr.}%
  \gdef\upm@format@lang@phdoctor{Ph.D.}%
  \gdef\upm@format@lang@scdoctor{Sc.D.}%
  \gdef\upm@format@lang@mdoctor{M.D.}%
  \gdef\upm@format@lang@professionalengineer{Ing.}%
  \gdef\upm@format@lang@incorporatedengineer{Ing.}%
  \gdef\upm@format@lang@listofalgorithms{Liste des algorithmes}%
  \gdef\upm@format@lang@listoffigures{Liste des figures}%
  \gdef\upm@format@lang@sourcename{Source}%
  \gdef\upm@format@lang@colonchar{\;:\xspace}%
}
\global\providecommand{\upm@format@lang@makedate}[3]{}%

%----------------------------------------
% OPTIONS
%----------------------------------------
\DeclareOption{french}{%
  \upm@format@lang@french
  \PassOptionsToPackage{french}{varioref}
}
\DeclareOption{francais}{%
  \upm@format@lang@french
  \PassOptionsToPackage{french}{varioref}
}
\DeclareOption{english}{%
  \upm@format@lang@english
  \PassOptionsToPackage{english}{varioref}
}
\DeclareOption{standardlists}{%
  \global\upm@use@override@standard@listsfalse
}
\ExecuteOptions{english}
\ProcessOptions
\upm@lang@@


\RequirePackage[explicit,calcwidth]{titlesec}
\RequirePackage{graphicx}
\RequirePackage{subcaption}
\RequirePackage{tabularx}
\RequirePackage{multicol}
\RequirePackage{colortbl}
\RequirePackage{tcolorbox}
\RequirePackage{picinpar}
\RequirePackage{amsmath}
\RequirePackage{amsthm}
\RequirePackage{thmtools}
\RequirePackage{pifont}
\RequirePackage{setspace}
\RequirePackage{varioref}
\RequirePackage{txfonts}
\RequirePackage{relsize}
\RequirePackage{xkeyval}
\RequirePackage{hyphenat}
\RequirePackage{bbm}
\RequirePackage{environ}% for advanced environment declaration
\RequirePackage{xcolor}
\RequirePackage{tikz}
\RequirePackage{fontawesome5}
\RequirePackage{tocbibind} % To automatically the common "Listof" in the outline


%----------------------------------------
% Exponent and indice
%----------------------------------------
% Exponent
%\newcommand{\textsup}[1]{\ensuremath{^{\text{#1}}}\xspace}
\newcommand{\textsup}[1]{\upm@textsuperscript{#1}\xspace}
% Indice
%\newcommand{\textsub}[1]{\ensuremath{_{\text{#1}}}\xspace}
\newcommand{\textsub}[1]{\upm@textsubscript{#1}\xspace}

%----------------------------------------
% Major Emphazing
%----------------------------------------
\newcommand{\Emph}[1]{\textbf{#1}\xspace}

%----------------------------------------
% SYMBOLS
%----------------------------------------
\renewcommand{\copyright}{\Pisymbol{psy}{211}\xspace}
\newcommand{\trademark}{\Pisymbol{psy}{228}\xspace}
\newcommand{\regmark}{\Pisymbol{psy}{226}\xspace}
\newcommand{\smalltrade}{{\tiny\trademark}\xspace}
\newcommand{\smallreg}{{\tiny\regmark}\xspace}
\newcommand{\smallcopy}{{\tiny\copyright}\xspace}
\newcommand{\ust}{\textsup{st}}
\newcommand{\und}{\textsup{nd}}
\newcommand{\urd}{\textsup{rd}}
\newcommand{\uth}{\textsup{th}}

%----------------------------------------
% MATH SYMBOLS
%----------------------------------------
\newcommand{\R}{\ensuremath{\mathbb{R}}}
\newcommand{\N}{\ensuremath{\mathbb{N}}}
\newcommand{\Z}{\ensuremath{\mathbb{Z}}}
\newcommand{\C}{\ensuremath{\mathbb{C}}}
\newcommand{\Q}{\ensuremath{\mathbb{Q}}}
\newcommand{\powerset}{\ensuremath{\mathcal{P}}}

\DeclareMathOperator{\sgn}{sgn}

%----------------------------------------
% DEFAULT GRAPHICX CONFIGURATION
%----------------------------------------

\ifpdf
  \DeclareGraphicsExtensions{.pdf,.png,.jpg,.jpeg,.gif}
\else
  \DeclareGraphicsExtensions{.eps,.png,.jpg,.jpeg,.gif}
\fi
\graphicspath{{./}}

%-----------------------------------------
% LOCAL DEFINITION OF TH GRAPHICS PATH
%-----------------------------------------

\newenvironment{graphicspathcontext}[1]{%
	\bgroup%
	\let\upm@tmp@graphicspathcontext@ginputpath\Ginput@path%
	\def\old{\upm@tmp@graphicspathcontext@ginputpath}%
	\protected@edef\upm@tmp@graphicspathcontext@tmp{\protect\graphicspath{#1}}%
	\upm@tmp@graphicspathcontext@tmp%
}{%
	\egroup%
}

%----------------------------------------
% FIGURES
%----------------------------------------

\colorlet{figuresourceforeground}{gray}
\global\let\figuresourcename\upm@format@lang@sourcename
\newcommand{\mfigureformatsource}[1]{%
    \centering\textcolor{figuresourceforeground}{\smaller\textit{#1}}%
}%
\newcommand{\upm@mfigure@formatsource}[1]{%
    \\ \mfigureformatsource{\figuresourcename\upm@format@lang@colonchar{#1}}%
}
\newcommand{\upm@mfigure@internal@}[7]{%
    \begin{#7}[#1]%
        \begin{center}%
            \protect\includegraphics[#2]{#3}%
            \protect\caption{#4#6}%
            \protect\label{fig:#5}%
        \end{center}%
    \end{#7}%
}

\newcommand{\upm@mfigure@internal}{%
    \protected@edef\upm@tmp{
        \protect\upm@mfigure@internal@%
        {\upm@mfigure@arga}%
        {\upm@mfigure@argb}%
        {\upm@mfigure@argc}%
        {\upm@mfigure@argd}%
        {\upm@mfigure@arge}%
        {\upm@mfigure@argf}%
        {figure}%
    }%
    \upm@tmp%
}
\gdef\upm@mfigure@sourcetext@reader[#1]{%
    \gdef\upm@mfigure@argf{\upm@mfigure@formatsource{#1}}\upm@mfigure@internal%
}
\newcommand{\upm@mfigure}[5][ht]{%
    \gdef\upm@mfigure@arga{#1}%
    \gdef\upm@mfigure@argb{#2}%
    \gdef\upm@mfigure@argc{#3}%
    \gdef\upm@mfigure@argd{#4}%
    \gdef\upm@mfigure@arge{#5}%
    \global\let\upm@mfigure@argf\@empty%
    \@ifnextchar[%
        \upm@mfigure@sourcetext@reader%
        \upm@mfigure@internal%
}

\newcommand{\upm@mfigurestar@internal}{%
    \protected@edef\upm@tmp{
        \protect\upm@mfigure@internal@%
        {\upm@mfigure@arga}%
        {\upm@mfigure@argb}%
        {\upm@mfigure@argc}%
        {\protect\upm@mfigure@argd}%
        {\upm@mfigure@arge}%
        {\protect\upm@mfigure@argf}%
        {figure*}%
    }%
    \upm@tmp%
}
\gdef\upm@mfigurestar@sourcetext@reader[#1]{%
    \gdef\upm@mfigure@argf{\upm@mfigure@formatsource{#1}}\upm@mfigurestar@internal%
}
\newcommand{\upm@mfigurestar}[5][ht]{%
    \gdef\upm@mfigure@arga{#1}%
    \gdef\upm@mfigure@argb{#2}%
    \gdef\upm@mfigure@argc{#3}%
    \gdef\upm@mfigure@argd{#4}%
    \gdef\upm@mfigure@arge{#5}%
    \global\let\upm@mfigure@argf\@empty%
    \@ifnextchar[%
        \upm@mfigurestar@sourcetext@reader%
        \upm@mfigurestar@internal%
}
%-----
%\mfigure[position]{options}{filename}{caption}{label}[source]
\def\mfigure{\@ifstar\upm@mfigurestar\upm@mfigure}
%-----
%\figref{label}
\newcommand{\figref}[1]{\ref{fig:#1}}
%-----
%\figpageref{label}
\newcommand{\figpageref}[1]{\pageref{fig:#1}}

%-----
% Multi-figures

\newcounter{upm@subfigure@count}

\newcommand{\upm@beginsubfigure}[4]{%
	\let\upm@mfiguresaved\mfigure%
	%options,filename,caption,label
	\renewcommand{\mfigure}[5][]{%
		\xdef\upm@tmp@subfigure@label{\alph{upm@subfigure@count}}%
		\subcaptionbox{##4%
			\label{fig:##5}%
			\label{fig:#4:\upm@tmp@subfigure@label}%
		}{\includegraphics[##2]{##3}}%
		\addtocounter{upm@subfigure@count}{1}%
	}
	%options,filename,caption
	\newcommand{\msubfigure}[3]{%
		\xdef\upm@tmp@subfigure@label{\alph{upm@subfigure@count}}%
		\subcaptionbox{##3%
			\label{fig:#4:\upm@tmp@subfigure@label}%
		}{\includegraphics[##1]{##2}}%
		\addtocounter{upm@subfigure@count}{1}%
	}
	\setcounter{upm@subfigure@count}{1}%
	\gdef\upm@mfigurescaption{#3}%
	\gdef\upm@mfigureslabel{fig:#4}%
	\begin{#1}[#2]\centering %
	\begingroup%
}

\newcommand{\upm@endsubfigure}[1]{%
	\endgroup%
	\caption{\upm@mfigurescaption}%
	\label{\upm@mfigureslabel}%
	\end{#1}%
	\let\mfigure\upm@mfiguresaved
}

%-----
%\mfigures[position]{caption}{label}
\newenvironment{mfigures}[3][ht]{
	\upm@beginsubfigure{figure}{#1}{#2}{#3}%
}{%
	\upm@endsubfigure{figure}%
}
%-----
%\mfigures*[position]{caption}{label}
\newenvironment{mfigures*}[3][ht]{
	\upm@beginsubfigure{figure*}{#1}{#2}{#3}%
}{%
	\upm@endsubfigure{figure*}%
}

%----------------------------------------
% IMAGES INCLUDING TeX EXPRESSIONS
%----------------------------------------

%
% This section is copied from the AutoLaTeX package
% http://www.arakhne.org/autolatex
%

%-----
%\DeclareGraphicsExtensionsWtex{coma separated extensions}
\providecommand{\DeclareGraphicsExtensionsWtex}[1]{%
	\xdef\@autolatex@wtfig@extensions{\zap@space#1 \@empty}%
}
\ifpdf
   \DeclareGraphicsExtensionsWtex{.pdftex_t,.pdf_tex}
\else
  \DeclareGraphicsExtensionsWtex{.pstex_t,.ps_tex}
\fi

\providecommand{\@autolatex@wtfig@searchinpath}[1]{%
	\IfFileExists{#1}{%
		\protected@edef\@autolatex@wtfig@tmp{\protect\resizebox{\@autolatex@wtfig@width}{\@autolatex@wtfig@height}{\protect\input{#1}}}%
	}{%
		\@for\@autolatex@wtfig@pathtmp:=\Ginput@path\do{%
			\ifx\@autolatex@wtfig@tmp\relax%
				\IfFileExists{\@autolatex@wtfig@pathtmp#1}{%
					\protected@edef\@autolatex@wtfig@tmp{\protect\resizebox{\@autolatex@wtfig@width}{\@autolatex@wtfig@height}{\protect\input{\@autolatex@wtfig@pathtmp#1}}}%
				}{}%
			\fi%
		}%
	}%
}

\define@key[autolatex]{withtex}{width}{%
	\gdef\@autolatex@wtfig@width{#1}%
}
\define@key[autolatex]{withtex}{height}{%
	\gdef\@autolatex@wtfig@height{#1}%
}

%-----
%\includefigurewtex[width=xx,height=yy]{filename}
\providecommand{\includefigurewtex}[2][width=\linewidth]{%
	\begingroup%
	\gdef\@autolatex@wtfig@width{!}%
	\gdef\@autolatex@wtfig@height{!}%
	\setkeys[autolatex]{withtex}{#1}%
	%
	\global\let\@autolatex@wtfig@tmp\relax%
	\global\let\@autolatex@wtfig@ext\relax%
	\global\let\@autolatex@wtfig@path\relax%
	\filename@parse{#2}%
	\ifx\filename@ext\relax%
		\@for\@autolatex@wtfig@exttmp:=\@autolatex@wtfig@extensions\do{%
			\@autolatex@wtfig@searchinpath{#2\@autolatex@wtfig@exttmp}%
		}%
	\else%
		\@autolatex@wtfig@searchinpath{#2\@autolatex@wtfig@exttmp}%
	\fi%
	%
	\ifx\@autolatex@wtfig@tmp\relax%
		\errmessage{Package upmethodology-fmt: File not found '#2', needed for figure inclusion}%
	\else%
		\@autolatex@wtfig@tmp%
	\fi%
	%
	\endgroup%
}

\global\let\includegraphicswtex\includefigurewtex

%----------------------------------------
% ENVIRONMENT FOR IMAGES INCLUDING TeX EXPRESSIONS
%----------------------------------------

\gdef\upm@figtex@dyncaption@remove{}
\gdef\upm@figtex@figremove#1{%
	\global\expandafter\let\csname FIG#1\endcsname\relax%
}
\gdef\upm@figtex@restore{%
	\upm@figtex@dyncaption@remove%
	\gdef\upm@figtex@dyncaption@remove{}
}
%-----
%\figmath{id}{content}
\def\figmath#1#2{%
	\expandafter\gdef\csname FIG#1\endcsname{\ensuremath{#2}}%
	\global\protected@edef\upm@figtex@dyncaption@remove{\upm@figtex@dyncaption@remove\protect\upm@figtex@figremove{#1}}%
}
%-----
%\figtext{id}{content}
\def\figtext#1#2{%
	\expandafter\gdef\csname FIG#1\endcsname{#2}%
	\global\protected@edef\upm@figtex@dyncaption@remove{\upm@figtex@dyncaption@remove\protect\upm@figtex@figremove{#1}}%
}

\let\upm@fmt@figtex@nil\@nil
\def\upm@fmt@figtex@parseparams#1=#2\upm@fmt@figtex@nil{\gdef\@tmp{#2}}

\newcommand{\upm@mfigurewtex}[5][ht]{
	\begin{figure}[#1]%
		\begin{center}%
			% Providing an ascendent compatibility on the second parameter:
			% - Prefered value of the parameter: a list of key/value pairs;
			% - Old fashion value of the parameter: the value for the "width" key.
			{\upm@fmt@figtex@parseparams #2====\upm@fmt@figtex@nil}%
			\ifthenelse{\equal{\@tmp}{===}}{%
				\includegraphicswtex[width=#2]{#3}%
			}{%
				\includegraphicswtex[#2]{#3}%
			}%
			\caption{#4}%
			\label{fig:#5}%
		\end{center}%
	\end{figure}%
	\upm@figtex@restore%
}
\newcommand{\upm@mfigurewtexstar}[5][ht]{
	\begin{figure*}[#1]%
		\begin{center}%
			% Providing an ascendent compatibility on the second parameter:
			% - Prefered value of the parameter: a list of key/value pairs;
			% - Old fashion value of the parameter: the value for the "width" key.
			{\upm@fmt@figtex@parseparams #2====\upm@fmt@figtex@nil}%
			\ifthenelse{\equal{\@tmp}{===}}{%
				\includegraphicswtex[width=#2]{#3}%
			}{%
				\includegraphicswtex[#2]{#3}%
			}%
			\caption{#4}%
			\label{fig:#5}%
		\end{center}%
	\end{figure*}%
	\upm@figtex@restore%
}
%-----
%\mfigurewtex[position]{options}{filename}{caption}{label}
\def\mfigurewtex{\@ifstar\upm@mfigurewtexstar\upm@mfigurewtex}



%----------------------------------------
% TABLES
%----------------------------------------

%table's colors
\definecolor{tableheaderbackground}{rgb}{0.92,0.94,1}
\definecolor{tableheaderforeground}{rgb}{0.23,0.33,0.48}
\colorlet{tablebackground}{white}
\colorlet{tableforeground}{black}
\colorlet{tablerule}{tableheaderbackground}

\AtBeginDocument{%
    \arrayrulecolor{tablerule}%
}

\tcbset{
	mtabular/.style={
		attach title,
            colbacktitle=tableheaderbackground,
            coltitle=tableheaderforeground,
		colback=tablebackground,
		colframe=tablerule,
		coltext=tableforeground,
		rounded corners,
		before upper=\tcbtitle,
		fonttitle=\bfseries,
		halign title=center,
        }
}

%title of a table
\def\upm@fmt@table@title#1{\color{tableheaderforeground} \cellcolor{tableheaderbackground} {\bfseries #1}}
%title of columns
\newcommand{\tabularheaderstyle}[1]{%
	\mbox{}{\cellcolor{tableheaderbackground} {\color{tableheaderforeground}\itshape\ignorespaces#1}}%
}%
\def\upm@fmt@table@column@title#1{\hfil{\color{tableheaderforeground} \cellcolor{tableheaderbackground} {\itshape#1}}\hfil}

% Utility functions for mtabular
\newcounter{upm@fmt@mtabular@columnnumber}

\gdef\upm@fmt@mtabular@expandtitle#1#2{%
	\multicolumn{#1}{|c|}{\upm@fmt@table@title{\ignorespaces#2\ignorespaces}}%
}

\newcommand{\tabulartitlespec}[1]{%
	\gdef\upm@fmt@mtabular@expandtitle##1##2{%
		\multicolumn{##1}{#1}{\upm@fmt@table@title{\ignorespaces##2\ignorespaces}}%
	}
}

%-----
%\mtabular[width]{ncolumns}{columns}{table title}
\global\NewEnviron{mtabular}[4][\linewidth]{%
    \newcommand*{\upm@fmt@mtabular@column@next}[1]{%
        & \upm@fmt@table@column@title{\ignorespaces##1\ignorespaces}%
        \addtocounter{upm@fmt@mtabular@columnnumber}{-1}%
        \ifnum0<\value{upm@fmt@mtabular@columnnumber}%
            \let\upm@fmt@mtabular@column@continue\upm@fmt@mtabular@column@next%
        \else%
            \\ \hline \let\upm@fmt@mtabular@column@continue\ignorespaces%
        \fi%
        \upm@fmt@mtabular@column@continue%
    }
    \newcommand*{\upm@fmt@mtabular@column@first}[1]{%
        \upm@fmt@table@column@title{\ignorespaces##1\ignorespaces}%
        \addtocounter{upm@fmt@mtabular@columnnumber}{-1}%
        \ifnum0<\value{upm@fmt@mtabular@columnnumber}%
            \let\upm@fmt@mtabular@column@continue\upm@fmt@mtabular@column@next%
        \else%
            \\ \hline \let\upm@fmt@mtabular@column@continue\ignorespaces%
        \fi%
        \upm@fmt@mtabular@column@continue%
    }
    \newcommand{\tabularheader}{%
        \setcounter{upm@fmt@mtabular@columnnumber}{#2}%
        \upm@fmt@mtabular@column@first%
    }%
    \newcommand{\tabulartitle}[1]{%
        \errmessage{The macro {\string\tabulartitle} is deprecated. Replace by the argument}%
    }%
    \newcommand{\tabulartitleinside}[1]{%
        \hline\hline%
        \upm@fmt@mtabular@expandtitle{#2}{##1} \\%
        \hline%
    }%
    \newcommand{\tabularrowheader}[1]{%
        \centering\upm@fmt@table@column@title{\ignorespaces##1}%
    }%
    \begin{tcolorbox}[mtabular,tabularx={#3},title={#4}]%
        \BODY%
    \end{tcolorbox}%
}

\newcommand{\upm@mtable@formatsource}[1]{%
    \mbox{}\\ \mfigureformatsource{\figuresourcename\upm@format@lang@colonchar{#1}}%
}
\gdef\upm@table@source{}

%-----
%\mtable[options]{width}{ncolumns}{columns}{caption}{label}[source text]
% size=<length>
\define@key[autolatex]{mtable}{size}{\gdef\@autolatex@mtable@size{#1}}
% position: h t b p H !
\define@key[autolatex]{mtable}{h}[\relax]{\gdef\@autolatex@mtable@position{[h]}}
\define@key[autolatex]{mtable}{t}[\relax]{\gdef\@autolatex@mtable@position{[t]}}
\define@key[autolatex]{mtable}{b}[\relax]{\gdef\@autolatex@mtable@position{[b]}}
\define@key[autolatex]{mtable}{p}[\relax]{\gdef\@autolatex@mtable@position{[p]}}
\define@key[autolatex]{mtable}{H}[\relax]{\gdef\@autolatex@mtable@position{[H]}}
\define@key[autolatex]{mtable}{ht}[\relax]{\gdef\@autolatex@mtable@position{[ht]}}
\define@key[autolatex]{mtable}{hb}[\relax]{\gdef\@autolatex@mtable@position{[hb]}}
\define@key[autolatex]{mtable}{hp}[\relax]{\gdef\@autolatex@mtable@position{[hp]}}
\define@key[autolatex]{mtable}{hH}[\relax]{\gdef\@autolatex@mtable@position{[hH]}}
\define@key[autolatex]{mtable}{h!}[\relax]{\gdef\@autolatex@mtable@position{[h!]}}
\define@key[autolatex]{mtable}{tb}[\relax]{\gdef\@autolatex@mtable@position{[tb]}}
\define@key[autolatex]{mtable}{tp}[\relax]{\gdef\@autolatex@mtable@position{[tp]}}
\define@key[autolatex]{mtable}{tH}[\relax]{\gdef\@autolatex@mtable@position{[tH]}}
\define@key[autolatex]{mtable}{t!}[\relax]{\gdef\@autolatex@mtable@position{[t!]}}
\define@key[autolatex]{mtable}{bp}[\relax]{\gdef\@autolatex@mtable@position{[bp]}}
\define@key[autolatex]{mtable}{bH}[\relax]{\gdef\@autolatex@mtable@position{[bH]}}
\define@key[autolatex]{mtable}{b!}[\relax]{\gdef\@autolatex@mtable@position{[b!]}}
\define@key[autolatex]{mtable}{pH}[\relax]{\gdef\@autolatex@mtable@position{[pH]}}
\define@key[autolatex]{mtable}{p!}[\relax]{\gdef\@autolatex@mtable@position{[p!]}}
\define@key[autolatex]{mtable}{H!}[\relax]{\gdef\@autolatex@mtable@position{[H!]}}
\define@key[autolatex]{mtable}{htb}[\relax]{\gdef\@autolatex@mtable@position{[htb]}}
\define@key[autolatex]{mtable}{htp}[\relax]{\gdef\@autolatex@mtable@position{[htp]}}
\define@key[autolatex]{mtable}{htH}[\relax]{\gdef\@autolatex@mtable@position{[htH]}}
\define@key[autolatex]{mtable}{ht!}[\relax]{\gdef\@autolatex@mtable@position{[ht!]}}
\define@key[autolatex]{mtable}{tbp}[\relax]{\gdef\@autolatex@mtable@position{[tbp]}}
\define@key[autolatex]{mtable}{tbH}[\relax]{\gdef\@autolatex@mtable@position{[tbH]}}
\define@key[autolatex]{mtable}{tb!}[\relax]{\gdef\@autolatex@mtable@position{[tb!]}}
\define@key[autolatex]{mtable}{bpH}[\relax]{\gdef\@autolatex@mtable@position{[bpH]}}
\define@key[autolatex]{mtable}{bp!}[\relax]{\gdef\@autolatex@mtable@position{[bp!]}}
\define@key[autolatex]{mtable}{pH!}[\relax]{\gdef\@autolatex@mtable@position{[pH!]}}
\define@key[autolatex]{mtable}{htbp}[\relax]{\gdef\@autolatex@mtable@position{[htbp]}}
\define@key[autolatex]{mtable}{htbH}[\relax]{\gdef\@autolatex@mtable@position{[htbH]}}
\define@key[autolatex]{mtable}{htb!}[\relax]{\gdef\@autolatex@mtable@position{[htb!]}}
\define@key[autolatex]{mtable}{tbpH}[\relax]{\gdef\@autolatex@mtable@position{[tbpH]}}
\define@key[autolatex]{mtable}{tbp!}[\relax]{\gdef\@autolatex@mtable@position{[tbp!]}}
\define@key[autolatex]{mtable}{bpH!}[\relax]{\gdef\@autolatex@mtable@position{[bph!]}}
\define@key[autolatex]{mtable}{htbpH}[\relax]{\gdef\@autolatex@mtable@position{[htbpH]}}
\define@key[autolatex]{mtable}{htbp!}[\relax]{\gdef\@autolatex@mtable@position{[htbp!]}}
\define@key[autolatex]{mtable}{htbpH!}[\relax]{\gdef\@autolatex@mtable@position{[htbpH!]}}
%
\newenvironment{mtable}[6][ht]{%
    \gdef\@autolatex@mtable@position{[ht]}%
    \gdef\@autolatex@mtable@size{\normalsize}%
    \setkeys[autolatex]{mtable}{#1}%
    %
    \gdef\upm@table@source{}%
    \gdef\upm@table@caption{#5}%
    \xdef\upm@table@label{tab:#6}%
    \gdef\upm@table@note{}%
    \newcommand{\captionastitle}{
        \errmessage{The macro {\string\captionastitle} is deprecated. Replace by the argument}%
    }%
    \newcommand{\tablenote}[1]{\gdef\upm@table@note{\bgroup ##1\egroup}}%
    \newcommand{\addsource}[1]{\gdef\upm@table@source{\upm@mtable@formatsource{\bgroup ##1 \egroup}}}%
    %%
    \expandafter\table\@autolatex@mtable@position%
    \center\@autolatex@mtable@size%
    \mtabular[#2]{#3}{#4}{}%
}{%
    \endmtabular\relax%
    \caption{\upm@table@caption\upm@table@source}%
    \label{\upm@table@label}%
    \endcenter%
    \upm@table@note%
    \endtable%
    \global\let\upm@table@caption\relax%
    \global\let\upm@table@label\relax%
    \global\let\upm@table@note\relax%
    \global\let\upm@mtable@optionalarg@value\relax%
}

%-----
%\tabref{label}
\newcommand{\tabref}[1]{\ref{tab:#1}}
%-----
%\tabpageref{label}
\newcommand{\tabpageref}[1]{\pageref{tab:#1}}

%----------------------------------------
% PARAGRAPHS
%----------------------------------------
\setlength{\parindent}{0pt}
\setlength{\parskip}{.2cm}

%----------------------------------------
% COLORIZED SECTION'S TITLES
%----------------------------------------

% PRIVATE COLORS
\definecolor{parttitlecolor}{rgb}{0.24,0.33,0.48}
\definecolor{chaptertitlecolor}{rgb}{0.24,0.33,0.48}
\colorlet{chaptertitlenumcolor}{chaptertitlecolor}
\definecolor{sectiontitlecolor}{rgb}{0.93,0.41,0}
\colorlet{sectiontitlenumcolor}{sectiontitlecolor}
\colorlet{sectiontitleboxcolor}{lightgray}
\colorlet{subsectiontitlecolor}{sectiontitlecolor}
\colorlet{subsectiontitlenumcolor}{sectiontitlecolor}
\colorlet{subsectiontitlecolor}{sectiontitlecolor}
\colorlet{subsubsectiontitlecolor}{sectiontitlecolor}
\colorlet{paragraphtitlecolor}{black}
\colorlet{subparagraphtitlecolor}{gray}

% PRIVATE FORMATTING MACROS
\newcounter{upm@format@section@sectionlevel}
\setcounter{upm@format@section@sectionlevel}{0}

\gdef\upm@format@partnum#1{\textcolor{parttitlecolor}{\expandafter\fontsize{40pt}{60pt}\selectfont#1\normalfont}}
\gdef\upm@format@parttitle#1{\textcolor{parttitlecolor}{\huge\scshape #1}}

\gdef\upm@format@chapternum{\color{chaptertitlenumcolor}\fontsize{90}{40}\sffamily\bfseries}
\gdef\upm@format@chaptertitle#1{\setstretch{2.5}\textcolor{chaptertitlecolor}{\Huge\scshape\sffamily\bfseries #1}}

\gdef\upm@format@sectionnum#1{#1}
\gdef\upm@format@sectiontitle{\normalfont\sffamily\large\bfseries\color{sectiontitlecolor}}

\gdef\upm@format@subsectionnum#1{#1}
\gdef\upm@format@subsectiontitle{\normalfont\large\sffamily\bfseries\color{subsectiontitlecolor}}

\gdef\upm@format@subsubsectionnum@postfix{\xspace|}
\gdef\upm@format@subsubsectionnum#1{#1\upm@format@subsubsectionnum@postfix\xspace}
\gdef\upm@format@subsubsectiontitle{\normalfont\normalfont\sffamily\itshape\color{subsubsectiontitlecolor}}

\gdef\upm@format@paragraphtitle@postfix{.}
\gdef\upm@format@paragraphtitle{\normalfont\normalsize\sffamily\bfseries\color{paragraphtitlecolor}}

\gdef\upm@format@subparagraphtitle@postfix{:}
\gdef\upm@format@subparagraphtitle{\normalfont\normalsize\sffamily\itshape\color{subparagraphtitlecolor}}

% PART
\ifupmbookformat
	\gdef\@part[#1]#2{%
	    \ifnum \c@secnumdepth >-2\relax
	      \refstepcounter{part}%
	      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
	    \else
	      \addcontentsline{toc}{part}{#1}%
	    \fi
	    \markboth{}{}%
	    {\huge\centering
	     \interlinepenalty \@M
	     \normalfont
	     \ifnum \c@secnumdepth >-2\relax
	       \upm@format@partnum{\thepart}
	       \par
	       \vskip 20\p@
	     \fi
	     \upm@format@parttitle{\nohyphens{#2}}\par}%
	    \@endpart}
	\gdef\@spart#1{%
	    {\centering
	     \interlinepenalty \@M
	     \normalfont
	     \upm@format@parttitle{\nohyphens{#1}}\par}%
	    \@endpart}
\fi

% CHAPTER
\ifupmarticleformat\else
	\titleformat{name=\chapter,numberless}[display]%
		{\flushright}%
		{}%
		{0pt}%
		{\upm@format@chaptertitle{\nohyphens{#1}}}%
	%
	\titleformat{\chapter}[display]%
		{\flushright\upm@format@chapternum}%
		{\thechapter}%
		{0pt}
		{\upm@format@chaptertitle{\nohyphens{#1}}}%
	\titlespacing*{\chapter} {0pt}{40pt}{40pt}
\fi

% SECTIONS

\newlength\sectionhoffset
\setlength\sectionhoffset{\dimexpr 1in+\hoffset\relax}
\setlength\sectionhoffset{\dimexpr 1in+\leftmargin\relax}

% implementation of sections.
\titleformat{\section}
	{\upm@format@sectiontitle}
	{}
	{0pt}
	{%
	\begin{tikzpicture}%
		\hspace*{-\sectionhoffset}\llap{%
		\node[%
			text depth=0pt,%
			anchor=east,%
			sectiontitlenumcolor,ultra thick,fill=sectiontitleboxcolor!40,%
			rectangle,%
			inner sep=10pt, outer sep=0pt,%
			align=right,%
			text width=\dimexpr\sectionhoffset-20pt\relax]%
			(O) at (0,0){\upm@format@sectionnum{\thesection}};%
		\draw (O.east) node[text depth=0pt,anchor=west,inner sep=10pt,text width=\linewidth]{\nohyphens{#1}};%
		\draw [sectiontitleboxcolor!40] (O.south east) --++ (\dimexpr\textwidth\relax,0);%
		\fill [sectiontitleboxcolor] (O.south east) ++ (\dimexpr\textwidth\relax,0) circle(.1);%
		}%
	\end{tikzpicture}
	}
\titlespacing*{\section}{0pt}{*5}{*-2}

% implementation of subsections.
\titleformat{\subsection}
	{\upm@format@subsectiontitle}
	{\rlap{\hspace{-1.2cm}\color{subsectiontitlenumcolor}\upm@format@subsectionnum{\thesubsection}}}
	{0pt}
	{\upm@format@subsectiontitle#1}
\titlespacing*{\subsection}{0pt}{*4}{*2}

% implementation of subsubsections.
\titleformat{\subsubsection}
	{\upm@format@subsubsectiontitle}
	{\upm@format@subsubsectionnum{\thesubsubsection}}
	{0pt}
	{#1}
\titlespacing*{\subsubsection}{0pt}{7pt}{3pt}

% implementation of paragraphs.
\titleformat{\paragraph}[runin]
	{\upm@format@paragraphtitle}
	{}
	{2pt}
	{#1\upm@format@paragraphtitle@postfix}
	{}

% implementation of subparagraphs.
\titleformat{\subparagraph}[runin]
	{\upm@format@subparagraphtitle}
	{}
	{2pt}
	{#1\upm@format@subparagraphtitle@postfix}
	{}

%----------------------------------------
% PAGE LAYOUT
%----------------------------------------

% Change the factors for determining the element positions
\renewcommand{\topfraction}{.99} % max fraction of floats at top
\renewcommand{\bottomfraction}{.99} % max fraction of floats at bottom
\renewcommand{\textfraction}{.5} % allow minimal text w. figs
\renewcommand{\dbltopfraction}{.66} % fit big float above 2-col. text
\renewcommand{\floatpagefraction}{0.99} % require fuller float pages | N.B.: floatpagefraction MUST be less than topfraction !!
\renewcommand{\dblfloatpagefraction}{.66} % fit big float above 2-col. text

% Update the format of the saved pages and sections
\renewcommand{\sectionmark}[1]{\markright{\thesection\ \textsc{#1}}}
\ifupmarticleformat\else
\renewcommand{\chaptermark}[1]{\markboth{\textsc{#1}}{}}
\renewcommand{\@mkboth}[2]{%
    \let\upm@doc@MakeUppercase\MakeUppercase%
    \gdef\MakeUppercase##1{##1}%
    \chaptermark{#1}%
    \let\MakeUppercase\upm@doc@MakeUppercase%
    \let\upm@doc@MakeUppercase\relax%
}
\fi
% Make sure that the page before a part or
% a chapter title was empty
\renewcommand{\cleardoublepage}{%
  \clearpage%
  \if@twoside\ifodd\c@page%
  \else%
  \thispagestyle{facingtochapter}%
  \hbox{}\newpage%
  \if@twocolumn\hbox{}\newpage%
  \fi\fi\fi%
}
\newcommand{\ps@facingtochapter}{\ps@empty}

%----------------------------------------
% ADDITIONAL SECTIONS
%----------------------------------------

\gdef\upm@format@newsection@alignment{}

%-----
% Part without number but inside the TOC
%\parttoc [toctitle]{title} % left-alignment inside TOC
%\parttoc*[toctitle]{title} % right-alignment inside TOC
\def\parttoc{\@ifstar%
	{\gdef\upm@format@newsection@alignment{\protect\numberline{}}\expandafter\upm@format@newsection@part}%
	{\gdef\upm@format@newsection@alignment{}\expandafter\upm@format@newsection@part}}
\def\upm@format@newsection@part{\@ifnextchar [%
	{\expandafter\upm@format@newsection@part@opt}%
	{\expandafter\upm@format@newsection@part@nopt}}
\def\upm@format@newsection@part@opt[#1]#2{%
	\part*{#2\addcontentsline{toc}{part}{\upm@format@newsection@alignment{#1}}}%
	\chaptermark{}%
}
\def\upm@format@newsection@part@nopt#1{%
	\part*{#1\addcontentsline{toc}{part}{\upm@format@newsection@alignment{#1}}}%
	\chaptermark{}%
}

%-----
% Chapter without number but inside the TOC
%\chaptertoc [toctitle]{title} % left-alignment inside TOC
%\chaptertoc*[toctitle]{title} % right-alignment inside TOC
\def\chaptertoc{\@ifstar%
    {\gdef\upm@format@newsection@alignment{\protect\numberline{}}\expandafter\upm@format@newsection@chapter}%
    {\gdef\upm@format@newsection@alignment{}\expandafter\upm@format@newsection@chapter}}

\def\upm@format@newsection@chapter{\@ifnextchar[%
	{\upm@format@newsection@chapter@a}%
	{\upm@format@newsection@chapter@b}%
}

\def\upm@format@newsection@chapter@a[#1]#2{%
	\expandafter\chapter*[#1]{#2}%
	\addcontentsline{toc}{chapter}{\upm@format@newsection@alignment{#1}}%
	\@ifundefined{minitoc}{}{%
		\global\addtocounter{mtc}{1}%
	}%
}

\def\upm@format@newsection@chapter@b#1{%
	\expandafter\chapter*{#1}%
	\addcontentsline{toc}{chapter}{\upm@format@newsection@alignment{#1}}%
	\@ifundefined{minitoc}{}{%
		\global\addtocounter{mtc}{1}%
	}%
}

\def\@chaptertoc{\@ifstar\upm@chaptertoc@a\upm@chaptertoc@b}
\def\upm@chaptertoc@a[#1]#2{%
    \chapter*[#1]{#2}%
    \addcontentsline{toc}{chapter}{#2}%
}
\def\upm@chaptertoc@b#1{%
    \chapter*{#1}%
    \addcontentsline{toc}{chapter}{#1}%
}

\def\@sectiontoc{\@ifstar\upm@sectiontoc@a\upm@sectiontoc@b}
\def\upm@sectiontoc@a[#1]#2{%
    \section*[#1]{#2}%
    \addcontentsline{toc}{section}{#2}%
}
\def\upm@sectiontoc@b#1{%
    \section*{#1}%
    \addcontentsline{toc}{section}{#1}%
}

%-----
% Section without number but inside the TOC
%\sectiontoc [toctitle]{title} % left-alignment inside TOC
%\sectiontoc*[toctitle]{title} % right-alignment inside TOC
\def\sectiontoc{\@ifstar%
	{\gdef\upm@format@newsection@alignment{\protect\numberline{}}\expandafter\upm@format@newsection@section}%
	{\gdef\upm@format@newsection@alignment{}\expandafter\upm@format@newsection@section}}
\def\upm@format@newsection@section{\@ifnextchar [%
	{\expandafter\upm@format@newsection@section@opt}%
	{\expandafter\upm@format@newsection@section@nopt}}
\def\upm@format@newsection@section@opt[#1]#2{%
	\section*{#2\addcontentsline{toc}{section}{\upm@format@newsection@alignment{#1}}}%
}
\def\upm@format@newsection@section@nopt#1{%
	\section*{#1\addcontentsline{toc}{section}{\upm@format@newsection@alignment{#1}}}%
}

%-----
% Subsection without number but inside the TOC
%\subsectiontoc [toctitle]{title} % left-alignment inside TOC
%\subsectiontoc*[toctitle]{title} % right-alignment inside TOC
\def\subsectiontoc{\@ifstar%
	{\gdef\upm@format@newsection@alignment{\protect\numberline{}}\expandafter\upm@format@newsection@subsection}%
	{\gdef\upm@format@newsection@alignment{}\expandafter\upm@format@newsection@subsection}}
\def\upm@format@newsection@subsection{\@ifnextchar [%
	{\expandafter\upm@format@newsection@subsection@opt}%
	{\expandafter\upm@format@newsection@subsection@nopt}}
\def\upm@format@newsection@subsection@opt[#1]#2{%
	\subsection*{#2\addcontentsline{toc}{subsection}{\upm@format@newsection@alignment{#1}}}%
}
\def\upm@format@newsection@subsection@nopt#1{%
	\subsection*{#1\addcontentsline{toc}{subsection}{\upm@format@newsection@alignment{#1}}}%
}

%-----
% Subsubsection without number but inside the TOC
%\subsubsectiontoc [toctitle]{title} % left-alignment inside TOC
%\subsubsectiontoc*[toctitle]{title} % right-alignment inside TOC
\def\subsubsectiontoc{\@ifstar%
	{\gdef\upm@format@newsection@alignment{\protect\numberline{}}\expandafter\upm@format@newsection@subsubsection}%
	{\gdef\upm@format@newsection@alignment{}\expandafter\upm@format@newsection@subsubsection}}
\def\upm@format@newsection@subsubsection{\@ifnextchar [%
	{\expandafter\upm@format@newsection@subsubsection@opt}%
	{\expandafter\upm@format@newsection@subsubsection@nopt}}
\def\upm@format@newsection@subsubsection@opt[#1]#2{%
	\subsubsection*{#2\addcontentsline{toc}{subsubsection}{\upm@format@newsection@alignment{#1}}}%
}
\def\upm@format@newsection@subsubsection@nopt#1{%
	\subsubsection*{#1\addcontentsline{toc}{subsubsection}{\upm@format@newsection@alignment{#1}}}%
}

%-----
% Chapter with different titles for in the TOC, the headers and on the pages
%\chapterfull[in toc]{on page}{in header} % with number
%\chapterfull*[in toc]{on page}{in header} % without number
\def\chapterfull{\@ifstar%
	{\gdef\upm@format@newsection@thesectionmacro{\chapter*}\upm@format@newsection@chapterfull}%
	{\gdef\upm@format@newsection@thesectionmacro{\chapter}\upm@format@newsection@chapterfull}%
}

\def\upm@format@newsection@chapterfull{\@ifnextchar[%
	\upm@format@newsection@chapterfull@a%
	\upm@format@newsection@chapterfull@b%
}

\def\upm@format@newsection@chapterfull@a[#1]#2#3{%
	\upm@format@newsection@thesectionmacro[#1]{#2}%
	\chaptermark{#3}%
}

\def\upm@format@newsection@chapterfull@b#1#2{%
	\upm@format@newsection@thesectionmacro{#1}%
	\chaptermark{#2}%
}

%-----
% Section with different titles for in the TOC, the headers and on the pages
%\sectionfull[in toc]{on page}{in header} % with number
%\sectionfull*[in toc]{on page}{in header} % without number
\def\sectionfull{\@ifstar%
	{\gdef\upm@format@newsection@thesectionmacro{\section*}\upm@format@newsection@sectionfull}%
	{\gdef\upm@format@newsection@thesectionmacro{\section}\upm@format@newsection@sectionfull}%
}

\def\upm@format@newsection@sectionfull{\@ifnextchar[%
	\upm@format@newsection@sectionfull@a%
	\upm@format@newsection@sectionfull@b%
}

\def\upm@format@newsection@sectionfull@a[#1]#2#3{%
	\upm@format@newsection@thesectionmacro[#1]{#2}%
	\global\sectionmark{#3}%
}

\def\upm@format@newsection@sectionfull@b#1#2{%
	\upm@format@newsection@thesectionmacro{#1}%
	\global\sectionmark{#2}%
}

%-----
%\upm@rootheadertoc and \upm@rootheadertoc@addtotoc
\AtBeginDocument{%
    \ifupmarticleformat%
        \global\let\upm@rootheadertoc\@sectiontoc%
        \gdef\upm@rootheadertoc@addtotoc#1{%
            \addcontentsline{toc}{section}{#1}%
        }%
    \else%
        \global\let\upm@rootheadertoc\@chaptertoc%
        \gdef\upm@rootheadertoc@addtotoc#1{%
            \addcontentsline{toc}{chapter}{#1}%
        }%
    \fi%
}

%----------------------------------------
% BIBLIOGRAPHY
%----------------------------------------

%-----
%\bibsize{size}
\newcommand{\bibsize}[1]{\gdef\upm@bibsize{#1}}

\gdef\upm@bibsize{\small}

\gdef\@biblabel#1{{\upm@bibsize{[#1]}}}

\gdef\@lbibitem[#1]#2{\item[\@biblabel{#1}\hfill]\upm@bibsize\if@filesw{%
	\let\protect\noexpand\immediate\write\@auxout{\string\bibcite{#2}{#1}}}\fi\ignorespaces}

\gdef\@bibitem#1{\item\upm@bibsize\if@filesw%
	\immediate\write\@auxout{\string\bibcite{#1}{\the\value{\@listctr}}}\fi\ignorespaces}


%----------------------------------------
% TABLE OF CONTENT
%----------------------------------------
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

% Change the color of the TOC for the "dotted" lines
%\let\upm@format@dottedtocline@old\@dottedtocline
%\gdef\@dottedtocline#1#2#3#4#5{%
%	%{depth}{left margin}{right margin}{text}{page number}
%	\upm@format@dottedtocline@old{#1}{#2}{#3}{#4}{#5}%
%}

% Change the color of the TOC for the parts
\@ifundefined{l@part}{}{
\let\upm@format@l@part@old\l@part
\renewcommand*\l@part[2]{%
	%{text}{page number}
	\upm@format@l@part@old{\textcolor{parttitlecolor}{#1}}{\textcolor{parttitlecolor}{#2}}%
}
}

% Change the color of the TOC for the chapters
\@ifundefined{l@chapter}{}{
\let\upm@format@l@chapter@old\l@chapter
\renewcommand*\l@chapter[2]{%
	%{text}{page number}
	\upm@format@l@chapter@old{\textcolor{chaptertitlecolor}{#1}}{\textcolor{chaptertitlecolor}{#2}}%
}
}

% Overide the color and font configurations of the MINITOC package
\AtBeginDocument{
	\@ifundefined{minitoc}{}{%
		% Chapter
		\gdef\mtifont{\normalfont\large\upshape\bfseries\color{chaptertitlecolor}}
		% Section
		\gdef\mtcSfont{\normalfont\small\upshape\bfseries\color{sectiontitlecolor}}
		% Sub-Section and SubSub-Section
		\gdef\mtcSSfont{\normalfont\small\upshape\mdseries\normalcolor}
		\global\let\mtcSSSfont\mtcSSfont
	}
}

%----------------------------------------
% ENUMERATIONS
%----------------------------------------
\newcounter{upm@fmt@savedcounter}

\newcommand{\savecounter}[1]{%
	\setcounter{upm@fmt@savedcounter}{\value{#1}}%
}
\newcommand{\restorecounter}[1]{%
	\setcounter{#1}{\theupm@fmt@savedcounter}%
}

\ifupm@use@override@standard@lists
	\newcommand{\saveenumcounter}{\savecounter{@upm@fmt@enumdescription@cnt@}}
	\newcommand{\restoreenumcounter}{\restorecounter{@upm@fmt@enumdescription@cnt@}}
	\newcommand{\setenumcounter}[1]{\setcounter{@upm@fmt@enumdescription@cnt@}{#1}}
	\newcommand{\getenumcounter}{\the@upm@fmt@enumdescription@cnt@}
\else
	\newcommand{\saveenumcounter}{\savecounter{@enumctr}}
	\newcommand{\restoreenumcounter}{\restorecounter{@enumctr}}
	\newcommand{\setenumcounter}[1]{\setcounter{@enumctr}{#1}\addtocounter{@enumctr}{-1}}
	\newcommand{\getenumcounter}{\value{@enumctr}}
\fi

%----------------------------------------
% FOOTNOTE
%----------------------------------------

\gdef\upm@footnoteref#1{\upm@textsuperscript{#1}}
\gdef\upm@footnotepageref#1#2{\upm@textsuperscript{{#1\tiny(#2)}}}

\def\upm@savefootnote#1#2{%
	\footnote{#1\label{\upm@protect{footnote:#2}}}%
	\upm@nameundef{footnote:#2:cmd}%
}
\def\upm@savefootnotestar#1#2{%
	\upm@namedef{footnote:#2:cmd}{\upm@savefootnote{#1}{#2}}%
}

\DeclareRobustCommand\savefootnote{\@ifstar\upm@savefootnotestar\upm@savefootnote}

\def\upm@reffootnote#1{%
	\upm@ifdefinedname{footnote:#1:cmd}{%
		\upm@nameuse{footnote:#1:cmd}}{%
		\upm@footnoteref{\upm@getref{\upm@protect{footnote:#1}}}%
	}%
	\xspace%
} 
\def\upm@reffootnotestar#1{%
	\upm@ifdefinedname{footnote:#1:cmd}{%
		\upm@nameuse{footnote:#1:cmd}}{%
		\xdef\upm@tmp@tmp{\upm@protect{footnote:#1}}%
		\upm@footnotepageref{\expandafter\upm@getref{\upm@tmp@tmp}}{\expandafter\upm@getpageref{\upm@tmp@tmp}}%
		\global\let\upm@tmp@tmp\relax%
	}%
	\xspace%
} 

\DeclareRobustCommand\reffootnote{\@ifstar\upm@reffootnotestar\upm@reffootnote}

%----------------------------------------
% IMAGES IN PARAGRAPHS
%----------------------------------------

\newenvironment{umlinpar}[2][width=.45\linewidth]{%
\begin{window}[0,r,{\mbox{\hspace{.5cm}\includegraphics[#1]{#2}\vspace{.5cm}}},{}]
}{%
\end{window}}

%----------------------------------------
% DATE
%----------------------------------------

%Build a date that has the format supported by tex-upmethodology
%\makedate{day}{month}{year}
\let\makedate\upm@format@lang@makedate

%-----
%Replies the year corresponding to the given supported date
%\extractyear{date}
\let\extractyear\upm@format@lang@extractyear

%-----
%Replies the month corresponding to the given supported date
%\extractmonth{date}
\let\extractmonth\upm@format@lang@extractmonth

%-----
%Replies the day corresponding to the given supported date
%\extractday{date}
\let\extractday\upm@format@lang@extractday

% Redefine the today function
\AtBeginDocument{\global\edef\today{\makedate{\the\day}{\the\month}{\the\year}}}

%----------------------------------------
% PEOPLE NAME
%----------------------------------------

\def\makenamespacing#1{%
	\upm@format@makenamespacing{#1}\xspace%
}

\def\upm@format@makenamespacing#1{%
	\upm@foreach.\in#1\do{%
		\ignorespaces\upm@foreach@term.\,%
	}{%
		\ignorespaces\upm@foreach@term%
	}%
}

\gdef\upm@format@people@title#1{\textsc{#1}}
\def\upm@format@firstname@format#1{%
	{\smaller\textsc{\upm@format@makenamespacing{#1}}}%
}
\def\upm@format@von@format#1{\mbox{\smaller\ignorespaces#1}}
\def\upm@format@lastname@format#1{\textsc{\ignorespaces#1}}

%\upmmakename[von]{firstname}{lastname}{separator}
\newcommand{\upmmakename}[4][\relax]{%
	\ifx#1\relax%
		{\upm@format@firstname@format{#2}#4\upm@format@lastname@format{#3}}%
	\else%
		{\upm@format@firstname@format{#2}#4\upm@format@von@format{#1}#4\upm@format@lastname@format{#3}}%
	\fi%
	\xspace%
}
\newcommand{\upmmakenamestar}[4][\relax]{%
	\ifx#1\relax%
		{\upm@format@lastname@format{#3}#4\upm@format@firstname@format{#2}}%
	\else%
		{\upm@format@lastname@format{#3}#4\upm@format@von@format{#1}#4\upm@format@firstname@format{#2}}%
	\fi%
	\xspace%
}

%\makename[von]{firstname}{lastname}
\newcommand{\makename}[3][\relax]{%
	\upmmakename[#1]{#2}{#3}{\ }%
}

%\makelastname[von]{lastname}
\newcommand{\makelastname}[2][\relax]{%
	\ifx#1\relax%
		\upm@format@lastname@format{#2}%
	\else%
		\upm@format@von@format{#1}\ \upm@format@lastname@format{#2}%
	\fi%
	\xspace%
}

%\makefirstname{firstname}
\newcommand{\makefirstname}[1]{%
	\upm@format@firstname@format{#1}\xspace%
}

%\prname[von]{firstname}{lastname}
%\prname*[von]{firstname}{lastname}
\def\prname{\@ifstar\upm@prnamestar\upm@prname}
\newcommand{\upm@prname}[3][\relax]{%
	\upm@format@people@title{\upm@format@lang@professor}\,\upmmakename[#1]{#2}{#3}{\ }%
}
\newcommand{\upm@prnamestar}[3][\relax]{%
	\upmmakename[#1]{#2}{#3}{\ }, \upm@format@people@title{\upm@format@lang@professor}%
}

%\drname[von]{firstname}{lastname}
%\drname*[von]{firstname}{lastname}
\def\drname{\@ifstar\upm@drnamestar\upm@drname}
\newcommand{\upm@drname}[3][\relax]{%
	\upm@format@people@title{\upm@format@lang@doctor}\,\upmmakename[#1]{#2}{#3}{\ }%
}
\newcommand{\upm@drnamestar}[3][\relax]{%
	\upmmakename[#1]{#2}{#3}{\ }, \upm@format@people@title{\upm@format@lang@doctor}%
}

%\phdname[von]{firstname}{lastname}
%\phdname*[von]{firstname}{lastname}
\def\phdname{\@ifstar\upm@phdnamestar\upm@phdname}
\newcommand{\upm@phdname}[3][\relax]{%
	\upm@format@people@title{\upm@format@lang@phdoctor}\,\upmmakename[#1]{#2}{#3}{\ }%
}
\newcommand{\upm@phdnamestar}[3][\relax]{%
	\upmmakename[#1]{#2}{#3}{\ }, \upm@format@people@title{\upm@format@lang@phdoctor}%
}

%\scdname[von]{firstname}{lastname}
%\scdname*[von]{firstname}{lastname}
\def\scdname{\@ifstar\upm@scdnamestar\upm@scdname}
\newcommand{\upm@scdname}[3][\relax]{%
	\upm@format@people@title{\upm@format@lang@scdoctor}\,\upmmakename[#1]{#2}{#3}{\ }%
}
\newcommand{\upm@scdnamestar}[3][\relax]{%
	\upmmakename[#1]{#2}{#3}{\ }, \upm@format@people@title{\upm@format@lang@scdoctor}%
}

%\mdname[von]{firstname}{lastname}
%\mdname*[von]{firstname}{lastname}
\def\mdname{\@ifstar\upm@mdnamestar\upm@mdname}
\newcommand{\upm@mdname}[3][\relax]{%
	\upm@format@people@title{\upm@format@lang@mdoctor}\,\upmmakename[#1]{#2}{#3}{\ }%
}
\newcommand{\upm@mdnamestar}[3][\relax]{%
	\upmmakename[#1]{#2}{#3}{\ }, \upm@format@people@title{\upm@format@lang@mdoctor}%
}

%\pengname[von]{firstname}{lastname}
%\pengname*[von]{firstname}{lastname}
\def\pengname{\@ifstar\upm@pengnamestar\upm@pengname}
\newcommand{\upm@pengname}[3][\relax]{%
	\upm@format@people@title{\upm@format@lang@professionalengineer}\,\upmmakename[#1]{#2}{#3}{\ }%
}
\newcommand{\upm@pengnamestar}[3][\relax]{%
	\upmmakename[#1]{#2}{#3}{\ }, \upm@format@people@title{\upm@format@lang@professionalengineer}%
}

%\iengname[von]{firstname}{lastname}
%\iengname*[von]{firstname}{lastname}
\def\iengname{\@ifstar\upm@iengnamestar\upm@iengname}
\newcommand{\upm@iengname}[3][\relax]{%
	\upm@format@people@title{\upm@format@lang@incorporatedengineer}\,\upmmakename[#1]{#2}{#3}{\ }%
}
\newcommand{\upm@iengnamestar}[3][\relax]{%
	\upmmakename[#1]{#2}{#3}{\ }, \upm@format@people@title{\upm@format@lang@incorporatedengineer}%
}

%----------------------------------------
% INLINE ENUMERATION
%----------------------------------------

\newcounter{@@upm@fmt@inlineenumeration}
\newcommand{\inlineenumerationlabel}[1]{\textit{(#1)}}
\let\upm@fmt@inlineenum@numberformat\roman
\newenvironment{inlineenumeration}{%
	\begingroup%
	\let\upm@fmt@inlineenum@currentlabel\@currentlabel%
	\renewcommand{\item}{\xdef\@currentlabel{\upm@fmt@inlineenum@numberformat{@@upm@fmt@inlineenumeration}}{\inlineenumerationlabel{\@currentlabel}{\addtocounter{@@upm@fmt@inlineenumeration}{1}}}~}%
	\setcounter{@@upm@fmt@inlineenumeration}{1}%
}{%
	\global\let\@currentlabel\upm@fmt@inlineenum@currentlabel%
	\endgroup%
}

%----------------------------------------
% DESCRIPTION LIST WITH NUMBERS
%----------------------------------------

\newcounter{@upm@fmt@enumdescription@cnt@}
\gdef\upm@fmt@enumdescription@savedlabel{}
\gdef\upm@fmt@enumdescription@savedcounter{}
\newcommand{\upm@fmt@enumdescription@fmt@}[1]{}
\newcommand{\enumdescriptionlabel}[1]{\textbf{#1}}
\newcommand{\enumdescriptioncounterseparator}{~-~}
\newcommand{\enumdescriptionlabelseparator}{\upm@column@char}
% #1: counter style.
% #2: text before the counter.
% #3: text after the counter.
% #4: text between the counter and the description.
% #5: text between the description and the rest of the text.
% #6: text between the counter (no description) and the rest of the text.
\newenvironment{upm@fmt@enumdescription}[6]{%
	\begin{list}{}{%
		\renewcommand{\upm@fmt@enumdescription@savedlabel}{\@currentlabel}%
		\edef\upm@fmt@enumdescription@savedcounter{\the@upm@fmt@enumdescription@cnt@}%
		\setcounter{@upm@fmt@enumdescription@cnt@}{1}%
		\ifthenelse{\equal{#1}{a}}{%
			\renewcommand{\upm@fmt@enumdescription@fmt@}[1]{#2\alph{##1}#3}%
		}{%
			\ifthenelse{\equal{#1}{A}}{%
				\renewcommand{\upm@fmt@enumdescription@fmt@}[1]{#2\Alph{##1}#3}%
			}{%
				\ifthenelse{\equal{#1}{i}}{%
					\renewcommand{\upm@fmt@enumdescription@fmt@}[1]{#2\roman{##1}#3}%
				}{%
					\ifthenelse{\equal{#1}{I}}{%
						\renewcommand{\upm@fmt@enumdescription@fmt@}[1]{#2\Roman{##1}#3}%
					}{%
						\renewcommand{\upm@fmt@enumdescription@fmt@}[1]{#2\arabic{##1}#3}%
					}%
				}%
			}%
		}%
		\renewcommand{\makelabel}[1]{%
			\xdef\@currentlabel{\upm@fmt@enumdescription@fmt@{@upm@fmt@enumdescription@cnt@}}%
			\enumdescriptionlabel{\@currentlabel#4##1\ifthenelse{\equal{a##1}{a}}{#6}{#5}}{\addtocounter{@upm@fmt@enumdescription@cnt@}{1}}}%
		\expandafter\settowidth{\labelwidth}{#2iii#3}%
	}
}{%
	\global\let\@currentlabel\upm@fmt@enumdescription@savedlabel%
	\setcounter{@upm@fmt@enumdescription@cnt@}{\upm@fmt@enumdescription@savedcounter}%
	\end{list}%
}
\newenvironment{enumdescriptionx}[3][i]{%
	\begin{upm@fmt@enumdescription}{#1}{#2}{#3}{\enumdescriptioncounterseparator}{\enumdescriptionlabelseparator}{\enumdescriptionlabelseparator}%
}{%
	\end{upm@fmt@enumdescription}%
}
\newenvironment{enumdescription}[1][i]{%
	\begin{upm@fmt@enumdescription}{#1}{}{}{\enumdescriptioncounterseparator}{\enumdescriptionlabelseparator}{\enumdescriptionlabelseparator}%
}{%
	\end{upm@fmt@enumdescription}%
}

%% Issue #14: enumerate behaves as enumdescription
\ifupm@use@override@standard@lists
	
	\AtBeginDocument{
		\message{*** Overriding the 'enumerate' environment. Pass option 'standardlists' for avoiding this override.}
		\global\let\enumerate\@undefined
		\global\let\endenumerate\@undefined
		\global\NewEnviron{enumerate}[1][1\string.~]{%
			% Parse the parameter for extracting the type of the enumeration, the prefix and the postfix
			\in@{a}{#1}\ifin@
				\gdef\upm@fmt@enumerate@style{a}%
				\def\reserved@a##1a##2\@nil{%
					\def\upm@fmt@enumerate@prefix{##1}%
					\def\upm@fmt@enumerate@postfix{##2}%
				}%
				\reserved@a#1\@nil%
			\else\in@{1}{#1}\ifin@
				\gdef\upm@fmt@enumerate@style{1}%
				\def\reserved@a##11##2\@nil{%
					\def\upm@fmt@enumerate@prefix{##1}%
					\def\upm@fmt@enumerate@postfix{##2}%
				}%
				\reserved@a#1\@nil%
			\else\in@{A}{#1}\ifin@
				\gdef\upm@fmt@enumerate@style{A}%
				\def\reserved@a##1A##2\@nil{%
					\def\upm@fmt@enumerate@prefix{##1}%
					\def\upm@fmt@enumerate@postfix{##2}%
				}%
				\reserved@a#1\@nil%
			\else\in@{i}{#1}\ifin@
				\gdef\upm@fmt@enumerate@style{i}%
				\def\reserved@a##1i##2\@nil{%
					\def\upm@fmt@enumerate@prefix{##1}%
					\def\upm@fmt@enumerate@postfix{##2}%
				}%
				\reserved@a#1\@nil%
			\else\in@{I}{#1}\ifin@
				\gdef\upm@fmt@enumerate@style{I}%
				\def\reserved@a##1I##2\@nil{%
					\def\upm@fmt@enumerate@prefix{##1}%
					\def\upm@fmt@enumerate@postfix{##2}%
				}%
				\reserved@a#1\@nil%
			\else%
				\errmessage{Invalid format of the enumerate counter}
			\fi\fi\fi\fi\fi%
			\protected@xdef\upm@tmp{\protect\protect\protect\begin{upm@fmt@enumdescription}{\upm@fmt@enumerate@style}{\upm@fmt@enumerate@prefix}{\upm@fmt@enumerate@postfix}{}{\protect\enumdescriptionlabelseparator}{}}%
			%
			\upm@tmp%
			%\protect\begin{upm@fmt@enumdescription}{#1}{}{\string.~}{}{\enumdescriptionlabelseparator}{}%
			\BODY%
			\protect\end{upm@fmt@enumdescription}%
		}
	}
\fi

%----------------------------------------
% DESCRIPTION LIST WITH BULLETS
%----------------------------------------
\ifupm@use@override@standard@lists
	\gdef\upm@fmt@itemizeddescription@separator{\upm@column@char\ }
	\newcommand{\upm@fmt@itemizeddescription@formatdescription}[1]{\textbf{#1}}
	\newcommand{\upm@fmt@itemizeddescription@desc}[2]{%
		\upm@fmt@itemizeddescription@formatdescription{#1#2}%
	}
	\let\upm@fmt@olditem\item
	\let\upm@item@param\upm@fmt@olditem
	\let\upm@item@noparam\upm@fmt@olditem
	\def\item{\@ifnextchar[\upm@item@param\upm@item@noparam}
	\newcommand{\overridedescriptionenvironment}{%
		\message{*** Overriding the 'description' environment. Pass option 'standardlists' for avoiding this override.}
		% Override the description environment
		\global\let\description\@undefined
		\global\let\enddescription\@undefined
		\global\NewEnviron{description}[1][\upm@fmt@itemizeddescription@separator]{
			\begin{itemize}%
			\renewcommand{\upm@item@param}[1][]{\upm@fmt@olditem \upm@fmt@itemizeddescription@desc{####1}{##1}}%
			\renewcommand{\upm@item@noparam}{\upm@fmt@olditem }%
			\BODY%
			\end{itemize}%
		}
	}
	\newcommand{\restoredescriptionenvironment}{%
		\message{*** Restoring the 'description' environment.}
		\global\let\description\@upm@fmt@overriden@description%
		\global\let\enddescription\@upm@fmt@overriden@enddescrption%
	}
	\AtBeginDocument{
		% Save the original definition for later restore
		\global\let\@upm@fmt@overriden@description\description%
		\global\let\@upm@fmt@overriden@enddescrption\enddescription%
		\overridedescriptionenvironment%
		\@ifundefined{printglossary}{}{%
			\message{*** Overriding the 'printglossary' macro.}
			\global\let\upm@fmt@printglossary@original\printglossary%
			\global\newcommand{\upm@fmt@printglossary}[1][]{%
				\message{*** Evaluating 'printglossary' macro.}%
				\restoredescriptionenvironment%
				\upm@fmt@printglossary@original[#1]%
				\overridedescriptionenvironment%
			}%
			\global\let\printglossary\upm@fmt@printglossary%
		}%
	}
\else
	\newcommand{\overridedescriptionenvironment}{}
	\newcommand{\restoredescriptionenvironment}{}
\fi

%----------------------------------------
% SIZE MANAGEMENT
%----------------------------------------
\newenvironment{upmfontsize}[1]{%
	\begingroup%
	\let\upm@Huge\Huge%
	\let\upm@huge\huge%
	\let\upm@normalsize\normalsize%
	\let\upm@small\small%
	\let\upm@scriptsize\scriptsize%
	\let\upm@footnotesize\footnotesize%
	\let\upm@tiny\tiny%
	%
	\ifx#1\Huge%
		\let\Huge\upm@Huge%
		\let\huge\upm@Huge%
		\let\small\upm@huge%
		\let\scriptsize\upm@normalsize%
		\let\footnotesize\upm@small%
		\let\tiny\upm@scriptsize%
	\else\ifx#1\huge%
		\let\Huge\upm@Huge%
		\let\huge\upm@Huge%
		\let\small\upm@normalsize%
		\let\scriptsize\upm@small%
		\let\footnotesize\upm@scriptsize%
		\let\tiny\upm@footnotesize%
	\else\ifx#1\small%
		\let\Huge\upm@huge%
		\let\huge\upm@normalsize%
		\let\small\upm@scriptsize%
		\let\scriptsize\upm@footnotesize%
		\let\footnotesize\upm@tiny%
		\let\tiny\upm@tiny%
	\else\ifx#1\scriptsize%
		\let\Huge\upm@normalsize%
		\let\huge\upm@small%
		\let\small\upm@footnotesize%
		\let\scriptsize\upm@tiny%
		\let\footnotesize\upm@tiny%
		\let\tiny\upm@tiny%
	\else\ifx#1\footnotesize%
		\let\Huge\upm@small%
		\let\huge\upm@scriptsize%
		\let\small\upm@tiny%
		\let\scriptsize\upm@tiny%
		\let\footnotesize\upm@tiny%
		\let\tiny\upm@tiny%
	\else\ifx#1\tiny%
		\let\Huge\upm@scriptsize%
		\let\huge\upm@footnotesize%
		\let\small\upm@tiny%
		\let\scriptsize\upm@tiny%
		\let\footnotesize\upm@tiny%
		\let\tiny\upm@tiny%
	\fi%
	\fi%
	\fi%
	\fi%
	\fi%
	\fi%
	#1%
}{\endgroup}

%----------------------------------------
% FRAMED MINIPAGE
%----------------------------------------

\newsavebox{\upm@framed@minipage}
%\begin{framedminipage}{width}...\end{framedminipage}
\newenvironment{framedminipage}[1]{%
	\begin{lrbox}{\upm@framed@minipage}\begin{minipage}{#1}%
	}{%
	\end{minipage}\end{lrbox}\fbox{\usebox{\upm@framed@minipage}}}

%\begin{framedcolorminipage}{width}{border}{background}...\end{framedcolorminipage}
\newenvironment{framedcolorminipage}[3]{%
	\newcommand{\upm@framed@minipage@border}{#2}%
	\newcommand{\upm@framed@minipage@background}{#3}%
	\begin{lrbox}{\upm@framed@minipage}\begin{minipage}{#1}%
	}{%
	\end{minipage}\end{lrbox}\fcolorbox{\upm@framed@minipage@border}{\upm@framed@minipage@background}{\usebox{\upm@framed@minipage}}}

%----------------------------------------
% HIGHLIGH BOXES
%----------------------------------------

% Colors for the highligh boxes
\colorlet{highlightboxbackground_caution}{white}
\colorlet{highlightboxforeground_caution}{black}
\colorlet{highlightboxborder_caution}{black}
\colorlet{highlightboxbackground_info}{white}
\colorlet{highlightboxforeground_info}{black}
\colorlet{highlightboxborder_info}{black}
\colorlet{highlightboxbackground_note}{white}
\colorlet{highlightboxforeground_note}{black}
\colorlet{highlightboxborder_note}{black}
\colorlet{highlightboxbackground_action}{white}
\colorlet{highlightboxforeground_action}{black}
\colorlet{highlightboxborder_action}{black}
\colorlet{highlightboxbackground_question}{white}
\colorlet{highlightboxforeground_question}{black}
\colorlet{highlightboxborder_question}{black}

% Include the skins definition with tcolorbox
\tcbuselibrary{skins}

\newtcolorbox{upm@highligh@box@caution}[1]{
	enhanced,
	colback=highlightboxbackground_caution,
	colframe=highlightboxborder_caution,
	fonttitle=\Huge\bfseries,
	rounded corners,
	sidebyside,
	sidebyside align=center,
	lefthand width=1cm, % Width for the icon area
	colupper=highlightboxforeground_caution,
	coltext=highlightboxforeground_caution,
}

\newenvironment{upmcaution}[1][\linewidth]{%
	\begin{upm@highligh@box@caution}{#1}%
	{\Huge\faExclamationTriangle}\tcblower %
}{%
	\end{upm@highligh@box@caution}%
}

\newtcolorbox{upm@highligh@box@info}[1]{
	enhanced,
	colback=highlightboxbackground_info,
	colframe=highlightboxborder_info,
	fonttitle=\Huge\bfseries,
	rounded corners,
	sidebyside,
	sidebyside align=center,
	lefthand width=1cm, % Width for the icon area
	colupper=highlightboxforeground_info,
	coltext=highlightboxforeground_info,
}

\newenvironment{upminfo}[1][\linewidth]{%
	\begin{upm@highligh@box@info}{#1}%
	{\Huge\faInfoCircle}\tcblower %
}{%
	\end{upm@highligh@box@info}%
}

\newtcolorbox{upm@highligh@box@question}[1]{
	enhanced,
	colback=highlightboxbackground_question,
	colframe=highlightboxborder_question,
	fonttitle=\Huge\bfseries,
	rounded corners,
	sidebyside,
	sidebyside align=center,
	lefthand width=1cm, % Width for the icon area
	colupper=highlightboxforeground_question,
	coltext=highlightboxforeground_question,
}

\newenvironment{upmquestion}[1][\linewidth]{%
	\begin{upm@highligh@box@question}{#1}%
	{\Huge\faQuestionCircle}\tcblower %
}{%
	\end{upm@highligh@box@question}%
}

\newtcolorbox{upm@highligh@box@note}[1]{
	enhanced,
	colback=highlightboxbackground_note,
	colframe=highlightboxborder_note,
	fonttitle=\Huge\bfseries,
	rounded corners,
	sidebyside,
	sidebyside align=center,
	lefthand width=1cm, % Width for the icon area
	colupper=highlightboxforeground_note,
	coltext=highlightboxforeground_note,
}

\newenvironment{upmnote}[1][\linewidth]{%
	\begin{upm@highligh@box@note}{#1}%
	{\Huge\faPen}\tcblower %
}{%
	\end{upm@highligh@box@note}%
}

\newtcolorbox{upm@highligh@box@action}[1]{
	enhanced,
	colback=highlightboxbackground_action,
	colframe=highlightboxborder_action,
	fonttitle=\Huge\bfseries,
	rounded corners,
	sidebyside,
	sidebyside align=center,
	lefthand width=1cm, % Width for the icon area
	colupper=highlightboxforeground_action,
	coltext=highlightboxforeground_action,
}

\newenvironment{upmaction}[1][\linewidth]{%
	\begin{upm@highligh@box@action}{#1}%
	{\Huge\faPlay}\tcblower %
}{%
	\end{upm@highligh@box@action}%
}

%----------------------------------------
% PROVIDE URL MACROS, WHICH WILL BE
% OVERRIDDEN BY THE DOCUMENT CLASS
%----------------------------------------

\providecommand{\url}[2][]{\texttt{#2}}
\providecommand{\href}[3][]{\texttt{#3}}

%----------------------------------------
% Exponents and Indices
%----------------------------------------
\gdef\textup#1{\textsuperscript{#1}\xspace}
\def\@textsubscript#1{%
  {\m@th\ensuremath{_{\mbox{\fontsize\sf@size\z@#1}}}}}
\gdef\textsubscript#1{\@textsubscript{\selectfont#1}}
\gdef\textdown#1{\textsubscript{#1}\xspace}


%----------------------------------------
% UNDERLINE
%----------------------------------------

\let\upm@oldunderline\underline
\renewcommand{\underline}[1]{\upm@oldunderline{\smash{#1}}}

%----------------------------------------
% ENVIRONMENT FOR DEFINITIONS
%----------------------------------------

% Include the theorem definition with tcolorbox
\tcbuselibrary{theorems}

%-----
% Defining the style for the definitions
\colorlet{definitionbackground}{tableheaderbackground!10}
\colorlet{definitionheaderforeground}{tableheaderforeground}
\colorlet{definitionborder}{tableheaderbackground}
\colorlet{definitiontextforeground}{tableheaderforeground}
\colorlet{definitionsourceforeground}{gray}

\ifupmlang{french}{
	\gdef\definitionname{D\'efinition}
	\gdef\listdefinitionname{Liste des d\'efinitions}
	\gdef\upm@definition@formatsource#1{\definitionsourcename\;:\xspace#1}
}{
	\gdef\definitionname{Definition}
	\gdef\listdefinitionname{List of Definitions}
	\gdef\upm@definition@formatsource#1{\definitionsourcename:\xspace#1}
}
\global\let\definitionsourcename\upm@format@lang@sourcename

\gdef\upm@definition@width{\linewidth}

\tcbset{
	upmdefinition/.style={
		attach title,
		titlebox=visible,
		colback=definitionbackground,
		colframe=definitionborder,
		coltitle=definitionheaderforeground,
		coltext=definitiontextforeground,
		collower=definitionsourceforeground,
		fonttitle=\bfseries,
		fontlower=\normalfont\smaller\itshape,
		lower separated=false,
		rounded corners,
		before upper=\tcbtitle,
		halign=justify,
		halign title=left,
		width=\upm@definition@width,
		leftrule=1mm,
	}
}

\newcommand{\upm@definition@argumentmanager}[4][]{%
	\gdef\upm@definition@arga{#1}%
	\gdef\upm@definition@argb{#3}%
	\gdef\upm@definition@argc{#4}%
	\gdef\upm@definition@startenv{\begin{upm@#2}}%
	\@ifnextchar[{\upm@definition@argumentmanager@a}{\upm@definition@argumentmanager@b}%
}
\gdef\upm@definition@argumentmanager@a[#1]{%
	\gdef\upm@definition@source{#1}%
	\expandafter\upm@definition@startenv[lowerbox=visible,\upm@definition@arga]{\upm@definition@argb}{\upm@definition@argc}%
}
\gdef\upm@definition@argumentmanager@b{%
	\global\let\upm@definition@source\@empty%
	\expandafter\upm@definition@startenv[lowerbox=ignored,\upm@definition@arga]{\upm@definition@argb}{\upm@definition@argc}%
}

%-----
% Declare a theorem with the standard UPM style
% \declareupmtheorem[theorem_style]{environment_name}{label}{list_label}{label_prefix}{list_name}{source_format_macro}
\newcommand{\declareupmtheorem}[7][upmdefinition]{%
	\expandafter\newtcbtheorem[list inside=#6]{upm@#2}{#3}{upmdefinition}{#5}%
	\newenvironment{#2}[3][]{%
		\upm@definition@argumentmanager[##1]{#2}{\nohyphens{##2}}{##3}%
	}{%
		\Ifnotempty{\upm@definition@source}{\tcblower#7{\upm@definition@source}}%
		\end{upm@#2}%
	}
	% Check the version of the thmtools because the TeXLive distribution
	% gives a too old version.
	\global\@namedef{listof#2s}{\tcblistof[\upm@rootheadertoc]{#2}{#4}}%
}
\@onlypreamble\declareupmtheorem

%-----
% Declare the definition environments
\declareupmtheorem{definition}{\definitionname}{\listdefinitionname}{def}{definition}{\upm@definition@formatsource}
%-----
%\defref{label}
\newcommand{\defref}[1]{\ref{def:#1}}
%-----
%\defpageref{label}
\newcommand{\defpageref}[1]{\pageref{def:#1}}

%----------------------------------------
% ENVIRONMENT FOR EMPHBOX
%----------------------------------------

%-----
% Defining the style for the emphbox
\colorlet{emphboxbackground}{tableheaderbackground}
\colorlet{emphboxborder}{tableheaderforeground}
\colorlet{emphboxtext}{tableheaderforeground}
\colorlet{emphboxbackgroundb}{yellow!7}
\colorlet{emphboxbackgroundc}{green!10}

%-----
% Draw an emph box without title
% [#1]: width of the box (linewidth by default)
\NewEnviron{emphbox}[1][\linewidth]{%
	\begin{tcolorbox}[halign=center,valign=center,coltext=emphboxtext,colback=emphboxbackground,colframe=emphboxborder,rounded corners]
		\BODY%
	\end{tcolorbox}%
}

%-----
% Draw an emph box with title
% [#1]: width of the box (linewidth by default)
% #2: text of the title
\NewEnviron{titleemphbox}[2][\linewidth]{%
	\begin{tcolorbox}[halign=center,valign=center,coltext=emphboxtext,colback=emphboxbackground,colframe=emphboxborder,rounded corners,fonttitle=\bfseries,halign title=center,title=#2]
		\BODY%
	\end{tcolorbox}%
}

%-----
% Draw an emph box without title with the second background color
% [#1]: width of the box (linewidth by default)
% #2: text of the title
\NewEnviron{titleemphbox2}[2][\linewidth]{%
	\begin{tcolorbox}[halign=center,valign=center,coltext=emphboxtext,colback=emphboxbackgroundb,colframe=emphboxborder,rounded corners,fonttitle=\bfseries,halign title=center,title=#2]
		\BODY%
	\end{tcolorbox}%
}

%-----
% Draw an emph box without title with the third background color
% [#1]: width of the box (linewidth by default)
% #2: text of the title
\NewEnviron{titleemphbox3}[2][\linewidth]{%
	\begin{tcolorbox}[halign=center,valign=center,coltext=emphboxtext,colback=emphboxbackgroundc,colframe=emphboxborder,rounded corners,fonttitle=\bfseries,halign title=center,title=#2]
		\BODY%
	\end{tcolorbox}%
}

%----------------------------------------
% FIXING THE CHAPTER/SECTION NAMES
%----------------------------------------

% Change the names of the section "List of *" when the language
% is French, because the LaTeX packages do not define them properly
\AtBeginDocument{%
    \@ifundefined{listfigurename}{}{%
        \global\let\listfigurename\upm@format@lang@listoffigures%
    }%
    \@ifundefined{listalgorithmname}{}{%
         \global\let\listalgorithmname\upm@format@lang@listofalgorithms%
    }
}

%----------------------------------------
% REDEFINE THE LISTOFALGORTIHMS MACRO FOR BEING IN TOC
%----------------------------------------

% Force the list of algorithms to be in the TOC.
\AtBeginDocument{%
    \@ifundefined{listofalgorithms}{}{%
        \renewcommand{\listofalgorithms}{%
            \global\let\upm@float@listhead@old\float@listhead%
            \global\let\float@listhead\upm@rootheadertoc%
            \listof{algorithm}{\listalgorithmname}%
            \global\let\float@listhead\upm@float@listhead@old%
        }%
    }%
}

%----------------------------------------
% REDEFINE THE STYLE FOR THE ALGORITHMS
%----------------------------------------

\colorlet{algorithmcaptionlabel}{black}
\colorlet{algorithmcaption}{black}
\colorlet{algorithmborder}{gray}

\AtBeginDocument{%
    \@ifundefined{captionsetup}{}{%
        \captionsetup[algorithm]{labelfont={bf,color=algorithmcaptionlabel}, font={color=algorithmcaption}, labelsep=colon, position=top}
    }%
    %
    \@ifundefined{fs@ruled}{}{%
        \gdef\fs@ruled{%
            \def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@toto%
            % Define the code before the label
            \def\@fs@pre{%
                \begingroup\color{algorithmborder}\hrule height.8pt depth0pt \kern2pt\endgroup%
            }%
            % Define the code between the label and the float content
            \def\@fs@mid{%
                \begingroup\color{algorithmborder}\kern2pt\hrule\kern2pt\endgroup%
            }%
            % Define the code after the float content
            \def\@fs@post{%
                \begingroup\color{algorithmborder}\kern2pt\hrule\relax\endgroup%
            }%
            \let\@fs@iftopcapt\iftrue%
        }%
    }%
}

\endinput