% NICE Version 2 macro package for plain TeX
% written by
%   Christian Rank
%   Br\"augasse 13/225
%   D-8390 Passau
%   E-Mail: rank@unipas.fmi.uni-passau.de
%   (please don't e-mail from outside Germany!)

% THIS MACRO PACKAGE MAY BE COPIED AND USED FREELY ONLY IN THIS ORIGINAL STATE
% WITHOUT ANY CHANGES.
% TO PRESERVE COMPATIBILITY, PLEASE DO NOT MODIFY THIS FILE UNDER ANY
% CIRCUMSTANCES. YOU CAN CUSTOMIZE THE NICE PACKAGE FOR YOUR NEEDS VIA AN
% AUXILIARY FILE WHICH READS IN NICE.TEX AND THEN CHANGES PARAMETERS
% AND/OR DEFINES ADDITIONAL COMMANDS.

% we check first if NICE has already been read, in which case we do not need
% to define the NICE macros again.
\expandafter\ifx\csname niceversion\endcsname \relax \else \endinput \fi

% NICE hasn't already been read, so we continue

\def\niceversion{2.0}
\def\versionof {17/09/90}

\immediate\write16 {NICE version \niceversion, (c) 1990 by C. Rank}
\everyjob {\immediate\write16 {NICE version \niceversion \space of \versionof}}

\catcode`\@=11 % for definition of private macros

%
% adjustment of general parameters
%
\vsize 9.2truein \hsize 6.5truein % page layout
\baselineskip=12pt \lineskiplimit=0pt \lineskip=0pt
\smallskipamount=6pt plus 1pt minus 1pt
\medskipamount=12pt plus 2pt minus 2pt
\bigskipamount=18pt plus 3pt minus 3pt
\parskip=6pt plus 1pt minus 1pt
\parindent=0pt

\tolerance=10000
\hbadness=5000

%
% the fonts used
%
\font\documenttitlefont=cmr10 scaled \magstep4
\font\sectiontitlefont=cmbx10 scaled \magstep2
\font\subsectiontitlefont=cmbx10 scaled \magstep1
\font\subsubsectiontitlefont=cmbx10 scaled \magstephalf
% fonts used for variable size styles
\font\ninerm=cmr9 \font\eightrm=cmr8 \font\sixrm=cmr6
\font\ninei=cmmi9 \font\eighti=cmmi8 \font\sixi=cmmi6
\font\ninesy=cmsy9 \font\eightsy=cmsy8 \font\sixsy=cmsy6
\font\ninebf=cmbx9 \font\eightbf=cmbx8 \font\sixbf=cmbx6
\font\ninesl=cmsl9 \font\eightsl=cmsl8
\font\ninett=cmtt9 \font\eighttt=cmtt8
\font\nineit=cmti9 \font\eightit=cmti8 \font\sevenit=cmti7

%
% the variable size styles
%
\def\ninept{\textfont0=\ninerm \scriptfont0=\sevenrm
        \scriptscriptfont0=\fiverm
        \def\rm{\fam0 \ninerm}
        \textfont1=\ninei \scriptfont1=\seveni \scriptscriptfont1=\fivei
        \def\oldstyle{\fam1 \ninei}
        \textfont2=\ninesy \scriptfont2=\sevensy \scriptscriptfont2=\fivesy
        \textfont\itfam=\nineit \def\it{\fam\itfam \nineit}
        \textfont\slfam=\ninesl \def\sl{\fam\slfam \ninesl}
        \textfont\bffam=\ninebf \scriptfont\bffam=\sevenbf
        \scriptscriptfont\bffam=\fivebf \def\bf{\fam\bffam \ninebf}
        \textfont\ttfam=\ninett \def\tt{\fam\ttfam \ninett}
        \baselineskip=11pt
        \rm
}

\def\eightpt{\textfont0=\eightrm \scriptfont0=\sixrm
        \scriptscriptfont0=\fiverm
        \def\rm{\fam0 \eightrm}
        \textfont1=\eighti \scriptfont1=\sixi \scriptscriptfont1=\fivei
        \def\oldstyle{\fam1 \eighti}
        \textfont2=\eightsy \scriptfont2=\sixsy \scriptscriptfont2=\fivesy
        \textfont\itfam=\eightit \def\it{\fam\itfam \eightit}
        \textfont\slfam=\eightsl \def\sl{\fam\slfam \eightsl}
        \textfont\bffam=\eightbf \scriptfont\bffam=\sixbf
        \scriptscriptfont\bffam=\fivebf \def\bf{\fam\bffam \eightbf}
        \textfont\ttfam=\eighttt \def\tt{\fam\ttfam \eighttt}
        \baselineskip=10pt
        \rm
}

\def\sevenpt{\textfont0=\sevenrm \scriptfont0=\sixrm
        \scriptscriptfont0=\fiverm
        \def\rm{\fam0 \sevenrm}
        \textfont1=\seveni \scriptfont1=\sixi \scriptscriptfont1=\fivei
        \def\oldstyle{\fam1 \seveni}
        \textfont2=\sevensy \scriptfont2=\sixsy \scriptscriptfont2=\fivesy
        \textfont\itfam=\sevenit \def\it{\fam\itfam \sevenit}
        \textfont\slfam=\eightsl \def\sl{\fam\slfam \eightsl}
        \textfont\bffam=\sevenbf \scriptfont\bffam=\sixbf
        \scriptscriptfont\bffam=\fivebf \def\bf{\fam\bffam \sevenbf}
        \textfont\ttfam=\eighttt \def\tt{\fam\ttfam \eighttt}
        \baselineskip=9pt
        \rm
}

\def\sixpt{\textfont0=\sixrm \scriptfont0=\fiverm
        \scriptscriptfont0=\fiverm
        \def\rm{\fam0 \sixrm}
        \textfont1=\sixi \scriptfont1=\fivei \scriptscriptfont1=\fivei
        \def\oldstyle{\fam1 \sixi}
        \textfont2=\sixsy \scriptfont2=\fivesy \scriptscriptfont2=\fivesy
        \textfont\itfam=\sevenit \def\it{\fam\itfam \sevenit}
        \textfont\slfam=\eightsl \def\sl{\fam\slfam \eightsl}
        \textfont\bffam=\sixbf \scriptfont\bffam=\fivebf
        \scriptscriptfont\bffam=\fivebf \def\bf{\fam\bffam \sixbf}
        \textfont\ttfam=\eighttt \def\tt{\fam\ttfam \eighttt}
        \baselineskip=8pt
        \rm
}

\def\fivept{\textfont0=\fiverm \scriptfont0=\fiverm
        \scriptscriptfont0=\fiverm
        \def\rm{\fam0 \fiverm}
        \textfont1=\fivei \scriptfont1=\fivei \scriptscriptfont1=\fivei
        \def\oldstyle{\fam1 \fivei}
        \textfont2=\fivesy \scriptfont2=\fivesy \scriptscriptfont2=\fivesy
        \textfont\itfam=\sevenit \def\it{\fam\itfam \sevenit}
        \textfont\slfam=\eightsl \def\sl{\fam\slfam \eightsl}
        \textfont\bffam=\fivebf \scriptfont\bffam=\fivebf
        \scriptscriptfont\bffam=\fivebf \def\bf{\fam\bffam \fivebf}
        \textfont\ttfam=\eighttt \def\tt{\fam\ttfam \eighttt}
        \baselineskip=7pt
        \rm
}

%
% this stuff defines a macro `include', which has the same effect as plain
% TeX's `input', except that it is no error if the file does not exist.
%
\newread\testinclude
\def\include#1{\immediate\openin\testinclude #1
        \ifeof\testinclude \immediate\write16 {No file #1.}
        \else \immediate\closein\testinclude \input #1
        \fi}

%
% general utilities
%
\def\newpage{\vfill\eject}

\def\\{$\backslash$}

\def\raggedcenter{\leftskip=0pt plus 4em \rightskip=\leftskip
        \parfillskip=0pt \spaceskip=.3333em \xspaceskip=.5em
        \pretolerance=9999 \tolerance=9999 \hbadness=10000
        \hyphenpenalty=9999 \exhyphenpenalty=9999}

\def\parwithoutskip{{\parskip=0pt plus 0.5pt\par\noindent}\ignorespaces}

\newdimen\narrowskip \narrowskip=20pt
\def\lnarrower{\advance\leftskip by \narrowskip}
\let\onarrower=\narrower
\def\narrower{\advance\leftskip by \narrowskip
        \advance\rightskip by \narrowskip}

\def\tw@num#1{\ifnum#1>9 #1\else 0#1\fi}
\def\date{\tw@num{\the\day}/\tw@num{\the\month}/\the\year}

\def\ifndef#1{\expandafter\ifx\csname#1\endcsname\relax}

%
% title and section layout
%
\long\def\title#1{{\raggedcenter \documenttitlefont #1 \par}}

\def\titlepage{\begingroup
        \def\title##1{{\raggedcenter \documenttitlefont ##1 \par}\medskip}
        \long\def\author##1{{\parskip=0pt \raggedcenter \rm ##1 \par}}
        \def\release##1{\centerline{\bf ##1}}
        \def\abstract{\centerline{\bf Abstract}\narrowskip=3truecm \narrower}
        \def\endtitlepage{\vfil\egroup \newpage \endgroup}
        \vbox to \vsize \bgroup \vfil}

\newcount\sectionno \sectionno=0
\newcount\subsectionno
\newcount\subsubsectionno

\newtoks\sectionnscheme
\sectionnscheme={\gensect. }
\newtoks\subsectionnscheme
\subsectionnscheme={\gensect.\number\subsectionno. }
\newtoks\subsubsectionnscheme
\subsubsectionnscheme={\gensect.\number\subsectionno
        .\number\subsubsectionno. }

\def\genheading#1#2#3{\vskip\parskip \vbox{
        \setbox0 \hbox{#1#2} \hangindent=\the\wd0 \hangafter=1
        \noindent \raggedright \pretolerance=10000 \box0 #1#3\par}}
\def\gensect{\ifnum \sectionno<0 \char\number-\sectionno
        \else \number\sectionno\fi}

\def\plainsection#1{\removelastskip
        \bigskip
        \genheading{\sectiontitlefont}{}{#1}
        \ifnum\contentslevel>0
        {\let\the=0 \edef\next{\write\fcontents
                {\vskip\contskip \hbox to \hsize
                {\scstyle \hskip\the\scindent #1 \the\contfill\ 
                 \the\pageno}}}\next}
        \immediate\write16 {#1}
        \fi
        \ifnum\marklevel>0 \mark {#1} \fi
        \nobreak}

\def\section#1{\removelastskip
        \bigskip
        \ifnum \sectionno<-1 \global\advance\sectionno by -1
        \else \global\advance\sectionno by 1
        \fi
        \global\subsectionno=0
        \genheading{\sectiontitlefont}{\the\sectionnscheme}{#1}
        {\edef\nscheme{\the\sectionnscheme}
        \ifnum\contentslevel>0
        {\let\the=0 \edef\next{\write\fcontents
                {\vskip\contskip \hbox to \hsize
                {\scstyle \hskip\the\scindent \nscheme #1 \the\contfill\
                \the\pageno}}}\next}
        \immediate\write16 {\nscheme #1}
        \fi
        \ifnum\marklevel>0 \mark {\nscheme #1} \fi
        }
        \nobreak}

\def\subsection#1{\removelastskip
        \smallskip
        \global\advance\subsectionno by 1 \global\subsubsectionno=0
        \genheading{\subsectiontitlefont}{\the\subsectionnscheme}{#1}
        {\edef\nscheme{\the\subsectionnscheme}
        \ifnum\contentslevel>1
        {\let\the=0 \edef\next{\write\fcontents
                {\hbox to \hsize
                {\sscstyle \hskip\the\sscindent \nscheme #1 \the\contfill\ 
                \the\pageno}}}\next}
        \immediate\write16 {\nscheme #1}
        \fi
        \ifnum\marklevel>1 \mark {\nscheme #1} \fi
        }
        \nobreak}

\def\subsubsection#1{
        \par
        \global\advance\subsubsectionno by 1
        \genheading{\subsubsectiontitlefont}{\the\subsubsectionnscheme}{#1}
        {\edef\nscheme{\the\subsubsectionnscheme}
        \ifnum\contentslevel>2
        {\let\the=0 \edef\next{\write\fcontents
                {\hbox to \hsize
                {\ssscstyle \hskip\the\ssscindent \nscheme #1 \the\contfill\
                \the\pageno}}}\next}
        \immediate\write16 {\nscheme #1}
        \fi
        \ifnum\marklevel>2 \mark {\nscheme #1} \fi
        }
        \nobreak}

\def\appendix{\global\sectionno=-64\relax}

%
% macros for making a table of contents
%
\newtoks\contfill
\contfill={\hfil}
\newskip\contskip \contskip=0pt % additional skip between section headings
                                % in contents table
\newcount\contentslevel \contentslevel=0
\newwrite\fcontents
\def\makevoidcontents{
        \openout\fcontents \jobname.toc
        \ifnum\contentslevel=0 \global\contentslevel=1 \fi
        \immediate\write16 {Writing contents on \jobname.toc.}
        }
\def\makecontents{
        \catcode`\@=11
        \include {\jobname.toc}
        \catcode`@=12
        \makevoidcontents
        }
\newdimen\scindent
\newdimen\sscindent
\newdimen\ssscindent % please forgive me;
                     % i know it's a horrible abbreviation
\scindent=0pt
\sscindent=12pt
\ssscindent=32pt
\let\scstyle=\rm
\let\sscstyle=\rm
\let\ssscstyle=\rm % please forgive me once again ...

%
% footnotes
%
\let\ovfootnote=\vfootnote
\newdimen\footnoteindent
\footnoteindent=20pt
\def\vfootnote#1{\insert\footins\bgroup
  \parindent=\footnoteindent % change
  \ifndef{footnotestyle} \baselineskip=\fbaselineskip \footfont
  \else \footnotestyle \fi
  \interlinepenalty\interfootnotelinepenalty
  \splittopskip\ht\strutbox % top baseline for broken footnotes
  \splitmaxdepth\dp\strutbox \floatingpenalty\@MM
  \leftskip\z@skip \rightskip\z@skip \spaceskip\z@skip \xspaceskip\z@skip
  \def\par{\endgraf \hangindent=\footnoteindent \hangafter=1}
  \hangindent=\footnoteindent \hangafter=1
  \textindent{#1}\footstrut\futurelet\next\fo@t}
\let\plainfootnote=\footnote
\newcount\footno \footno=0
\newskip\fbaselineskip \fbaselineskip=\baselineskip
\font\footfont=cmr10
\def\footnote{\global\advance\footno by 1
        \plainfootnote{\hbox{$^{\the\footno}$}}
        }
\long\def\f@t#1{#1\@foot} % enable \par in footnotes

%
% defs for staggered layout
%
\newbox\staggbox
\def\staggered#1{\begingroup
        \setbox\staggbox \hbox {#1}
        \edef\key##1{\par \hangindent=\the\wd\staggbox \hangafter=1
                \noindent \hbox to \the\wd\staggbox {##1\hfil}\ignorespaces}
        \def\endstaggered{\endgraf \endgroup}
        \skip0=\hangindent
        \parskip=0pt plus 0.5pt \vskip\parskip
        \advance \leftskip by \skip0
        \def\par{\endgraf \hangindent=\the\wd\staggbox \hangafter=0}
        }

\def\itemlist#1{\begingroup
        \setbox\staggbox \hbox {#1}
        \edef\next{\par \hangindent=\the\wd\staggbox \hangafter=1
                \noindent \hbox{#1}\ignorespaces}
        \def\enditemlist{\endgraf \endgroup}
        \skip0=\hangindent
        \parskip=0pt plus 0.5pt \vskip\parskip
        \advance \leftskip by \skip0
        \def\par{\endgraf \hangindent=\the\wd\staggbox \hangafter=0}
        }

\newcount\itemno
\def\numbered#1{\ifcase #1 \staggered {0. } \or \staggered {0. } \or
        \staggered {00. } \or \staggered {000. } \fi
        \itemno=0
        \def\next{\advance \itemno by 1 \key {\hfill \the\itemno. }}
        \def\endnumbered{\endstaggered}
        }

\def\alphanumbered{\staggered {m) }
        \itemno=96
        \def\next{\advance \itemno by 1 \key {\char\itemno ) }}
        \def\endalphanumbered{\endstaggered}
        }

\def\pnumbered{\staggered{(0) }
        \itemno=0
        \def\next{\advance \itemno by 1 \key {(\the\itemno)}}
        \def\endpnumbered{\endstaggered}
        }

\def\prnumbered{\staggered{(iii) }
        \itemno=0
        \def\next{\advance \itemno by 1 \key {(\romannumeral\itemno)}}
        \def\endprnumbered{\endstaggered}
        }

%
% the style for headlines and footlines
%
\newcount\marklevel \marklevel=1
\newdimen\hdrulepos \hdrulepos=-2pt
\def\hdrule{\kern\hdrulepos \hrule}
\def\book{
        \headline={\ifnum\pageno>1\vbox
                {\line{\strut \ifodd\pageno \tenit\firstmark\hfil\tenbf\folio
                \else \tenbf\folio\hfil\tenit\firstmark \fi}\hdrule}\else
                \hfil \fi}
        \footline={\hfil}
}
\def\article{
        \headline={\ifnum\pageno>1\vbox
                {\line{\strut \tenit\firstmark\hfil\tenbf\folio}\hdrule}\else
        \hfil \fi}
        \footline={\hfil}
}

%
% macros for verbatim mode
%
\font\verbatimfont=cmtt10
\newskip\vbaselineskip
\vbaselineskip=\baselineskip
\let\d@specials=\dospecials
\def\uncatcodespecials{\def\do##1{\catcode`##1=12}\dospecials}
\def\beginverbatim{\par\begingroup \let\oldpar=\par
        \ifndef{verbatimstyle} \baselineskip=\vbaselineskip \verbatimfont
        \else \verbatimstyle\tt \fi
        \noindent\parskip=0pt
        \catcode`|=12
        \setupverbatim \doverbatim}
{\catcode`\|=0 \catcode`\\=12
 |obeylines|gdef|doverbatim^^M#1\endverbatim{#1|endgroup}}
\def\setupverbatim{\def\par{\leavevmode\oldpar}\catcode`\`=\active
        \obeylines \uncatcodespecials \obeyspaces}
{\obeyspaces\global\let =\ }
{\catcode`\`=\active \gdef`{\relax\lq}}

%
% macros for verbatim mode inside paragraph
%
\def\spvert{\ifmmode\def\n@xt{|}\else\let\n@xt=\txver\fi\n@xt}
\catcode`\|=\active \let |=\spvert
{\obeylines\gdef\txver{\begingroup\tt\setupverbatim\let^^M=\ \let|=\endgroup}}

%
% this defines the environment for \usemathsymbols
%
{\catcode`|=12
\global\let\nice@mvert=|
}
\let\nice@mlt=<
\let\nice@mgt=>
\let\nice@mlbr=\{
\let\nice@mrbr=\}
\def\{{\ifmmode \nice@mlbr \else $\nice@mlbr$\fi}
\def\}{\ifmmode \nice@mrbr \else $\nice@mrbr$\fi}

{
\catcode`\|=\active
\catcode`\<=\active
\catcode`\>=\active
\gdef\usemathsymbols{
        \catcode`\|=\active
        \catcode`\<=\active
        \catcode`\>=\active
        \def|{\ifmmode \nice@mvert \else $\nice@mvert$\fi}
        \def<{\ifmmode \nice@mlt \else $\nice@mlt$\fi}
        \def>{\ifmmode \nice@mgt \else $\nice@mgt$\fi}
        \let\d@@specials=\dospecials
        \def\dospecials{\d@@specials \do \< \do \>}
}
}

%
% cross references
%
\newwrite\frefs
\def\userefs{
        \catcode`\@=11
        \include {\jobname.crf}
        \catcode`@=12
        \openout\frefs \jobname.crf
        \immediate\write16 {Writing references on \jobname.crf.}
        }
{\catcode`\|=0 \catcode`\\=12
|gdef|escapeit{\}
}

\def\label#1{{\let\the=0\edef\next{\write\frefs
        {\def\noexpand\escapeit rs@#1{\number\sectionno
        \ifnum\subsectionno=0 \else
                .\number\subsectionno
        \ifnum\subsubsectionno=0 \else
                .\number\subsubsectionno
        \fi\fi}}}\next
        \edef\next{\write\frefs
                {\def\noexpand\escapeit rp@#1{\the\pageno}}}\next
        }}
\def\sref#1{{\catcode`\@=11 \toks0=\expandafter{\csname rs@#1\endcsname}\relax
        \expandafter\ifx\the\toks0\relax
                [`#1']\write16{Label `#1' undefined on page \the\pageno.}\else
                \the\toks0 \fi
        }}
\def\pref#1{{\catcode`\@=11 \toks0=\expandafter{\csname rp@#1\endcsname}\relax
        \expandafter\ifx\the\toks0\relax
                [`#1']\write16{Label `#1' undefined on page \the\pageno.}\else
                \the\toks0 \fi
        }}

%
% automatic numbering of figures
%
\newcount\figureno \figureno=0
\def\figure#1#2{\global\advance\figureno by 1 \centerline {\bf Fig.\
        \the\figureno: #2}{\let\the=0\edef\next{\write\frefs
                {\def\noexpand\escapeit rf@#1{\number\figureno}}}\next
        }}
\def\fref#1{{\catcode`\@=11 \toks0=\expandafter{\csname rf@#1\endcsname}\relax
        \expandafter\ifx\the\toks0\relax
                [`#1']\write16{Figure `#1' undefined on page \the\pageno.}\else
                \the\toks0 \fi
        }}

%
% \program macro for the comfortable typing of program texts
%
\newdimen\pindent \pindent=0pt
\newdimen\ppindent
\newif\ifinb@x \inb@xfalse
{\let\+=\undefined
\gdef\program{\begingroup
        \def\bb@x{\setbox0=\hbox\bgroup\inb@xtrue\ignorespaces}
        \def\cr{\egroup \hbox {\hskip\leftskip \hskip\ppindent 
                \unhbox1 \unhbox0}
                \ppindent=\pindent
                \bb@x}
        \def\+{\egroup \begingroup
                \def\endprogram{\errmessage{\noexpand\- inserted}
                        \ifinb@x \egroup \fi \endgroup \endprogram}
                \advance \pindent by \wd0
                \setbox1=\hbox{\unhbox1 \unhbox0}
                \bb@x}
        \def\-{\egroup \endgroup \ppindent=\pindent
                \bb@x}
        \def\noalign##1{\egroup ##1\bb@x}
        \def\endprogram{\ifinb@x \egroup \fi \endgroup}
        \setbox1=\null
        \ppindent=\pindent
        \futurelet\next\pr@gram}
}
\def\pr@gram{\ifx\next\obeylines \let\par=\cr 
        \let\next=\pr@gr@m \obeylines \else \let\next=\relax \fi
        \bb@x\next}
\def\pr@gr@m{\let\next=}

%
% macros for making framed boxes
%
\long\def\gbox#1#2#3#4{\vbox{\hrule height#1 \hbox
        {\vrule width#1\kern#3\vbox{
        \kern#2 #4\ifhmode \par \fi \kern#2}\kern#3\vrule width#1}
        \hrule height#1}
}
\newdimen\boxedkern \boxedkern=12pt
\newdimen\rulethickness \rulethickness=0.4pt
\long\def\boxed#1{\gbox\rulethickness\boxedkern\boxedkern{
        \advance\hsize by -\rulethickness
        \advance\hsize by -\rulethickness
        \advance\hsize by -\boxedkern
        \advance\hsize by -\boxedkern
        {\parskip=0pt \noindent}\ignorespaces #1}}

\catcode`@=12 % disable use of private macros
