%% This is file `tudathesis.cfg' version 3.41 (2024-07-02),
%% it is part of
%% TUDa-CI -- Corporate Design for TU Darmstadt
%% ----------------------------------------------------------------------------
%%
%%  Copyright (C) 2018--2024 by Marei Peischl <marei@peitex.de>
%%
%% ============================================================================
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008/05/04 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainers of this work are
%%   Marei Peischl <tuda-ci@peitex.de>
%%
%% The development respository can be found at
%% https://github.com/tudace/tuda_latex_templates
%% Please use the issue tracker for feedback!
%%
%% ============================================================================
%%
\def\fileversion{3.41}
\def\filedate{2024-07-02}
\RequirePackage{expl3}
\ProvidesExplFile{tudathesis.cfg}
{\filedate}{\fileversion}{Special Features for publication type 'thesis' using TU Darmstadt's Corporate Design (tuda-ci)}

\RequirePackage{l3keys2e}


\tl_new:N \g_ptxcd_thesis_drtext_tl
\clist_if_exist:NF \g_ptxcd_Required_title_data_clist {\clist_new:N \g_ptxcd_Required_title_data_clist}

%Declare macros for department
\cs_new:Nn \ptxcd_select_department:n {
	\str_case:nnTF {#1} {
		{arch}   {\ptxcd_declare_caption:Nnn \ptxcd_department: {Architektur} {Architecture}}
		{bauing} {\ptxcd_declare_caption:Nnn \ptxcd_department: {Bau-~und~Umweltingenieurwissenschaften}{Civil~and~Environmental~Engineering}}
		{bio}    {\ptxcd_declare_caption:Nnn \ptxcd_department: {Biologie}{Biology}}
		{chem}   {\ptxcd_declare_caption:Nnn \ptxcd_department: {Chemie}{Chemistry}}
		{etit}   {\ptxcd_declare_caption:Nnn \ptxcd_department: {Elektrotechnik~und~Informationstechnik}{Electrical~Engineering~and~Information~Technology}}
		{gugw}   {\ptxcd_declare_caption:Nnn \ptxcd_department: {Gesellschafts-~und~Geschichtswissenschaften}{History~and~Social~Sciences}}
		{humanw} {\ptxcd_declare_caption:Nnn \ptxcd_department: {Humanwissenschaften}{Human~Sciences}}
		{inf}    {\ptxcd_declare_caption:Nnn \ptxcd_department: {Informatik}{Computer~Science}}
		{mb}     {\ptxcd_declare_caption:Nnn \ptxcd_department: {Maschinenbau}{Mechanical~Engineering}}
		{matgeo} {\ptxcd_declare_caption:Nnn \ptxcd_department: {Material-~und~Geowissenschaften}{Materials~and~Earth~Sciences}}
		{math}   {\ptxcd_declare_caption:Nnn \ptxcd_department: {Mathematik}{Mathematics}}
		{phys}   {\ptxcd_declare_caption:Nnn \ptxcd_department: {Physik}{Physics}}
		{wi}     {\ptxcd_declare_caption:Nnn \ptxcd_department: {Rechts-~und~Wirtschaftswissenschaften}{Law~and~Economics}}
	}
	{
		\ptxcd_declare_caption:Nnn \departmentname {Fachbereich} {department}
		\ptxcd_declare_caption:Nnn \departmentfullname {\departmentname{}~ \ptxcd_department:} { \ptxcd_department:{}~ \text_titlecase:n{\departmentname}}
		\ptxcd_declare_caption:Nnn \ptxcd_departmentprefix: {im~ \departmentname}{in~the~\departmentname{}~ of}
		\ptxcd_declare_caption:Nnn \ptxcd_in_department {\ptxcd_departmentprefix:{}~\ptxcd_department:}{\ptxcd_departmentprefix:{}~\ptxcd_department:}
	}
	{\bool_if:NTF \g_ptxcd_dr_bool
		{
			\msg_warning:nnn{tudapub/thesis} {unrecognized-department} {#1}
			\gdef\ptxcd_department:{#1}
			\ptxcd_declare_caption:Nnn \departmentname {Fachbereich} {department}
		}
		{\ptxcd_select_studyfield:n {#1}}
	}
}


\cs_new:Nn \ptxcd_select_studyfield:n {
	\str_case:nnTF {#1} {
		{ce}{\ptxcd_declare_caption:Nnn \ptxcd_department: {Computational\nobreakspace Engineering}{Computational\nobreakspace Engineering}}
		{ese}{\ptxcd_declare_caption:Nnn \ptxcd_department: {Energy~Science~and~Engineering}{Energy~Science~and~Engineering}}
		{ist}{\ptxcd_declare_caption:Nnn \ptxcd_department: {Informationssystemtechnik} {Information~Systems~Technology}}
		{mech}{\ptxcd_declare_caption:Nnn \ptxcd_department: {Mechanik}{Mechanics}}
		{metro}{\ptxcd_declare_caption:Nnn \ptxcd_department: {Mechatronik}{Mechatronics}}
	}
	{
		\ptxcd_declare_caption:Nnn \departmentname {Studienbereich} {field~of~study}
		\ptxcd_declare_caption:Nnn \departmentfullname {\departmentname{}~  \ptxcd_department:} {\departmentname{}:~\ptxcd_department:}
		\ptxcd_declare_caption:Nnn \ptxcd_departmentprefix: {im~ \departmentname}{in~the~\departmentname}
		\ptxcd_declare_caption:Nnn \ptxcd_in_department {\ptxcd_departmentprefix:{}~\ptxcd_department:} {\ptxcd_departmentprefix:{}~``\ptxcd_department:''}
	}
	{
		\msg_warning:nnn{tudapub/thesis} {unrecognized-department} {#1}
		\gdef\ptxcd_department:{#1}
		\ptxcd_declare_caption:Nnn \departmentname {Fachbereich} {department}
	}
}

\cs_new:Nn \ptxcd_insert_studentID:n {
	   (\ptxcd_studentIDname :\nobreakspace#1)
}

\ptxcd_declare_caption:Nnn \ptxcd_byname {von} {by}
\ptxcd_declare_caption:Nnn \ptxcd_fromname {aus} {from}
\ptxcd_declare_caption:Nnn \ptxcd_departmentprefix: {im~ \departmentname}{in~the~\departmentname{}~ of}
\ptxcd_declare_caption:Nnn \ptxcd_reviewname {Gutachten}{review}
\ptxcd_declare_caption:Nnnn \ptxcd_examdatename {Tag~ der~ Prüfung}{Date~ of~ thesis~ defense}{Date~ of~ thesis~ defence}
\ptxcd_declare_caption:Nnn \ptxcd_submissiondatename {Tag~ der~ Einreichung}{Date~ of~ submission}
\ptxcd_declare_caption:Nnn \ptxcd_studentIDname {Matrikelnummer} {Student\nobreakspace ID}

%Fallback content for box if not overwritten
\newcommand*\ptxcd_box_department {\cs_if_exist_use:NF \departmentfullname {\ptxcd_department:}}
\newcommand*\ptxcd_in_department {}
\newcommand*{\ptxcd_thesisStatus}{}
\tl_new:N \g__ptxcd_affidavit_version_tl
\def\@ThesisTypeArticle{die}

\keys_define:nn {ptxcd/thesis} {
	dr .choice:,
	dr/rernat .code:n = \tl_gset:Nn \g_ptxcd_thesis_drtext_tl {Zur~Erlangung~des~Grades~eines~Doktors~der~Naturwissenschaften~(Dr.\,rer.\,nat.)},
	dr/ing .code:n = \tl_gset:Nn \g_ptxcd_thesis_drtext_tl {Zur~Erlangung~des~akademischen~Grades~Doktor-Ingenieur~(Dr.-Ing.)},
	dr/phil .code:n =  \tl_gset:Nn \g_ptxcd_thesis_drtext_tl {Zur~Erlangung~des~Grades~eines~Doktor~der~Philosophie~(Dr.\,phil.)},
	dr/rerpol .code:n = \tl_gset:Nn \g_ptxcd_thesis_drtext_tl {Zur~Erlangung~des~Grades~eines~Doctor~rerum~politicarum (Dr. rer. pol.)},
	type .choice:,
	type/sta .code:n = {\def\ptxcd_thesisType{Studienarbeit}
		\clist_gset:Nn \g_ptxcd_Required_title_data_clist {title, author, date}
		\bool_gset_false:N \g_ptxcd_dr_bool
	},
%	type/diplom  .code:n = {\def\ptxcd_thesisType{Diplomarbeit}\clist_gset:Nn \g_ptxcd_Required_title_data_clist {title, author, submissiondate, reviewer, department}},
	type/bsc  .meta:n = {type=bachelor},
	type/bachelor  .code:n = {\ptxcd_declare_caption:Nnn \ptxcd_thesisType{Bachelorarbeit}{bachelor~ thesis}\def\@ThesisTypeArticle{die}\clist_gset:Nn \g_ptxcd_Required_title_data_clist {title, author, submissiondate, department, reviewer}\bool_gset_false:N \g_ptxcd_dr_bool},
	type/pp  .code:n = { \ptxcd_declare_caption:Nnn \ptxcd_thesisType {Project-Proposal}{project~ proposal}\def\@ThesisTypeArticle{das}\clist_gset:Nn \g_ptxcd_Required_title_data_clist {title, author, date, department}\bool_gset_false:N \g_ptxcd_dr_bool},
	type/msc  .meta:n = {type=master},
	type/master  .code:n = \ptxcd_declare_caption:Nnn \ptxcd_thesisType{Masterarbeit}{master~ thesis}\def\@ThesisTypeArticle{die}\clist_gset:Nn \g_ptxcd_Required_title_data_clist {title, author, submissiondate, department, reviewer}\bool_gset_false:N \g_ptxcd_dr_bool,
	type/dr  .code:n = \ptxcd_declare_caption:Nnn \ptxcd_thesisType{Dissertation}{doctoral~ thesis}\ptxcd_declare_caption:Nnn\ptxcd_thesisStatus{vorgelegte}{submitted}\def\@ThesisTypeArticle{die}\clist_gset:Nn \g_ptxcd_Required_title_data_clist {title, author, submissiondate , birthplace, department, reviewer}\bool_gset_true:N \g_ptxcd_dr_bool,
	type/drfinal  .code:n = \ptxcd_declare_caption:Nnn \ptxcd_thesisType {Dissertation}{doctoral~ thesis}\ptxcd_declare_caption:Nnn\ptxcd_thesisStatus{genehmigte}{accepted}\def\@ThesisTypeArticle{die}\clist_gset:Nn \g_ptxcd_Required_title_data_clist {title, author, submissiondate,examdate, birthplace, department, reviewer}\bool_gset_true:N \g_ptxcd_dr_bool,
	type/unknown  .code:n = \def\ptxcd_thesisType{#1}\clist_gset:Nn \g_ptxcd_Required_title_data_clist {}\def\@ThesisTypeArticle{die}\bool_gset_false:N \g_ptxcd_dr_bool,
	ignore-missing-data .bool_gset:N = \g_ptxcd_missing_data_warning_bool,
	ignore-missing-data .initial:n = false,
	department .tl_gset:N  = \g_ptxcd_department_choice_tl,
	status .code:n = \tl_if_head_is_group:nTF {#1} {\ptxcd_declare_caption:Nnn\ptxcd_thesisStatus #1 {}} {\ptxcd_declare_caption:Nnn\ptxcd_thesisStatus{#1}{#1}},
	fieldofstudy .meta:n ={department = #1},
	ignore-title-language .bool_gset:N = \g_ptxcd_ignore_title_language_bool,
	ignore-title-language .initial:n ={false},
	noinstbox .bool_gset:N = \g_ptxcd_manual_info_box_bool,
	instbox .bool_gset_inverse:N = \g_ptxcd_manual_info_box_bool,
	instbox .initial:n = true,
	reviewer-on-uppertitleback .bool_gset:N = \g__ptxcd_reviewer_on_uppertitleback_bool,
	reviewer-on-uppertitleback .initial:n = false,
	hide-architecture-note .bool_gset_inverse:N = \g__ptxcd_architecture_note_bool,
	hide-architecture-note .initial:n = false,
	hide-architecture-note .default:n = true,
}


\prop_map_inline:Nn \g_ptxcd_unknown_clsopts_prop {
	\keys_if_exist:nnT {ptxcd/thesis} {#1} {
	\keys_set:nn {ptxcd/thesis} {#1=#2}
	}
}

\tl_if_empty:NF  \g_ptxcd_thesis_options_tl {\keys_set:nV {ptxcd/thesis} \g_ptxcd_thesis_options_tl}


\cs_new:Npn \drtext #1 {\tl_gset:Nn \g_ptxcd_thesis_drtext_tl {#1}}
\tl_new:N \g_ptxcd_titleintro_tl
\cs_new:Npn \titleintro #1 {\tl_gset:Nn \g_ptxcd_titleintro_tl {#1}}
\tl_new:N \g_ptxcd_titleaddendum_tl
\cs_new:Npn \titleaddendum #1 {\tl_gset:Nn \g_ptxcd_titleaddendum_tl {#1}}

\msg_new:nnnn{tudapub/thesis} {required-data-missing} {You~did~not~provide~#1~data~for~the~title.~Either~provide~it~or~change~your~publication~type.} {See~ the~ TUDa-CI~ documentation~ for~ further~ information~ and~ workarounds.}

\cs_new:Nn \ptxcd_missing_title_data:n {
	\bool_if:NTF \g_ptxcd_missing_data_warning_bool
	\msg_warning:nnn
	\msg_error:nnn{tudapub/thesis} {required-data-missing} {#1}
}

\cs_new:Nn \ptxcd_check_title_data:Nn {
	\clist_if_in:NnT \g_ptxcd_Required_title_data_clist {#2} {
		\tl_if_empty:NT #1 {
			\bool_if:NTF \g_ptxcd_missing_data_warning_bool
			{\msg_warning:nnn}
			{\msg_error:nnn}  {tudapub/thesis} {required-data-missing} {#2}
		}
	}
}

\cs_generate_variant:Nn \ptxcd_check_title_data:Nn {cn}

\renewcommand*\author[2][]{
	\seq_gset_split:Nnn \g_ptxcd_author_seq {\and} {#2}
	\tl_if_empty:nTF {#1}
	{\tl_set:Nn \l_ptxcd_signature_tl {#2}}
	{\tl_set:Nn \l_ptxcd_signature_tl {#1}}
}

\newcommand*{\studentID}[1]{
  \tl_set:Nn \l_ptxcd_studentID_tl {#1}
}

\gdef\ptxcd_institution{}
\gdef\ptxcd_institute{}
\gdef\ptxcd_department:{}
%\gdef\ptxcd_studentID{}

\NewDocumentCommand{\department}{som}{%
	\IfBooleanTF{#1}{
	  \tl_gset:Nn \ptxcd_department: {#3}
	  \tl_gset:Nn \ptxcd_in_department{#3}
	  \IfNoValueTF {#2} {\tl_gset:Nn \ptxcd_box_department {#3}} {\tl_gset:Nn \ptxcd_box_department{#2}}
	  \clist_remove_all:Nn \g_ptxcd_Required_title_data_clist {department}
	}{
	  \tl_gset:Nn \g_ptxcd_department_choice_tl {#3}
	  \IfNoValueF {#2} {\tl_gset:Nn \ptxcd_departmentprefix: {#2}}
	}
}

\newcommand*{\institute}[1]{
  \gdef\ptxcd_institute{#1}
}

\gdef\ptxcd_group{}
\newcommand*{\group}[1]{%
  \gdef\ptxcd_group{#1}
}

\gdef\ptxcd_birthplace{}
\newcommand*{\birthplace}[1]{%
	\bool_if:NTF \g_ptxcd_dr_bool
		{\gdef\ptxcd_birthplace{#1}}
		{\msg_info:nnn{tudapub/thesis} {dr-field-only} {birthplace}}
}

\publishers{Darmstadt\bool_if:NT \g_ptxcd_dr_bool {,~Technische~Universität~Darmstadt}}

\seq_new:N \g_ptxcd_reviewer_seq
\NewDocumentCommand{\reviewer}{som}{
	\IfNoValueF {#2} {
		\IfBooleanTF{#1}
			{\setupReviewName*{#2}}
			{\setupReviewName{#2}}
	}
	\tl_if_empty:nTF {#3}
		{\let\@reviewer\@empty}
		{\seq_gset_split:Nnn \g_ptxcd_reviewer_seq {\and} {#3}}
}

\cs_set:Nn \ptxcd_thesis_print_reviewer: {
	\clist_if_in:NnT \g_ptxcd_Required_title_data_clist {reviewer} {
		\seq_if_empty:NT \g_ptxcd_reviewer_seq   {\ptxcd_missing_title_data:n {reviewer}}
	}
	\int_zero:N \l_tmpb_int
	\par\vspace*{\baselineskip}
	{
	\seq_map_inline:Nn \g_ptxcd_reviewer_seq
		{
			\int_incr:N \l_tmpb_int
			\cs_if_exist_use:cF {__ptxcd_reviewname_\int_use:N \l_tmpb_int :}
				{\int_to_arabic:n {\l_tmpb_int}.~\text_titlecase:n{\ptxcd_reviewname}}
			:~\exp_not:n {##1}\\
		}
	}
}


\gdef\ptxcd_examdate{}
\newcommand*{\examdate}[1]{
	\bool_if:NTF \g_ptxcd_dr_bool
	{\gdef\ptxcd_examdate{#1}}
	{\msg_info:nnn{tudapub/thesis} {dr-field-only} {examdate}}
}

\gdef\ptxcd_submissiondate{}
\newcommand*{\submissiondate}[1]{
	\gdef\ptxcd_submissiondate{#1}
}

\gdef\@date{}

\cs_new:Nn \ptxcd_thesis_print_dates:n {
	\bool_set_false:N \l_tmpa_bool
	\tl_if_empty:NF \@date {
		\ptxcd_datename\tl_if_empty:NF \ptxcd_datename {\ptxcd_dateseparator}\@date
		\bool_set_true:N  \l_tmpa_bool
	}
	\tl_if_empty:NF \ptxcd_submissiondate {
		\bool_if:NTF \l_tmpa_bool {#1} {\bool_set_true:N  \l_tmpa_bool}\ptxcd_submissiondatename\ptxcd_dateseparator\ptxcd_submissiondate
	}
	\tl_if_empty:NF \ptxcd_examdate {
		\bool_if:NTF \l_tmpa_bool {#1} {\bool_set_true:N  \l_tmpa_bool}\ptxcd_examdatename\ptxcd_dateseparator\ptxcd_examdate
	}
}

\tl_new:N  \g_ptxcd_license_info_tl

\keys_define:nn {ptxcd/thesis} {
	urn .tl_gset:N =\g_ptxcd_thesis_urn_tl,
	urn .initial:V = \c_empty_tl,
	printid .tl_gset:N = \g_ptxcd_thesis_tuprints_tl,
	printid .initial:V = \c_empty_tl,
	doi .tl_gset:N = \g_ptxcd_thesis_doi_tl,
	year .tl_gset:N = \g_ptxcd_thesis_publication_year_tl,
	year .initial:n = ,
	license .choices:nn = {cc-by-4.0,cc-by-sa-4.0,cc-by-nc-sa-4.0,cc-by-nc-4.0,cc-by-nd-4.0,cc-by-nc-nd-4.0} {
		\tl_gset:Nx \g_ptxcd_license_info_tl {\exp_not:N \g__ptxcd_cc_license:n {\l_keys_choice_tl} \exp_not:N \iflanguage{\exp_not:N \bbl@main@language}{}{\exp_not:n {\par\smallskip\otherlanguage{\bbl@main@language}}{\exp_not:N \g__ptxcd_cc_license:n {\l_keys_choice_tl}}}}
	},
	license / cc-by-nc-nd-2.0-de .code:n = \tl_gset:Nn  \g_ptxcd_license_info_tl {\use:c {g__ptxcd_cc-by-nc-nd-2.0-de:}},
	license / inc-1.0-de  .code:n = \tl_gset:Nn \g_ptxcd_license_info_tl {
		Die~Veröffentlichung~ist~urheberrechtlich~geschützt\newline
		\url{https://rightsstatements.org/page/InC/1.0/}
	},
	license / inc-1.0-en .code:n = \tl_gset:Nn \g_ptxcd_license_info_tl {
		This~work~is~protected~by~copyright\newline
		\url{https://rightsstatements.org/page/InC/1.0/}
	},
	license / inc-1.0 .code:n = \tl_if_in:NnTF \languagename {german} {\keys_set:nn {ptxcd/thesis}{license=inc-1.0-de}}{\keys_set:nn {ptxcd/thesis}{license=inc-1.0-en}},
	license / initial .code:n = {\keys_set:nn {ptxcd/thesis} {license=cc-by-4.0}},
	license / unknown .code:n  = \tl_gset:Nn \g_ptxcd_license_info_tl {#1},
	license .initial:n = initial,
	signature .tl_set:N = \l_ptxcd_signature_tl,
	studentID .tl_set:N = \l_ptxcd_studentID_tl,
	studentID .initial:n =,
	signature-image .tl_set:N = \l_ptxcd_signature_image_tl,
	signature-image .initial:n =,
	signature-location .tl_set:N = \l_ptxcd_signature_location_tl,
	signature-location .initial:n = Darmstadt,
}

\msg_new:nnnn {tudapub/thesis} {default-license-will-change} {
	TUprints~changed~their~default~license.\\
	tuda-ci~will~adapt~this~change~in~the~next~major~update.~\\
	Please~choose~your~license~manually~to~avoid~unintended~changes.
} {Use~either~the~old~default~value~license=cc-by-nc-nd-2.0-de or~license=cc-by-4.0~or~license={<custom~text>}~with~\string\tuprints.}


\cs_new:cn {g__ptxcd_cc-by-nc-nd-2.0-de:} {
	Die~Veröffentlichung~steht~unter~folgender~Creative~Commons~Lizenz:\\
	Namensnennung~--~Keine~kommerzielle~Nutzung~--~Keine~Bearbeitung~ 2.0~Deutschland\\
	\url{http://creativecommons.org/licenses/by-nc-nd/2.0/de/}
}

\defcaptionname{ngerman, german}{\g__ptxcd_cc_attr_by:}{Namensnennung}
\defcaptionname{ngerman, german}{\g__ptxcd_cc_attr_nc:}{Nicht~kommerziell}
\defcaptionname{ngerman, german}{\g__ptxcd_cc_attr_sa:}{Weitergabe~unter~gleichen~Bedingungen}
\defcaptionname{ngerman, german}{\g__ptxcd_cc_attr_nd:}{Keine~Bearbeitungen}

\defcaptionname{english, USenglish, american, UKenglish, british}{\g__ptxcd_cc_attr_by:}{Attribution}
\defcaptionname{english, USenglish, american, UKenglish, british}{\g__ptxcd_cc_attr_nc:}{NonCommercial}
\defcaptionname{english, USenglish, american, UKenglish, british}{\g__ptxcd_cc_attr_sa:}{ShareAlike}
\defcaptionname{english, USenglish, american, UKenglish, british}{\g__ptxcd_cc_attr_nd:}{NoDerivatives}

\defcaptionname{ngerman,german}{\g__ptxcd_cc_intro:}{Die~Veröffentlichung~steht~unter~folgender~Creative~Commons~Lizenz:}
\defcaptionname{english, USenglish, american, UKenglish, british}{\g__ptxcd_cc_intro:}{This~work~is~licensed~under~a~Creative~Commons~License:}

\defcaptionname{ngerman,german}{\g__ptxcd_cc_sep:}{~--~}
\defcaptionname{english, USenglish, american, UKenglish, british}{\g__ptxcd_cc_sep:}{--}

\cs_new:Nn \g__ptxcd_cc_license:n {
	\group_begin:
	\g__ptxcd_cc_intro:\\
	\seq_set_split:Nnn \l_tmpa_seq {-} {#1}
	\bool_set_false:N \l_tmpa_bool
	\seq_remove_all:Nn \l_tmpa_seq {cc}
	\seq_pop_right:NN \l_tmpa_seq \l_tmpa_tl
	\seq_map_inline:Nn \l_tmpa_seq {
		\bool_if:NTF \l_tmpa_bool {\g__ptxcd_cc_sep:} {\bool_set_true:N \l_tmpa_bool}
		\use:c {g__ptxcd_cc_attr_##1:}
	}~\l_tmpa_tl{}~International\\
	\url{https://creativecommons.org/licenses/\seq_use:Nn \l_tmpa_seq {-}/\l_tmpa_tl/}
	\group_end:
}


\newcommand{\tuprints}[1]{%
  \tl_if_in:nnTF {#1} {=}
	  {\keys_set:nn {ptxcd/thesis} {#1}}
	  {\keys_set:nn {ptxcd/thesis} {printid=#1}}
  \lowertitleback{
  	\urlstyle{same}
	\selectlanguage{german}
  	Bitte~zitieren~Sie~dieses~Dokument~als:
    \tl_if_empty:NF \g_ptxcd_thesis_urn_tl {\\URN:~urn:nbn:de:tuda-tuprints-\g_ptxcd_thesis_urn_tl}\\
    URL:~\url{https://tuprints.ulb.tu-darmstadt.de/\g_ptxcd_thesis_tuprints_tl}\\
	\tl_if_empty:NF \g_ptxcd_thesis_doi_tl {DOI:~\url{https://doi.org/\g_ptxcd_thesis_doi_tl}\\}
	\tl_if_empty:NF \g_ptxcd_thesis_publication_year_tl {Jahr~der~Veröffentlichung~auf~TUprints:~\g_ptxcd_thesis_publication_year_tl}
	\par\vspace{\baselineskip}
    Dieses~Dokument~wird~bereitgestellt~von~tuprints,\\
    E-Publishing-Service~der~TU~Darmstadt\\
    \url{https://tuprints.ulb.tu-darmstadt.de}\\
   	\url{tuprints@ulb.tu-darmstadt.de}\\[2\baselineskip]
   \tl_if_empty:NF \g_ptxcd_license_info_tl {\\[2\baselineskip]\g_ptxcd_license_info_tl}
  }%
}

\gdef\@subject{
	\text_titlecase_first:n{\tl_if_empty:NF \ptxcd_thesisStatus {\ptxcd_thesisStatus{}~}\ptxcd_thesisType}~
	\tl_if_empty:NF \ptxcd_in_department {\ptxcd_in_department{}~}
	\seq_if_empty:NF  \g_ptxcd_author_seq {\ptxcd_byname\nobreakspace\@author}
	\tl_if_empty:NF \ptxcd_birthplace {\space\ptxcd_fromname\space\ptxcd_birthplace}
	\tl_if_empty:NF \l_ptxcd_studentID_tl {\space\ptxcd_insert_studentID:n {\l_ptxcd_studentID_tl}}
}

\uppertitleback{
	\liningnums
	\raggedright
	\@title\par\@subtitle
	\par\vspace*{\baselineskip}
	%ignore birthplace on english subject
	\let\ptxcd_birthplace\@empty
	\@subject
	\bool_if:NT \g__ptxcd_reviewer_on_uppertitleback_bool
		\ptxcd_thesis_print_reviewer:
	\exp_args:Nx \tl_if_empty:nF {\@date\ptxcd_submissiondate}{
		\par\vspace*{\baselineskip}
		\ptxcd_thesis_print_dates:n {\\}
	}
	\tl_if_empty:NF \@publishers {
		\par\vspace*{\baselineskip}
		\@publishers
	}
}

%%Studienbereich (field of study):
%%ce     - Computational Engineering
%%ese    - Energy Science and Engineering
%%ist    - Informationssystemtechnik
%%mech   - Mechanik
%%metro  - Mechatronik
%
%{ce}{Computational~Engineering}{Computational~Engineering}
%{ese}{Energy~Science~and~Engineering}{Energy~Science~and~Engineering}
%{ist}{Information~Systems~Engineering}{Information~Systems~Engineering}
%{mech}{Mechanics}{Mechanics}
%{metro}{Mechatronics}{Mechatronics}

\defcaptionname{english}{\researchgroupname}{research group}
\defcaptionname{ngerman, german}{\researchgroupname}{Fachgebiet}
\defcaptionname{english}{\institutename}{institute}
\defcaptionname{ngerman, german}{\istitutename}{Institut}

\renewcommand{\titlepagestyle}{title.TUDa}

\box_new:N \g_ptxcd_thesis_institution_box

% The following macro is an adapted version of the corresponding KOMA-Script macro
% Copyright (c) 1994-2019 Markus Kohm [komascript at gmx info]
\renewcommand*{\maketitle}[1][1]{
	\bool_if:NF \g_ptxcd_ignore_title_language_bool {
		\bool_set_false:N \l_tmpa_bool
		\clist_map_inline:nn {english, british, ngerman, german} {
			\iflanguage{##1}
			{\bool_set_true:N \l_tmpa_bool
			\clist_map_break:}{}
		}
		\bool_if:NF \l_tmpa_bool {
			\msg_error:nnx{tudapub/thesis}	{unsupported-title-language} {\languagename}
		}
	}
	\exp_args:NV \ptxcd_select_department:n \g_ptxcd_department_choice_tl
	\clist_map_inline:nn {author, date} {
		\ptxcd_check_title_data:cn {@##1} {##1}
	}
	\clist_map_inline:nn {examdate, birthplace, group, department, institution} {
		\ptxcd_check_title_data:cn {TUDa@##1} {##1}
	}
	\cs_if_exist_use:N \ptxcd_pass_TitleData:
	\edef\titlepage@restore{%
		\noexpand\endgroup
		\noexpand\global\noexpand\@colht\the\@colht
		\noexpand\global\noexpand\@colroom\the\@colroom
		\noexpand\global\vsize\the\vsize
		\noexpand\global\noexpand\@titlepageiscoverpagefalse
		\noexpand\let\noexpand\titlepage@restore\noexpand\relax
	}%
	\ptxcd_disable_marginpar:
	\cleardoublepage
	\begin{titlepage}
		\setcounter{page}{%
			#1%
		}%
		\def\thefootnote{\fnsymbol{footnote}}
		\if@titlepageiscoverpage
		\begingroup
		\topmargin=\dimexpr \coverpagetopmargin-1in\relax
		\oddsidemargin=\dimexpr \coverpageleftmargin-1in\relax
		\evensidemargin=\dimexpr \coverpageleftmargin-1in\relax
		\textwidth=\dimexpr
		\paperwidth-\coverpageleftmargin-\coverpagerightmargin\relax
		\textheight=\dimexpr
		\paperheight-\coverpagetopmargin-\coverpagebottommargin\relax
		\headheight=0pt
		\headsep=0pt
		\footskip=\baselineskip
		\@colht=\textheight
		\@colroom=\textheight
		\vsize=\textheight
		\columnwidth=\textwidth
		\hsize=\columnwidth
		\linewidth=\hsize
		\else
		\let\titlepage@restore\relax
		\fi
		\setparsizes{\z@}{\z@}{\z@\@plus 1fil}\par@updaterelative
		\ptxcd_setup_sponsor_box:
		\hbox_gset:Nn \g_ptxcd_title_box {
			\parbox[t]{\linewidth}{
				\begin{minipage}[b]{\bool_if:NT \g__ptxcd_LogoInHead_bool {.75}\linewidth}
                    \bool_lazy_and:nnT {\g_ptxcd_colorback_bool} {\g_ptxcd_colorbacktitle_bool} {\color{textonaccentcolor}}
					\tl_if_empty:NF \@titlehead {
						\begin{addmargin}{3mm}
							{\usekomafont{titlehead}{\@titlehead\par}}
						\end{addmargin}
					}
					\begin{addmargin}[\dim_eval:n {\box_if_empty:NF \g_ptxcd_PaperID_box {\box_wd:N\g_ptxcd_PaperID_box+.5\c_ptxcd_logoheight_dim} +3mm}]{3mm}
						\raggedright
						\leavevmode\usekomafont{title}
						\expandafter\fontsize\ptxcd_title_fontsize:
						\selectfont
						\llap{\raisebox{\dimexpr-\height+.5\baselineskip}[0pt][0pt]{\box_use:N \g_ptxcd_PaperID_box}\hspace{.5\c_ptxcd_logoheight_dim}}
						\@title\strut
						\par
						\box_if_empty:NTF \g_ptxcd_PaperID_box
						{\vskip0pt}
						{\rule{0pt}{.5\c_ptxcd_logoheight_dim}}
					\end{addmargin}
				\end{minipage}%
				\bool_if:NT \g_ptxcd_colorbacksubtitle_bool {\color{textonaccentcolor}}
				\par\nointerlineskip
				\rule{\linewidth}{\g_ptxcd_titlerule_dim}\par\vspace{\c_ptxcd_rulesep_dim}
				\begin{addmargin}{3mm}
					\usekomafont{titleinfo}
					\raggedright
					\expandafter\fontsize\ptxcd_titleinfo_fontsize:
					\selectfont
					{\ifx\@subtitle\@empty\else\usekomafont{subtitle}{\@subtitle\par}\fi}%
					\usekomafont{subject}
					\bool_if:NT \g_ptxcd_dr_bool {\selectlanguage{german}}
					\tl_if_empty:NF \g_ptxcd_titleintro_tl {\g_ptxcd_titleintro_tl\par}
					\tl_if_empty:NF \g_ptxcd_thesis_drtext_tl {\g_ptxcd_thesis_drtext_tl\par}
					{%
						\usekomafont{author}
						\lineskip 0.75em
						\@subject
						\par
					}%
					{\usekomafont{date}{\ptxcd_thesis_print_dates:n {,~}\par}}%
					\ptxcd_thesis_print_reviewer:\par
					{\usekomafont{publishers}{\@publishers \par}}%
					\tl_if_empty:NF \g_ptxcd_titleaddendum_tl {\g_ptxcd_titleaddendum_tl\par}
				\end{addmargin}
				\tl_if_empty:NF \@thanks {
					\expandafter\fontsize\ptxcd_titlethanks_fontsize:\selectfont\par
					\rule{\linewidth}{\g_ptxcd_titlerule_dim}\par
					\begin{addmargin}{3mm}
						\let\footnotetext\ptxcd_title@footnote
						\@thanks
					\end{addmargin}
					\par\vspace{-\dp\strutbox}
				}
                \normalcolor
				\rule{\linewidth}{\g_ptxcd_titlerule_dim}\par
			}
		}
		\let\@thanks\@empty
		\bool_if:NF \g_ptxcd_manual_info_box_bool {
			\exp_args:Nf \tl_if_empty:nF {\ptxcd_institution\ptxcd_department:\ptxcd_institute\ptxcd_group} {
				\addTitleBox{
					\setlength{\parskip}{\c_ptxcd_rulesep_dim}
					\tl_if_empty:NF \ptxcd_institution {\ptxcd_institution\par}
					\tl_if_empty:NF \ptxcd_box_department {\ptxcd_box_department\par}
					\tl_if_empty:NF \ptxcd_institute {\ptxcd_institute\par}
					\tl_if_empty:NF \ptxcd_group {\ptxcd_group}
			}}
		}
		\ptxcd_adjust_titlepage_style:
		\thispagestyle{title.TUDa}
		\nointerlineskip\box_use:N \g_ptxcd_title_box
		\par
		\vfill
		\box_if_empty:NTF \g_ptxcd_sponsor_box {
			\raisebox{-\c_ptxcd_rulesep_dim}[0pt][0pt]{\rule{\linewidth}{\g_ptxcd_titlerule_dim}}
		}{
			\box_use:N \g_ptxcd_sponsor_box
		}
		\if@twoside
			\@tempswatrue
			\expandafter\ifnum \@nameuse{scr@v@3.12}>\scr@compatibility\relax
			\else
				\ifx\@uppertitleback\@empty
				\ifx\@lowertitleback\@empty
				\@tempswafalse
				\fi
				\fi
			\fi
		\else
		\exp_args:Nf \tl_if_empty:nTF  {\g_ptxcd_thesis_urn_tl\g_ptxcd_thesis_tuprints_tl}
		{\@tempswafalse}
		{\@tempswatrue}
		\fi
		\if@tempswa
		\next@tpage
		\begin{minipage}[t]{\textwidth}
			\@uppertitleback
		\end{minipage}\par
		\vfill
		\begin{minipage}[b]{\textwidth}
			\@lowertitleback
		\end{minipage}\par
		\@thanks\let\@thanks\@empty
		\fi
		\ifx\@dedication\@empty
		\else
		\next@tdpage\null\vfill
		{\centering\usekomafont{dedication}{\@dedication \par}}%
		\vskip \z@ \@plus3fill
		\@thanks\let\@thanks\@empty
		\cleardoubleemptypage
		\fi
		\ifx\titlepage@restore\relax\else\clearpage\titlepage@restore\fi
	\end{titlepage}
	\setcounter{footnote}{0}%
	\global\let\and\relax
	\cleardoublepage
	\ptxcd_restore_typearea:
	\aftergroup\ptxcd_restore_typearea:
}

\newcommand*{\@ThesisType}{\ptxcd_thesisType}

\bool_if:NTF \g_ptxcd_dr_bool {
	\keys_define:nn {ptxcd/thesis} {
		affidavit .choices:nn = {dr}{\tl_gset_eq:NN  \g__ptxcd_affidavit_version_tl \l_keys_choice_tl},
		affidavit / default .meta:n = {affidavit=dr},
		affidavit .initial:n = dr,
	}
} {
	\keys_define:nn {ptxcd/thesis} {
	affidavit .choices:nn = {digital,print}{\tl_gset_eq:NN  \g__ptxcd_affidavit_version_tl \l_keys_choice_tl},
	affidavit / default .meta:n = {affidavit=digital},
	affidavit .initial:n = default,
	}
}

\NewDocumentCommand{\affidavit}{so}{%
	\IfNoValueF {#2} {%
		\tl_if_in:nnTF {#2} {=}
			{\keys_set:nn {ptxcd/thesis} {#2}}
			{\keys_set:nn {ptxcd/thesis} {affidavit=#2}}%
	}%
	\clearpage
\begin{otherlanguage}{german}
	\bool_if:NTF \g_ptxcd_dr_bool {
		\g__ptxcd_affidavit_dr_tl
	} {
		\tl_use:c {g__ptxcd_affidavit_\g__ptxcd_affidavit_version_tl _tl}
	}
\par
\bigskip
\AffidavitSignature
\end{otherlanguage}
\IfBooleanF{#1}{\clearpage}
}

\ExplSyntaxOff

\expandafter\def\csname g__ptxcd_affidavit_dr_tl\endcsname {%
	\section*{Erklärungen laut Promotionsordnung}
	\subsection*{\S\,8 Abs. 1 lit. d PromO}
	Ich versichere hiermit, dass zu einem vorherigen Zeitpunkt noch keine Promotion versucht wurde. In diesem Fall sind nähere Angaben über Zeitpunkt, Hochschule, Dissertationsthema und Ergebnis dieses Versuchs mitzuteilen.

	\subsection*{\S\,9 Abs. 1 PromO}
	Ich versichere hiermit, dass die vorliegende Dissertation – abgesehen von den in ihr ausdrücklich genannten Hilfen – selbstständig verfasst wurde und dass die „Grundsätze zur Sicherung guter wissenschaftlicher Praxis an der Technischen Universität Darmstadt“ und die „Leitlinien zum Umgang mit digitalen Forschungsdaten an der TU Darmstadt“ in den jeweils aktuellen Versionen bei der Verfassung der Dissertation beachtet wurden.

	\subsection*{\S\,9 Abs. 2 PromO}
	Die Arbeit hat bisher noch nicht zu Prüfungszwecken gedient.
}

% Quelle: https://www.tu-darmstadt.de/studieren/studierende_tu/studienorganisation_und_tucan/hilfe_und_faq/artikel_details_de_en_37824.de.jsp
\expandafter\def\csname g__ptxcd_affidavit_digital_tl\endcsname {%
	\subsection*{Erklärung zur Abschlussarbeit gemäß \S\,22~Abs.~7~APB TU~Darmstadt}
	\begin{sloppypar}%
	Hiermit erkläre ich, \@author, dass ich die vorliegende Arbeit gemäß \S\,22~Abs.~7~APB der TU Darmstadt selbstständig, ohne Hilfe Dritter und nur mit den angegebenen Quellen und Hilfsmitteln angefertigt habe.
	 Ich habe mit Ausnahme der zitierten Literatur und anderer in der Arbeit genannter Quellen keine fremden Hilfsmittel benutzt. Die von mir bei der Anfertigung dieser wissenschaftlichen Arbeit wörtlich oder inhaltlich benutzte Literatur und alle anderen Quellen habe ich im Text deutlich gekennzeichnet und gesondert aufgeführt. Dies gilt auch für Quellen oder Hilfsmittel aus dem Internet.
	\end{sloppypar}%
	\par
	Diese Arbeit hat in gleicher oder ähnlicher Form noch keiner Prüfungsbehörde vorgelegen.
	\par
	Mir ist bekannt, dass im Falle eines Plagiats (\S\,38~Abs.~2 ~APB) ein Täuschungsversuch vorliegt, der dazu führt, dass die Arbeit mit 5,0 bewertet und damit ein Prüfungsversuch verbraucht wird. Abschlussarbeiten dürfen nur einmal wiederholt werden.
	\csname bool_if:cT\endcsname {g__ptxcd_architecture_note_bool} {%
		\par
		Bei einer Thesis des Fachbereichs Architektur entspricht die eingereichte elektronische Fassung dem vorgestellten Modell und den vorgelegten Plänen.
	}
}

\ExplSyntaxOn

\cs_set_eq:NN \g__ptxcd_affidavit_print_tl \g__ptxcd_affidavit_digital_tl

\NewDocumentEnvironment{affidavit*}{om}{
	\IfNoValueF {#1} {\begin{otherlanguage}{#1}}
	\section*{#2}
}{
	\IfNoValueF {#1} {\end{otherlanguage}}
}

\NewDocumentCommand{\AffidavitSignature}{o}{
	\par
	\begingroup
	\IfNoValueF {#1} {%
		\tl_if_in:nnTF {#1} {=}
			{\keys_set:nn {ptxcd/thesis} {#1}}
			{\keys_set:nn {ptxcd/thesis} {signature-location=#1}}%
	}%
	\tl_if_empty:NT \l_ptxcd_signature_image_tl {\bigskip}
	\noindent \l_ptxcd_signature_location_tl,~ \ptxcd_submissiondate\hfill
	\SignatureBox{\l_ptxcd_signature_tl}
	\endgroup
	\\\strut
}

\newcommand*{\SignatureBox}[2][5cm]{\parbox[t]{#1}{\centering
		\tl_if_empty:NF \l_ptxcd_signature_image_tl
			{\let\width\linewidth\l_ptxcd_signature_image_tl\par\nointerlineskip}
		\rule{\linewidth}{.3pt}\\\makebox[0pt][c]{#2}}
}

%messages:
\msg_new:nnn{tudapub/thesis} {dr-field-only} {
	You~submitted~#1~data~for~title~information.\\
	This~field~is~only~used~for~type=dr/drfinal.\\
	It~will~be~ignored.
}

\msg_new:nnn{tudapub/thesis} {unrecognized-department} {
	I~can't~recognize~your~department~#1.\\
	I~will~use~the~string~'#1'~directly.\\
	Ensure~your~department~has~to~shortcut.\\
	See~tudathesis~documentation~for~further~details.
}

\msg_new:nnnn{tudapub/thesis}	{unsupported-title-language}  {
	You~chose~an~unsupported~language~"#1".\\
	\string\maketitle\ ~ist~not~configured~for~this~language.
}{
	You~can~manually~configure~it,~as~described~in~tudathesis~documentation.\\
	Use~"ignore-title-language"~Option~to~ignore~this~message~at~your~own~risk.
}

\PassOptionsToPackage{german}{babel}
\AtBeginDocument{
	\@ifpackageloaded{babel}{}{
	\msg_new:nnnn{tudapub/thesis}	{missing-babel}  {
		The~babel~package~is~not~loaded.\\
		Please~load~babel~with~option\\
		main=<main~language~of~your~document>\\
		to~ensure~correct~hyphenation.
	}{
		I~will~use~a~workaround~(redefine~\string\otherlanguagen)~to~be~able~to~compile,~but~can't~configure~hyphenation~correctly.
	}
	\msg_warning:nn {tudapub/thesis} {missing-babel}
	\renewenvironment{otherlanguage}[1]{}{}
	}
}

% Fallback mechanism for older l3 kernels
\cs_if_exist:NF \text_titlecase:n {
	\cs_set_eq:NN \text_titlecase:n \tl_mixed_case:n
}

\seq_new:N \g_ptxcd_reviewer_name_seq
\NewDocumentCommand{\setupReviewName}{som}{
	\IfBooleanTF {#1} {
		\clist_map_inline:nn {#3} {
			\int_incr:N \l_tmpb_int
			\cs_set:cn {__ptxcd_reviewname_\int_use:N \l_tmpb_int :} {##1}
		}
	} {
		\IfNoValueTF {#2} {
			\cs_set:Npn \ptxcd_reviewname  {#3}
		} {
		\ifnum #2 > 0
		\cs_set:cn {__ptxcd_reviewname_#2:}
		{#3}
		\fi
		}
	}
}

\endinput
