%% handin v0.0.3b41 - 2018/04/04
%% The LaTeX package handin - version v0.0.3 (2018/04/04) build 41
%% handin.sty
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2018 by Andreas Storvik Strauman
%% -------------------------------------------------------------------------------------------
%% 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 `author-maintained'.
%% This work consists of all files listed in README.txt
\ProvidesPackage{handin}[2018/04/04 v0.0.3 Creates a setup that is ideal for handing in hard-science school papers that are divided in exercises.]
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{lastpage}
\usepackage{scrextend}
\def\exerciseNr{0}
\gdef\problem{\@ifnextchar*{\expandafter\@problem\@secondoftwo}{\@problemTOC}}
\gdef\@problemTOC#1{  \addcontentsline{toc}{section}{\@tr{Problem} #1}
  \@problem{#1}
}
\newcommand{\@problem}[1]{  \def\exerciseNr{#1}
  \begin{addmargin}{-1.5em}
    {\normalfont\Large\bfseries \@tr{Problem} #1}
  \end{addmargin}
}
\gdef\pproblem{\@ifnextchar*{\expandafter\@pproblem\@secondoftwo}{\@pproblemTOC}}
\gdef\@pproblemTOC#1{  \addcontentsline{toc}{subsection}{\exerciseNr #1}
  \@pproblem{#1}
}
\newcommand{\@pproblem}[1]{  \vspace*{1em}
  \hspace*{-0.5em}{\normalfont\Large\bfseries\exerciseNr #1)}
}
 \usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{bm}
\usepackage{esint}
\usepackage{iflang}
\def\@tr#1{  \ifcsname tr@#1\endcsname%
    \csname tr@#1\endcsname%
  \else%
    #1%
  \fi%
}
\newcommand{\set@tr}[2]{  \expandafter\def\csname tr@#1\endcsname{#2}
}
\set@tr{Problem}{Problem}
\set@tr{problem}{problem}
\set@tr{containspages}{Contains \pageref{LastPage} pages, front page included}
\set@tr{pagetext}{Page \thepage~of \pageref{LastPage}}
 \IfLanguageName{norsk}{%
\set@tr{Problem}{Oppgave}
\set@tr{problem}{oppgave}
\set@tr{pagetext}{Side \thepage~av \pageref{LastPage}}
\set@tr{containspages}{Inneholder \pageref{LastPage} sider, inkludert forside.}
}{}
\IfLanguageName{german}{%
\set@tr{Problem}{Aufgabe}
\set@tr{problem}{Aufgabe}
\set@tr{containspages}{Enthält \pageref{LastPage} Seiten, inklusive Titelseite}
\set@tr{pagetext}{Seite \thepage~von \pageref{LastPage}}
}{}
 \newif\ifshowoff
\showofffalse
\let\ea = \expandafter
\newcommand{\settable}[2][\@nil]{  \ea\def\csname #2\ea\endcsname##1{    \ea\def\csname @#2\endcsname{##1}
    \ea\def\csname @#2@noerror\endcsname{##1}
    \ea\def\csname isset@#2\endcsname{1}
}
  \ea\def\csname ifset@#2\endcsname##1##2{    \ifcsname isset@#2\endcsname%
    ##1
    \else
    ##2
    \fi
}
  \ea\def\csname default@#2\endcsname{#1}%
  \ea\def\csname @#2@noerror\endcsname{#1}%
  \ea\ifx\csname default@#2\endcsname\@nnil
    \ea\def\csname default@#2\endcsname{      \textbackslash #2%
      {\ea\@latex@warning{\ #2 not given}}
}
  \fi
  \ea\def\csname @#2\endcsname{    \csname default@#2\endcsname
}
}
\ifshowoff
\@latex@warning{Settable: showing off, no settable is actually set!}
\renewcommand{\settable}[2][\@nil]{  \ea\def\csname #2\endcsname##1{\relax}%
  \ea\def\csname @#2\endcsname{}%
  \ea\def\csname @#2@noerror\endcsname{}%
  \ea\def\csname ifset@#2\endcsname##1##2{##2}
  \ea\def\csname default@#2\endcsname{#1}%
  \ea\def\csname @#2@noerror\endcsname{#1}%
  \ea\def\csname @#2\endcsname{\textbackslash #2}
}
\fi
\settable{title}
\settable{author}
\settable{logo}
\settable{coursename}
\settable{coursetitle}
\settable{institute}
\settable{containspages}
\settable{pagetext}
\setlength\parindent{0pt}
\geometry{paper=a4paper, bottom=3cm, top=3cm, footnotesep=3cm}
\fancyhf{}
\addtolength\headwidth{4em}
\fancyheadoffset{2em}
\pagestyle{fancy}
\let\old@maketitle = \maketitle
\def\maketitle{	\old@maketitle
	\thispagestyle{empty}
	\clearpage
}
\def\@maketitle{%
\begin{center}
  \ifshowoff
    \Huge{\textbackslash logo}\\
    \Large{\@title} \\[1.5cm]
  \else
  \ifset@logo{    \includegraphics[scale=1]{\@logo}\\[0.5cm]
    \Large{\@title} \\[1.5cm]
}{    \ea\@latex@warning{Use \noexpand\logo{path/to/image} to set a logo on the front page}
    \Huge{\@title} \\[1.0cm]
}
  \fi
\end{center}
\begin{center}
  \textbf{\@coursename - \@coursetitle}\\[1cm]
  \textbf{\@author} \\[1cm]
  \textbf{\today} \\[3cm]
\end{center}
\begin{center}
  \vfill
  \ifset@containspages{    \@containspages
}{    \@tr{containspages}
}\\[0.5cm]
  \textsc{\@institute}
\end{center}
 	\rhead{\@author}
	\lhead{\@coursename - \@coursetitle}
	\ifset@pagetext{		\rfoot{\@pagetext}
}{		\rfoot{\@tr{pagetext}}
}
}
