% Copyright 2017-2022 Martin Ruckert, Hochschule Muenchen, Lothstrasse 64, 80336 Muenchen
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be
% included in all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
% OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
% THE SOFTWARE.
%
% Except as contained in this notice, the name of the copyright holders shall
% not be used in advertising or otherwise to promote the sale, use or other
% dealings in this Software without prior written authorization from the
% copyright holders.
\input idxmac.tex
\let\displayverbatimfont=\tt
% V E R B A T I M . T E X
%
% THIS SET OF MACROs IS TAKEN FROM D.E.K.'s TeXBook
% AND PROVIDES AN EASY WAY OF TYPESETTING TEXTS VERBATIM:
%
% 1. \verbatim<character><text without that character><character>
% causes the text to be set verbatim using \tt font;
% 2. if the text uses up all the alphabet, \doubleverbatim macro
% can be used instead; this is similar to the previous one but
% a pair of characters is now used as a delimiter;
% 3. in case of emergency \tripleverbatim macro may be of help...
%
%---------------------------------------------
\def\uncatcodespecials % see D.E.K., pp. 344 and 380
{\def\do##1{\catcode`##1=12}\dospecials}%
%---------------------------------------------
{\catcode`\^^I=\active \gdef^^I{\ \ \ \ }% TAB character is replaced by
% 4 spaces; it is better than
% nothing, but it does not mimic
% true tabbing satisfactorily---maybe
% some nice day...
\catcode`\`=\active\gdef`{\relax\lq}}% this line inhibits Spanish
% ligatures ?` and !` of \tt font
\def\setupverbatim % see D.E.K., p. 381
{\tt %
\spaceskip=0pt \xspaceskip=0pt % just in case...
\catcode`\^^I=\active %
\catcode`\`=\active %
\def\par{\leavevmode\endgraf}% this causes that empty lines aren't
% skipped
\obeylines \uncatcodespecials \obeyspaces}%
{\obeyspaces \global\let =\ }% this causes that leading blanks aren't
% skipped; cf. also def's of \space, \endgraf,
% \lq, \obeyspaces, and \obeylines,
% D.E.K., pp. 351--352
%---------------------------------------------
% see D.E.K., p. 382
\def\doverbatim#1{\def\next##1#1{##1\endgroup}\next}%
\def\verbatim{\begingroup\setupverbatim\doverbatim}%
%----------
\def\dodoubleverbatim#1#2{\def\next##1#1#2{##1\endgroup}\next}%
\def\doubleverbatim{\begingroup\setupverbatim\dodoubleverbatim}%
%----------
\def\dotripleverbatim#1#2#3{\def\next##1#1#2#3{##1\endgroup}\next}%
\def\tripleverbatim{\begingroup\setupverbatim\dotripleverbatim}%
%---------------------------------------------
\font\tenss=cmss10 % used for the HINT name
\font\tenssbx=cmssbx10 % used for the bold HINT name
\font\largess=cmss12 scaled\magstep1 % used for large HINT name
\font\largessbx=cmssbx10 scaled\magstep2 % used for large bold HINT name
\font\manual=manfnt % font used for the METAFONT logo, etc.
\let\sf\tenss
\def\bf{\let\sf\tenssbx\fam\bffam\tenbf}
%% Large Font for sections
%\font\largebf=cmb14 scaled\magstep0
%\font\largebf=cmb12 scaled\magstep1
\font\largebf=cmbx12 scaled\magstep1
%\font\largebf=cmbx8 scaled\magstep3
%\font\largeit=cmti14 scaled\magstep0
\font\largeit=cmti12 scaled\magstep1
%\font\largett=cmtt14 scaled\magstep0
\font\largett=cmtt12 scaled\magstep1
%\font\largerm=cmr14 scaled\magstep0
\font\largerm=cmr12 scaled\magstep1
% for mathbolditalic
%\font\tenmib=cmmib10 scaled\magstep0
\font\tenmib=cmmib10 scaled\magstep0
\font\largemib=cmmib10 scaled\magstep1
%% Small Fonts for Figure and Table descriptions
\font\figbf=cmbx9 scaled\magstep0
\font\figit=cmti9 scaled\magstep0
\font\figmit=cmmi9 scaled\magstep0
\font\figsy=cmsy9 scaled\magstep0
\font\figtt=cmtt9 scaled\magstep0
\font\figrm=cmr9 scaled\magstep0
% for mathbolditalic
\font\figmib=cmmib9 scaled\magstep0
\def\abs#1{\left|#1\right|}
\def\<#1>{$\langle\,$#1$\,\rangle$}
\def\registered{{\ooalign{\hfil\raise.07ex\hbox{\sevenrm R}\hfil\crcr\Orb}}}
\def\hair{\kern.05em\relax} % teeny tiny space
\def\center#1{\bigskip\line{\hfil#1\hfil}\bigbreak}
\chardef\VB=`\| % vertical bar character in a string
\def\^{\ifmmode\mathchar"222 \else\char`^ \fi}%from webmac.tex: pointer or hat
\ifhint
\def\_{{\tt\UL}} % make underline an ordinary character for better searching
\fi
% Bibtex needs this
\def\mbox#1{\leavevmode\hbox{#1}}
% URLs
{\gdef\urldot{.}\catcode`.=13
\gdef\urlslash{/}\catcode`/=13
\gdef\urlspecials{\def.{\urldot\penalty 0}\def/{\urlslash\penalty 0}}
}
\def\url{\bgroup\hskip 1cm plus 5cm\penalty -100\hskip -1cm plus -5cm\tt
\catcode`_=12\catcode`\~=12\catcode`.=13\catcode`/=13\urlspecials}
\def\endurl{\egroup}
% for the index
\def\see#1#2{\hskip 0pt plus 100pt\penalty 0\hskip 0 pt plus -100pt{\it see\/} #1}
% typewriter type for strings
\def\.#1{{\tentex\spaceskip=0.333em minus 0.1em\relax
\let\\=\BS% backslash in a string
\let\{=\LB% left brace in a string
\let\}=\RB% right brace in a string
\let\~=\TL% tilde in a string
\let\ =\SP% space in a string
\let\_=\UL% underline in a string
\let\&=\AM% ampersand in a string
\let\^=\CF% circumflex in a string
\let\|=\VB% vertical bar in a string
\ifmmode\hbox{#1\kern.05em}\else #1\kern.05em\fi}}
%{\rm\gdef\strutdepth{\dp\strutbox}}
%%
%% Environments
%%
% Quotations (form the standard)
\def\beginquote{\bgroup\narrower\noindent\sl}
\def\endquote{\egroup}
% Enumerate
\newcount\enum
%other styles use \medskip instead of \par
\def\enumerate{\par\bgroup\advance\leftskip by\parindent\enum=0%
\def\item{\advance\enum by 1\par\enumdest\smallskip\noindent\hbox to 0pt{\hss\the\enum.~}\ignorespaces}}
\def\endenumerate{\medskip\egroup\noindent}
%defining how to output terminals and nonterminals
\def\ts#1{\ifmmode\hbox{\sc #1}\else{\sc #1}\fi}% terminal symbol
\def\nts#1{{\sl #1\/}}% nonterminal symbol
% redefining the box around verbatim code
\def\vb#1{\hbox{\strut\.{#1}}}
% regular expressions and actions
\newbox\rebox
\def\re#1{\leavevmode\setbox\rebox\hbox{#1\hfill}\ifdim\wd\rebox<7em\wd\rebox=7em\fi\box\rebox\quad}
\def\ac{\global\ind=10\hangindent=\ind em\relax}
\def\eac{\global\ind=3\hangindent=\ind em\relax}
% yskip is usually a smallskip = 3pt pus 1pt minus 1pt
% I give it some extra stretchability
%\def\yskip{\vskip 3pt plus 3pt minus 1pt}
\let\yskip\smallbreak
% redefine \5 for an optional break without the 2.5em reduced indentation
%\def\5{\hskip 0pt plus 2.5em\penalty-1\hskip 0pt plus -2.5em\kern0.5em\ignorespaces}% optional break
%redefine \5 to give some shrinkability
% from hitex and hint style:
%\def\5{\hfil\penalty-1\hskip 0pt minus 6pt\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
\def\5{\hfil\penalty10\hfilneg\hskip 0pt minus 6pt\kern2.5em\copy\bakk\ignorespaces}% optional break
\def\J{}% dont show @& in the tex output
\def\Y{\par\yskip}
% start sections
\def\stsec{\rightskip=0pt % get out of C mode (cf. \B)
\sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 %
}
% the box for the points to operator "->" in C
\setbox\MGbox=\hbox{$\rightarrow$}
% how to display NULL
\def\NULL{\tt NULL}
%other styles make this a \par
\def\note#1#2.{}
%\Y\noindent{\hfill%
% \baselineskip10pt\tiny#1~\ifacro{\pdfnote#2.}\else#2\fi.\par}}
%other styles make this minus 10pt
\def\B{\rightskip=0pt plus 100pt minus 0pt % go into C mode
\sfcode`;=3000
\pretolerance 10000
\hyphenpenalty 1000 % so strings can be broken (discretionary \ is inserted)
\exhyphenpenalty 1000
\codedest
\global\ind=2 \1\ \unskip
\vadjust{\vtop to 0pt{\vss\hbox to \hsize{\hfill\tiny(\secstar)}\kern 0pt}}}
% formating of C comments
\def\C#1{\5\hfill$/\ast\,${\cmntfont #1}$\,\ast/$}
% section begin
\def\M#1{\MN{#1}\ifon\stsec\smallskip
%\everypar{{\setbox0=\lastbox}\everypar{}}% no indentation in the next paragraph
\noindent\ignorespaces}% beginning of section
\def\N#1#2#3.{\MN{#1}\ifon\stsec\smallskip
%\everypar{{\setbox0=\lastbox}\everypar{}}% no indentation in the next paragraph
\noindent{\bf#3\quad}\ignorespaces}% beginning of section
\def\MN#1{\smallskip
{\xdef\secstar{#1}\let\*=\empty\xdef\secno{#1}}%
\gdef\thecode{#1}% common code for \M, \N
\ontrue}
% Used in section text
\def\U{\rightnote{Used in}} % xref for use of a section
\def\Us{\rightnote{Used in}} % xref for uses of a section
% replacing \note in \U and \Us by \rightnote
%\def\rightnote#1#2.{\vskip-\baselineskip\vtop to 0pt{\vss\hbox to \hsize{\hfill
% \tiny#1~\ifacro{\pdfnote#2.}\else#2\fi.}\kern 0pt}}
%\def\rightnote#1#2.{\vskip-\baselineskip\hbox to \hsize{\hfill
% \tiny#1~\ifacro{\pdfnote#2.}\else#2\fi.}}
%\def\rightnote#1#2.{\penalty1000\discretionary{}{\hbox{}}{\kern 2em}\penalty1000\hfill
% \hbox{\tiny#1~\ifacro{\pdfnote#2.}\else#2\fi.}}
\def\rightnote#1#2.{%
\penalty1000\discretionary{}{\hbox{}}{\kern 4em}\penalty1000\hfill
\hskip -4em plus 4em\hbox{\tiny #1~\codenote#2.}.}
\def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi %$% section name
\XX$\langle\,${\let\I=\ne#2\kern.5em\coderef{#1}$\,\rangle$\XX}}
% how to display hex numbers
\def\hex{\hbox{$^{\scriptstyle\#}$\tt\aftergroup}} % CWEB style
\def\(#1){} % this is used to make section names sort themselves better
%%
%% Dimensions to achive the desired layout
%%
% the other variables are defined in cwebmac.tex
\newdimen\headheight
\newdimen\footheight
\newdimen\leftmargin
\newdimen\rightmargin
\newdimen\topmargin
\newdimen\bottommargin
\newdimen\marginwidth
\parskip 0pt plus .8pt
\leftmargin=22mm
\rightmargin=22mm
\topmargin=15mm
\bottommargin=27mm
\marginwidth=0pt % we do not have notes in the margin
\headheight=12pt % Text in Head
\advance\headheight+13pt % Abstand 1pt, Linie 0.47pt und Abstand zum Text 11.53pt
\footheight=0pt % Text in Footer
\pagewidth=6.69in
\advance\pagewidth-\leftmargin % left margin/offset
\advance\pagewidth-\rightmargin % left margin/offset
%\abovesecskip= 6ex plus 1ex minus .2ex %space above the section
%\belowsecskip=3.7ex plus .2ex% space after section
\abovesecskip= 0.15\vsize plus 5ex minus 1ex %space above the section
\belowsecskip=10pt plus 2pt% space after section
\abovesubsecskip=9pt plus 4pt minus 2pt%space above the section
\belowsubsecskip=3pt plus 1pt minus 0.5pt% space after section
\newif\ifappendix
\appendixfalse
\mark{{0}{0}}\vskip 0pt minus 100pt
%\hbox{Mark empty empty}%
\def\thesection{\the\sectioncount}
\def\topsection{\the\sectioncount}
%\def\sectionbox#1{\hskip-\marginwidth\hbox to \marginwidth{#1\hfil}}
\def\heading#1#2{%
\def\secno{{\noindent\large\bf\strut{#1}#2}}%
\par\ifhmode\unskip\fi% end paragraph and remove vertical space
\penalty-500
\vskip 0pt plus 72pt%allow some empty space at the bottom
\penalty-500
\vskip 0pt plus -72pt% room for stetching and a page break
\hbox{}\vskip\abovesecskip% space above the section
%%\titletrue % omits page header for section
%\hbox{Mark null null}%
\mark{{0}{0}}%
\secno% The section title
\mark{{\sectionname}{\sectionname}}%
%\message{Mark heading {\sectionname}{\subsectionname}}
\nobreak\vskip\belowsecskip% space after section
\everypar{{\setbox0=\lastbox}\everypar{}}% no indentation in the next paragraph
\ignorespaces}
\def\subsection#1{%
\subsubsectioncount=0\advance\subsectioncount by 1%updating counts
\def\thesection{\topsection.\the\subsectioncount}
\def\secno{{\noindent\bf\strut\sectionbox{\thesection~}#1}}%
\par\ifhmode\unskip\fi% end paragraph and remove vertical space
\tocsection{1}{\thesection}{#1}%
\penalty-200
\vskip 0pt plus 36pt% allow some empty space at the bottom
\penalty-200
\vskip 0pt plus -36pt% room for stetching and a page break
\gdef\subsectionname{\thesection\quad#1}%
\mark{{\sectionname}{\subsectionname}}%
%\message{Mark subsection {\sectionname}{\subsectionname}}
\vskip\abovesubsecskip% space above the subsection
\secno% The subsection title
\gdef\subcodetitle{#1}%
%\mark{{\sectionname}{\subsectionname}}%
%\hbox{Mark {\sectionname}{\subsectionname}}%
\nobreak\vskip\belowsubsecskip% space after subsection
\everypar{{\setbox0=\lastbox}\everypar{}}% no indentation in the next paragraph
\ignorespaces}
\def\subsubsection#1{%
%\mark{{\sectionname}{\subsectionname}}%
%\hbox{Mark {\sectionname}{\subsectionname}}%
\advance\subsubsectioncount by 1%updating counts
\def\thesection{\topsection.\the\subsectioncount.\the\subsubsectioncount}
\def\secno{{\noindent\it\strut\sectionbox{\thesection~}#1}}%
\par\ifhmode\unskip\fi% end paragraph and remove vertical space
\tocsection{2}{\thesection}{#1}%
\penalty-200
\vskip 0pt plus 36pt% allow some empty space at the bottom
\penalty-200
\vskip 0pt plus -36pt% room for stetching and a page break
\vskip\abovesubsecskip% space above the subsection
\secno% The subsubsection title
\nobreak\vskip\belowsubsecskip% space after subsection
\everypar{{\setbox0=\lastbox}\everypar{}}% no indentation in the next paragraph
\ignorespaces}
%%
%% Crossreference of Identifiers and Sections
%%
\iftrue %% No Crossreference of identifiers
\def\inx{\def\lr{L}} % this tells whether the left or right column is next
\else
\def\inx{%
\hsize=\pagewidth
\def\page{\box255 } \normalbottom
\output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
\global\setbox\sbox=\page \global\pagesavedtrue}
\pagesavedfalse
\plainsection{Crossreference of Identifiers}% we are beginning the index
\mark{{0}{0}}%
%\hbox{Mark empty empty}%
\eject % eject the page-so-far and predecessors
\setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
\vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
\hsize=.5\pagewidth \advance\hsize by -10pt
% column width for the index (20pt between cols)
\parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
\def\lr{L} % this tells whether the left or right column is next
\output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
\else\nomarginoutput{\vbox to\pageheight{\box\sbox\vss
\hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
\global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse
\mark{{Crossreference of Identifiers}{Crossreference of Identifiers}}%
\fi}
\parfillskip 0pt plus 1fil
\let\topsecno=\nullsec
\message{Crossreference of Identifiers:}
\parskip 0pt plus .5pt
\outer\def\I##1, ##2.{\par\hangindent2em\noindent##1:\kern1em
\ifbook##2\else\ifpdf\pdfnote##2.\else##2\fi\fi.} % index entry
\def\[##1]{$\underline{##1}$} % underlined index item
\rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
\hyphenpenalty 10000 \parindent0pt
\small
\readindex
}
\fi
\def\fin{%
\if L\lr\mark{{}{}}\fi
\vfill\eject % complete the current column.
\mark{{}{}}
\if R\lr\null\vfill\eject\fi % if necessarry add a right column
\setpage
\def\page{\box255 } \normalbottom
\output={\nomarginoutput\page\lheader\rheader}
}
\ifbook
\let\crosssections=\relax
\else
\def\crosssections{
\plainsection{Crossreference of Code}% this is done when we are ending the index
\parindent 0pt
\parfillskip 0pt plus 1fil
\let\topsecno=\nullsec
\message{Crossreference of Code:}
\def\note##1##2.{\hfil\penalty-1\hfilneg\quad{\tiny##1~\ifbook##2\else
\ifpdf{\pdfnote##2.}\else
\ifhint\codenote##2.\else##2.\fi\fi\fi}}
\def\Q{\note{Cited in section}} % crossref for mention of a section
\def\Qs{\note{Cited in sections}} % crossref for mentions of a section
\def\U{\note{Used in}} % crossref for use of a section
\def\Us{\note{Used in}} % crossref for uses of a section
\def\I{\par\hangindent 2em}\let\*=*
\def\X##1:##2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi %$% section name
\XX$\langle\,${\let\I=\ne##2}$\,\rangle$\XX\quad{\tiny Defined in~\codenote##1.}}
\readsections
}
\fi
%%
%% Table of Content
%%
% we separate the identification of a section used in links
%from the identification on paper, because plain sections dont
%have the latter.
\newcount\toccount
\toccount=0
\def\tocsection#1#2#3{% depth sectionnumber sectiontitle
\global\advance\toccount by 1%
\newtopdest{SC.\the\toccount}%
\ifhint
\immediate\write\cont{\noexpand\ZZ {#1}{#2}{#3}% write to contents file
{\noexpand\thepageno}{\the\toccount}}
\else
\edef\next{\write\cont{\noexpand\ZZ {#1}{#2}{#3}% write to contents file
{\noexpand\thepageno}{\the\toccount}}}\next % \tocline{depth}{sec}{title}{page}{toccount}
\fi
}
\output{
\ifhint
\shipout\box255\relax% otherwise I loose open, write, or close commands
\else
\setbox0=\page % the first page is garbage
\fi
% \openout\cont=\contentsfile
% \write\cont{\catcode `\noexpand\@=11\relax} % \makeatletter
\global\output{\normaloutput\page\lheader\rheader}}
\def\tableofcontent{\plainsection{Contents}\ifhint\HINTdest name {HINT.home}\fi
\unvbox\tocbox
}
\def\tocline#1#2#3#4#5{% depth sectionnumber sectiontitle page toccount
\ifnum#1=0 \smallskip\vskip 0pt plus 12pt\penalty -100\vskip 0pt plus -12pt\fi
\noindent
\line{%
\ifnum#1=0%
\hbox to 2em{\bf#2\hfill}{\bf#3~}\hfill
\hbox to 2em{\hss\bf\tocref{#1}{#3}{#4}{#5}}%
\else \ifnum#1=1%
\kern 2em\hbox to 3em{\rm#2\hfill}{\rm#3~}\leaders\hbox to .5em{.\hfil}\hfill
\hbox to 2em{\hss\tocref{#1}{#3}{#4}{#5}}%
\else
\kern 2em\hbox to 5em{\rm#2\hfill}{\it#3~}\leaders\hbox to .5em{.\hfil}\hfill
\hbox to 2em{\hss\tocref{#1}{#3}{#4}{#5}}\fi\fi
}}
%%
%% Figures and Tables
%%
\def\fig#1{\global\advance\figcount by 1%
\ifvmode\noindent\fi
\def\captype{Fig}%
\capskip=1em%
\vbox{\nointerlineskip\figdest
\hbox{\noindent#1\hskip -2pt\hskip 0pt plus 2pt minus 2pt}%
\medskip
\rlap{\small\unhbox\capbox}%
}}
%\long\def\leftfig#1#2#3{%
%\ifvmode\noindent\fi
%\def\captype{Fig}%
%\capskip=1em%
%\vbox{%
% \tabskip=0pt\halign to \hsize{%
% \vtop{\vskip 0pt\parskip=0pt\hsize=62.5mm\relax
% ##}\tabskip=5mm plus 2pt minus 2pt&
% \vtop{\vskip 0pt\parskip=0pt\hsize=62.5mm\relax##}\tabskip=0pt\cr
% #1&\capskip=0pt\nextfigcaption{#2} #3\cr}\medbreak}}
\long\def\leftright#1#2#3#4{%
\ifvmode\noindent\else\par\noindent\fi
\vbox{\nointerlineskip
\advance\hsize by -\leftskip\advance\hsize by -\rightskip%
\leftskip=0pt\rightskip=0pt%
\hbox to \hsize{\strut
\raise\ht\strutbox
\vtop{\vskip 0pt\parskip=0pt\hsize=#1\hsize\advance\hsize by -2.5mm\relax
\noindent\strut\ignorespaces#3\vfill}\hfil
\raise\ht\strutbox
\vtop{\vskip 0pt\parskip=0pt\hsize=#2\hsize\advance\hsize by -2.5mm\relax
\noindent\strut\ignorespaces#4\vfill}}}}
\long\def\leftfig#1#2#3{%
\def\captype{Fig}%
\capskip=0pt%
\leftright{0.5}{0.5}{#1\kern -2pt\hskip 2pt plus 2pt minus 2pt}{\nextfigcaption{#2}\strut #3}}
\def\subindex#1{%
\par\ifhmode\unskip\fi% end paragraph and remove vertical space
\vskip\abovesubsecskip% space above the subsection
\vskip 0pt plus 72pt% allow some empty space at the bottom
\penalty-200\vskip 0pt plus -72pt % room for stetching and a page break
\noindent{\bf\strut#1}%
\nobreak\vskip\belowsubsecskip% space after subsection
\everypar{{\setbox0=\lastbox}\everypar{}}% no indentation in the next paragraph
\ignorespaces
}
\def\thecodeindex{%
\immediate\closeout\@getfile\relax
\immediate\closeout\@putfile\relax
\immediate\closeout\@redfile\relax
\immediate\closeout\@wrtfile\relax
\def\indexentry##1##2##3##4{% codecount, depth, pagenumber, section
\ifnum##2=0 \smallskip\vskip 0pt plus 12pt\penalty -100\vskip 0pt plus -12pt\fi
\noindent
\line{%
\ifnum##2=0##4\hfill
\else\qquad\rm##4\ \leaders\hbox to .5em{.\hfil}\hfill
\hbox to 1.4em{\hss\pagelnk{##3}}
\fi
}\par
}%
\section{Format Definitions}
\makeatletter
\subsection{Reading the Long Format}\label{codeindex}
\input\jobname.red.srt\relax
\subsection{Writing the Long Format}
\input\jobname.wrt.srt\relax
\subsection{Reading the Short Format}
\input\jobname.get.srt\relax
\subsection{Writing the Short Format}
\input\jobname.put.srt\relax
}
\def\codelabel#1#2#3{
\getindex{#1}{#2}{#3}%
\putindex{#1}{#2}{#3}%
\redindex{#1}{#2}{#3}%
\wrtindex{#1}{#2}{#3}}
\def\getsymbol{$\cdots\Longrightarrow$}
\def\putsymbol{$\Longrightarrow\cdots$}
\def\redsymbol{$-{}-{}-{}\Longrightarrow$}
\def\wrtsymbol{$\Longrightarrow{}-{}-{}-$}
\def\getcode{\codesection{\getsymbol}{Reading the short format}\getindex{1}{\the\codecount}{\subcodetitle}}
\def\putcode{\codesection{\putsymbol}{Writing the short format}\putindex{1}{\the\codecount}{\subcodetitle}}
\def\writecode{\codesection{\wrtsymbol}{Writing the long format}\wrtindex{1}{\the\codecount}{\subcodetitle}}
\def\readcode{\codesection{\redsymbol}{Reading the long format}\redindex{1}{\the\codecount}{\subcodetitle}}
\newdimen\coderule
\def\codesection#1#2{%
\par\ifhmode\unskip\fi% end paragraph and remove vertical space
\penalty-200
\vskip 0pt plus 72pt% allow some empty space at the bottom
\penalty-200
\vskip 0pt plus -72pt% room for stetching and a page break
\vskip\abovesubsecskip% space above the subsection
%\line{\setbox0=\hbox{#1}%
%\coderule=\hsize\advance\coderule by -\wd0\advance\coderule by -2em%
%$\vcenter{\hrule width \coderule}$\hss\box0}
\line{{\it #2\/}:\hfill#1}
\nobreak\vskip\belowsubsecskip\nobreak% space after subsection
%\everypar{{\setbox0=\lastbox}\everypar{}}% no indentation in the next paragraph
%\noindent
\ignorespaces}
\def\hascode{\global\advance\codecount by 1%
\codelabel{0}{\the\codecount}{\codetitle}}%
%%
%% Makeindex and the Index
%%
\newwrite\@indexfile
% new jobname for index file
\def\makeindex{
\immediate\openout\@indexfile=\jobname.inx%
\def\index{\@bsphack\begingroup\@sanitize\@wrindex\@indexfile}%
\typeout{Writing index file \jobname.inx }%
}
\def\@idxitem{\par\hangindent 40pt}
\newif\ifnextindex
\nextindexfalse
\def\beginindex{%
\ifhint\relax\else
\def\page{\box255} \normalbottom
\output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
\global\setbox\sbox=\page \global\pagesavedtrue}
\pagesavedfalse \eject % eject the page-so-far and predecessors
\setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
\vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
\hsize=.5\pagewidth \advance\hsize by -10pt
% column width for the index (20pt between cols)
\parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
\def\lr{L} % this tells whether the left or right column is next
\output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
\else\nomarginoutput{\vbox to\pageheight{\box\sbox\vss
\hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
\global\nextindextrue
\global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
\fi
\message{Index:}
\mark{{0}{0}}
\noindent\par
\begingroup
\rightskip 0pt plus 12pt
\parskip 0pt plus .5pt
\hyphenpenalty 10000 \parindent0pt
\small\baselineskip=11pt
\def\item{\par\hangindent 40pt\relax\ifnextindex\mark{{Index}{Index}}\fi}%
\def\subitem{\par\hangindent 40pt\hskip 20pt\relax}%
\def\subsubitem{\par\hangindent 40pt\hskip 30pt\relax}%
\def\indexspace{\par\vskip 12pt plus 6pt minus 4pt\vskip 12pt\goodbreak\vskip -12pt\relax}%
\def\indexheading##1{{\tenbf ##1}\nobreak\vskip 3pt\relax}
}
\def\endindex{%
\endgroup
\vfill\eject % complete the current column.
\ifhint\relax\else
\if R\lr\null\vfill\eject\fi % if necessarry add a right column
\fi
}
\ifbook
\def\pdflinkcolor{0 0 0} % the RGB values for hyperlink color
\def\linkcolor{\Black}
\def\pdflink#1#2{#1}
\def\pdfnote#1.{#1}
\message{No PDF Links}
\else
\def\pdflinkcolor{0 0 1} % the RGB values for hyperlink color
\def\linkcolor{\Blue}
\message{PDF Links are blue}
\fi
%The number is set be \M and \N and stored as \secno
%The destination is set in \B where we go into C mode
\def\codedest{%
\ifbook\else
\ifhint\HINTdest num \thecode top\relax
\else\ifpdf\pdfdest num \thecode fith\relax
\else\relax
\fi\fi\fi
}
\def\coderef#1{% used in \X
\ifbook${}_{#1}$\else
\ifhint\HINTstartlink goto num #1 \hbox{${}_{#1}$}\HINTendlink
\else\ifpdf{\eightrm\pdfnote#1.}
\else${}_{#1}$\fi\fi\fi
}
\def\codenote#1.{% replaces \pdfnote
\setbox0=\hbox{\toksA={#1.}\toksB={}\maketoks}\the\toksA}
% define the following like for pdf
\def\firstsecno#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}%
\def\makenote{\addtokens\toksB{\the\toksC}\def\makenote{\toksD={}
\toksC={}\let\space\empty}\makenote}\maketoks}}
\def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
\def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}%
\ifcat\noexpand\first0\countB=`#1\else\countB=0\fi\toksA={#2}}
\def\maketoks{\expandafter\poptoks\the\toksA|ENDTOKS|%
\ifnum\countB>`9 \countB=0 \fi
\ifnum\countB<`0
\ifnum0=\countC\else\makenote\fi
\ifx\first.\let\next=\maketoksdone\else
\let\next=\maketoks
\addtokens\toksB{\the\toksD}
\ifx\first,\addtokens\toksB{\space}\fi
\fi
\else \addtokens\toksC{\the\toksD}\global\countC=1\let\next=\maketoks
\fi
\next
}
\def\makenote{\addtokens\toksB
{\noexpand\codelink{\the\toksC}{\romannumeral\the\toksC}}\toksC={}\global\countC=0}
\def\maketoksdone{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
\def\codelink#1#2{
\ifbook#1\else
\ifhint\HINTstartlink goto num #1 #1\HINTendlink
\else\ifpdf\pdflink{#1}{#2}%
\else#1%
\fi\fi\fi}
%
% new destinations and links: by name
%
\def\newdest#1{% used to make a new destination
%\message{New destination #1}%
\ifbook
\else\ifpdf
\pdfdest name {#1} fith%\message{Defining pdf label #1}%
\else\ifhint
\HINTdest name {#1}%\message{Defining HINT label #1}%
\fi\fi\fi}
\def\newtopdest#1{% used to make a new destination
%\message{New destination #1}%
\ifbook
\else\ifpdf
\pdfdest name {#1} fith%\message{Defining pdf label #1}%
\else\ifhint
\HINTdest name {#1} top%\message{Defining HINT label #1 top}%
\fi\fi\fi}
\def\newlink#1#2{%
\ifbook #2\else
\ifpdf
\pdfstartlink goto name {#1}\linkcolor#2\Black\pdfendlink
\else\ifhint
\HINTstartlink goto name {#1}#2\HINTendlink
\else
#2%
\fi\fi\fi
}
%SC.-\the\plaincount for plain sections
%SC.\thesection for regular sections, with subsections and letters for the appendix
\def\tocref#1#2#3#4{% depth, title, page, label used in tocline
\ifbook#3\else
\ifpdf
\pdfstartlink goto name {SC.#4}\relax \linkcolor#3\Black\pdfendlink
\ifnum#1=0\pdfoutline goto name {SC.#4} {#2}\fi
\else\ifhint
\HINTstartlink goto name {SC.#4}\relax $\rightarrow$\HINTendlink
\HINToutline goto name {SC.#4} depth #1 {#2}%
\else
#3%
\fi\fi\fi
}%
%
% Page references from the index
%
% \index{keyword} -> \@wrindex{file}{keyword} writes the nectessary information
% makeindex produces the index and pages are enclosed in \hyperref{pagenumber}
% Problems:
% pagenumbers may be roman numerals in the frontmatter
% hyperpage has to cope with 6 different formats
% \hyperpage{50} a single page number
% \hyperpage{51, 52} two numbers
% \hyperpage{53--59} a page range
% \hyperpage{xi} a roman numeral
% \hyperpage{xi, xii} two numbers
% \hyperpage{xi--xx} a page range
% Writing the index file: in HINT replacing the page number by the index count
\newcount\indexcount
\def\theindexcount{\the\indexcount}
% for HINT and PDF we used hyperrange and hypercomma to split the
% arguments into index/page numbers and then use pagelink
\ifbook
\def\hyperpage#1{#1}\else
\ifhint
\def\hyperpage#1{\hyperrange#1----+\relax}
\else\ifpdf
\def\hyperpage#1{\hyperrange#1----+\relax}
\else
\def\hyperpage#1{#1}
\fi\fi\fi
\def\hypercomma#1, #2,#3+{%
\ifx\empty#2\empty%
\pagelnk{#1}%
\else\ifhint%
\pagelink{#1}{$\longrightarrow$}%
\else
\pagelnk{#1}%
% I omit the second page number \ifpdf, \pagelnk{#2}\fi
\fi\fi
}
%
% Labels
%
% section references from \secref use \sectionlink
% for plainsections, we display the label name because there
%is no section number.
% page references from \label and \pageref use \pagelink as before
\def\indexdest{\newdest{page.\the\indexcount}}
\def\pagelnk#1{%
\ifhint
\pagelink{#1}{$\rightarrow$}%
\else
\pagelink{#1}{#1}%
\fi
}
\def\pagelink#1#2{\newlink{page.#1}{#2}}
% For hint the destination is generated with each \index and \label
% Because of the roman numerals, for pdf files
% the pdf destination is generated in the header using \pagelabel
\ifbook\let\pagelabel=\relax\else
\ifpdf
\def\pagelabel{%\message{pagelabel=\thepageno}
\pdfdest name {page.\thepageno} fitv\relax}
\else
\let\pagelabel=\relax
\fi\fi
%
% References to the bibliography
%
\def\citedest#1{\newdest{CI.#1}}
\def\citelink#1{%\message{Citelink #1}%
\newlink{CI.#1}{#1}}
\def\bblhook{%defined before reading the .bbl file
\def\biblabelprint##1{%
\citedest{##1}%
\noindent
\hbox to \biblabelwidth{%
\biblabelprecontents
\biblabelcontents{##1}%
\biblabelpostcontents
}%
\kern\biblabelextraspace
}%
}
\def\@onecitation#1\@@{%called for each citation
\if@notfirstcitation
\printbetweencitations
\fi
%
\expandafter \ifx \csname\@citelabel{#1}\endcsname \relax
\if@citewarning
\message{\@linenumber Undefined citation `#1'.}%
\fi
% Give it a dummy definition:
\expandafter\gdef\csname\@citelabel{#1}\endcsname{%
{\tt
\escapechar = -1
\nobreak\hskip0pt
\expandafter\string\csname#1\endcsname
\nobreak\hskip0pt
}%
}%
\fi
% Now produce the text, whether it was undefined or not.
\citelink{\csname\@citelabel{#1}\endcsname}%
\@notfirstcitationtrue
}%
%%
%% Images
%%
\ifbook
\def\includefig#1{\leavevmode\hbox{\immediate\pdfximage{image/#1.pdf}\pdfrefximage\pdflastximage}}
\else\ifpdf
\def\includefig#1{\leavevmode\hbox{\immediate\pdfximage{image/#1.pdf}\pdfrefximage\pdflastximage}}
\else\ifhint
\def\includefig#1{\HINTimage=image/#1.png\relax}
\else
\input epsf.tex
\def\includefig#1{\epsfbox{image/#1.eps}}% this is a \leavevmode\hbox{...}
\fi\fi\fi
\ifhint\eject\fi% hitex will remove empty pages that were introduced by cwebmac
\makeatother