\def\RCS$#1: #2${\expandafter\def\csname RCS#1\endcsname{#2}}
%   $RCSfile: normat.cls,v $ $Locker:  $
\RCS$Date: 2008/05/09 06:07:00 $
\RCS$State: Exp $
\RCS$Revision: 1.29 $

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{normat}[\RCSDate \RCSRevision \RCSState
  Klassefil for Normatartikler.]

\errorcontextlines99

\newif\ifcropmark\cropmarkfalse
\DeclareOption{cropmark}{\cropmarktrue}
\newif\ifutkast\utkastfalse
\DeclareOption{utkast}{\utkasttrue}
\newif\iflmodern\lmoderntrue
\DeclareOption{nolmodern}{\lmodernfalse}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\PassOptionsToClass{twoside}{article}
\InputIfFileExists{normat-optionhook.def}{}{}
\ProcessOptions
\LoadClass{article}
\RequirePackage{amsmath}
\RequirePackage{graphicx}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paperheight 242mm
\paperwidth  165mm
% Klippemerker, hentet fra cropmark.sty og tilpasset
\ifcropmark
\let\xshipout\shipout
\def\shipout{\futurelet\SomeBox\yshipout}
% \shipAfterBox er her pga spesielle regler for \afterassignment:
% \afterassignment\next\setbox0=\hbox{...} == \setbox0=\hbox{\next...}
% tilsvarende for \vbox, \vtop
\def\yshipout
   {\ifx\SomeBox\box        \let\next\shipAfterRegister
    \else \ifx\SomeBox\copy \let\next\shipAfterRegister
    \else                   \let\next\shipAfterBox \fi\fi
    \afterassignment\next\setbox0=
    }
\def\shipAfterBox{\aftergroup\shipAfterRegister}
\ifx\pdfoutput\undefined\else
  \pdfpageheight 297mm
  \pdfpagewidth  210mm
\fi
% sentrering på A4-ark:
\advance\hoffset-1in \advance\hoffset 105mm \advance\hoffset-.5\paperwidth
\newdimen\cropsep\cropsep 4mm
\newdimen\croplen\croplen 8mm
\newdimen\cropwid\cropwid 0.2pt
\newbox\crophrulebox
\newbox\cropvrulebox
\setbox\crophrulebox=\hbox to \paperwidth % horisontale klippemerker: -   -
  {\llap{\vrule height\cropwid depth0pt width\croplen\kern\cropsep}\hfil
   \rlap{\kern\cropsep\vrule height\cropwid depth0pt width\croplen}}
\setbox\cropvrulebox=\hbox to \paperwidth % vertikale klippemerker:   |   |
  {\kern-.5\cropwid
   \vrule width\cropwid depth0pt height\croplen\hfil
   \vrule width\cropwid depth0pt height\croplen
   \kern-.5\cropwid}
\def\shipAfterRegister
  {\setbox0\vbox
    {\offinterlineskip
     \kern-\croplen \kern-\cropsep \copy\cropvrulebox \kern\cropsep
     \kern-.5\cropwid \copy\crophrulebox \kern-.5\cropwid
     \copy0 \kern-\ht0 \kern-\dp0 \kern\paperheight
     \kern-.5\cropwid \copy\crophrulebox \kern-.5\cropwid
     \kern\cropsep \copy\cropvrulebox
     \ifutkast\kern\cropsep
       \hbox to\paperwidth{\normalfont\hfil\revisjonsinfo\hfil}
     \fi}
    \xshipout\box0\relax}
\else % ikke klippemerker
  \advance\hoffset-1in
  \advance\voffset-1in
  \ifx\pdfoutput\undefined\else
    \pdfpageheight \paperheight
    \pdfpagewidth  \paperwidth
  \fi
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\textwidth  126 mm
\ifcase\@ptsize\relax
  \textheight 47\baselineskip \advance\textheight\topskip\relax
\else
  \errhelp{Go back to using 10pt.}
  \errmessage{Pointsizes other than 10pt are not supported.}
\fi
\parskip      0 pt
\parindent   12 pt
\oddsidemargin 21 mm
\evensidemargin\oddsidemargin
\headsep     15 pt
\topmargin   28 pt
% Det ferdige produktet skal aldri bruke \marginpar,
% men det er kjekt å ha underveis i prosessen:
\marginparsep   11 pt
\marginparwidth 60 pt
\let\STDmarginpar\marginpar
\def\marginpar#1{\STDmarginpar{\footnotesize\raggedright#1\par}}
\frenchspacing
\clubpenalty \@M % Hvis horunger absolutt ikke er til å unngå, får vi
		 % heller redusere parameteren lokalt etter behov.
\widowpenalty \@M % ditto
\brokenpenalty\@M

\renewcommand\normalsize{% Jfr originalen i size10.clo:
   \@setfontsize\normalsize\@xpt\@xiipt
   \abovedisplayskip 13\p@ \@plus2\p@ \@minus5\p@
   \abovedisplayshortskip \z@ \@plus3\p@
   \belowdisplayshortskip 9\p@ \@plus3\p@ \@minus3\p@
   \belowdisplayskip \abovedisplayskip
   \let\@listi\@listI}

\DeclareRobustCommand\bseries
        {\not@math@alphabet\bseries\mathbf
         \fontseries\bdefault\selectfont}
\newcommand{\bdefault}{b}
\DeclareMathAlphabet{\mathb}{OT1}{cmr}{b}{n}
\DeclareTextFontCommand{\textb}{\bseries}

% For gresk tekst:
% Krever type1-utgaven av greek/cbfonts.
% Denne finnes kun i designstørrelse 10pt.
% Nedenstående er kopiert fra LGRcmr.fd og tilpasset.
\input{lgrenc.def}
\DeclareFontFamily{LGR}{lmr}{}
\DeclareFontShape{LGR}{lmr}{m}{n}    {<-> grmn1000}{}
\DeclareFontShape{LGR}{lmr}{m}{sl}   {<-> grmo1000}{}
\DeclareFontShape{LGR}{lmr}{m}{it}   {<-> grmi1000}{}
\DeclareFontShape{LGR}{lmr}{m}{sc}   {<-> grmc1000}{}
\DeclareFontShape{LGR}{lmr}{m}{ui}   {<-> grmu1000}{}
\DeclareFontShape{LGR}{lmr}{bx}{sc}  {<-> grxc1000}{}
\DeclareFontShape{LGR}{lmr}{bx}{n}   {<-> grxn1000}{}
\DeclareFontShape{LGR}{lmr}{bx}{sl}  {<-> grxo1000}{}
\DeclareFontShape{LGR}{lmr}{bx}{it}  {<-> grxi1000}{}
\DeclareFontShape{LGR}{lmr}{bx}{ui}  {<-> grxu1000}{}
\DeclareFontShape{LGR}{lmr}{b}{n}
       {<->ssub*lmr/bx/n}{}
\DeclareFontShape{LGR}{lmr}{b}{sc}
       {<->ssub*lmr/bx/sc}{}

\def\tospalteoppsett{%
     \setlength{\columnsep}{\textwidth}%
     \addtolength{\columnsep}{-121mm}% spaltebredde skal være 60.5 mm
     \tolerance = 2000 \brokenpenalty = 100 }

\newenvironment{tospalter}[1][]%
  {\begin{multicols}{2}[\tospalteoppsett#1]}
  {\end{multicols}}

\newenvironment{tospalter*}[1][]%
  {\begin{multicols*}{2}[\tospalteoppsett#1]}
  {\end{multicols*}}

% ToDo:
% - gå gjennom size10.clo og se om det er mer som trenger justering

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Revisjonsinfo

\begingroup
  \expandafter\ifx\csname redigert\endcsname\relax
    \count0=\time \divide\count0by60 % Hour
    \count2=\count0 \multiply\count2by-60 \advance\count2by\time % Minute
    \def\2#1{\ifnum#1<10 0\fi\the#1}
    \xdef\textid{\the\year-\2\month-\2\day\space\2{\count0}:\2{\count2}}
  \fi
\endgroup

\def\revisjonsinfo{\DOKRCSfile\DOKRevision\ifx\DOKLocker\empty\else\textid\fi}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Sidelayout

\def\ps@std{%
  \def\@oddhead{\@anyhead\@oddheadline}%
  \def\@evenhead{\@anyhead\@evenheadline}%
  \def\@outerhead{{\large\thepage}}%
  \def\@@outerhead{{\small\@ytrehode}}%
  \def\@innerhead{{\small\hefteid}}%
  \def\@oddheadline{\@innerhead\hfil\@@outerhead\kern10pt \@outerhead}%
  \def\@evenheadline{\@outerhead\kern10pt \@@outerhead\hfil\@innerhead}%
  \def\@oddfoot{}%
  \let\@evenfoot\@oddfoot%
}%

\def\ps@firstpage{%
  \def\@innerhead{{\sjekkheftenummeret\small\artikkelref}}%
  \def\@oddheadline{\@innerhead\hfil\@outerhead}%
  \def\@evenheadline{\@outerhead\hfil\@innerhead}%
}

\def\@anyhead#1{%
  \def\\{\ifhmode\unskip\fi\relax\space\ignorespaces}%
  \reset@font
  \vbox to \z@{
    \vss
    \hb@xt@\textwidth{\vrule depth 6pt width 0 pt height 0 pt\relax#1}
    \hrule}}

\pagestyle{std}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Heftenummerering:  Heftig!
\newcount \hefte
\newcount \aargang
\newcount \aargangno
\newcount \sisteside
\countdef\side=0
\def\sider{\afterassignment\p@ges\sisteside}
\def\p@ges{\advance\sisteside\count0 \advance\sisteside-1 }

\newif \ifheftenrok
\def\hefteid{Normat ?/20??}
\def\artikkelref{Normat \textb{\the\aargangno}:\the\hefte,
                 \the\side\ifnum\sisteside>\side--\the\sisteside\fi
                 \space(\the\aargang)}

\def \sjekkheftenummeret
  {\ifnum \hefte < 1 \heftenrokfalse
   \else \ifnum \hefte > 4 \heftenrokfalse
         \else \ifnum \aargang < 1991 \heftenrokfalse
               \else \ifnum \aargang > 2099 \heftenrokfalse
                     \else \heftenroktrue \fi \fi \fi \fi
   \aargangno=\aargang \advance\aargangno-1952
   \begingroup
       \newlinechar = `@
       \message {@ Normat, hefte nr. \the\hefte, \the\aargang.@@}%
       \ifheftenrok
       \gdef\hefteid{Normat \the\hefte/\the\aargang}%
       \else \message { OBS! Angi riktig heftenummer med
                          \noexpand \hefte = nummeret!@}%
       \fi
   \endgroup}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Fonter etc
\RequirePackage[T1]{fontenc}
\iflmodern
\RequirePackage{lmodern}
\fi

% size10.clo sier 9pt/11pt og 8pt/9.5pt; vi sier 9pt/10pt og 8pt/9pt
\@temptokena\expandafter{\small\fontsize\@ixpt\@xpt\selectfont}
\edef\small{\the\@temptokena}
\@temptokena\expandafter{\footnotesize\fontsize\@viiipt\@ixpt\selectfont}
\edef\footnotesize{\the\@temptokena}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Artikkel-environment:

%%% Merk at variabler som brukes direkte eller indirekte i sidehoder,
%%% må settes globalt, siden vi har forlatt artikkel-environment før
%%% siste side settes!

\def\@clearheadvars{\def\do##1{\global\let##1\@empty}%
   \do\@tittel\do\@undertittel\do\@forfatter\do\@adresse}
\@clearheadvars

\newenvironment{artikkel}
  {\clearpage\thispagestyle{firstpage}
   \@clearheadvars}
  {\clearpage
   \begingroup\advance\side-1
     \ifnum\side=\sisteside\else
       \newlinechar = `@
       \message{@@*** SIDENUMMER STEMMER IKKE!
                \string\side=\the\side, \string\sisteside=\the\sisteside @@}
     \fi
   \endgroup}

\def\do#1#2#3{\def#1##1{\gdef#2{##1}}\let#3#1}
\do\tittel\@tittel\title
\do\undertittel\@undertittel\subtitle
\do\forfatter\@forfatter\author
\do\adresse\@adresse\address
\do\ytrehode\@ytrehode\outerhead

%% ToDo:  Bytt ut masse plain-TeX-ismer med LaTeX-ismer
%% Spesielt fontvalg!

\def\makestrut#1#2{\hbox{\vrule height#1 depth#2 width\z@}}
\def\Largestrut{\makestrut{12.5 pt}{4.5 pt}} %% er ikke disse ...
\def\largestrut {\makestrut{10.5 pt}{4.5 pt}} %% ... i minste laget?

\def\artikkelhode{%
  \thispagestyle{firstpage}
  \@@tittel
  \@@undertittel
  \@@forfatter
  \@@adresse
  \donotindent}

\let\@maketitle\artikkelhode
\toks@\expandafter{\maketitle\thispagestyle{firstpage}}
\edef\maketitle{\the\toks@}

\def\font@tittel
  {\fontsize{17.28}{21}\usefont{\encodingdefault}{\sfdefault}{bx}{n}}

\def\@@tittel{%
  \ifx\@tittel\@empty % Vi burde klage høyt og inderlig
  \else
    \begingroup
      \def \\{\hfil \break}
      \clearpage
      {\font@tittel
       \mathversion{bold}%
       \vglue 4 pt \noindent
       \Largestrut
       \@tittel\unskip \Largestrut \par }
     \endgroup
     \gdef\@ytrehode{\@tittel} % overstyres normalt av \@forfatter
     \prevdepth\z@
     \vskip 30 pt \relax
  \fi}

\def\font@undertittel
  {\fontsize{14.4}{21}\usefont{\encodingdefault}{\sfdefault}{bx}{n}}

\def\@@undertittel{%
  \ifx\@undertittel\@empty
  \else
    \begingroup
      \def \\{\hfil \break}
      \vskip-\lastskip
      \vskip 15pt
      {\font@undertittel
       \mathversion{bold}%
       \baselineskip 21 pt \vglue 4 pt \noindent
       \largestrut
       \@undertittel\unskip \largestrut \par }
     \endgroup
     \prevdepth\z@
     \vskip 30 pt \relax
  \fi}

\def\font@forfatter
  {\fontsize{12}{14}\usefont{\encodingdefault}{\sfdefault}{bx}{sl}}

\def\@@forfatter{%
  \ifx\@forfatter\@empty\@tempdima\z@\else
    {\par\raggedleft\leavevmode\font@forfatter
     \setbox0\vbox{\let \\=\cr
       \halign{\strut\hfil##\cr\Largestrut\@forfatter\crcr}}
     \global\@tempdima\wd0
     \box0\par\prevdepth\z@}
     \vskip 24 pt plus 8 pt minus 8 pt
     \gdef\@ytrehode{\@forfatter\/}
  \fi}

\def\font@adresse
  {\fontsize{10}{11}\usefont{\encodingdefault}{\sfdefault}{m}{n}}

\def\@@adresse{%
  \ifx\@adresse\@empty\else
    \begingroup
      \vskip -\lastskip
      \font@adresse
      \kern -1.2ex
      \let \\=\cr
      \hbox to\hsize{\hfil
	\vtop{\halign{\strut\hfil##\cr
        \omit\vrule height\z@ depth\z@ width\@tempdima\cr
	\noalign{\nointerlineskip\hrule\vskip6pt} \@adresse\crcr}}}
      \vskip 24 pt plus 8 pt minus 8 pt
    \endgroup
  \fi}

% ToDo:
% oppgaver, bokspalte, bokmeldinger, boknotiser,
% mottatteboeker, summary

% Elementer til overskrifter etc:
% tittel, undertittel, forfatter, adresse

% Strukturelementer:
% avsnitt, underavsnitt

  \newif\ifavsnittopp \avsnittoppfalse

  \def \preavsnitt{
       \skip0 = \lastskip \goodbreak
       \ifdim \skip0 < 36pt
              \vskip -\skip0 \vskip36pt plus 18pt minus 6pt
       \else \vskip 0 pt
       \fi}

  \def\avsnittfont
    {\fontsize{12}{14}\usefont{\encodingdefault}{\sfdefault}{bx}{sl}%
     \mathversion{bold}}

%%% LaTeX hack:
% \@nobreaktrue, \@nobreakfalse: \@ifnobreak er LaTeX-magi som brukes
% for å sette inn en \nobreak i mange makroer som ellers kunne
% ødelegge for effekten av \nobreak.  For eksempel \label, som
% genererer en \write og dermed muliggjør sideskift ved en derpå
% følgende \parskip.

  \newcommand \avsnitt[2][\preavsnitt]{\begingroup
       \par
       \def \\{\hfil \break}
       #1
       \vbox {\baselineskip 14 pt \noindent
                  \avsnittfont
		  \advance\leftskip-1pt
                  \largestrut #2\unskip
                  \largestrut }\nobreak
       \endgroup
       \prevdepth\z@
       \donotindent
       \avsnittopptrue
       \@nobreaktrue
       \everypar\expandafter{\the\everypar\global\avsnittoppfalse\@nobreakfalse}
       \nobreak \vskip 2 pt minus 1 pt \relax}

  \def \underavsnittfont
       {\fontsize{10}{12}\usefont{\encodingdefault}{\sfdefault}{bx}{n}%
        \mathversion{bold}}

  \def \preunderavsnitt{\ifavsnittopp\else\bigbreak\medskip\fi}

  \def \underavsnitt #1{\preunderavsnitt
       \begingroup
       \def \\{\hfil \break}
       \vbox {\underavsnittfont
              \noindent #1\unskip}
       \endgroup
       \prevdepth\z@
       \donotindent
       \nobreak \relax}

  \def \underunderavsnittfont
       {\fontsize{10}{12}\usefont{\encodingdefault}{\sfdefault}{m}{sl}}

  \def \preunderunderavsnitt{\ifavsnittopp\else\medbreak\fi}

  \def \underunderavsnitt #1{\preunderunderavsnitt
       \noindent {\underunderavsnittfont #1\enspace} \ignorespaces}

\def\section{\@ifnextchar*{\@firstoftwo\avsnitt}\@numberedsection}
\def\@numberedsection#1{\refstepcounter{section}%
  \avsnitt{\thesection\quad#1}}

\def\subsection{\@ifnextchar*{\@firstoftwo\underavsnitt}\@numberedsubsection}
\def\@numberedsubsection#1{\refstepcounter{subsection}%
  \underavsnitt{\thesubsection\quad#1}}

\def\subsubsection{\@ifnextchar*{\@firstoftwo\underunderavsnitt}\@numberedsubsubsection}
\def\@numberedsubsubsection#1{\refstepcounter{subsubsection}%
  \underunderavsnitt{\thesubsubsection\enspace#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Figurtekster

\newdimen\@captionin \@captionin\parindent
\newdimen\@captionwidth
\long\def\MakeCaption#1#2{\textit{#1}\ifx#2\ignorespaces\else: \fi#2}
\long\def\@makecaption#1#2{%
  \@captionwidth\hsize \advance\@captionwidth-2\@captionin
  \vskip\abovecaptionskip
  \sbox\@tempboxa{\small\MakeCaption{#1}{#2}}%
  \ifdim \wd\@tempboxa >\@captionwidth
    {\advance\leftskip\@captionin\advance\rightskip\@captionin
     \small\leavevmode\kern-1pt\MakeCaption{#1}{#2}\par}
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Spesialdefinisjoner for bokspalten:

\newenvironment{bokmelding}
  {\par\ifdim\lastskip>\z@\else\vskip 12pt plus 6pt \fi
   \def\signert##1{\par\nobreak\vskip6pt plus 3pt\rightline{##1}}
   \vtop\bgroup
   \raggedright
   \fontfamily{\sfdefault}\selectfont
   \def\par{\endgraf\egroup\vskip 6pt plus 3pt\donotindent}
   \def\\{\hfil\break}
   \donotindent}
  {}

\def\mottattbok
       {\ifdim\lastskip>\z@\else\smallskip\fi
        \begingroup \parindent = 0 pt \hangindent = 12 pt
        \hangafter = 1 \def\par{\endgraf\endgroup}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Bibliografi

\newenvironment{bibliografi}[1][9]%
  {\small\raggedright
   \begin{list}{{[?]}}
     {\setbox0\hbox{n}\setlength{\labelsep}{\wd0}
      \setbox0\hbox{[#1]}\setlength{\labelwidth}{\wd0}
      \setlength{\leftmargin}{\labelwidth}\addtolength{\leftmargin}{\labelsep}
      \setlength{\itemindent}{0pt}
      \setlength{\topsep}{0pt}
      \setlength{\parsep}{1pt plus 0.5pt}
      \renewcommand{\bibitem}[1]{\item[{[##1]}]}}}
  {\end{list}}

\renewcommand{\@openbib@code}{\raggedright\small}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Spesielle definisjoner

   \def \slashfrac #1/#2{\sfrac{#1}{#2}} % for kompatibilitet; bruk \sfrac
   \def\sfrac#1#2{\leavevmode
       \raise 0.5ex \hbox {$\scriptstyle {#1}$}\kern -0.1em
       /\kern -0.1 em \lower 0.25 ex \hbox {$\scriptstyle {#2}$}}

% \spacelet{0.5} er et halvt mellomrom i nåværende font
\def\spacelet#1{\nobreak\hskip
   #1\fontdimen2\font plus #1\fontdimen3\font minus #1\fontdimen4\font
   \ignorespaces}

\def\@doendpe % Changed from the standard LaTeX definition:
  {\@endpetrue
   %\def\par  {\@restorepar\everypar{}\par\@endpefalse}%
   \everypar {{\setbox\z@\lastbox}\everypar{}\@endpefalse}}
\let\donotindent\@doendpe
\def\@endtheorem{\endtrivlist\donotindent}

% Sett tekst i en ramme som akkurat fyller spaltebredden:
\newcommand{\fparbox}[1]{\par
  \hbox{\fbox{%
    \setlength  {\@tempdima}{\hsize}%
    \addtolength{\@tempdima}{-2\fboxrule}%
    \addtolength{\@tempdima}{-2\fboxsep}%
    \parbox{\@tempdima}{#1\unskip\par}}}}

\newcommand{\inputpath}[1]{\def\input@path{#1}}
\InputIfFileExists{normat-extras.sty}{}
  {\InputIfFileExists{normat-extras}{}
    {\message{Ingen normat-extras}}}
