%with "draft" the PDF is compiled without images
% \documentclass[10pt,openright,twoside,draft]{scrbook}
\documentclass[10pt,openright,twoside]{scrbook}
\usepackage{xargs}

% Basic packages used for if-else
\usepackage{xifthen}
\usepackage{ifplatform}

\newboolean{isxml}
\setboolean{isxml}{false}
\newcommand{\EOAifxml}[2]{\ifthenelse{\boolean{isxml}}{#1}{#2}}

% new version
% \usepackage[markcase=nouppercase]{scrlayer-scrpage}
% \renewcommand*{\chaptermarkformat}{\thechapter .~}
% \setkomafont{pagehead}{\footnotesize\upshape}
% \ohead[]{\thepage}
% \ihead[]{\leftmark}
% \ofoot[]{}

% Redefining the header
\usepackage{fancyhdr}
\pagestyle{fancy} % eigenen Seitenstil aktivieren}
\fancyhfoffset{0pt}
\fancyhead[RO,LE]{\footnotesize \nouppercase\thepage}
\fancyhead[RE,LO]{\footnotesize \nouppercase\leftmark}
%Use to change the size of the header font
%\fancyhead[RO,LE]{\normalfont\changefontsizes{8pt} \nouppercase\thepage}
%\fancyhead[RE,LO]{\normalfont\changefontsizes{8pt} \nouppercase\leftmark}
\renewcommand\chaptermark[1]{\markboth{\thechapter. #1}{}}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
\fancypagestyle{plain}{%
\fancyhead{}}

% Activate fontspec for various fonts
\usepackage[no-math]{fontspec}
\setmainfont{Times New Roman}
%\setsansfont[Mapping=tex-text]{Skia}
%\setromanfont{Geneva}

% Activate Unicode-Support
\usepackage{xltxtra}
\usepackage{xunicode}

% Polyglossia is being used instead of babel
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage[variant=polytonic]{greek}
\setotherlanguage{german}

% Rename "Abbildung" to "Abb." for german texts
\addto\captionsgerman{%
  \renewcommand{\figurename}{Abb.}%
}

\usepackage[autostyle]{csquotes}

% Definition of fonts for Chinese based on OS
\ifwindows
\newfontfamily\zhfont{DFKai-SB}
\newfontfamily\zhpunctfont{DFKai-SB}
\else
\newfontfamily\zhfont{Noto Serif CJK SC}
\newfontfamily\zhpunctfont{Noto Serif CJK SC}
\fi

% The package zhspacing makes typesetting chinese much better
\usepackage{zhspacing}
\zhspacing

% assigning explicit character classes for CJK ambiguous characters
\XeTeXcharclass`“=6
\XeTeXcharclass`”=6
\XeTeXcharclass`‘=6
\XeTeXcharclass`’=6
\XeTeXcharclass`’=6
\XeTeXcharclass`…=6

% Definition of various fonts based on OS
\ifwindows
\newfontfamily\textchinese{DFKai-SB}
\newfontfamily\chinesefont{DFKai-SB}
\else
\newfontfamily\textchinese{Noto Serif CJK SC}
\newfontfamily\chinesefont{Noto Serif CJK SC}
\fi
\newfontfamily\germanfont{Times New Roman}
\newfontfamily\englishfont{Times New Roman}
\newfontfamily\greekfont{Times New Roman}
\newfontfamily\russianfont{Times New Roman}
\newfontfamily\hebrewfont{Times New Roman}
\newfontfamily\EOAmfont{XITS Math}
% Those fonts are being used in Berlin only, no need for Windows
\ifwindows
\else
\newfontfamily\Arial{ArialMT}
\newfontfamily\Courier{TeXGyreCursor}
\newfontfamily\Helvetica{TeXGyreHeros}
\newfontfamily\Verdana{Verdana}
\fi

% Equation- and formula-fun
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{braket}
\usepackage{slashed}

\usepackage{mdframed}

% amsfonts and similar produce broken PDF X/4 - we need unicode-math
% and use the font XITS-Math (https://github.com/khaledhosny/xits-math)
\usepackage[bold-style=TeX,math-style=TeX]{unicode-math}
\setmathfont[active-frac=small]{XITS Math}
\setmathfont[version=bold,FakeBold=1.5]{XITS Math}
\DeclareMathSizes{8}{6.5}{6}{5}

% Chemical formulas
\usepackage[version=3]{mhchem}
\newcommand{\EOAchem}[1]{\ce{#1}}

% kt add marginnote
%\usepackage{marginnote}

% Definition of page dimensions depending on series
\newcommand{\EOAseries}[1]{
  \ifthenelse%
   {\equal{#1}{Sources}}%
   %% changing format to A4. What about the margins?
   {\usepackage[a4paper,inner=30mm,outer=30mm,top=14mm,bottom=20mm,includehead]{geometry}
     \KOMAoption{fontsize}{12pt}
   }%
   % the else part
    {
    \ifthenelse%
    {\equal{#1}{Studies}}%
    {\usepackage[paperwidth=170mm,paperheight=240mm,inner=22mm,outer=20mm,top=14mm,bottom=20mm,includehead]{geometry}}%
     % another else part
     {
     \ifthenelse%
     {\equal{#1}{Proceedings}}%
     {\usepackage[paperwidth=148mm,paperheight=210mm,inner=20mm,outer=15mm,top=13mm,bottom=15mm,includehead]{geometry}}%
     % and another else part
      {
      \ifthenelse%
      {\equal{#1}{Textbooks}}%
      {\usepackage[paperwidth=148mm,paperheight=210mm,inner=20mm,outer=15mm,top=13mm,bottom=15mm,includehead]{geometry}}%
      % the last else part
      {\PackageError{EOALatex}{Wrong EOAseries}{Accepted values are: Sources, Studies, Proceedings or Textbooks}}
    }}}
}

\usepackage{pdflscape}

% Schusterjungen und Hurenkinder
\clubpenalty = 10000
\widowpenalty = 10000
\displaywidowpenalty = 10000

% Mit raggedbottom wird verhindert, dass Seiten nach unten hin aufgefüllt werden, das Paket here ermöglicht die fixe Positionierung von Bildern
\usepackage{here}
\raggedbottom

% Gestaltung von Auflistungen im Text
\usepackage{paralist}

% soul-package being used for strikeout and spacing out
%\usepackage{letterspacing}

% Für die Formatierung von URLs im Fließtext, escapen ist damit nicht mehr notwendig
\usepackage{url}
% enable breaking of URLs at uppercase letters
\urlstyle{rm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% One Command to tweak the style of the bibliography
\newcommand{\EOAbibtweaks}{
% Remove pp from references
\DeclareFieldFormat{postnote}{##1}
% Remove quotation marks from certain titles
\DeclareFieldFormat[thesis]{title}{\mkbibemph{##1}}
\DeclareFieldFormat[article]{title}{##1}
\DeclareFieldFormat[incollection]{title}{##1}
\DeclareFieldFormat[inproceedings]{title}{##1}
\DeclareFieldFormat[inbook]{title}{\mkbibemph{##1}}
\DeclareFieldFormat{title}{\mkbibemph{##1}}
% Remove pp from bibliography at all
\DeclareFieldFormat{pages}{##1}%
\DeclareFieldFormat{urldate}{%
    \addcomma\addspace accessed %
    \mkbibmonth{\thefield{urlmonth}}\addspace%
    \thefield{urlday}\addcomma \addspace     %  addcomma works !!!
    \thefield{urlyear}\isdot}
% make namedash longer
%https://tex.stackexchange.com/questions/239369/modify-the-dash-in-biblatex-ibid
\setlength\bibhang{3.5em}
\renewcommand*{\bibnamedash}{%
  \ifdimless{\leftmargin}{0.75em}
    {\mbox{\textemdash\space}}
    {\makebox[\leftmargin][l]{%
       \ifdimless{\leftmargin}{1.25em}
         {\textendash}
         {\rule[0.2em]{4em}{0.05em}}}}}
% Remove "In:" from articles
\renewbibmacro{in:}{%
  \ifentrytype{article}{}{%
  \printtext{\bibstring{in}\intitlepunct}}}
% Delete Vol. as praefix
\DeclareFieldFormat*{volume}{##1}
% Use : for pages of an article, use .  for the rest
\renewcommand*{\bibpagespunct}{%
\ifentrytype{article}%
{%
\iffieldundef{Number}%
{\addcolon\hspace{0pt}}%
{}%
}%
{,\space}%
}
% Group Volume and Issue in {Brackets}
\renewbibmacro*{journal+issuetitle}{%
  \usebibmacro{journal}%
  \setunit*{\addspace}%
  \iffieldundef{series}
    {}
    {\newunit
     \printfield{series}%
     \setunit{\addspace}}%
  \printfield{volume}%
  \iffieldundef{number}
     {}
     {\printfield[parens]{number}}
  \setunit{\addcomma\space}%
  \printfield{eid}%
  \setunit{\addspace}%
  \usebibmacro{issue+date}%
  \setunit{\addcolon\space}%
  \usebibmacro{issue}%
  \newunit}

% origdate, thanks to https://tex.stackexchange.com/questions/134644/how-to-get-automatically-origdate-with-the-date-in-a-citation
\DeclareFieldFormat{origdate}{\mkbibbrackets{##1}}
\renewbibmacro*{cite:labeldate+extradate}{%
  \iffieldundef{origyear}
    {}
    {\printorigdate
     \setunit{\addspace}}%
  \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{\printlabeldateextra}}}

\DeclareCiteCommand{\citeorigyear}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printfield{origyear}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\renewbibmacro*{date+extradate}{%
  \iffieldundef{origyear}
    {}
    {\printorigdate
     \setunit{\addspace}}%
  \iffieldundef{labelyear}
    {}
    {\printtext[parens]{%
       \iflabeldateisdate
         {\printdateextra}
         {\printlabeldateextra}}}}

% Bug fix for Windows
\defbibheading{none}[]{}
}

% Einbindung des biblatex-Pakets mittels \EOAbibliographytype
\newcommand{\EOAbibliographytype}[1]{%
\ifthenelse%
{\equal{#1}{anthology}}%
{\usepackage[mincitenames=1,maxcitenames=3,maxbibnames=100,style=authoryear,backend=biber,autolang=hyphen,uniquename=false,dateabbrev=false,datecirca=true,dateuncertain=true,dateera=christian,urldate=long]{biblatex}
\newboolean{anthology}
\setboolean{anthology}{true}
\EOAbibtweaks
}{}%
\ifthenelse%
{\equal{#1}{anthology-numeric}}%
{\usepackage[mincitenames=1,maxcitenames=3,maxbibnames=100,style=numeric-comp,sorting=none,backend=biber,babel=hyphen,dateabbrev=false,urldate=long]{biblatex}
\newboolean{anthology}
\setboolean{anthology}{true}
\EOAbibtweaks
}{}%
\ifthenelse%
{\equal{#1}{monograph}}%
{\usepackage[mincitenames=1,maxcitenames=3,maxbibnames=100,style=authoryear,backend=biber,autolang=hyphen,dateabbrev=false,datecirca=true,dateuncertain=true,dateera=christian,urldate=long]{biblatex}
\newboolean{anthology}
\setboolean{anthology}{false}
\EOAbibtweaks
}{}%
\ifthenelse%
{\equal{#1}{monograph-numeric}}%
{\usepackage[mincitenames=1,maxcitenames=3,maxbibnames=100,style=numeric-comp,sorting=none,backend=biber,babel=hyphen,dateabbrev=false,urldate=long]{biblatex}
\newboolean{anthology}
\setboolean{anthology}{false}
\EOAbibtweaks
}{}%
% Small font for Bibliography
\renewcommand*{\bibfont}{\footnotesize}
}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% The command EOApublicationtype may be used to adjust some settings

% If the type is essay, then the numbering of sections etc. need to be
% adjusted, ie. 1. Headline and not 0.1 Headline
\newboolean{essaynumbering}
\setboolean{essaynumbering}{false}
\newcommand{\EOApublicationtype}[1]{%
\ifthenelse%
{\equal{#1}{essay}}%
{
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\theequation}{\arabic{equation}}
\renewcommand{\thefigure}{\arabic{figure}}
\renewcommand{\thetable}{\arabic{table}}
\setboolean{essaynumbering}{true}
}{}
}

% removing chapter info
\renewcommand{\thefigure}{\arabic{figure}}
\renewcommand{\thetable}{\arabic{figure}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ------------------- formatierung der Fussnoten Anfang ---------
\usepackage[flushmargin]{footmisc}
\setlength{\footnotemargin}{2.4mm}

%%%%%%%%%%%% Footnote Sets
% WARNUNG 2
% Package etex Warning: Extended allocation already in use.
% (etex)                etex.sty code will not be used.
% (etex)                To force etex package to load, add
% (etex)                \RequirePackage{etex}
% (etex)                at the start of the document.

\usepackage{etex}
\usepackage{bigfoot}
\usepackage{alphalph}
% Allocate some extra registers so that we don't run out when
% declaring footnotes
%\reserveinserts{4}

\DeclareNewFootnote{arabic}[arabic]
\DeclareNewFootnote{alph}[alph]
%allow for more than 26 alpha-numbered footnotes per chater
%(aa,ab,ac,...)
\renewcommand{\thefootnotealph}{\emph{\alphalph{\value{footnotealph}}}}

\newcommand{\EOAfnalph}[1]{\protect\footnotealph{#1}}
\newcommand{\EOAfnarabic}[1]{\protect\footnotearabic{#1}}
%%%%%%%%%%%% Footnote Sets  --end

% ------------------- formatierung der Fussnoten Ende ---------

% caption dient zur Realisierung der Bildunterschriften
\usepackage{caption}
% footnote-package needed to typeset footnotes in captions
% problem was that both footnotes and captions are fragile
\usepackage{footnote}
% Für die Einbindung von Grafiken
\usepackage{graphicx}
% Mit float wird die Option H bei der Positionierung von Grafiken ermöglicht
\usepackage{float}
\usepackage[innercaption]{sidecap}

% Stichwortverzeichnis mit den Standard-TeX-Funktionen
%\usepackage{imakeidx}
%\makeindex[name=keywords]
%\makeindex[name=persons]
%\makeindex[name=locations]
%Use to add alphabetical headers within the index
%\usepackage{imakeidx}
\usepackage{imakeidx}
% set noautomatic=true to disable generation of ind file (in case you made manual changes there)
\makeindex[name=keywords,title=Subject Index,options=-s preambel/dontdeleteindex.ist, noautomatic=false]
\makeindex[name=persons,title=Name Index,options=-s preambel/dontdeleteindex.ist, noautomatic=false]
\makeindex[name=locations,title=Index of Locations,options=-s preambel/dontdeleteindex.ist]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Formatierung der Überschriften Anfang
\usepackage{setspace}
% WARNUNG 3
% Class scrbook Warning: Usage of package `titlesec' together
% (scrbook)              with a KOMA-Script class is not recommended.
% (scrbook)              I'd suggest to use the package only
% (scrbook)              if you really need it, because it breaks several
% (scrbook)              KOMA-Script features, i.e., option `headings' and
% (scrbook)              the extended optional argument of the section
% (scrbook)              commands.
% (scrbook)              Nevertheless, using requested
% (scrbook)              package `titlesec' on input line 324.
\usepackage{titlesec}
\usepackage{titletoc}

\titleformat{\part}[block]
{\normalfont \rmfamily}%
{\singlespacing\raggedleft\textbf{Teil \thepart}\\}%
{0em}%
{\flushright\textbf}
\titlespacing*{\part} {0pt}{-30pt}{0pt}

\titleformat{\chapter}[display]
{\normalfont \rmfamily\large}
{\singlespacing\textbf{Chapter \thechapter\quad}}%
{0em}%
{\raggedright\textbf}
\titlespacing*{\chapter} {0pt}{-30pt}{80pt}

\titleformat{\section}[hang]
{\normalfont \rmfamily}
{\bfseries\thesection\quad}%
{0em}%
{\textbf}

\titleformat{\subsection}[hang]
{\normalfont \rmfamily}
{\textbf\thesubsection\quad}%
{0em}%
{\textbf}

\titleformat{\subsubsection}[hang]
{\normalfont \rmfamily}
{\textbf\thesubsection\quad}%
{0em}%
{\textbf}

\titleformat{\paragraph}[display]
{\normalfont \rmfamily}
{}%{\textbf\theparagraph\quad}%
{0em}%
{\textbf}
%% spacing stimmt noch nicht ganz?
\titlespacing*{\paragraph} {0pt}{15pt}{7pt}


% Formatierung der Überschriften Ende
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Depth of table of contents. If value = 0, listoffigures will be empty
\setcounter{tocdepth}{1}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Formatierung des Inhaltsverzeichnisses
\titlecontents{part}[0.2em]{\addvspace{1em}\bfseries}{}{}{\normalfont\rmfamily\hfill\contentspage}
\titlecontents{chapter}[3em]{\addvspace{1em}\bfseries}{\contentslabel{2.8em}}{}{\normalfont\rmfamily\dotfill\contentspage}
\titlecontents{section}[3em]{}{\contentslabel{2.8em}}{}{\dotfill\contentspage}
\makeatletter
\renewcommand\@pnumwidth{2em}
\makeatother
% Formatierung des Inhaltsverzeichnisses
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition einiger Makros zur Erhöhung des Bedienkomforts - Anfang

% red text
\newcommand{\EOAred}[1]{\textcolor{red}{#1}}
% Makro für kursiven Text
\newcommand{\EOAemph}[1]{\emph{#1}}
% Makro für fetten Text
\newcommand{\EOAbold}[1]{\textbf{#1}}
% Makro für einen URL
\makeatletter%
\def\EOAurl{\@ifnextchar[{\@date}{\@nodate}}
\def\@date[#1]#2{\protect\url{#2}, #1}
\def\@nodate#1{\protect\url{#1}}
\makeatother
\Urlmuskip=0mu plus 2mu
% Makro für hochgestellten Text
\newcommand{\EOAup}[1]{\textsuperscript{#1}}
% Makro für tiefgestelten Text
\newcommand{\EOAdown}[1]{\textsubscript{#1}}
% Makro for Greek Text: \greek{}
\newcommand{\EOAgreek}[1]{{\greekfont #1}}
% Makro for striked out Text
\newcommand{\EOAst}[1]{\st{#1}}
% Makro for letter spacing
\newcommand{\EOAls}[1]{}
% Makro for letter CAPS
% Since Times does not have Caps, we use 'Times New Roman' on Linux and 'Palatino Linotype' on Windows
\newcommand{\EOAcaps}[1]{%
\ifwindows%
{\fontspec[Scale=0.7]{Palatino Linotype}\textsc{#1}}%
\else%
{\fontspec[Scale=1]{Times New Roman}\textsc{#1}}%
\fi%
}
% Makro for Math font: \greek{}
\newcommand{\EOAmathfont}[1]{{\EOAmfont #1}}
% Makro for Chinese Text: \EOAchinese{}
\newcommand{\EOAchinese}[1]{{\chinesefont #1}}
% Makro for Russian Text: \EOArussian{}
\newcommand{\EOArussian}[1]{{\russianfont #1}}
% Makro for Hebrew Text: \EOAhebrew{}
\newcommand{\EOAhebrew}[1]{{\hebrewfont #1}}
% Makro for Inline-Figure: \EOAinline{File}
\newcommand{\EOAinline}[1]{\includegraphics[height=0.85em,keepaspectratio]{#1}}
% New command for Footnotes
\newcommand{\EOAfn}[1]{\protect\footnote{#1}}
\newcommand{\EOAfnpar}{\newline\indent}
% New command for ~
\newcommand{\EOAtilde}{\textasciitilde{}}
% New command for referencing objects (i.e. figures)
\newcommand{\EOAref}[1]{\ref{#1}}
% New command for referencing pages
\newcommand{\EOApageref}[1]{\pageref{#1}}
% New command for referencing with text
\newcommand{\EOAtextref}[2]{\hyperref[#1]{#2}}
% New command for label
\newcommand{\EOAlabel}[1]{\phantomsection\label{#1}}
% New command for marking index entries
\newcommand{\EOAindex}[1]{\index[keywords]{#1}}
% New command for printing index
\newcommand{\EOAprintindex}{\printindex[keywords]}
% New command for marking person index entries
\newcommand{\EOAindexperson}[1]{\index[persons]{#1}}
% New command for printing person index
\newcommand{\EOAprintpersonindex}{\printindex[persons]}
% New command for marking person index entries
\newcommand{\EOAindexlocation}[1]{\index[locations]{#1}}
% New command for printing person index
\newcommand{\EOAprintlocationindex}{\printindex[locations]}
% New command for Table of Content
\newcommand{\EOAtoc}{\tableofcontents}
% New command for ToC-Entries
%% hier ist irgendwas passiert!
%% \newcommand{\EOAtocentry}[1]{\addtocontents{toc}{\hspace{15pt}\normalfont{\textbf{#1}}\par}}
% \newcommand{\EOAtocentry}[1]{\addtocontents{toc}{\normalfont{\textbf{#1}}\par}}
\newcommand{\EOAtocentry}[1]{\clearpage\phantomsection\addcontentsline{toc}{chapter}{#1}}
% New command for parts
\newcommand{\EOApart}[1]{\part*{#1}}
% New command for parts
\newcommand{\EOAfacsimilepart}[1]{\part*{#1}
%--------------------- Formatting the facsimile part
\pagestyle{fancy} % eigenen Seitenstil aktivieren}
\fancyhf{} % Alle Felder loeschen
\renewcommand{\headrulewidth}{0pt}
\fancyhead[EL,OR]{\footnotesize\thepage}
\fancypagestyle{plain}{%
\fancyhead{}}
}
% New command for numbered chapters
\newcommand{\EOAchapter}[2]{
\chapter[#2]{#2}
\chaptermark{#1}
\ifthenelse{\boolean{anthology}}{
\newrefsection
}
{}
}
% New command for not numbered chapters
\newcommand{\EOAchapternonumber}[2]{
\setcounter{secnumdepth}{-1}
\setcounter{footnote}{0}
\chapter[#2]{#2}
\markboth{#1}{}
\ifthenelse{\boolean{anthology}}{
\newrefsection
}
{}
\ifthenelse{\boolean{essaynumbering}}{
\setcounter{section}{0}
\setcounter{equation}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
}
{}
\setcounter{secnumdepth}{2}
}
% New command for Author in Headline
\newcommand{\EOAauthor}[1]{\\ \textnormal{\textit{ #1}}}
% New command for sections
\newcommand{\EOAsection}[1]{\section{#1}}
% New command for sections that won't appear in table of contents
\newcommand{\EOAsectionnotoc}[1]{\section*{#1}}
% New command for subsections
\newcommand{\EOAsubsection}[1]{\subsection{#1}}
% New command for subsections that won't appear in table of contents
\newcommand{\EOAsubsectionnotoc}[1]{\subsection*{#1}}
% New command for not numbered sections
\newcommand{\EOAsectionnonumber}[1]{\setcounter{secnumdepth}{-1}\section{#1}\setcounter{secnumdepth}{2}}
% New command for not numbered subsections
\newcommand{\EOAsubsectionnonumber}[1]{\setcounter{secnumdepth}{-1}\subsection{#1}\setcounter{secnumdepth}{2}}
% % New command for not numbered subsections that are excluded from toc
% \newcommand{\EOAsubsectionnonumbernotoc}[1]{\setcounter{secnumdepth}{-1}\subsection*{#1}\setcounter{secnumdepth}{2}}
%New command for subsubsection
\newcommand{\EOAsubsubsection}[1]{\subsubsection*{#1}}
% New command for paragraph
\newcommand{\EOAparagraph}[1]{\paragraph{#1}}



% New command for an empty page
\newcommand{\EOAemptypage}{\clearpage%
\thispagestyle{empty}%
     %-------------------------- using invisible characters
\newpage%
}
% New command for a pagebreak
\newcommand{\EOAnewpage}{
\ifthenelse%
{\strcmp{\@currenvir}{EOAtranscripted}=1}%
{\newpage\EOAtranscriptedheader}
{\clearpage}
}
% New Environment for bilingual doublesided transcription
\newenvironment{EOAtranscripted}[2]{
\renewcommand{\EOAtranscriptedheader}{\noindent\makebox[\textwidth][c]{\footnotesize\MakeUppercase{#2}}\vspace*{0.5cm}\\}
\makeatletter
\clearpage\if@twoside
  \ifodd\c@page \hbox{}\newpage\if@twocolumn\hbox{}%
  \newpage\fi\fi\fi
\makeatother
\noindent\makebox[\textwidth][c]{\footnotesize\MakeUppercase{#1}}\vspace*{0.5cm}\\
}{\clearpage}
% Here defined pro forma in conjunction with EOAtranscripted
\newcommand{\EOAtranscriptedheader}{}
% Environment for quoting
\newenvironment{EOAquote}{\begin{quote}}{\end{quote}}

% Environment for Lists, if optional argument is given, it starts at another number
\newenvironment{EOAlist}[1][]{%
  \medskip\begin{compactenum}
  \ifthenelse{\equal{#1}{}}
  {}
  {\setcounter{enumi}{#1-1}}}
{\end{compactenum}\medskip
}

% abstract
\newenvironment{EOAabstract}{\begin{quote}\small}{\end{quote}}
% \newenvironment{EOAlist}{\medskip\begin{compactenum}}{\end{compactenum}\medskip}
% Environment for undordered list
\newenvironment{EOAitems}{\medskip\begin{compactitem}}{\end{compactitem}\medskip}
% Command to define a theorem
\newcommand{\EOAnewtheorem}[2]{\newtheorem{#1}{#2}}
% Environment for descriptions
\newenvironment{EOAdescription}{\medskip\begin{description}}{\end{description}\medskip}
\renewcommand{\descriptionlabel}[1]{\hspace{\labelsep}\emph{#1}}
% New command for short equation
\newcommand{\EOAineq}[1]{$#1$}
% Environment for Equations
% Multilines may be used with \begin{split} and \\ to mark a linebreak
\newenvironment{EOAequation}[1]{\begin{equation}
\label{#1}
}{\end{equation}}
% Environment for Subequations
\newenvironment{EOAsubequations}[1]{\begin{subequations}
\label{#1}
}{\end{subequations}}
% Environment for unnumbered Equation
\newenvironment{EOAequationnonumber}{\begin{equation*}}{\end{equation*}}
% Environment for numbered Equation array
\newenvironment{EOAequationarray}[1]{\csname align\endcsname}{\csname endalign\endcsname\ignorespacesafterend}
% Environment for not numbered Equation array
\newenvironment{EOAequationarraynonumber}{\csname align*\endcsname}{\csname endalign*\endcsname\ignorespacesafterend}

% allow for more space above and below captions
\setlength{\abovecaptionskip}{15pt plus 3pt minus 2pt}
\setlength{\belowcaptionskip}{15pt plus 3pt minus 2pt}

% Makro for Figure: \EOAfigure{File}{Caption}{Label}{Width}{Position}
\makeatletter%
\def\EOAfigure{\@ifnextchar[{\@figoption}{\@fignooption}}
\def\@figoption[#1]#2#3#4#5#6{%
  \makesavenoteenv[figure*]{figure}
  \begin{figure*}[#6]
    \centering
    \includegraphics[width=0.#5\textwidth]{#2}
    \captionsetup{singlelinecheck=false,font=small,format=hang,justification=raggedright}
    \caption[#1]{#3}
    \label{#4}
  \end{figure*}
}
\def\@fignooption#1#2#3#4#5{%
  \makesavenoteenv[figure*]{figure}
  \begin{figure*}[#5]
    \begin{center}
    \includegraphics[width=0.#4\textwidth]{#1}
    \captionsetup{singlelinecheck=false,font=small,format=hang,justification=raggedright}
    \caption{#2}
    \label{#3}
    \end{center}
  \end{figure*}
}
\makeatother

% Makro for non numbered Figure: \EOAfigurenonumber{File}{Width}{Position}
\newcommand{\EOAfigurenonumber}[3]{
% Redefinition and \makesavenoteenv necessary to enable footnotes in captions
\makesavenoteenv[figure*]{figure}
\begin{figure*}[#3]
\begin{center}
\includegraphics[width=0.#2\textwidth]{#1}
\end{center}
\end{figure*}
}

% Makro for Landscape-Figure: \EOAfigure{File}{Caption}{Label}
\newcommand{\EOAlsfigure}[3]{
\begin{landscape}
\begin{figure}[p]
\begin{center}
\includegraphics[width=1.35\textwidth]{#1}
\captionsetup{singlelinecheck=false,font=small,format=hang,justification=raggedright}
\caption{#2}
\label{#3}
\end{center}
\end{figure}
\end{landscape}
}

% Makro for Facimile: \EOAfacsimile{File}{Label}
\makeatletter%
\def\EOAfacsimile{\@ifnextchar[{\@backref}{\@nobackref}}
% \EOAfacsimile[pb0049]{facsim/0049.jpg}{facsimile0049}{First facsimile page extended}
\def\@backref[#1]#2#3#4{\fancyhead[RE,LO]{\footnotesize \nouppercase #4}\begin{figure}[H] \begin{center} \label{#3}  \includegraphics[width=0.9\textwidth]{#2} \newline\footnotesize{Transkription auf Seite~\EOApageref{#1}.} \end{center}
\end{figure}\clearpage}

% \EOAfacsimile{facsim/0049.jpg}{facsimile0049}{First facsimile page}
\def\@nobackref#1#2#3{\fancyhead[RE,LO]{\footnotesize \nouppercase #3}\begin{figure}[H] \begin{center} \label{#2} \includegraphics[width=0.9\textwidth]{#1} \end{center} \end{figure}\clearpage}
\makeatother

\makeatletter%
\def\EOAsidecaptionfigure{\@ifnextchar[{\@sidecapoption}{\@sidecapnooption}}
\def\@sidecapoption[#1]#2#3#4#5#6{%
  \makesavenoteenv[SCfigure*]{SCfigure}
  \begin{SCfigure*}[][#6]
    \centering
    \includegraphics[width=0.#5\textwidth]{#2}
    \captionsetup{singlelinecheck=false,font=small,format=hang,justification=raggedright}
    \caption[#1]{#3}
    \label{#4}
  \end{SCfigure*}
}
\def\@sidecapnooption#1#2#3#4#5{%
  \makesavenoteenv[SCfigure*]{SCfigure}
  \begin{SCfigure*}[][#5]
    \centering
    \includegraphics[width=0.#4\textwidth]{#1}
    \captionsetup{singlelinecheck=false,font=small,format=hang,justification=raggedright}
    \caption{#2}
    \label{#3}
  \end{SCfigure*}
}
\makeatother

% Command for bibliographies as sections within a chapter
\newcommand{\EOAprintbibliography}[1][]{
  \ifthenelse{\equal{#1}{}}{\printbibliography[heading=none]}{\printbibliography[heading=none,keyword=#1]}%
}
% Command for list of shorthands
\newcommand{\EOAprintshorthands}{
  \printbiblist[heading=none]{shorthand}
}

% Command for .bib-Database
\newcommand{\EOAbibliographydatabase}[1]{
\bibliography{#1}
}
% Command for quotation Name Year, Page
\newcommand{\EOAciteauthoryear}[2][seitenangabe]{%
\ifthenelse%
{\equal{#1}{seitenangabe}}%
{\cite{#2}}%
{\cite[#1]{#2}}%
}
% Command for quotation Year, Page
\newcommand{\EOAciteyear}[2][seitenangabe]{%
\ifthenelse%
{\equal{#1}{seitenangabe}}%
{\cite*{#2}}%
{\cite*[#1]{#2}}%
}
% Command for manual quotation
\newcommand{\EOAcitemanual}[2][kuerzel]{%
\ifthenelse%
{\equal{#1}{kuerzel}}%
{\notecite{#2}}%
{\notecite[#1]{#2}}%
}
% Command for manual quotation
\newcommand{\EOAcitenumeric}[2][seitenangabe]{%
\ifthenelse%
{\equal{#1}{seitenangabe}}%
{\cites{#2}}%
{\cites[#1]{#2}}%
}
% Definition einiger Makros zur Erhöhung des Bedienkomforts - Ende
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%% Tables - Beginning


\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{longtable}

% Middle rule should be thicker, therefore redefining lightrulewidth for \midrule
\setlength\lightrulewidth{1.2pt}

\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}} % linksbündig mit Breitenangabe
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} % zentriert mit Breitenangabe
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}} % rechtsbündig mit Breitenangabe

\newcommand{\EOAtablehead}[2][1]{%
#2\\%
\midrule%
}


\newenvironment{EOAtable}[5][1]%
{


\ifthenelse%
{\strcmp{#3}{nonumber}=0}%
{
% if the caption is equal to 'no number', then omit caption and label
}
{
% if the caption is not equal to 'no number', then use caption and label
\renewcommand{\tmpEOAtablecaption}{\captionsetup{singlelinecheck=false,font=small,format=hang,justification=raggedright}\caption{#3}}
\renewcommand{\tmpEOAtablelable}{\label{#4}}
}
\begin{table}[#5]
\begin{center}
  % KT put it here
\tmpEOAtablecaption
\tmpEOAtablelable

\ifthenelse%
{\strcmp{#1}{blank}=0}%
{
% if the optional parameter is "blank" then omit borders
\begin{tabular}{#2}
\renewcommand{\tmpEOAtablebottomborder}{}
}
{
% if the optional parameter is not "blank" or missing then enable borders
\renewcommand{\tmpEOAtablebottomborder}{\bottomrule}
\begin{tabular}{#2}%
\toprule%
}

}
{
\tmpEOAtablebottomborder
\end{tabular}
\end{center}
% \tmpEOAtablecaption
% \tmpEOAtablelable
\renewcommand{\tmpEOAtablecaption}{}
\renewcommand{\tmpEOAtablelable}{}
\end{table}
}
% Definition of temporary commands to enable the caption and the label in the ending part of the EOAtable-environment
\newcommand{\tmpEOAtablecaption}{}
\newcommand{\tmpEOAtablelable}{}
\newcommand{\tmpEOAtablebottomborder}{}

%%%%%%%%%%%% Tables - End

%%%%%%%%%%%% Letter - Beginning (Work in Progress)
\mdfdefinestyle{mdfeoaletterhead}{%
backgroundcolor=white, linecolor=black, innerleftmargin=4pt, innerrightmargin=4pt}
\newcommand{\EOAletterhead}[4]{%
\begin{mdframed}[style=mdfeoaletterhead]
\noindent\emph{#1}\\
\emph{#2}\\
\emph{#3}, \emph{#4}
\end{mdframed}
}
\newcommand{\kopf}[1]{#1}
\newcommand{\kurz}[1]{#1}
%%%%%%%%%%%% Letter - End

%%%%%%%%%%%% Box - Beginning
% \usepackage{mdframed}
\definecolor{shadecolor}{gray}{0.9}
\mdfdefinestyle{mdfeoabox}{%
backgroundcolor=shadecolor, linecolor=shadecolor, innerleftmargin=4pt, innerrightmargin=4pt}
\newenvironment{EOAbox}[1][]%
{\begin{mdframed}[style=mdfeoabox,frametitle=#1]}
{\end{mdframed}}
%%%%%%%%%%%% Box - End

%%%%%%%%%%%%%
% Verse
\newenvironment{EOAverse}%
{\begin{verse}}%
{\end{verse}}


%%%%%%%%%%%%%

% Some fixes concerning XeTeX and the n-dash

\XeTeXinterchartokenstate=1
\XeTeXcharclass`\–=150
\XeTeXinterchartoks 150 0 = {\kern0em }

% Give more space per line, makes hyphenation better
\setlength\emergencystretch{3em}

% kt add marginnote and qrcode
% \usepackage{marginnote}
% \usepackage{qrcode}

% https://tex.stackexchange.com/questions/474807/how-can-i-access-and-store-the-current-value-of-a-counter/474955#474949
% \newcounter{counterA}
\newcounter{hionlycounter}
\newcommand\hionlyfigid[1]{%
  \setcounter{hionlycounter}{\value{figure}}%
  % \setcounter{hionlycounter}{\value{counterA}}%
  % \stepcounter{hionlycounter}%
  % the following must be \edef or \protected@edef if you have
  % more material that would fail in \edef such as \textbf
  \expandafter\edef\csname data:#1\endcsname{%
    \noexpand{\arabic{hionlycounter}}%
  }%
}
\newcommand\hionlyfignumber[1]{\csname data:#1\endcsname}
% end


\usepackage[colorlinks=false,
  %% urlcolor=SteelBlue4,
  %% linkcolor=DarkSlateGrey,
  pdfusetitle,
  pdfdisplaydoctitle=true,
  pdfstartpage={1},             %what page to start at
  pdfstartview={FitH},         %% zoom to pagewidth
  ]{hyperref}

  % WARNUNG 4
% Class scrbook Warning: \float@addtolists detected!
% (scrbook)              Implementation of \float@addtolist became
% (scrbook)              deprecated in KOMA-Script v3.01 2008/11/14 and
% (scrbook)              has been replaced by several more flexible
% (scrbook)              features of package `tocbasic`.
% (scrbook)              Since Version 3.12 support for deprecated
% (scrbook)              \float@addtolist interface has been
% (scrbook)              restricted to only some of the KOMA-Script
% (scrbook)              features and been removed from others.
% (scrbook)              Loading of package `scrhack' may help to
% (scrbook)              avoid this warning, if you are using a
% (scrbook)              a package that still implements the
% (scrbook)              deprecated \float@addtolist interface .
