% THESIS TEMPLATE FOR LATEX
% Pedher Johansson (pedher@cs.umu.se), january 2012
% Mod: Anna Jonsson (aj@cs.umu.se), spring 2016
\NeedsTeXFormat{LaTeX2e} 
\ProvidesPackage{UmUThesis} [2016/06/01 Layout for Master Thesis Reports]

% INCLUDED PACKAGES
% -----------------

% If you got a latex distribution where one of them are not included,
% either download it or remove it. If it is removed you may get
% problems with some of the other stuff in the package, but it should
% be save to comment out that row. 
\RequirePackage{remreset}          % For internal use in the package.
\RequirePackage{float}             % Adds functionality for floats.
\RequirePackage{fancyhdr}          % Used for nice page headings.
\RequirePackage{changepage}        % Used for changing page size on front page.
\RequirePackage%[hang]
{caption}     % Nicer figure and table captions.
\RequirePackage{lastpage}          % Used to get the last page of the document.
\ifx\pdftexversion\undefined
  \RequirePackage[dvips]{graphicx} % Graphics package used for ps-files.
\else
  \RequirePackage[pdftex]{graphicx}% Graphics package used for pdf-files.
\fi


% INTERNAL COMMAND
% ----------------

% Ignore this.
\newif\if@article\@articlefalse
\@ifundefined{chapter}{\@articletrue}

\def\subtitle#1{\gdef\@subtitle{#1}}
\def\@subtitle{}
\def\course#1{\gdef\@course{#1}}
\def\@course{\@latex@warning@no@line{No \noexpand\course given}}
\def\education#1{\gdef\@education{#1}}
\def\@education{}
\def\semester#1{\gdef\@semester{#1}}
\def\@semester{\@latex@warning@no@line{No \noexpand\semester given}}
\def\supervisor#1{\gdef\@supervisor{#1}}
\def\@supervisor{\@latex@warning@no@line{No \noexpand\supervisor given}}
\def\supervisore#1{\gdef\@supervisore{#1}}
\def\@supervisore{}
\def\examiner#1{\gdef\@examiner{#1}}
\def\@examiner{\@latex@warning@no@line{No \noexpand\examiner given}}
\def\supervisorname{Supervisor}
\def\supervisorename{External supervisor}
\def\examinername{Examiner}

\def\redefine#1#2{
   \ifx#1\@undefined\else%
   \renewcommand#1{#2}%
   \fi%
}
\def\title#1{\gdef\@title{#1}\gdef\thetitle{#1}}
\redefine{\bibname}{References}

% PAGE SIZE
% ---------
\hoffset         -1in % reset offset to top left corner
\voffset         -1in %       - " - 
\textheight     231mm 
\textwidth      140mm 
\topmargin       12mm % Distance before the head
\oddsidemargin   45mm % Good for two sided printing
\evensidemargin  25mm %       - " -
\headheight      14mm
\headsep         5mm  % Distance betwen the head and the text.
\marginparwidth  15mm % You should not use margins.
\marginparsep     7pt  
\marginparpush   12pt

\widowpenalty=10000 % For maximum penalty for widows and orphans
\clubpenalty=10000  

%>>>>>>>>>>>>> Removed for no parskip
%\setlength{\parskip}{3pt}

% PACKAGE OPTIONS
% ---------------

% Swedish option. Use the package as 
%   \usepackage[se]{umuthesis} 
% if it is written in Swedish. 
\DeclareOption{se}{
  % Text indentation and paragraph separation usualy differs between
  % text writing in Swedish and text in English. In Swedish texts (and
  % sometimes in English texts) you prefer to have a larger space
  % between paragraphs, but no indentation. This is can be adjusted with
  % the following commands. If you like to have this style even in
  % English texts, copy these two line and put the in the document.
  \setlength{\parindent}{0pt}  % Text indentation.
  \setlength{\parskip}{6pt}  % Space between paragraphs 

  % French spacing makes non-english text more readable.
  \frenchspacing

  % The following commands redefines some commands to use Swedish
  % instead of English labels.
  \redefine{\today}{\number\day\space\ifcase\month\or
    januari\or februari\or mars\or april\or maj\or juni\or
    juli\or augusti\or september\or oktober\or november\or december\fi
    \space\number\year}
  \redefine{\chaptername}{Kapitel}
  \redefine{\contentsname}{Inneh{\aa}llsf{\"o}rteckning}
  \redefine{\listfigurename}{Figurf{\"o}rteckning}
  \redefine{\listtablename}{Tabellf{\"o}rteckning}
  \redefine{\figurename}{Figur}
  \redefine{\tablename}{Tabell}
  \redefine{\partname}{Del}
  \redefine{\appendixname}{Appendix}
  \redefine{\bibname}{K{\"a}llf{\"o}rteckning}
  \redefine{\refname}{K{\"a}llf{\"o}rteckning}
  \redefine{\indexname}{Index}
  \redefine{\supervisorname}{Handledare}
  \redefine{\supervisorename}{Extern handledare}
  \redefine{\examinername}{Examinator}
}

\DeclareOption{noindent}{
  % If you prefer not to have indentation of paragraphs
  \setlength{\parindent}{0pt}  % Text indentation.
  \setlength{\parskip}{6pt}  % Space between paragraphs 
}

\ProcessOptions

% DOCUMENT SETTINGS
% -----------------

% Only number chapters, sections and subsections. Change this to 1, if
% you only like to number chapter and sections.
\setcounter{secnumdepth}{2}
% This makes chapters, sections and subsections, but not
% subsubsections appear in the table of contents.
\setcounter{tocdepth}{2}

% This does not make the text stretch to absolutely fill each page. 
\raggedbottom


% PAGE HEADERS
% ------------

\fancyheadoffset[LE,RO]{12mm}
\fancyheadoffset[LO,RE]{12mm}

\renewcommand{\headrulewidth}{0pt} % was 0 pt
%\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
%\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
%\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
%\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\renewcommand{\chaptermark}[1]{ \markboth{#1}{} }
\renewcommand{\sectionmark}[1]{ \markright{#1}{} }

\fancyhf{}
\fancyfoot[LE,RO]{\thepage%(\pageref{LastPage})
}
%\fancyhead[LO]{\leftmark}
%\fancyhead[RE]{\rightmark}
\fancyhead[RE]{\textit{ \nouppercase{\leftmark}} }
\fancyhead[LO]{\textit{ \nouppercase{\rightmark}} }
%\fancyhead[C]{}
%\fancyfoot[L,R,C]{}

\fancypagestyle{plain}{
  \fancyhf{}
%  \renewcommand{\headrulewidth}{0pt}
  \fancyfoot[LE,RO]{\thepage}
}


% CHANGE HEADERS
% --------------

% If you use the report document class, this makes sure a new chapter
% will be on an odd page. If this is not necessary, comment out the
% following redefinition.
\if@article\else
  \renewcommand\cleardoublepage{
  \clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi
  \fi\fi}
  \renewcommand\chapter{
    \cleardoublepage
    \thispagestyle{plain}% plain for only numbering, empty for no numbering either
    \global\@topnum\z@
    \@afterindentfalse
    \secdef\@chapter\@schapter}
  \renewcommand\@makechapterhead[1]{%
    \vspace*{20\p@}%
      \ifnum \c@secnumdepth >\m@ne
	{\noindent\huge\bfseries \thechapter\space\space}
      \fi
      {\interlinepenalty\@M
      \huge\bfseries #1\par}
   
    \nobreak
    \vskip 40\p@}
  \renewcommand\@makeschapterhead[1]{%
    \vspace*{20\p@}%
      {\interlinepenalty\@M
      \noindent\huge\bfseries #1\par}
   
    \nobreak
    \vskip 40\p@
  }
\fi

\renewcommand\maketitle{%
  \renewcommand{\thefootnote}{\fnsymbol{footnote}}
  %\changepage { text height }{ text width }{ even-side margin }
  %                   { odd-side margin }{ column sep. } { topmargin }{ headheight }{ headsep }{ footskip }
  \changepage { 10mm }{ 20mm }{ -10mm }{ -10mm }{}{}{-10mm}{}{}
  \begin{raggedright}%
    \includegraphics[width=3cm]{umu-logo}
    \par\vskip3\baselineskip\par\noindent\Huge\bfseries{\@title}\normalfont%
    \if\@empty\@subtitle\else%
      \par\vskip.3\baselineskip\par\noindent\Large{\@subtitle}\normalfont\fi%
    \par\vskip3\baselineskip\par\noindent\Large\slshape\@author\normalfont%
    \vfill
    \par\noindent\small\sffamily\bfseries{\@author}\normalfont\newline
    \mbox{\noindent\small\sffamily{\@course}}\normalfont\newline
    \mbox{\noindent\small\sffamily{\@semester\normalfont}}\newline
    \if\@empty\@supervisor\else%
      \mbox{\noindent\small\sffamily{\supervisorname:\ \@supervisor}}\normalfont\newline\fi
    \if\@empty\@supervisore\else%
      \mbox{\noindent\small\sffamily{\supervisorename:\ \@supervisore}}\normalfont\newline\fi
    \mbox{\noindent\small\sffamily{\examinername:\ \@examiner}}\normalfont\newline
    \if\@empty\@education\else%
      \mbox{\noindent\small\sffamily{\@education}}\normalfont\fi
  \end{raggedright}%
   
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
  \renewcommand{\thefootnote}{\arabic{footnote}}
  \newpage
  \changepage { -10mm }{ -20mm }{ 10mm }{ 10mm }{}{}{10mm}{}{}}


% Redefines the \section command
\renewcommand{\section}{%
 \@startsection%
  {section}%
  {1}%                          % Level
  {0pt}%                        % Indentation
  {-2\baselineskip}%            % Distance before the header (ignore
                                % the `-` sign. It indicatas that the
                                % indentation of the paragraph
                                % following the section is surpressed).
  {0.5\baselineskip}%           % Distance after the header.
  {\normalfont\large\bfseries}} % The font used for the header. Add 
                                % \sffamily if you like a sans-serif font.

% Redefines the \subsection command
\renewcommand{\subsection}{%
 \@startsection%
  {subsection}%
  {2}%
  {0pt}%
  {-\baselineskip}%>>>>>>>>>> ADDED '-'
  {0.25\baselineskip}%
  {\normalfont\normalsize\bfseries}}

% TABLE OF CONTENTS
% ------------------------

\def\@nodottedtocline#1#2#3#4#5{\ifnum #1>\c@tocdepth \else
  \vskip \z@ \@plus.2\p@
  {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
    \parindent #2\relax\@afterindenttrue
   \interlinepenalty\@M
   \leavevmode
   \@tempdima #3\relax
   \advance\leftskip \@tempdima \null\hskip -\leftskip
    {#4}\nobreak\leaders\hbox{$\m@th
       \mkern \@dotsep mu\hbox{ }\mkern \@dotsep
       mu$}\hfill \nobreak
           \hb@xt@\@pnumwidth{%
             \hfil\normalfont \normalcolor #5}\par}\fi}
\renewcommand*\l@section{\@nodottedtocline{1}{1.5em}{2.3em}}
\renewcommand*\l@subsection{\@nodottedtocline{2}{3.8em}{3.2em}}
\renewcommand*\l@subsubsection{\@nodottedtocline{3}{7em}{4.1em}}
\renewcommand*\l@figure{\@nodottedtocline{1}{1.5em}{2.3em}}

% ABSTRACT
% --------

\renewenvironment{abstract}[1][Abstract]{
  \vskip\baselineskip\begin{center}{\large\bfseries#1}\end{center}
  \begin{adjustwidth}{15mm}{15mm}
}{\end{adjustwidth}}

% TABLES AND FIGURES
% ------------------

% Let tables have a continuous numbering and not reset by chapters
%\if@article\else
%  \@removefromreset{table}{chapter}
%  \@removefromreset{figure}{chapter}
%\fi
%\renewcommand\thetable{\mbox{\@arabic\c@table}}
%\renewcommand\thefigure{\mbox{\@arabic\c@figure}}

% This makes (in my opinion) the table floats look nicer. 
\renewcommand\floatc@ruled[2]{{\@fs@cfont #1} #2\par}
\renewcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
  \def\@fs@pre{\hrule height1.5pt depth0pt \kern4pt}%
  \def\@fs@post{\kern2pt\hrule height0.8pt\relax}%
  \def\@fs@mid{\kern2pt\hrule height0.8pt\kern2pt}%
  \let\@fs@iftopcapt\iftrue}
\floatstyle{ruled} 
\restylefloat{table}

% Captions (requires caption package)
\renewcommand{\captionlabelfont}{\bfseries} % Font used for the name
\renewcommand{\captionfont}{\small}         % Font size 
\setlength{\captionmargin}{0.05\linewidth}

% THEOREMS AND SUCH (added by aj)
% -----------------

% From LLNCS

%options
%\let\if@envcntreset\iffalse
%\DeclareOption{envcountreset}{\let\if@envcntreset\iftrue}
%\let\if@envcntsame\iffalse
%\DeclareOption{envcountsame}{\let\if@envcntsame\iftrue}
%\let\if@envcntsect\iffalse
%\DeclareOption{envcountsect}{\let\if@envcntsect\iftrue}

\def\@thmcountersep{}
\def\@thmcounterend{.}

\def\spnewtheorem{\@ifstar{\@sthm}{\@Sthm}}

% definition of \spnewtheorem with number

\def\@spnthm#1#2{%
  \@ifnextchar[{\@spxnthm{#1}{#2}}{\@spynthm{#1}{#2}}}
\def\@Sthm#1{\@ifnextchar[{\@spothm{#1}}{\@spnthm{#1}}}

\def\@spxnthm#1#2[#3]#4#5{\expandafter\@ifdefinable\csname #1\endcsname
   {\@definecounter{#1}\@addtoreset{#1}{#3}%
   \expandafter\xdef\csname the#1\endcsname{\expandafter\noexpand
     \csname the#3\endcsname \noexpand\@thmcountersep \@thmcounter{#1}}%
   \expandafter\xdef\csname #1name\endcsname{#2}%
   \global\@namedef{#1}{\@spthm{#1}{\csname #1name\endcsname}{#4}{#5}}%
                              \global\@namedef{end#1}{\@endtheorem}}}

\def\@spynthm#1#2#3#4{\expandafter\@ifdefinable\csname #1\endcsname
   {\@definecounter{#1}%
   \expandafter\xdef\csname the#1\endcsname{\@thmcounter{#1}}%
   \expandafter\xdef\csname #1name\endcsname{#2}%
   \global\@namedef{#1}{\@spthm{#1}{\csname #1name\endcsname}{#3}{#4}}%
                               \global\@namedef{end#1}{\@endtheorem}}}

\def\@spothm#1[#2]#3#4#5{%
  \@ifundefined{c@#2}{\@latexerr{No theorem environment `#2' defined}\@eha}%
  {\expandafter\@ifdefinable\csname #1\endcsname
  {\global\@namedef{the#1}{\@nameuse{the#2}}%
  \expandafter\xdef\csname #1name\endcsname{#3}%
  \global\@namedef{#1}{\@spthm{#2}{\csname #1name\endcsname}{#4}{#5}}%
  \global\@namedef{end#1}{\@endtheorem}}}}

\def\@spthm#1#2#3#4{\topsep 7\p@ \@plus2\p@ \@minus4\p@
\refstepcounter{#1}%
\@ifnextchar[{\@spythm{#1}{#2}{#3}{#4}}{\@spxthm{#1}{#2}{#3}{#4}}}

\def\@spxthm#1#2#3#4{\@spbegintheorem{#2}{\csname the#1\endcsname}{#3}{#4}%
                    \ignorespaces}

\def\@spythm#1#2#3#4[#5]{\@spopargbegintheorem{#2}{\csname
       the#1\endcsname}{#5}{#3}{#4}\ignorespaces}

\def\@spbegintheorem#1#2#3#4{\trivlist
                 \item[\hskip\labelsep{#3#1\ #2\@thmcounterend}]#4}

\def\@spopargbegintheorem#1#2#3#4#5{\trivlist
      \item[\hskip\labelsep{#4#1\ #2}]{#4(#3)\@thmcounterend\ }#5}

% definition of \spnewtheorem* without number

\def\@sthm#1#2{\@Ynthm{#1}{#2}}

\def\@Ynthm#1#2#3#4{\expandafter\@ifdefinable\csname #1\endcsname
   {\global\@namedef{#1}{\@Thm{\csname #1name\endcsname}{#3}{#4}}%
    \expandafter\xdef\csname #1name\endcsname{#2}%
    \global\@namedef{end#1}{\@endtheorem}}}

\def\@Thm#1#2#3{\topsep 7\p@ \@plus2\p@ \@minus4\p@
\@ifnextchar[{\@Ythm{#1}{#2}{#3}}{\@Xthm{#1}{#2}{#3}}}

\def\@Xthm#1#2#3{\@Begintheorem{#1}{#2}{#3}\ignorespaces}

\def\@Ythm#1#2#3[#4]{\@Opargbegintheorem{#1}
       {#4}{#2}{#3}\ignorespaces}

\def\@Begintheorem#1#2#3{#3\trivlist
                           \item[\hskip\labelsep{#2#1\@thmcounterend}]}

\def\@Opargbegintheorem#1#2#3#4{#4\trivlist
      \item[\hskip\labelsep{#3#1}]{#3(#2)\@thmcounterend\ }}

%\if@envcntsect
   \def\@thmcountersep{.}
   \spnewtheorem{theorem}{Theorem}[section]{\bfseries}{\itshape}
%\else
%   \spnewtheorem{theorem}{Theorem}{\bfseries}{\itshape}
%   \if@envcntreset
%      \@addtoreset{theorem}{section}
%   \else
%      \@addtoreset{theorem}{chapter}
%   \fi
%\fi

%definition of divers theorem environments
\spnewtheorem*{claim}{Claim}{\itshape}{\rmfamily}
\spnewtheorem*{proof}{Proof}{\itshape}{\rmfamily}
%\if@envcntsame % alle Umgebungen wie Theorem.
%   \def\spn@wtheorem#1#2#3#4{\@spothm{#1}[theorem]{#2}{#3}{#4}}
%\else % alle Umgebungen mit eigenem Zaehler
%   \if@envcntsect % mit section numeriert
      \def\spn@wtheorem#1#2#3#4{\@spxnthm{#1}{#2}[section]{#3}{#4}}
%   \else % nicht mit section numeriert
%      \if@envcntreset
%         \def\spn@wtheorem#1#2#3#4{\@spynthm{#1}{#2}{#3}{#4}
%                                   \@addtoreset{#1}{section}}
%      \else
%         \def\spn@wtheorem#1#2#3#4{\@spynthm{#1}{#2}{#3}{#4}
%                                   \@addtoreset{#1}{chapter}}%
%      \fi
%   \fi
%\fi
\spn@wtheorem{case}{Case}{\itshape}{\rmfamily}
\spn@wtheorem{conjecture}{Conjecture}{\itshape}{\rmfamily}
\spn@wtheorem{corollary}{Corollary}{\bfseries}{\itshape}
\spn@wtheorem{definition}{Definition}{\bfseries}{\itshape}
\spn@wtheorem{example}{Example}{\itshape}{\rmfamily}
\spn@wtheorem{exercise}{Exercise}{\itshape}{\rmfamily}
\spn@wtheorem{lemma}{Lemma}{\bfseries}{\itshape}
\spn@wtheorem{note}{Note}{\itshape}{\rmfamily}
\spn@wtheorem{problem}{Problem}{\itshape}{\rmfamily}
\spn@wtheorem{property}{Property}{\itshape}{\rmfamily}
\spn@wtheorem{proposition}{Proposition}{\bfseries}{\itshape}
\spn@wtheorem{question}{Question}{\itshape}{\rmfamily}
\spn@wtheorem{solution}{Solution}{\itshape}{\rmfamily}
\spn@wtheorem{remark}{Remark}{\itshape}{\rmfamily}

