% Document class for the PhD thesis
%
% Copyright (c) 2012-25 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.

%%--------------------
%% Declare the LaTeX class
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{spimbasephdthesis}[2026/05/08]

\RequirePackage{lettrine}
\RequirePackage[export]{adjustbox}

%%--------------------
%% Check for the correct version of tex-upmethodology
\@ifclasslater{UPMVERSION}{2025/04/20}{}{\@latex@error{You must install a version of tex-upmethodology greater or equal to 2025-03-14}\@eha}

%%--------------------
%% Change the default baseline
\renewcommand{\baselinestretch}{1.25} 

%%--------------------
%% Underlining if the author's name (in bibliography)
\newcommand{\underlineifauthor}[2]{%
	\ifdocumentauthor{#1}{\underline{#2}}{#2}%
}

%%--------------------
%% Colors dedicated to the PhD style
\colorlet{standardphdcolor}{black}

%%--------------------
%% Utility functions
\gdef\edspim@phdthesis@class@firstword#1 #2\@nil{#1}
\gdef\edspim@phdthesis@class@nextwords#1 #2\@nil{#2}
\gdef\edspim@phdthesis@class@firstcolumn#1,#2\@nil{#1}
\gdef\edspim@phdthesis@class@nextcolumns#1,#2\@nil{#2}
\gdef\edspim@phdthesis@class@makejury{}
\gdef\edspim@phdthesis@class@addjury#1#2{%
	\addjury%
		{\expandafter\edspim@phdthesis@class@firstword\edspim@phdthesis@class@firstcolumn#2\@nil\@nil}%
		{\expandafter\edspim@phdthesis@class@nextwords\edspim@phdthesis@class@firstcolumn#2\@nil\@nil}%
		{#1}%
		{\edspim@phdthesis@class@nextcolumns#2\@nil}%
}

%%--------------------
% Define the PhD thesis document
%\declarethesis[subtitle]{title}{defense date}{defense location}{ID}
\newcommand{\declarethesis}[5][] {
	\declaredocument{#2}{#1}{#5}%
	\Set{defensedate}{#3}%
	\Set{defenselocation}{#4}%
	\initialversion{\makedate{11}{04}{2006}}{PhD Thesis}{\upmpublic}%
}

%%--------------------
% Define the title in the minor language for PhD thesis document
%\declareminorthesistitle{title}
\newcommand{\declareminorthesistitle}[1] {
	\Set{minorlanguagethesistitle}{#1}%
}

%%--------------------
% Add member of the jury
%\addjury[email]{firstname}{lastname}{role}{position}
\newcommand{\upm@phdthesis@protectnl}[1]{%
	\begingroup%
		\let\\\newline%
		\nohyphens{\Get{jurystyle}#1}%
	\endgroup%
}
\gdef\upm@phdthesis@jurylist{}
\global\let\thejurytab\relax
\newcommand{\addjury}[5][]{%
	\upm@phdthesis@addjuryex{#1}{}{#2}{#3}{#4}{#5}%
}

%%--------------------
% Add member of the jury
%\addjuryex[email]{civility}{firstname}{lastname}{role}{position}
\newcommand{\addjuryex}[6][]{%
	\upm@phdthesis@addjuryex{#1}{#2~}{#3}{#4}{#5}{#6}%
}
\newcommand{\upm@phdthesis@addjuryex}[6]{%
	\global\protected@edef\upm@phdthesis@jurylist{\upm@phdthesis@jurylist\protect\protect\Get{jurystyle}\protect\upm@phdthesis@protectnl{#2}~\protect\protect\upmmakenamestar{#3}{#4}{~} & \protect\upm@phdthesis@protectnl{#6} & \protect\upm@phdthesis@protectnl{#5} \protect\\}%
	\global\protected@edef\thejurytab{\protect\noindent\protect\begin{tabularx}{\Get{jurytabwidth}}{@{}lXl@{}}\upm@phdthesis@jurylist\protect\end{tabularx}}%
}

%%--------------------
% Add affiliation
%\addlaboratory{lab description}
\newif\ifphdthesishaslaboratory
\global\phdthesishaslaboratoryfalse
\newif\ifphdthesishaslaboratorymulti
\global\phdthesishaslaboratorymultifalse
\gdef\thethesislaboratories{}
\newcommand{\addlaboratory}[1]{%
	\ifphdthesishaslaboratory%
		\phdthesishaslaboratorymultitrue%
		\global\protected@edef\thethesislaboratories{\thethesislaboratories,\protect\\\protect{#1}}%
	\else%
		\phdthesishaslaboratorytrue%
		\global\protected@edef\thethesislaboratories{\thethesislaboratories\protect{#1}}%
	\fi%
}
%%--------------------
% Set affiliation logo (only one logo is possible)
%\setlaboratorylogo{lab logo image}
\newif\iflaboratorylogo
\laboratorylogofalse
\let\thethesislaboratorylogo\relax
\newcommand{\setlaboratorylogo}[2][]{%
	\global\laboratorylogotrue%
	\gdef\thethesislaboratorylogo{\raisebox{-.5\height}{\includegraphics[max width=4cm,max height=1.5cm,keepaspectratio,#1]{#2}}}%
}
%%--------------------
% Reset affiliation
%\resetlaboratories
\newcommand{\resetlaboratories}{%
	\global\phdthesishaslaboratoryfalse%
	\global\phdthesishaslaboratorymultifalse%
	\gdef\thethesislaboratories{}%
	\global\laboratorylogofalse%
	\global\let\thethesislaboratorylogo\relax%
}

%%--------------------
%% Add partner logo
%\addpartner[picture_options]{logo_picture}
\newif\ifpartnerlist
\global\partnerlistfalse
\gdef\thepartnerlist{}
\newcommand{\upm@phdthesis@partner@raisedincludegraphics}[2][]{%
	\raisebox{-.5\height}{%
		\includegraphics[max width=4cm,max height=1.5cm,keepaspectratio,#1]{#2}%
	}%
}
\newcommand{\addpartner}[2][]{%
	\ifpartnerlist%
		\protected@xdef\thepartnerlist{\thepartnerlist%
			\protect\hspace{.2cm}%
			\protect\upm@phdthesis@partner@raisedincludegraphics[#1]{#2}%
		}%
	\else%
		\global\partnerlisttrue%
		\protected@xdef\thepartnerlist{\thepartnerlist%
			\protect\upm@phdthesis@partner@raisedincludegraphics[#1]{#2}%
		}%
	\fi%
}

%%--------------------
%% Reset the list of the partner logos
%\resetpartners
\newif\ifpartnerlist
\newcommand{\resetpartners}{%
	\global\partnerlistfalse%
	\gdef\thepartnerlist{}%
}

%%--------------------
% Change the color of the TOC
\let\upm@phdthesis@l@contentsline\contentsline
\renewcommand{\contentsline}[4]{%
	%{subsection}{\numberline {1.1.2}Extension de la plateforme \textsc {JaSIM}\xspace et Application}{18}{subsection.1.1.2}
	\ifthenelse
		{\equal{#1}{part}}
		{\upm@phdthesis@l@contentsline{#1}{\textcolor{parttitlecolor}{#2}}{\textcolor{parttitlecolor}{#3}}{#4}}%
		{\ifthenelse
			{\equal{#1}{chapter}}
			{\upm@phdthesis@l@contentsline{#1}{\textcolor{chaptertitlecolor}{#2}}{\textcolor{chaptertitlecolor}{#3}}{#4}}%
			{\upm@phdthesis@l@contentsline{#1}{#2}{#3}{#4}}}%
}

%%--------------------
% Set the abstract of the thesis
% \thesisabstract [lang]{text}
\newif\ifphdthesismainabstract
\phdthesismainabstractfalse
\newif\ifphdthesisminorabstract
\phdthesisminorabstractfalse
\gdef\phdthesismainabstract{}
\gdef\phdthesisminorabstract{}
\gdef\phdthesismaindocumenttitle{Titre\;:}
\gdef\phdthesismainabstracttitle{R\'esum\'e\;:}
\gdef\phdthesisminorabstracttitle{Abstract:}
\newcommand{\thesisabstract}[2][\upmcurrentlang]{%
	\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
		\global\phdthesismainabstracttrue%
		\gdef\phdthesismainabstract{#2}%
		\setdocabstract{#2}%
		\ifthenelse{\equal{english}{#1}}{%
			\gdef\phdthesismaindocumenttitle{Title:}
			\gdef\phdthesismainabstracttitle{Abstract:}
		}{%
			\gdef\phdthesismaindocumenttitle{Titre\;:}
			\gdef\phdthesismainabstracttitle{R\'esum\'e\;:}
		}%
	}{%
		\global\phdthesisminorabstracttrue%
		\gdef\phdthesisminorabstract{#2}%
		\ifthenelse{\equal{english}{#1}}{%
			\gdef\phdthesisminordocumenttitle{Title:}
			\gdef\phdthesisminorabstracttitle{Abstract:}
		}{%
			\gdef\phdthesisminordocumenttitle{Titre\;:}
			\gdef\phdthesisminorabstracttitle{R\'esum\'e\;:}
		}%
	}%
}

%%--------------------
% Set the keywords of the thesis
% \thesiskeywords [lang]{keywords}
\newif\ifphdthesismainkeywords
\phdthesismainkeywordsfalse
\newif\ifphdthesisminorkeywords
\phdthesisminorkeywordsfalse
\gdef\phdthesismainkeywords{}
\gdef\phdthesisminorkeywords{}
\gdef\phdthesismainkeywordstitle{}
\gdef\phdthesisminorkeywordstitle{}
\newcommand{\thesiskeywords}[2][\upmcurrentlang]{%
	\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
		\global\phdthesismainkeywordstrue%
		\gdef\phdthesismainkeywords{#2}%
		\ifthenelse{\equal{english}{#1}}{%
			\gdef\phdthesismainkeywordstitle{Keywords:}
		}{%
			\gdef\phdthesismainkeywordstitle{Mots-cl\'es\;:}
		}%
	}{%
		\global\phdthesisminorkeywordstrue%
		\gdef\phdthesisminorkeywords{#2}%
		\ifthenelse{\equal{english}{#1}}{%
			\gdef\phdthesisminorkeywordstitle{Keywords:}
		}{%
			\gdef\phdthesisminorkeywordstitle{Mots-cl\'es\;:}
		}%
	}%
}

%%--------------------
% Utility function that is looping on the character of a text
% \foreachchar {for first char}{for the rest of the chars}
\gdef\@endfe{}
\def\upm@foreachchar#1#2\@endfe{%
	\def\thechar{#1}%
	\upm@foreach@do%
	\renewcommand{\onfirstchar}[1]{}%
	\renewcommand{\onnextchar}[1]{##1}%
	\ifthenelse{\equal{{#2}}{{\@endfe}}}{}{
		\expandafter\upm@foreachchar#2\@endfe%
	}%
}

\newcommand{\foreachchar}[2]{%
	\begingroup%
	\newcommand{\upm@foreach@do}{#2}%
	\newcommand{\onfirstchar}[1]{##1}%
	\newcommand{\onnextchar}[1]{}%
	{\expandafter\upm@foreachchar#1\@endfe\@endfe}%
	\endgroup%
}

%%--------------------
% Build card with the PhD thesis reference ID inside.
% This ID is given by the SPIM doctoral school.
\newcommand{\thespimthesisdocrefcard}{%
	\gdef\upm@spimthesis@reserveda{|}%
	\gdef\upm@spimthesis@reservedb{}%
	\foreachchar{\theupmdocref}{%
		\protected@xdef\upm@spimthesis@reserveda{|c\upm@spimthesis@reserveda}%
		\protected@xdef\upm@spimthesis@reservedb{\upm@spimthesis@reservedb \onnextchar{\protect&} \thechar}%
	}%
	\protected@xdef\upm@spimthesis@reserveda{%
		\protect\tabular[c]{\upm@spimthesis@reserveda}}%
	N\ensuremath{^{\circ}}~\upm@spimthesis@reserveda%
	\upm@spimthesis@reservedb \\ \hline\endtabular%
}

%%--------------------
%% Define emphazing macros
\renewcommand{\Emph}[1]{\textcolor{emphemphtextcolor}{\textbf{#1}}}
\renewcommand{\emph}[1]{\textcolor{emphtextcolor}{#1}}

%%--------------------
%% Macros for formating the bibliography
\newcommand{\phdthesisbibemph}[1]{\textit{#1}}
\newcommand{\phdthesisbibEmph}[1]{\textcolor{bibemphemphtextcolor}{\textbf{#1}}}
\newcommand{\phdthesisbibkeyemph}[1]{\textbf{#1}}

\ifthenelse{\equal{french}{\upmcurrentlang}}{
	\gdef\phdthesisbibmasterthesis{Th\`ese de Master\xspace}
	\gdef\phdthesisbibphdthesis{Th\`ese de Doctorat\xspace}
	\gdef\phdthesisbibSee{Voir\xspace}
	\gdef\phdthesisbibAccessDate{Date d'acc\`es~:\xspace}
	\gdef\phdthesisbibevent{\'ev\'enement\xspace}
	\gdef\phdthesisbiband{et\xspace}
	\gdef\phdthesisbibetal{et~al.\xspace}
	\gdef\phdthesisbibeditors{\'editeurs\xspace}
	\gdef\phdthesisbibeditor{\'editeur\xspace}
	\gdef\phdthesisbibvolume{volume\xspace}
	\gdef\phdthesisbibVolume{Volume\xspace}
	\gdef\phdthesisbibof{de\xspace}
	\gdef\phdthesisbibvolumenumber{volume et num\'ero\xspace}
	\gdef\phdthesisbibnumber{num\'ero\xspace}
	\gdef\phdthesisbibNumber{Num\'ero\xspace}
	\gdef\phdthesisbibin{dans\xspace}
	\gdef\phdthesisbibIn{Dans\xspace}
	\gdef\phdthesisbibedition{\'edition\xspace}
	\gdef\phdthesisbibpages{pages\xspace}
	\gdef\phdthesisbibpage{page\xspace}
	\gdef\phdthesisbibchapter{chapitre\xspace}
	\gdef\phdthesisbibChapter{Chapitre\xspace}
	\gdef\phdthesisbibresearchreport{Rapport de Recherche\xspace}
	\gdef\phdthesisbibtechnicalreport{Rapport technique\xspace}
	\gdef\phdthesisbibJanuary{Janvier\xspace}
	\gdef\phdthesisbibFebruary{F\'evrier\xspace}
	\gdef\phdthesisbibMarch{Mars\xspace}
	\gdef\phdthesisbibApril{Avril\xspace}
	\gdef\phdthesisbibMay{Mai\xspace}
	\gdef\phdthesisbibJune{Juin\xspace}
	\gdef\phdthesisbibJuly{Juillet\xspace}
	\gdef\phdthesisbibAugust{Ao\^ut\xspace}
	\gdef\phdthesisbibSeptember{Septembre\xspace}
	\gdef\phdthesisbibOctober{Octobre\xspace}
	\gdef\phdthesisbibNovember{Novembre\xspace}
	\gdef\phdthesisbibDecember{D\'ecembre\xspace}
}{%
	\gdef\phdthesisbibmasterthesis{Master Thesis\xspace}
	\gdef\phdthesisbibphdthesis{PhD Thesis\xspace}
	\gdef\phdthesisbibSee{See\xspace}
	\gdef\phdthesisbibAccessDate{Access date:\xspace}
	\gdef\phdthesisbibevent{event\xspace}
	\gdef\phdthesisbiband{and\xspace}
	\gdef\phdthesisbibetal{et~al.\xspace}
	\gdef\phdthesisbibeditors{editors\xspace}
	\gdef\phdthesisbibeditor{editor\xspace}
	\gdef\phdthesisbibvolume{volume\xspace}
	\gdef\phdthesisbibVolume{Volume\xspace}
	\gdef\phdthesisbibof{of\xspace}
	\gdef\phdthesisbibvolumenumber{volume and number\xspace}
	\gdef\phdthesisbibnumber{number\xspace}
	\gdef\phdthesisbibNumber{Number\xspace}
	\gdef\phdthesisbibin{in\xspace}
	\gdef\phdthesisbibIn{In\xspace}
	\gdef\phdthesisbibedition{edition\xspace}
	\gdef\phdthesisbibpages{pages\xspace}
	\gdef\phdthesisbibpage{page\xspace}
	\gdef\phdthesisbibchapter{chapter\xspace}
	\gdef\phdthesisbibChapter{Chapter\xspace}
	\gdef\phdthesisbibresearchreport{Research Report\xspace}
	\gdef\phdthesisbibtechnicalreport{Technical Report\xspace}
	\gdef\phdthesisbibJanuary{January\xspace}
	\gdef\phdthesisbibFebruary{February\xspace}
	\gdef\phdthesisbibMarch{March\xspace}
	\gdef\phdthesisbibApril{April\xspace}
	\gdef\phdthesisbibMay{May\xspace}
	\gdef\phdthesisbibJune{June\xspace}
	\gdef\phdthesisbibJuly{July\xspace}
	\gdef\phdthesisbibAugust{August\xspace}
	\gdef\phdthesisbibSeptember{September\xspace}
	\gdef\phdthesisbibOctober{October\xspace}
	\gdef\phdthesisbibNovember{November\xspace}
	\gdef\phdthesisbibDecember{December\xspace}
}

%%--------------------
%% Force the name of the bibliography and other sections for French
\AtBeginDocument{
	\ifthenelse{\equal{\edspimphdthesisclasslanguage}{french}}{%
		\renewcommand{\refname}{Bibliographie}%
		\renewcommand{\listtablename}{Liste des tables}%
		\renewcommand{\contentsname}{Sommaire}%
	}{}
}

%%--------------------
%% Format the keys in the bibliography section
\global\let\upm@phdthesis@old@biblabel\@biblabel
\gdef\@biblabel#1{\phdthesisbibkeyemph{\upm@phdthesis@old@biblabel{#1}}}


%%--------------------
% Lettrine

% Color of the lettine
\colorlet{lettrinecolor}{standardphdcolor}

% The following macro put its parameter into a lettrine with the
% proper layout
\gdef\upm@phdthesis@MakeLettrine@lettrine#1{%
	\lettrine[findent=.5mm,nindent=0pt,lines=3,loversize=0.1]{\rmfamily\textcolor{lettrinecolor}{\uppercase{#1}}}{}%
}

% Macro that contains the string "the letter"
\gdef\upm@phdthesis@MakeLettrine@letterstr{\string t\string h\string e\space\string l\string e\string t\string t\string e\string r}

% Macro that contains the string "the character"
\gdef\upm@phdthesis@MakeLettrine@characterstr{\string t\string h\string e\space\string c\string h\string a\string r\string a\string c\string t\string e\string r}

% Macro to search for the first letter in its second parameter
% and put it in a lettrine.
% First parameter: are the macros to ignore and put back before
%                  the lettrine. The value of this parameter will
%                  evolve during the recursive calls.
% Second parameter: TeX give the token following the macro in
%                   this parameter (because the macros is always
%                   invoked with only one explicit parameter).
\newcommand{\upm@phdthesis@MakeLettrine}[2]{%
	% Detect the meaning of the second parameter.
	\edef\upm@phdthesis@reserveda{\meaning#2}%
	% Test if the meaning string contains "the letter"
	\edef\upm@phdthesis@reservedb{\noexpand\in@{\upm@phdthesis@MakeLettrine@letterstr}{\upm@phdthesis@reserveda}}%
	\upm@phdthesis@reservedb%
	\ifin@%
		% The meaning indicates that the second parameter
		% is a letter. It may be put in the lettrine.
		% The macro \upm@phdthesis@reserveda is defined to avoid
		% to consume the tokens written in this recursive
		% macro. This temp macro is invoked at the end of
		% this recursive macro. In this way it will consume
		% the token that are available in the document core.
		\gdef\upm@phdthesis@reserveda{#1\upm@phdthesis@MakeLettrine@lettrine{#2}}%
	\else%
		% Test if the meaning string contains "the character"
		\edef\upm@phdthesis@reservedb{\noexpand\in@{\upm@phdthesis@MakeLettrine@characterstr}{\upm@phdthesis@reserveda}}%
		\upm@phdthesis@reservedb%
		\ifin@%
			% The meaning indicates that the second parameter
			% is a character. It may be put in the lettrine.
			% The macro \upm@phdthesis@reserveda is defined to avoid
			% to consume the tokens written in this recursive
			% macro. This temp macro is invoked at the end of
			% this recursive macro. In this way it will consume
			% the token that are available in the document core.
			\gdef\upm@phdthesis@reserveda{#1\upm@phdthesis@MakeLettrine@lettrine{#2}}%
		\else%
			% The meaning indicates that the second parameter
			% is not a letter nor a character.
			% It may be put back before the lettrine without
			% change.
			% The macro \upm@phdthesis@reserveda is defined to avoid
			% to consume the tokens written in this recursive
			% macro. This temp macro is invoked at the end of
			% this recursive macro. In this way it will consume
			% the token that are available in the document core.
			\gdef\upm@phdthesis@reserveda{\upm@phdthesis@MakeLettrine{#1#2}}%
		\fi%
	\fi%
	\upm@phdthesis@reserveda%
}

%%--------------------
%% Macros for starting a chapter with a standard format

% The public interface of the macro that permits to put a lettrine
\newcommand{\chapterintrolettrine}[1]{%
	\upm@phdthesis@MakeLettrine@lettrine#1%
}

% Output a local etoc or a minitoc with the standard formatting
\newcommand{\chapterintrominitoc}{%
	\@ifundefined{minitoc}{%
		\@ifundefined{localtableofcontents}{%
		}{%
			\etocsettocstyle{\section*{\contentsname}}{}%
			\localtableofcontents%
		}%
	}{%
		\begin{figure}[bt]%
		\minitoc%
		\end{figure}%
	}%
}

% Add a lettrine and a minitoc at the next following \section
\global\long\def\chapterintrotosection#1\section{%
	\chapterintrominitoc%
	\ignorespaces\upm@phdthesis@MakeLettrine{}#1%
	\expandafter\section}

% Add a lettrine and a minitoc at the next following \input
\global\long\def\chapterintrotoinput#1\input{%
	\chapterintrominitoc%
	\ignorespaces\upm@phdthesis@MakeLettrine{}#1%
	\expandafter\input}

% Add a lettrine and a minitoc at the next following \include
\global\long\def\chapterintrotoinclude#1\include{%
	\chapterintrominitoc%
	\ignorespaces\upm@phdthesis@MakeLettrine{}#1%
	\expandafter\include}

% No lettrine at the begining of the chapter
\global\long\def\upm@phdthesis@chapterintro@notoc{%
	\ignorespaces\upm@phdthesis@MakeLettrine{}}

% Standard formating with looking forward for \section, \input, or \include
\gdef\chapterintro{\@ifstar\upm@phdthesis@chapterintro@notoc\chapterintrotosection}

%%--------------------
%% Add a small message on the backcover.
\Set{backcovermessage}{%
	\begin{center}\tiny
		\ifthenelse{\equal{french}{\upmcurrentlang}}{
			Document r\'ealis\'e avec \LaTeX,
			le style \LaTeX\ pour th\`ese de Doctorat \url{https://www.arakhne.org/latex/tex-templates} et \\
			la collection d'outils \texttt{tex-upmethodology} \url{http://www.arakhne.org/latex/tex-upmethodology}\\[.25cm]
		}{
			Document generated with \LaTeX,
			the \LaTeX\ template for PhD dissertations \url{https://www.arakhne.org/latex/tex-templates
} and \\
			the \texttt{tex-upmethodology} suite \url{http://www.arakhne.org/tex-upmethodology}\\[.25cm]
		}
	\end{center}
}

%%--------------------
%% Command for determing to prefix with "de" or "d'".
%\De{text}
\let\upm@phdthesis@firstchartok\relax
\newcommand{\upm@phdthesis@firstchar}[1]{\upm@phdthesis@firstcharaux#1\@nil}
\def\upm@phdthesis@firstcharaux#1#2\@nil{\gdef\upm@phdthesis@firstchartok{\detokenize{#1}}}
\newcommand{\De}[1]{%
	\protected@edef\upm@phdthesis@tmp{\protect\upm@phdthesis@firstchar{#1}}%
	\upm@phdthesis@tmp%
	\ifthenelse{%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{a}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{A}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{e}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{E}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{i}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{I}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{o}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{O}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{u}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{U}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{y}}\or%
		\equal{\upm@phdthesis@firstchartok}{\detokenize{Y}}%
	}{d'#1}{de #1}%
}

%%--------------------
%% Environment for showing up a research question of the PhD thesis.
%% The star version does not add the research question's counter in the title
%\begin{researchquestion}[title] description \end{researchdirection}
%\begin{researchquestion*}[title] description \end{researchdirection*}
\ifupmlang{french}{%
	\gdef\upm@phdthesis@researchquestion@label{Question de recherche}%
	\gdef\upm@phdthesis@researchquestion@slabel{QR}%
}{%
	\gdef\upm@phdthesis@researchquestion@label{Research Question}%
	\gdef\upm@phdthesis@researchquestion@slabel{RQ}%
}
\gdef\upm@phdthesis@researchquestion@format@title#1{\textbf{#1}}%

\newcounter{upm@phdthesis@researchquestion@count}
\setcounter{upm@phdthesis@researchquestion@count}{0}

\newenvironment{upm@phdthesis@researchquestion}[2]{%
	\global\addtocounter{upm@phdthesis@researchquestion@count}{1}%
	\begin{tcolorbox}[coltitle=researchquestiontitle, colback=researchquestionbackground!10, colframe=researchquestionbackground!40, title=\upm@phdthesis@researchquestion@format@title{\upm@phdthesis@researchquestion@label#1\Ifnotempty{#2}{ -- #2}}]%
	\renewcommand{\@currentlabel}{\upm@phdthesis@researchquestion@slabel\theupm@phdthesis@researchquestion@count}%

}{%
	\end{tcolorbox}%
}

\newenvironment{researchquestion}[1][\@empty]{%
	\begin{upm@phdthesis@researchquestion}{\xspace\theupm@phdthesis@researchquestion@count\xspace(\upm@phdthesis@researchquestion@slabel\theupm@phdthesis@researchquestion@count)}{#1}%
}{%
	\end{upm@phdthesis@researchquestion}%
}
\newenvironment{researchquestion*}[1][\@empty]{%
	\begin{upm@phdthesis@researchquestion}{}{#1}%
}{%
	\end{upm@phdthesis@researchquestion}%
}

%%--------------------
%% Environment for showing up an objective of the PhD thesis.
%% The star version does not add the contribution's counter in the title
%\begin{objective}[title] description \end{objective}
%\begin{objective*}[title] description \end{objective*}
\ifupmlang{french}{%
	\gdef\upm@phdthesis@objective@label{Objectif}%
}{%
	\gdef\upm@phdthesis@objective@label{Objective}%
}
\gdef\upm@phdthesis@objective@slabel{O}%
\gdef\upm@phdthesis@objective@format@title#1{\textbf{#1}}%

\newcounter{upm@phdthesis@objective@count}
\setcounter{upm@phdthesis@objective@count}{0}

\newenvironment{upm@phdthesis@objective}[2]{%
	\global\addtocounter{upm@phdthesis@objective@count}{1}%
	\begin{tcolorbox}[coltitle=objectivetitle, colback=objectivebackground!10, colframe=objectivebackground!40, title=\upm@phdthesis@objective@format@title{\upm@phdthesis@objective@label#1\Ifnotempty{#2}{ -- #2}}]%
	\renewcommand{\@currentlabel}{\upm@phdthesis@objective@slabel\theupm@phdthesis@objective@count}%

}{%
	\end{tcolorbox}%
}

\newenvironment{objective}[1][\@empty]{%
	\begin{upm@phdthesis@objective}{\xspace\theupm@phdthesis@objective@count\xspace(\upm@phdthesis@objective@slabel\theupm@phdthesis@objective@count)}{#1}%
}{%
	\end{upm@phdthesis@objective}%
}
\newenvironment{objective*}[1][\@empty]{%
	\begin{upm@phdthesis@objective}{}{#1}%
}{%
	\end{upm@phdthesis@objective}%
}

%%--------------------
%% Environment for showing up a contribution of the PhD thesis.
%% The star version does not add the contribution's counter in the title
%\begin{objective}[title] description \end{objective}
%\begin{objective*}[title] description \end{objective*}
\ifupmlang{french}{%
	\gdef\upm@phdthesis@contribution@label{Contribition}%
}{%
	\gdef\upm@phdthesis@contribution@label{Contribution}%
}
\gdef\upm@phdthesis@contribution@slabel{C}%
\gdef\upm@phdthesis@contribution@format@title#1{\textbf{#1}}%

\newcounter{upm@phdthesis@contribution@count}
\setcounter{upm@phdthesis@contribution@count}{0}

\newenvironment{upm@phdthesis@contribution}[2]{%
	\global\addtocounter{upm@phdthesis@contribution@count}{1}%
	\begin{tcolorbox}[coltitle=contributiontitle, colback=contributionbackground!10, colframe=contributionbackground!40, title=\upm@phdthesis@contribution@format@title{\upm@phdthesis@contribution@label#1\Ifnotempty{#2}{ -- #2}}]%
	\renewcommand{\@currentlabel}{\upm@phdthesis@contribution@slabel\theupm@phdthesis@contribution@count}%

}{%
	\end{tcolorbox}%
}

\newenvironment{contribution}[1][\@empty]{%
	\begin{upm@phdthesis@contribution}{\xspace\theupm@phdthesis@contribution@count\xspace(\upm@phdthesis@contribution@slabel\theupm@phdthesis@contribution@count)}{#1}%
}{%
	\end{upm@phdthesis@contribution}%
}
\newenvironment{contribution*}[1][\@empty]{%
	\begin{upm@phdthesis@contribution}{}{#1}%
}{%
	\end{upm@phdthesis@contribution}%
}

%%--------------------
%% Default roles for the jury
\let\ifenglish\relax%
\newcommand{\rolePresidentM}{\ifenglish{President}{Pr\'esident}}%
\newcommand{\rolePresidentF}{\ifenglish{President}{Pr\'esidente}}%
\newcommand{\roleReviewerM}{\ifenglish{Reviewer}{Rapporteur}}%
\newcommand{\roleReviewerF}{\ifenglish{Reviewer}{Rapporteuse}}%
\newcommand{\roleExaminerM}{\ifenglish{Examiner}{Examinateur}}%
\newcommand{\roleExaminerF}{\ifenglish{Examiner}{Examinatrice}}%
\newcommand{\roleDirectorM}{\ifenglish{Director}{Directeur}}%
\newcommand{\roleDirectorF}{\ifenglish{Director}{Directrice}}%
\newcommand{\roleCodirectorM}{\ifenglish{Codirector}{Co-Directeur}}%
\newcommand{\roleCodirectorF}{\ifenglish{Codirector}{Co-Directrice}}%
\newcommand{\roleSupervisorM}{\ifenglish{Supervisor}{Encadrant}}%
\newcommand{\roleSupervisorF}{\ifenglish{Supervisor}{Encadrante}}%
\newcommand{\roleCosupervisorM}{\ifenglish{Co-Supervisor}{Co-Encadrant}}%
\newcommand{\roleCosupervisorF}{\ifenglish{Co-Supervisor}{Co-Encadrante}}%
\newcommand{\roleInviteeM}{\ifenglish{Invitee}{Invit\'e}}%
\newcommand{\roleInviteeF}{\ifenglish{Invitee}{Invit\'ee}}%

%%--------------------
% Labels for the front page
\SetLangDefault{english}{frontpagephdthesis}{DOCTORAL THESIS}
\SetLangDefault{french}{frontpagephdthesis}{TH\`ESE DE DOCTORAT}
\SetLangDefault{english}{frontpagejointphdthesis}{JOINT DOCTORAL THESIS}
\SetLangDefault{french}{frontpagejointphdthesis}{TH\`ESE DE DOCTORAT EN CO-TUTELLE}
\SetLangDefault{english}{frontpageuniversity}{OF}
\SetLangDefault{french}{frontpageuniversity}{DE L'\'ETABLISSEMENT}
\SetLangDefault{english}{frontpageuniversity2}{AND OF}
\SetLangDefault{french}{frontpageuniversity2}{ET DE L'\'ETABLISSEMENT}
\SetLangDefault{english}{frontpagedoctoralschool}{Doctoral School \#}
\SetLangDefault{french}{frontpagedoctoralschool}{\'Ecole doctorale n\textdegree}
\SetLangDefault{english}{frontpagedoctorof}{Doctor in\ }
\SetLangDefault{french}{frontpagedoctorof}{Doctorat \De}
\SetLangDefault{english}{frontpageby}{by}
\SetLangDefault{french}{frontpageby}{par}

\Set{doctoralschoolnumber}{37}
\SetLangDefault{english}{doctoralschoolname}{Physical Sciences for Engineering and Microtechnologies}
\SetLangDefault{french}{doctoralschoolname}{Sciences Physiques pour l'Ing\'enieur et Microtechniques}


%%--------------------
%% Default front page for the SPIM doctoral thesis
% #1: the language
% #2: university logo
\newcommand{\upmspimthesisstandardfrontpage}[2]{
	\ifthenelse{\equal{#1}{english}}{%
		\gdef\ifenglish##1##2{##1}%
	}{%
		\gdef\ifenglish##1##2{##2}%
	}%
	\pagestyle{empty}%
	\begin{picture}(0,0)%
	\put(-40,30){\parbox[t]{16.75cm}{%
		\raggedright\raisebox{-.5\height}{\includegraphics[max width=5cm,max height=2cm,keepaspectratio]{#2}}%
		\iflaboratorylogo%
			\hfill\thethesislaboratorylogo%
		\fi%
		\IfFileExists{spimbasephdthesis-spim.pdf}{%
			\hfill\raisebox{-.5\height}{\includegraphics[max width=4cm,max height=1.5cm,keepaspectratio]{spimbasephdthesis-spim}}%
		}{%
			\hfill\raisebox{-.5\height}{\includegraphics[max width=4cm,max height=1.5cm,keepaspectratio]{spimbasephdthesis-nologo}}%
		}%
	}}%
	\put(-40,-30){\parbox[t]{16.75cm}{%
		\ifpartnerlist%
			\raggedleft\thepartnerlist%
		\fi%
	}}
	\Ifelseundefined{jointuniversity}{%
		\put(-45,-70){\parbox[t][12cm][t]{17cm}{%
			% Reset the baseline
			\renewcommand{\baselinestretch}{1} 
			\begin{center}%
				{\bfseries\GetLang{#1}{frontpagephdthesis}} \\[.5cm]
				{\bfseries\GetLang{#1}{frontpageuniversity} \MakeUppercase{\GetLang{#1}{universityname}}} \\[1cm]

				{\large\GetLang{#1}{frontpagedoctoralschool}\Get{doctoralschoolnumber}} \\[.25cm]
				{\large\GetLang{#1}{doctoralschoolname}} \\[1cm]

				{\large\GetLang{#1}{frontpagedoctorof}{\GetLang{#1}{speciality}}} \\[1cm]

				{\large\GetLang{#1}{frontpageby}} \\[.5cm]

				{\Large\theauthorlist} \\[1.5cm]%

				\parbox{\linewidth}{\centering\Large%
					\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
						\nohyphens{\theupmproject}%
					}{%
						\nohyphens{\Get{minorlanguagethesistitle}}%
					}%
				}%
				\Ifnotempty\theupmdocname{\\[.25cm]\parbox{\linewidth}{\centering\large\nohyphens{\theupmdocname}}}%
			\end{center}%
		}}%
	}{%
		\put(-45,-60){\parbox[t][12cm][t]{17cm}{%
			% Reset the baseline
			\renewcommand{\baselinestretch}{1} 
			\begin{center}%
				{\bfseries\GetLang{#1}{frontpagejointphdthesis}} \\[.5cm]
				{\bfseries\GetLang{#1}{frontpageuniversity} \MakeUppercase{\GetLang{#1}{universityname}}} \\[.5cm]
				{\bfseries\GetLang{#1}{frontpageuniversity2} \MakeUppercase{\Get{jointuniversity}}} \\[1cm]

				{\large\GetLang{#1}{frontpagedoctoralschool}\Get{doctoralschoolnumber}} \\[.25cm]
				{\large\GetLang{#1}{doctoralschoolname}} \\[1cm]

				{\large\GetLang{#1}{frontpagedoctorof}{\GetLang{#1}{speciality}}} \\[1cm]

				{\large\GetLang{#1}{frontpageby}} \\[.5cm]

				{\Large\theauthorlist} \\[1.5cm]%

				\parbox{\linewidth}{\centering\Large%
					\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
						\nohyphens{\theupmproject}%
					}{%
						\nohyphens{\Get{minorlanguagethesistitle}}%
					}%
				}%
				\Ifnotempty\theupmdocname{\\[.25cm]\parbox{\linewidth}{\centering\large\nohyphens{\theupmdocname}}}%
			\end{center}%
		}}%
	}
	\put(-45,-520){\mbox{\parbox[t]{17cm}{%
		% Reset the baseline
		\renewcommand{\baselinestretch}{2}%
		{\Get{defensemessagestyle}\GetLang{#1}{defensemessage}}\\%
		\thejurytab%
	}}}
	\put(-60,-710){%
		\mbox{\parbox[t]{17cm}{%
			\ifthenelse{\equal{\theupmdocref}{}}{}{%
				\thespimthesisdocrefcard%\hfill\mbox{}%
			}%
		}}%
	}
	\end{picture}%
	\ifthenelse{\equal{\upmcurrentlang}{english}}{%
		\gdef\ifenglish##1##2{##1}%
	}{%
		\gdef\ifenglish##1##2{##2}%
	}%
}

%%--------------------
%% Default back page for the SPIM doctoral thesis
% #1: university logo
% #2: id of the value of the university address
% #3: the shifting of the university logo
\newcommand{\upmspimthesisstandardbackpage}[3]{
	\pagestyle{empty}%
	\begin{picture}(0,0)%
	\put(-50,30){\includegraphics[width=100\unitlength]{\Get{doctoralschoollogo}}}%
	\put(-50,-710){%
		\begin{tabular}{@{}ll@{}}%
			\raisebox{-#3\height}{\includegraphics[height=1.1cm]{#1}} & \parbox[c]{10cm}{\scriptsize\Get{#2}}%
		\end{tabular}%
	}%
	\put(-45,-325){\parbox[c][23cm][t]{17cm}{%
		% Reset the baseline
		\renewcommand{\baselinestretch}{1} 
		\ifphdthesismainabstract%
			\begin{tabularx}{\linewidth}{|X|}%
			\hline%
			\normalsize\small\Get{primarytitlestyle}\textbf{\phdthesismaindocumenttitle} \nohyphens{\ignorespaces\theupmproject} \\
			\ifphdthesismainkeywords%
				\normalsize\small\Get{primarykeywordstyle}\textbf{\phdthesismainkeywordstitle} \nohyphens{\ignorespaces\phdthesismainkeywords} \\%
			\fi%
			\normalsize\small\Get{primaryabstractstyle}\textbf{\phdthesismainabstracttitle} \\%
			\vspace{-.8cm}%
			\begin{multicols}{2}%
				\normalsize\small\Get{primaryabstractstyle}\nohyphens{\ignorespaces\phdthesismainabstract}%
			\end{multicols}\\%
			\hline%
			\end{tabularx}%
			\ifphdthesisminorabstract%
				\par\vspace{1cm}%
			\fi%
		\fi%
		\ifphdthesisminorabstract%
			\begin{tabularx}{\linewidth}{|X|}%
			\hline
			\normalsize\small\Get{secondarytitlestyle}\textbf{\phdthesisminordocumenttitle} \nohyphens{\ignorespaces\Get{minorlanguagethesistitle}} \\
			\ifphdthesismainkeywords%
				\normalsize\small\Get{secondarykeywordstyle}\textbf{\phdthesisminorkeywordstitle} \nohyphens{\ignorespaces\phdthesisminorkeywords} \\%
			\fi%
			\normalsize\small\Get{secondaryabstractstyle}\textbf{\phdthesisminorabstracttitle} \\
			\vspace{-.8cm}%
			\begin{multicols}{2}%
				\normalsize\small\Get{secondaryabstractstyle}\nohyphens{\ignorespaces\phdthesisminorabstract}%
			\end{multicols}\\
			\hline
			\end{tabularx}%
		\fi%
	}}%
	\end{picture}%
}

\endinput

