%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document type, global settings, and packages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[english,11pt,twoside]{report}   %12 point font for Times New Roman
\usepackage[a4paper,hmargin=3.5cm,vmargin=5.3cm,head=1.5cm,foot=3.2cm]{geometry}
\usepackage[bookmarks=true, hidelinks]{hyperref}     % hyperlink
\usepackage{url}          % simple URL typesetting
% https://tex.stackexchange.com/questions/47576/combining-ifxetex-and-ifluatex-with-the-logical-or-operation
\usepackage{ifxetex,ifluatex}
\newif\ifxetexorluatex
\ifxetex
  \xetexorluatextrue
\else
  \ifluatex
    \xetexorluatextrue
  \else
    \xetexorluatexfalse
  \fi
\fi
\ifxetexorluatex
  % To fix LaTeX command is already defined error, load amssymb before unicode-math
  % https://tex.stackexchange.com/a/547153/56364
  % \usepackage{stix}
  \usepackage{amssymb}
  \usepackage{fontspec}
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase,Ligatures=TeX}
  % \setmainfont{STIX Two Text}
  \setmainfont{Noto Serif}
  \setmathfont{TeX Gyre Schola Math}
  \usepackage[scale=0.8]{noto-mono}
  \setmonofont{Noto Sans Mono}
  % small url fonts
  \renewcommand{\UrlFont}{\ttfamily\small}
  \ifxetex
    % https://gist.github.com/dlimpid/5454229
    % Use xeCJK in XeLaTeX
    \usepackage{xeCJK}
    \xeCJKsetup{%
      CJKspace=true,% % true이면 띄어쓰기 사용. 중국어, 일어는 필요 없을수도
      % CJKmath=true,%  % true면 math environment 안에서 CJK 글자 사용
      CJKecglue={}%   % Western과 CJK 사이의 공백 지정: {}로 간격을 없앰
    }
    \setCJKmainfont[
      Path=fonts/,
      Extension=.otf,
      BoldFont=NotoSerifkr-Bold,
      AutoFakeSlant,
      Ligatures=TeX]{NotoSerifkr-Regular.otf}
    \setCJKsansfont[
      Path=fonts/,
      Extension=.otf,
      BoldFont=NotoSerikr-Bold,
      AutoFakeSlant,
      Ligatures=TeX]{NotoSerifkr-Regular.otf}
    \setCJKmonofont[
      Path=fonts/,
      Extension=.ttf,
      BoldFont=NotoSansMono-Bold,
      AutoFakeSlant,
      Ligatures=TeX]{NotoSansMono-Regular.ttf}
  \fi
  \ifluatex
    \usepackage[hangul]{luatexko}
    \setmainhangulfont[
      Path=fonts/,
      UprightFont=*-Regular,
      BoldFont=*-Bold,
      Extension=.otf,
      AutoFakeSlant,
      Ligatures=TeX]{NotoSerifkr}
    \hangulbyhangulfont=1
    \setmainfont{Noto Serif}
    \setmathfont{TeX Gyre Schola Math}
    \usepackage[scale=0.8]{noto-mono}
    \setmonofont{Noto Sans Mono}
  \fi
\else
  % pdflatex doesn't work due to siunitx and kotex conflict
  % https://t.co/PgBfFh9rTU?amp=1
  \usepackage{amsmath,amsthm,amsfonts}
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage[finemath]{kotex} % Use kotex in PDFLaTeX
  % \usepackage{CJKutf8}
  \usepackage{textcomp} % provide euro and other symbols
  % use nanum font in Korean
  \usepackage{dhucs-nanumfont}
  % otherwise, use Noto fonts
  \usepackage{noto}
\fi
\ifxetex
  \XeTeXinputnormalization=1
\fi
\renewcommand{\floatpagefraction}{0.1} % one figure in one page
\usepackage[english]{babel}    % babel set language
\usepackage[bibencoding=utf8,backend=biber,sorting=none,bibstyle=phys]{biblatex}  %reference manager
\usepackage{csquotes}
\usepackage{setspace}   %use this package to set linespacing as desired
\doublespacing
\usepackage{afterpage}    % separate page for floats and tables
\usepackage{titlefoot}    % keywords on footnote
\usepackage{bookmark}
\usepackage[explicit]{titlesec}  %title control and formatting
\usepackage[titles]{tocloft}  %table of contents control and formatting
\usepackage[page]{appendix}  %for appendices
\usepackage[normalem]{ulem}  %for underlined section titles
\usepackage{graphicx}  %for images and plots
\usepackage[figuresright]{rotating}  %for rotated, landscape images
\usepackage{adjustbox}    % fit table to page width
\usepackage{algorithm}      % algorithm
\usepackage{algpseudocode}  % algorithm
\usepackage{booktabs}     % proessional-quality tables
\usepackage{multicol} 		% use multicol in table
\usepackage{multirow} 		% use multirow in table
\usepackage{xcolor}			  % color fonts
\usepackage[super]{nth}		% th
\usepackage{siunitx}		  % SI unit
\usepackage[noabbrev,nameinlink]{cleveref}		% for multiple cross-reference
\usepackage[intoc]{nomencl}  % nomenclature
\makenomenclature
\setlength{\nomitemsep}{-\parsep}
\setlength{\nomlabelwidth}{1.7cm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Bibliography
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Add your bibliography file here
\addbibresource{references.bib}
% escape % in abstract of bibfile (due to it is perl program)
\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
       \step[fieldsource = abstract,
          match = \regexp{([^\\])\%},
          replace = \regexp{$1\\\%}]
    }
  }
}
% prevent certain fields in references from printing in bibliography
\AtEveryBibitem{\clearfield{abstract}}
\AtEveryBibitem{\clearlist{abstract}}
\AtEveryBibitem{\clearfield{issn}}
\AtEveryBibitem{\clearlist{issn}}
\AtEveryBibitem{\clearfield{language}}
\AtEveryBibitem{\clearlist{language}}
\AtEveryBibitem{\clearfield{doi}}
\AtEveryBibitem{\clearlist{doi}}
\AtEveryBibitem{\clearfield{url}}
\AtEveryBibitem{\clearlist{url}}
\AtEveryBibitem{%
  \ifentrytype{online}
    {}
    {\clearfield{urlyear}\clearfield{urlmonth}\clearfield{urlday}}}
% footnote for keywords in abstract
% https://tex.stackexchange.com/questions/30720/footnote-without-a-marker
\newcommand\blfootnote[1]{%
  \begingroup
  \renewcommand\thefootnote{}\footnote{#1}%
  \addtocounter{footnote}{-1}%
  \endgroup
}
%%%%%%%%%%%%%%%%%%%%%%
% Start of Document
%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Cover Page
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{cover.tex}
\currentpdfbookmark{Cover Page}{coverPage}  %add PDF bookmark for this page
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title Page
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{titlePage.tex}
\currentpdfbookmark{Title Page}{titlePage}  %add PDF bookmark for this page
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Approval Page
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{approvalPage.tex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Acknowledgments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \pagenumbering{roman}
% \addcontentsline{toc}{chapter}{Acknowledgments}
% \setcounter{page}{5} % set the page number appropriately based on the number of intro pages
\input{acknowledgements.tex}
%\addtocontents{toc}{\cftpagenumbersoff{chapter}}
%\currentpdfbookmark{Acknowledgments}{acknowledgments}
%\addtocontents{toc}{\cftpagenumberson{chapter}}
% Set location of page numbering as just below text body
\newgeometry{hmargin=3.5cm,vmargin=5.3cm,head=1.5cm,foot=3.2cm,footskip=1cm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Table of Contents
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagenumbering{roman}
\setcounter{page}{1} % set the page number appropriately based on the number of intro pages
% Format for Table of Contents
\renewcommand{\cftchapdotsep}{\cftdotsep}  %add dot separators
\renewcommand{\cftchapfont}{\bfseries}  %set title font weight
\renewcommand{\cftchappagefont}{}  %set page number font weight
\renewcommand{\cftchappresnum}{Chapter }
\renewcommand{\cftchapaftersnum}{:}
\renewcommand{\cftchapnumwidth}{7em}
\renewcommand{\cftchapafterpnum}{\vskip\baselineskip} %set correct spacing for entries in single space environment
\renewcommand{\cftsecafterpnum}{\vskip\baselineskip}  %set correct spacing for entries in single space environment
\renewcommand{\cftsubsecafterpnum}{\vskip\baselineskip} %set correct spacing for entries in single space environment
\renewcommand{\cftsubsubsecafterpnum}{\vskip\baselineskip} %set correct spacing for entries in single space environment
%format title font size and position (this also applys to list of figures and list of tables)
\titleformat{\chapter}[display]
{\normalfont\bfseries\filcenter}{\chaptertitlename\ \thechapter}{0pt}{\MakeUppercase{#1}}
\renewcommand\contentsname{Table of Contents}
\begin{singlespace}
\tableofcontents
\end{singlespace}
\currentpdfbookmark{Table of Contents}{TOC}
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% List of figures and tables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\addcontentsline{toc}{chapter}{List of Tables}
\begin{singlespace}
	\setlength\cftbeforetabskip{\baselineskip}  %manually set spacing between entries
	\listoftables
\end{singlespace}
\clearpage
\addcontentsline{toc}{chapter}{List of Figures}
\begin{singlespace}
\setlength\cftbeforefigskip{\baselineskip}  %manually set spacing between entries
\listoffigures
\end{singlespace}
\clearpage
\printnomenclature
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is the Abstract
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\addcontentsline{toc}{chapter}{Abstract}
% \setcounter{page}{5} % set the page number appropriately based on the number of intro pages
\input{abstract-eng.tex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Remark
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{remark.tex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Chapters
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
% formatting
%%%%%%%%%%%%%%%%%%%%%%
% resume page numbering for rest of document
\clearpage
\pagenumbering{arabic}
\setcounter{page}{1} % set the page number appropriately
% Adjust chapter title formatting
\newcommand{\chapternamefont}{\scshape\Large}% Chapter name font
\newcommand{\chaptertitlefont}{\LARGE\bfseries}% Chapter title font
\titleformat{\chapter}[display]
{\normalfont\bfseries\chapternamefont\raggedright}{\MakeUppercase\chaptertitlefont\chaptertitlename\ \thechapter}{0pt}{\MakeUppercase{#1}}  %spacing between titles
\titlespacing*{\chapter}
  {0pt}{\topskip}{30pt}	%controls vertical margins on title
% Adjust section title formatting
\titleformat{\section}{\normalfont\bfseries}{\thesection}{1em}{#1}
% Adjust subsection title formatting
% \titleformat{\subsection}{\normalfont}{\uline{\thesubsection}}{0em}{\uline{\hspace{1em}#1}}
\titleformat{\subsection}{\normalfont\bfseries}{\thesubsection}{1em}{#1}
% Adjust subsubsection title formatting
\titleformat{\subsubsection}{\normalfont\itshape}{\thesubsection}{1em}{#1}
%%%%%%%%%%%%%%%%
% Chapter 1
%%%%%%%%%%%%%%%%
\input{chapter1.tex}
%%%%%%%%%%%%%%%%
% Chapter 2
%%%%%%%%%%%%%%%%
\input{chapter2.tex}
%%%%%%%%%%%%%%%%
% Chapter 3
%%%%%%%%%%%%%%%%
\input{chapter3.tex}
%%%%%%%%%%%%%%%%
% Chapter 4
%%%%%%%%%%%%%%%%
\input{chapter4.tex}
%%%%%%%%%%%%%%%%
% Chapter 5
%%%%%%%%%%%%%%%%
\input{chapter5.tex}
%%%%%%%%%%%%%%%%
% Appendices
%%%%%%%%%%%%%%%%
\input{appendix.tex}
%%%%%%%%%%%%%%%%
% References
%%%%%%%%%%%%%%%%
% \nocites
\setlength\bibitemsep{\baselineskip}  %manually set separataion betwen items in bibliography to double space
\printbibliography[title={References}]
\addcontentsline{toc}{chapter}{References}  %add References section to Table of Contents
%%%%%%%%%%%%%%%%
% Summary (Korean)
%%%%%%%%%%%%%%%%
% To fix incorrect incorrect page numbering in ToC, add cleardoublepage and phantomsection
% https://tex.stackexchange.com/questions/23499/incorrect-bookmarks-and-page-number-in-table-of-contents
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{국문초록}  %add References section to Table of Contents
\input{abstract-kor.tex}
\end{document}