% \file{style/mu/fithesis-med.sty}
% \changes{v1.0.0}{2021/02/21}{Files were renamed after
%   breaking changes in package loading after PR 438 in \LaTeXe. [VN]}
% \changes{v1.0.0}{2021/03/19}{Updated urls to show the most recent
%   requirements and recommendations used in preparation of the
%   template. [TV]}
% This is the style file for the theses written at the Faculty of
% Medicine at the Masaryk University in Brno. It has been prepared
% in accordance with the formal requirements published at the
% website of the faculty \footnote {See \url{https://is.muni.cz/do/^^A
% med/uredni_deska/pravni_normy/smernice_dekana/2020/smernice_lf_mu^^A
% _2_2020_-_pokyny_k_formalnim_nalezitostem_zaverecnych_bakalarskyc^^A
% h/Smernice_LF_MU_2-2020_-_Pokyny_k_formalnim_nalezitostem_zaverec^^A
% nych_bakalarskych_a_diplomovych_praci_vypracovanych_na_Lekarske_f^^A
% akulte_MU.pdf}}.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{fithesis/style/mu/fithesis-mu-med}[2024/03/06]
%    \end{macrocode}
% The file defines the color scheme of the respective faculty. Note
% the the color definitions are in RGB, which makes the resulting
% files generally unsuitable for printing.
%    \begin{macrocode}
\thesis@color@setup{
  links={HTML}{F58E76},
  tableEmph={HTML}{FF9D85},
  tableOdd={HTML}{FFF5F6},
  tableEven={HTML}{FFDEDF}}
%    \end{macrocode}
% The bibliography support is enabled. The |authortitle| citations
% are used and the bibliography is sorted by year, name, and title.
%    \begin{macrocode}
\thesis@bibliography@setup{%
  style=authortitle,
  sorting=ynt}
\thesis@bibliography@load
%    \end{macrocode}
% The AMA citation style is defined using |authortitle| as the basis.
% The following code has been adapted from
% \url{https://tex.stackexchange.com/a/233423/70941}.
% \changes{v1.0.0}{2021/03/26}{^^A
%   The Faculty of Medicine at the Masaryk University in Brno uses the
%   AMA citation and reference style. [VN]}
%    \begin{macrocode}
\ifthesis@bibliography@loaded@
  \DeclareNameAlias{sortname}{last-first}
  \renewcommand*{\revsdnamepunct}{}
  \DeclareFieldFormat[%
    article,inbook,incollection,inproceedings,patent,thesis,unpublished]%
    {title}{{#1\isdot}}
  \renewbibmacro{in:}{}
  \DeclareFieldFormat{pages}{#1}
  \renewcommand*{\bibpagespunct}{\addcolon}
  \DeclareFieldFormat{journaltitle}{#1\addperiod}
  \DeclareFieldFormat{booktitle}{{#1}}
  \DeclareFieldFormat{title}{{#1}}
  \renewbibmacro*{journal+issuetitle}{%
    \usebibmacro{journal}%
    \setunit*{\addspace}%
    \iffieldundef{series}
    {}
    {\newunit
      \printfield{series}%
      \setunit{\addspace}}%
    \usebibmacro{issue+date}%
    \setunit{\addsemicolon\addspace}%
    \usebibmacro{volume+number+eid}%
    \setunit{\addcolon\space}%
    \usebibmacro{issue}%
    \newunit%
  }
  \renewbibmacro*{issue+date}{\printfield{year}}
  \renewcommand*{\finalnamedelim}{\multinamedelim}
\fi
%    \end{macrocode}
% The file loads the following packages:
% \begin{itemize}
%   \item\textsf{tikz} -- Used for dimension arithmetic.
%   \item\textsf{geometry} -- Allows for modifications of the type
%     area dimensions.
%   \item\textsf{setspace} -- Allows for line height modifications.
% \end{itemize}
% In addition to this, the type area width is set to
% 16\,cm in accordance with the formal requirements of the faculty.
% This leads to overfull lines and is against the good conscience
% of the author of this style.
%    \begin{macrocode}
\thesis@require{tikz}
\thesis@require{geometry}
\thesis@require{setspace}
\geometry{top=25mm,bottom=20mm,left=25mm,right=25mm,includeheadfoot}
%    \end{macrocode}
% The style file configures the upper part of the title page headers
% to include the the name of the department and the study programme
% which are by default in the bottom part of the title page. Upon failure
% of the \textit{xpatchcmd}, \cs{thesis@xpatchError} is called.
% \changes{v0.3.49}{2018/02/11}{Removed an extraneous \cs{vskip} in
%   the style files for the Masaryk University in Brno. [VN]}
% \changes{v1.0.0}{2021/02/26}{^^A
%   The style files for the Faculty of Medicine
%   at the Masaryk University in Brno
%   no longer redefine the \cs{thesis@blocks@titlePage@footer}
%   and \cs{thesis@blocks@titlePage@content} macros, which are no
%   longer defined. [VN]}
% \changes{v1.0.0}{2021/03/22}{Added redefinition of the titlePage
%   layout as per the faculty requirements. Department name and
%   programme are in the upper part of the titlePage. [TV]}
% \changes{v1.0.0}{2021/04/23}{^^A
%   The style files of the Faculty of Medicine at the Masary University
%   in Brno no longer redefine the \cs{thesis@blocks@cover} macro.
%   [TV]}
% \changes{v1.0.0}{2021/05/06}{Added conditional redefinition for the
%   study field. [TV]}
%    \begin{macrocode}
% \changes{v1.1.1}{2024/03/06}{Updated the study field redefinition to
%   match the base definition. [TV]}
\thesis@blocks@titlePage@field@false

\thesis@xpatch\thesis@blocks@titlePage{%
  {\sf\thesis@titlePage@large\thesis@@{advisorTitle}: \thesis@advisor\par}%
   \vspace{0.75cm}%
   \ifthesis@blocks@titlePage@department@
     {\sf\thesis@titlePage@large\thesis@department@name\par}%
   \fi
   \ifthesis@blocks@titlePage@programme@
     \vspace{0.25cm}%
     {\sf\thesis@titlePage@large\thesis@@{bib@programme}:
      \thesis@programme\par}%
   \fi
   \ifthesis@blocks@titlePage@field@
     \ifx\thesis@field\empty\else
     \vspace{0.25cm}%
     {\sf\thesis@titlePage@large\thesis@@{fieldTitle}: 
      \thesis@field@name\par}%
     \fi
   \fi
   \vfill
}{}

\thesis@xpatch\thesis@blocks@titlePage{%
  {\sf\thesis@titlePage@large\thesis@@upper{facultyName}\par}%
  \vfill
}{%
  {\sf\thesis@titlePage@large\thesis@@upper{facultyName}\par}%
  \vspace{0.5cm}%
  {\sf\thesis@titlePage@large\thesis@programme\par}%
  \vspace{0.25cm}%
  {\sf\thesis@titlePage@large\thesis@department@name\par}%
  \vspace{1cm}%
}
%    \end{macrocode}
% \begin{macro}{\thesis@blocks@frontMatter}
% The |\thesis@blocks@frontMatter| macro sets up the style of the
% front matter of the thesis. The page numbering is arabic in
% accordance with the formal requirements and it is hidden. In case
% of double-sided typesetting, the geometry is altered according to
% the requirements of the faculty.
% \begin{macrocode}
\def\thesis@blocks@frontMatter{%
  \thesis@blocks@clear
  \newgeometry{top=25mm,bottom=20mm,left=35mm,
    right=15mm, includeheadfoot}
  \pagestyle{empty}
  \parindent 1.5em
  \setcounter{page}{1}
  \pagenumbering{arabic}}
%    \end{macrocode}
% \end{macro}\begin{macro}{\thesis@blocks@mainMatter}
% The |\thesis@blocks@mainMatter| macro sets up the style
% of the main matter of the thesis. The leading is adjusted in
% accordance with the requirements of the faculty. The page
% numbering doesn't reset at the beginning of the main thesis in
% accordance with the formal requirements of the faculty.
% \changes{v1.0.1}{2021/07/18}{^^A
%   Display page numbers for the Faculty of Medicine starting with
%   the declaration. [VN]}
% \begin{macrocode}
\def\thesis@blocks@mainMatter{%
  \thesis@blocks@clear
  \newgeometry{top=25mm,bottom=20mm,left=35mm,
    right=15mm, includeheadfoot}
  \pagestyle{thesisheadings}
  \parindent 1.5em
  \onehalfspacing}
%    \end{macrocode}
% \end{macro}
% Note that there is no direct support for the seminar paper and
% thesis proposal types.  If you would like to change the contents
% of the preamble and the postamble, you should modify the
% |\thesis@blocks@preamble| and |\thesis@blocks@postamble| macros.
%
% All blocks within the autolayout preamble and postamble that are
% not defined within this file are defined in the
% \texttt{style/mu/fithesis-base.sty} file.
% \changes{v1.0.0}{2021/03/22}{Reorganised the blocks to fit the
%   faculty's requirements. [TV]}
% \changes{v1.0.0}{2021/04/24}{^^A
%   Change \cs{thesis@facultyLogo},
%   \cs{thesis@blocks@facultyLogo@monochrome}, and
%   \cs{thesis@blocks@facultyLogo@color} to use the new logotype
%   of the Masaryk University in Brno in the correct size and
%   localization. Add \cs{thesis@blocks@seal}. [VN]}
%    \begin{macrocode}
\def\thesis@blocks@preamble{%
  \thesis@blocks@coverMatter
    \thesis@blocks@cover
  \thesis@blocks@frontMatter
    \thesis@blocks@titlePage
    \thesis@blocks@seal
%    \end{macrocode}
% \changes{v1.0.1}{2021/07/18}{^^A
%   Display page numbers for the Faculty of Medicine starting with
%   the declaration. [VN]}
%    \begin{macrocode}
    \thesis@blocks@clear
      \pagestyle{plain}
      \setcounter{page}{1}
      \thesis@blocks@declaration
    \thesis@blocks@clear
      \thesis@blocks@abstract
      \thesis@blocks@keywords
    \thesis@blocks@clear
      \thesis@blocks@abstractEn
      \thesis@blocks@keywordsEn
    \thesis@blocks@thanks
    \thesis@blocks@tables}
\def\thesis@blocks@postamble{%
  \thesis@blocks@bibliography}
%    \end{macrocode}
