%
%% vxutentamen.sty
%%
%% (C) Robert Nyqvist, 2005-2007
%%
%% Du få ändra i denna fil förutsatt att du döper om filen.
%%
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{vxutentamen}
\DeclareOption{svenska}{%
  \def\@vxu{V\"{a}xj\"{o} universitet}
  \def\tentamens@typ{Tentamen}
  \def\@kryssa{Kryssa f\"{o}r de uppgifter du l\"{a}mnar in}
  \def\@uppgift{Uppgift}
  \def\@png{Po\"{a}ng}
  \def\@kryss{S\"{a}tt X}
  \def\@Examinator{Examinator}
  \def\@datum{Datum}
  \def\@tid{Tid}
  \def\@lokal{Plats}
  \def\@Kurskod{Kurskod}
  \def\@hjlp{Till{\aa}tna hj\"{a}lpmedel}
  \def\@Meddelande{Meddelande fr{\aa}n l\"{a}raren}
  \def\@betyg{Betyg}
  \def\@klegitimation{Uppvisat k{\aa}rlegitimation}
  \def\@legitimation{Uppvisat legitimation}
  \def\@ja{Ja}
  \def\@nej{Nej}
  \def\@tidinlmn{Tid f\"{o}r inl\"{a}mmnande}
  \def\@tvakt{Tentamensvaktens signatur}
  \def\@tentanden{F\"{a}lten nedan fylls i av tentanden}
  \def\@namn{Namn}
  \def\@adress{Adress}
  \def\@epost{E-post}
  \def\@telefonnummer{Telefonnummer}
  \def\@personnummer{Personnummer}
  \def\@antalblad{Antal inl\"{a}mnade blad}
  \def\tentamensdatum{%
    \@dag dagen den
    \oldstylenums{\@tday}
    \ifcase\@tmonth\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
    \oldstylenums{\@tyear}, klockan
    \oldstylenums{\@start}.\oldstylenums{00}%
    --\oldstylenums{\@slut}.\oldstylenums{00}
  }
  \def\@rubrik{\tentamens@typ\ i \@kursnamn, \@kurskod, \@kurspoang}
  \def\@lrubrik{%
    L\"{o}sningsf\"{o}rslag till \MakeLowercase{\tentamens@typ}
    i \@kursnamn, \@kurskod, \@kurspoang
  }
}
\DeclareOption{engelska}{%
  \def\@vxu{V\"{a}xj\"{o} University}
  \def\tentamens@typ{Examination}
  \def\@kryssa{Tick the exercises you hand in}
  \def\@uppgift{Exercises}
  \def\@png{Points}
  \def\@kryss{Put a tick}
  \def\@Examinator{Examiner}
  \def\@datum{Date}
  \def\@tid{Time}
  \def\@lokal{Place}
  \def\@Kurskod{Course Code}
  \def\@hjlp{Allowed aids}
  \def\@Meddelande{Messages from the teacher}
  \def\@betyg{Grade}
  \def\@klegitimation{Uppvisat k{\aa}rlegitimation}
  \def\@legitimation{Uppvisat legitimation}
  \def\@ja{Ja}
  \def\@nej{Nej}
  \def\@tidinlmn{Tid f\"{o}r inl\"{a}mmnande}
  \def\@tvakt{Tentamensvaktens signatur}
  \def\@tentanden{The student complete the form below}
  \def\@namn{Name}
  \def\@adress{Address}
  \def\@epost{E-mail}
  \def\@telefonnummer{Telephone}
  \def\@personnummer{Personal code number}
  \def\@antalblad{The number of sheets handed in}
  \def\tentamensdatum{%
    \ifcase\@tmonth\or
      January \or February \or March \or April \or May\or June\or
      July\or August\or September\or October\or November\or
      December%
    \fi
    \space
    \oldstylenums{\@tday},
    \oldstylenums{\@tyear} from
    \oldstylenums{\@start}:\oldstylenums{00} to
    \oldstylenums{\@slut}:\oldstylenums{00}
  }
  \def\@rubrik{\tentamens@typ\ in \@kursnamn, \@kurskod, \@kurspoang}
  \def\@lrubrik{%
    Solutions to \MakeLowercase{\tentamens@typ} in
    \@kursnamn, \@kurskod, \@kurspoang
  }
}
\ExecuteOptions{svenska}
\ProcessOptions
\RequirePackage{ifpdf}
\ifpdf
  \RequirePackage[pdftex]{graphicx,color}
  \pdfcompresslevel 9
  \pdfadjustspacing 1
  \AtBeginDocument{%
    \DeclareGraphicsExtensions{.mps,.pdf,.jpg,.png}%
    \DeclareGraphicsRule{*}{mps}{*}{}%
  }
\else
  \RequirePackage[dvips]{graphicx,color}
  \AtBeginDocument{%
    \DeclareGraphicsExtensions{.mps,.eps}%
    \DeclareGraphicsRule{*}{eps}{*}{}%
  }
\fi
\RequirePackage{geometry,calc,array}
\geometry{width=16cm,height=24cm,nohead,nofoot}
\pagestyle{empty}
\def\tentamenstyp#1{\gdef\tentamens@typ{#1}}
\def\examinator#1{\gdef\@examinator{#1}}
\def\institution#1{\gdef\@institution{#1}}
\def\kurs#1#2#3{%
  \gdef\@kursnamn{#1}%
  \gdef\@kurskod{#2}%
  \gdef\@kurspoang{#3}%
}
\def\datum#1#2#3#4{%
  \gdef\@tyear{#1}%
  \gdef\@tmonth{#2}%
  \gdef\@tday{#3}%
  \gdef\@dag{#4}%
}
\def\@tday{}
\def\@tmonth{}
\def\@tyear{}
\def\@dag{}
\def\tid#1#2{\gdef\@start{#1}\gdef\@slut{#2}}
\def\@start{}
\def\@slut{}
\def\plats#1{\gdef\@plats{#1}}
\def\@meddelandei{}
\def\@meddelandeii{}
\def\@hjlpmedel{}
\newif\if@meddelande
\@meddelandefalse
\newcommand{\meddelande}[3][\VF]{%
  \def\VF{#2}%
  \gdef\@meddelandei{#1}%
  \gdef\@meddelandeii{#2}%
  \gdef\@hjlpmedel{#3}%
  \@meddelandetrue
}
\newcount\@antaluppgifter
\def\antaluppgifter#1{\global\@antaluppgifter=#1}
\def\@boxrubrik(#1,#2)#3{\put(#1,#2){\makebox(0,0)[lt]{%
  \fontsize{7}{8}\usefont{T1}{phv}{b}{n}#3}}%
}
\def\@boxrubrikkursiv(#1,#2)#3{\put(#1,#2){\makebox(0,0)[lt]{%
  \fontsize{7}{8}\usefont{T1}{phv}{m}{sl}#3}}%
}
\def\@boxtext(#1,#2)#3{\put(#1,#2){\makebox(0,0)[lt]{%
  \usefont{T1}{phv}{m}{n}#3}}%
}
\def\@boxtextkursiv(#1,#2)#3{\put(#1,#2){\makebox(0,0)[lb]{%
  \usefont{T1}{phv}{m}{sl}#3}}%
}
\def\@ruta{%
  \begin{picture}(4,4)
    \put(0,0){\line(1,0){4}}
    \put(0,4){\line(1,0){4}}
    \put(0,0){\line(0,1){4}}
    \put(4,0){\line(0,1){4}}
  \end{picture}%
}
\def\@uppgifter{%
  \bgroup
  \setlength{\unitlength}{6mm}%
  \begin{picture}(0,12)(0,-12)
    \@boxrubrikkursiv(0.2,1.3){\@kryssa}
    \@boxtext(2.222,0.1){\makebox(0,0)[b]{%
        \fontsize{8}{9}\usefont{T1}{phv}{m}{n}\@uppgift}%
    }
    \@boxtext(6.666,0.1){\makebox(0,0)[b]{%
        \fontsize{8}{9}\usefont{T1}{phv}{b}{n}\@png}%
    }
    \@boxtextkursiv(11.1,0.1){\makebox(0,0)[b]{%
        \fontsize{8}{9}\usefont{T1}{phv}{m}{sl}\@kryss}%
    }
    \put(0,1.45){\line(1,0){13.333}}
    \put(4.444,0){\line(0,-1){12}}
    \put(8.888,0){\line(0,-1){12}}
    \newcount\@kvar
    \@kvar=\@antaluppgifter
    \ifnum\@kvar<12
      \loop
        \put(0,-\the\@kvar.5){%
          \makebox(0,0)[l]{%
            \textcolor[gray]{.8}{\rule{80mm}{6mm}}%
          }%
        }%
        \advance\@kvar by 1
      \ifnum\@kvar<12\repeat
    \fi
    \newcount\@y
    \newcount\@nr
    \newcount\@au
    \@nr=1
    \@au=\@antaluppgifter
    \advance\@au by 1
    \loop
      \put(0,-\the\@y){\line(1,0){13.333}}
      \ifnum\@nr<\@au
        \put(2.222,-\the\@y.5){%
          \makebox(0,0){\fontsize{12}{9}\usefont{T1}{phv}{m}{n}\the\@nr}%
        }
      \fi
      \advance\@nr by 1
      \advance\@y by 1
    \ifnum\@y<\@au\repeat
  \end{picture}
  \egroup
}
\def\@ifyll(#1,#2)#3{%
  \@boxtextkursiv(#1,#2){
    \makebox(76,0)[bl]{#3\space\hrulefill}%
  }%
}
\def\blankett{%
  \noindent
  \parbox[t]{.5\textwidth}{%
    \fontsize{20.74}{20.74}\usefont{T1}{ppl}{m}{n}%
    \includegraphics[width=1.4em]{vxusymbol.1}%
    \kern.25em\hbox{\raisebox{\depth}{\@vxu}}\\
    \mbox{}\kern1.65em\parbox{5cm}{%
      \fontsize{10.37}{12.444}\usefont{T1}{ppl}{m}{n}\@institution}}
  \hspace*{\fill}%
  \bgroup
    \fontsize{35}{25}\usefont{T1}{phv}{m}{n}\tentamens@typ
  \egroup
  \vskip7ex
  \setlength{\unitlength}{1mm}
  \noindent
  \begin{picture}(160,190)(0,-190)
    \put(80,-160){\makebox(0,0)[lb]{\@uppgifter}}
    % Horisontella linjer
    \put(0,0){\line(1,0){160}}
    \put(0,-10){\line(1,0){80}}
    \put(0,-20){\line(1,0){80}}
    \put(0,-30){\line(1,0){80}}
    \put(0,-40){\line(1,0){80}}
    \put(0,-65){\line(1,0){80}}
    \put(0,-142){\line(1,0){80}}
    \put(0,-160){\line(1,0){160}}
    \put(0,-170){\line(1,0){160}}
    \put(0,-180){\line(1,0){160}}
    \put(0,-190){\line(1,0){160}}
    % Vertikala linjer
    \put(0,0){\line(0,-1){190}}
    \put(160,0){\line(0,-1){190}}
    \put(80,0){\line(0,-1){160}}
    \put(40,-142){\line(0,-1){18}}
    \put(80,-180){\line(0,-1){10}}
    % Text
    \@boxrubrik(1,-1){\@Examinator}
    \@boxtext(2,-5){\@examinator}
    \@boxrubrik(1,-11){\@datum}
    \@boxtext(2,-15){%
      \@tyear--%
      \ifnum\@tmonth<10\relax0\fi\@tmonth--%
      \ifnum\@tday<10\relax0\fi\@tday
    }
    \@boxrubrik(60,-11){\@tid}
    \@boxtext(61,-15){\@start--\@slut}
    \@boxrubrik(1,-21){\@lokal}
    \@boxtext(2,-25){\@plats}
    \@boxrubrik(1,-31){\@Kurskod}
    \@boxtext(2,-35){\@kurskod}
    \@boxrubrik(1,-41){\@hjlp}
    \@boxtext(2,-45){\parbox[t]{76mm}{\raggedright\@hjlpmedel}}
    \@boxrubrik(1,-66){\@Meddelande}
    \@boxtext(2,-70){\parbox[t]{76mm}{%
      \raggedright\@meddelandei}}
    \@boxrubrik(1,-143){\@png}
    \@boxrubrik(41,-143){\@betyg}
    \@boxtext(2,-163.5){\@klegitimation}
    \put(60,-167){\@ruta}
    \@boxtext(66,-163.5){\@ja}
    \put(85,-167){\@ruta}
    \@boxtext(91,-163.5){\@nej}
    \@boxtext(2,-173.5){\@legitimation}
    \put(60,-177){\@ruta}
    \@boxtext(66,-173.5){\@ja}
    \put(85,-177){\@ruta}
    \@boxtext(91,-173.5){\@nej}
    \@boxrubrik(1,-181){\@tidinlmn}
    \@boxrubrik(81,-181){\@tvakt}
    \@boxrubrikkursiv(81,-1){\@tentanden}
    \@ifyll(82,-12){\@namn:}
    \@ifyll(82,-22){\@adress:}
    \@ifyll(82,-32){\phantom{\@adress:}}
    \@ifyll(82,-42){\@epost:}
    \@ifyll(82,-52){\@telefonnummer:}
    \@ifyll(82,-62){\@personnummer:}
    \@ifyll(82,-76){\@antalblad:}
  \end{picture}
  \newpage
}
\def\huvud{
  \noindent\textbf{\large\@vxu}\\
  \@institution\\
  \textit{\@examinator}
  \vskip4ex
  \begin{center}
    \textbf{\@rubrik}
    \ifx\@tday\empty\else
      \\
      \tentamensdatum
    \fi
  \end{center}
  \if@meddelande
    \vskip3ex
    \begin{center}
      \setlength{\fboxsep}{2mm}
      \setlength{\fboxrule}{.01mm}
      \fbox{\parbox[l]{155.8mm}{\@meddelandeii
        \ifx\@meddelandeii\@empty\else
          \ifx\@hjlpmedel\@empty\else
            \par
          \fi
        \fi
        \ifx\@hjlpmedel\@empty\else
          \textsl{\@hjlp:} \@hjlpmedel
        \fi}%
      }
    \end{center}
  \fi
  \vskip3ex
}
\def\poang#1{\hspace*{\fill}(#1)}
\newcounter{uppgift}
\newenvironment{uppgifter}{%
  \begin{list}{%
      \hfill\textbf{\arabic{uppgift}.}%
    }{%
      \usecounter{uppgift}%
      \settowidth{\labelwidth}{\textbf{22.}}%
      \setlength{\labelsep}{1em}%
      \setlength{\leftmargin}{\labelwidth+\labelsep}%
      \setlength{\rightmargin}{0pt}%
    }
  }{%
    \write\@auxout{\string\antaluppgifter{\theuppgift}}%
  \end{list}
}
\newcounter{duppgift}
\renewcommand{\theduppgift}{(\alph{duppgift})}
\newenvironment{duppgifter}{%
  \begin{list}{\theduppgift\hfill}{%
      \usecounter{duppgift}%
      \setlength{\leftmargin}{2em}%
      \setlength{\rightmargin}{0pt}%
      \setlength{\labelwidth}{2em}%
      \setlength{\labelsep}{0pt}%
      \setlength{\itemindent}{0pt}%
      \setlength{\listparindent}{.75em}%
      \setlength{\itemsep}{5pt}%
      \setlength{\parsep}{0pt}%
      \setlength{\topsep}{.5ex}%
    }%
  }{%
  \end{list}
}
\newcounter{deluppgift}
\renewcommand{\thedeluppgift}{(\alph{deluppgift})}
\newlength{\koli}
\setlength{\koli}{2em}
\newlength{\kolii}
\newcommand{\du}{%
  \makebox[\koli][l]{\thedeluppgift}%
  \refstepcounter{deluppgift}%
}
\newenvironment{deluppgifter}[1][2]{%
  \par
  \setlength{\kolii}{\linewidth}%
  \addtolength{\kolii}{-#1\koli}%
  \ifcase#1\or\or
    \setlength{\kolii}{.5\kolii}%   Om #1 = 2
  \or
    \setlength{\kolii}{.332\kolii}% Om #1 = 3
  \or
    \setlength{\kolii}{.25\kolii}%  Om #1 = 4
  \or
    \setlength{\kolii}{.2\kolii}%  Om #1 = 5
  \fi
  \setcounter{deluppgift}{1}%
  \let\oldarraystretch=\arraystretch
  \renewcommand{\arraystretch}{1.35}%
  \noindent
  \begin{tabular}[t]{*{#1}{@{\du}p{\kolii}}@{}}
  }{%
  \end{tabular}
  \par
  \renewcommand{\arraystretch}{\oldarraystretch}
}
\def\mvh#1{%
  \vskip3ex
  \begin{center}
    \usefont{T1}{pzc}{m}{it}\Large#1
  \end{center}%
}
\newcommand{\facit}{%
  \clearpage
   \noindent\textbf{\@vxu}\\
   \@institution\\
   \textit{\@examinator}
   \vskip4ex
   \begin{center}
     \textbf{\@lrubrik}%
     \ifx\@tday\empty\else
       \\
       \tentamensdatum
     \fi
   \end{center}
   \vskip3ex
 }
\newenvironment{lsn}{%
  \begin{list}{\hfill\textbf{\arabic{uppgift}.}}{%
      \usecounter{uppgift}%
      \settowidth{\labelwidth}{\textbf{22.}}%
      \setlength{\labelsep}{1em}%
      \setlength{\leftmargin}{\labelwidth+\labelsep}%
      \setlength{\rightmargin}{0pt}%
    }
  }{%
  \end{list}%
}
