forth.tex 42.8 KB
Newer Older
1
\documentclass[10pt]{book}
pknaggs's avatar
pknaggs committed
2
%\setlength\overfullrule{5pt}	% Draft
3
\usepackage{a4wide}
pknaggs's avatar
pknaggs committed
4 5
%\includeonly{titlepage,foreword,foreword-ans,process,members-2x}
%\includeonly{intro,notation,usage,doc,label}
pknaggs's avatar
pknaggs committed
6 7
%\includeonly{core,block,double,exception,facility,file,float}
%\includeonly{locals,memory,tools,search,string,xchar}
pknaggs's avatar
pknaggs committed
8
%\includeonly{rationale,bib,history,diff,port,implement,testsuite}
pknaggs's avatar
pknaggs committed
9
%\includeonly{locals}
10 11 12

% ========== Document Organisation Flags ==========

pknaggs's avatar
pknaggs committed
13
\newif\ifinline			% Inline Rationale glossary matter
pknaggs's avatar
pknaggs committed
14
%\inlinetrue
pknaggs's avatar
pknaggs committed
15
\inlinefalse
16 17

\newif\ifshowref		% Display Cross Reference labels
pknaggs's avatar
pknaggs committed
18
%\showreftrue
19 20
\showreffalse

pknaggs's avatar
pknaggs committed
21 22 23 24 25 26 27 28 29 30 31
\newif\ifrelease			% Draft/Release version
%\releasetrue
\releasefalse

\ifrelease
	\inlinefalse
	\showreffalse
\fi

\newcommand{\revision}{12.1}	% Document Revision
\newcommand{\snapshot}{2012}	% Year of Snapshot
32 33 34

% =================================================

35
% Tell LaTeX to record a list of all the files
pknaggs's avatar
pknaggs committed
36
%\listfiles
37

38 39 40 41 42 43 44
% To Do
%
% Get rid of labels
% code environment
% auto xref ambiguous conditions
% add \log to History / Change Log

45
%\usepackage{supertabular}
pknaggs's avatar
pknaggs committed
46
\usepackage{graphicx}
47
\usepackage{randtext}	% Randamize text (for email addresses)
48

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

% ========== Remember Include Filename  ==========

% Patch the \include command to remember the current include
% filename.

\makeatletter

% Define a blank file name to start with
\def\includefile{}

% Make a note of the original version of \include
\let\forth@include=\include

% Define a our new version
\renewcommand{\include}[1]{%
pknaggs's avatar
pknaggs committed
65 66 67 68 69 70
	\IfFileExists{#1.tex}{%
		\gdef\includefile{#1}%	Remember the filename
		\forth@include{#1}%		Include it
	}{%
		\@latex@error{File "#1.tex" Not Found!}\@ehc
	}
71 72
}

73 74 75 76 77 78 79 80
% ========== Page Header / Footer ==========

\usepackage{fancyhdr}
\pagestyle{fancy}

\makeatletter
\newcommand{\docversion}{%
	\revision
pknaggs's avatar
pknaggs committed
81
	\ifinline
82
		\textit{r}%		word Rationale only
83 84 85 86 87
	\fi%
	\ifshowref
		\textit{x}
	\fi
}
88

89 90 91 92
\makeatother

\lhead[\leftmark]{Forth 200\emph{x} / \docversion}
\rhead[Forth 200\emph{x} / \docversion]{\leftmark}
pknaggs's avatar
pknaggs committed
93 94 95 96 97 98 99
\ifrelease
	\lfoot[\rm\thepage]{}
	\rfoot[]{\rm\thepage}
\else
	\lfoot[\rm\thepage]{\sf\small\includefile}
	\rfoot[\sf\small\includefile]{\rm\thepage}
\fi
100 101 102 103 104 105 106 107 108 109 110
\cfoot{}
\renewcommand{\footrulewidth}{0.4pt}
\newcommand{\collate}{%
	! `` \# \$ \% \& ' ( ) * + , - . / digits : ; $<$ = $>$
	? @ ALPHA [ \bs{} ] \^{} \_ ` alpha \{ | \} \tilde}

% ==========================================


% ========== Deferred Placement ==========

111

112 113 114 115 116 117
\usepackage{answers}

% The answerfile switch controls the use of deferred text.
% Turning it on will allow text to be exported to a "solution"
% file, while turning it off will simply place the text in line.

pknaggs's avatar
pknaggs committed
118
\ifinline
119 120 121 122
	\answerfilesfalse
\else
	\answerfilestrue
\fi
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140

% =======================================


% ========== Change Log / History =========

\usepackage{history}
%\openhistory

% =========================================


% ========== PostScript Fonts ==========

\usepackage[T1]{fontenc}
\usepackage[safe,warn]{textcomp}

\usepackage{mathptmx}			% Times for roman and formula
141
%\usepackage{avant}				% Avant Guard for sans-serif
142 143 144 145 146 147 148 149 150 151 152 153 154
\usepackage[scaled=.88]{helvet}	% Helvetica for sans-serif
\usepackage{courier}			% Courier for teletype

% ======================================

\usepackage[colorlinks,
	pageanchor=false,
	pdfpagelabels=false,
	breaklinks=true]{hyperref}


% ========== Block Paragraphs ==========

155
\usepackage{parskip}
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

% ======================================

\makeatletter

% ========== Word Glossary ==========

% .wrd	the list of raw (unsorted) word entries
% .wds	the sorted list of word entries.
%
% Note that this requires an external program (sort.pl) to sort
% the entries.

\newwrite\wordfile
\immediate\openout\wordfile=\jobname.wrd

% Note the "core" wordlist chapter so we can handle this as a
% special case. Of particular interest to worddef and wref.

\newcounter{word@core}
\setcounter{word@core}{6}

% "Normal" or "Extended" wordset
\newif\if@ext

\newcommand{\extended}{%
	\@exttrue
	\label{wordlist:\word@list-ext}
}

\newcommand{\setwordlist}[1]{%
	\gdef\word@list{#1}
}
\setwordlist{core}

\newcommand{\wordlist}[1]{%
	\gdef\word@list{#1}		% Set the current wordlist
	\@extfalse				% Core wordset, non-extended wordlist
	\label{wordlist:#1}		% Label the wordlist, just in case
	\chaptermark{\MakeUppercase{#1} Word Set}	% Set the page heading
	%
	% Set up a file ready for the deferred text
	%
	\ifanswerfiles
pknaggs's avatar
pknaggs committed
200 201 202 203 204 205 206
		\Closesolutionfile{rationale}
		\Closesolutionfile{testing}
		\Closesolutionfile{implementation}

		\Opensolutionfile{rationale}[r-#1]
		\Opensolutionfile{testing}[t-#1]
		\Opensolutionfile{implementation}[i-#1]
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
	\fi
}

% ===================================

% The following environment define a glossary entry of a word.
% It has two mandatory arguments and three optional ones.
%
% \begin{worddef*}[<label>]{<number>}[<sub-number>]{<name>}[<english>][<proposal>]
%
% <label>	Is the LaTeX label given to the word. It is used when
%			processing links, and should not include any PDF or HTML
%			Special characters. This is the label by which the word
%			in known to the LaTeX system, and the name which should
%			should be used in the \word{<label>} and \wref{<label>}
%			commands.
%			Default: <name> is assumed to be the label.
%
% <number>	The word's number in the alphabetical listing of words.
%			This should be the full four digit number.
%
% <sub-number>
%			The Forth200x standard requires we add new words between
%			existing words. I.e., a new word between 0124 and 0125,
%			we can only archive this by further dividing the number
%			with a two digit sub-number.
%			Default: None.
%
% <name>	This is the display name of the word. It is typeset in
%			standard LaTeX.
%
% <english>	Is the english pronunciation of the word.
%			Default: None.
%
% <proposal>
%			The name of the proposal which introduced this word. All
%			words introduced by Forth 200x should have a proposal.
%			Default: None.
%
% The stared version of worddef, adds change bars to the output. This
% is used to introduce a new word into the standard for the first time.
%
% The worddef environment will automatically generate an index entry
% for the word.
%
% The following commands are provided to aid the word definition:
%
% \compile			Compilation time semantics
% \execute[<type>]	Execution semantics, with a given <type>
% \init				Initiation
% \interpret		Interpretation semantics
% \note[<number>]	Note with an optional <number>
% \runtime[<type>]	Run-time semantics, with a given <type>
% \see				Reference to other words (See)
%
% \item[<name>]		None standard section "<name>:"
%
% \param{<stack item>}
%		Type set <stack item> according to the notation rule.
%		See the definition of \param for the rules.
%
% \stack[<stack>]{<before>}{<after>}
pknaggs's avatar
pknaggs committed
269 270 271 272 273 274 275
%		Type set a stack picture according to the same notation
%		rules as used form \param.
%
% All text which should appear in one of the appendices in the
% final document must appear within the associated environment.
% This allows the text to be shipped out to a separate .sub support
% file, when inlineing is disabled (\ifinline is false).
276
%
pknaggs's avatar
pknaggs committed
277 278
% \begin{rationale} ... \end{rationale}
% \begin{testing}   ... \end{testing}
279
%   \test[<format>]{<pre>}{<post>}	A test case
pknaggs's avatar
pknaggs committed
280
% \begin{implement} ... \end{implement}
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331

% ==== worddef ====

% Unfortunately, LaTeX does not provide an easy way of identifying
% more than one optional arguments. The worddef environment, calls
% on a chain of intermediate macros (word@def@a, word@def@b, and
% so on) to extract each of the optional parameters, one at a time.
% They define a number of macros:
%
% \if@star		True if the change bar is required (worddef*)
% \word@label	LaTeX label for the word, for use in \word{} or \wref{}
% \word@num		the four digit number
% \word@sub		the two digit sub-division number
% \word@name	the name of the word being defined
% \word@read	the english pronunciation / reading of the word name
% \word@prop	Proposal which introduced the new definition
%
% In addition to these macros we also have two global macros:
%
% \word@list	name of the current word list
% \if@ext		true if in extended word list

% Before we start, we define a error reporting macro which identifies
% both the word and the word list in which the error was found

\newcommand{\word@error}[1]{%
	\@latex@error{%
		In \ifnum\value{word@core}=\value{chapter}\thesection\else\thesubsection\fi
		\ifx\word@num\empty .----\else.\word@num\fi
		\ifx\word@sub\empty\else .\word@sub\fi
		\space
		"\word@name" of wordset "\word@list" \MessageBreak
		#1}\@ehc
}

\newif\if@star
\newenvironment{worddef}{\@starfalse\word@def@a}{\word@def@end}
\newenvironment{worddef*}{\@startrue\word@def@a}{\word@def@end}

% So we must start by processing the first two parameters:
% <label> and <number>. Defines the macros:
% \word@label	\empty or the text label
% \word@num		\empty or the four digit number

\newcommand{\word@def@a}[2][\empty]{% [<label>]{<number>}...
	\ifx#1\empty\let\word@label=\empty\else\def\word@label{#1}\fi
	\def\word@num{#2}
	\word@def@b
}

% Now we process the second pair of parameters: <sub-number> and
pknaggs's avatar
pknaggs committed
332
% <name>.  So we define (or redefine) the macros:
333 334 335 336
% \word@label	if \word@label is \empty this is redefined to <name>
% \word@sub		the two digit sub-division number
% \word@name	the name of the word being defined

pknaggs's avatar
pknaggs committed
337 338 339 340 341 342 343
% For some reason I have yet to work out, this treats numbers with
% duplicate digits (such as 11, 22, 33, and so on) an empty.  Thus
% the use of a magic number (100) to signify an empty sub-number,
% as the maximum sub-number should only be 99, this should be sufficient.

\newcommand{\word@def@b}[2][100]{% ...[<sub-number>]{<name>}...
	\ifnum#1<100\def\word@sub{#1}\else\let\word@sub=\empty\fi
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
	\ifx\word@label\empty\def\word@label{#2}\fi
	\def\word@name{#2}
	\word@def@c
}

% Now we can process the next optional parameter: <english>
% Note that if the word has a <proposal> parameter, the
% <english> parameter is required.
% Rather surprisingly this defines a new macro:
% \word@read	the english pronunciation / reading of the word name

\newcommand{\word@def@c}[1][\empty]{% ...[<english>]...
	\ifx#1\empty\let\word@read=\empty\else\def\word@read{#1}\fi
	\word@def@d
}

% Finally we can process the final optional parameter: <proposal>
% Note that all additions to the ANS Forth standard require the
% <proposal> parameter. Thus a new word which has a <proposal> but
% not a separate english pronunciation, MUST provide an empty
% pronunciation parameter. This macro defines the new macro:
% \word@prop	Proposal which introduced the new definition

\newcommand{\word@def@d}[1][\empty]{% ...[<proposal>]
	\ifx#1\empty\let\word@prop=\empty\else\def\word@prop{#1}\fi
pknaggs's avatar
pknaggs committed
369 370 371 372 373 374 375 376 377 378 379 380 381
%	\word@def@test
	\word@def@begin
}

% Now we have collected all of the parameters we can start the word
% definition.  We break this into separate sections, first we generate
% the word index entry (\word@def@index) then the word's banner in the
% glossary (\word@def@head), and finally we set up the environment for
% the text of the definition itself (\word@def@body).
% However, before we do any of this, we ensure that all new words have
% a proposal attached. 

\newcommand{\word@def@begin}{%
pknaggs's avatar
pknaggs committed
382 383
	\typeout{%
		\ifx\empty\word@num----\else\word@num\fi
pknaggs's avatar
pknaggs committed
384
		\ifx\empty\word@sub\space\space\space\else.\word@sub\fi
pknaggs's avatar
pknaggs committed
385
		\space\includefile:\word@label}
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
	\ifx\empty\word@prop
		% No proposal - word must be from ANS Forth '94
		\if@star
			% We have a new word without a proposal?
			\word@error{New words MUST have a proposal}
		\fi
	\fi
	\word@def@index
	\word@def@head
	\word@def@body
}

% Write the index entry for the word, based on our collected macros

\newcommand{\word@def@index}{%
	\immediate\write\wordfile{\string\indexentry%
pknaggs's avatar
pknaggs committed
402
		\if@star*\fi%			* = Changebar
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
		\ifnum\value{word@core}=\value{chapter}{\thesection}\else{\thesubsection}\fi%	1: <section>
		{\word@num}%			2: <number>
		{\word@sub}%			3: <sub number>
		{\word@name}%			4: <name>
		{\word@list}%			5: <wordlist>
		{\if@ext\space EXT\fi}%	6: <ext>
		{\word@prop}%			7: <proposal>
		{\word@label}%			8: <label>
		{\word@read}%			9: <english>
	}
}

% Show the macros, used for debugging

\newcommand{\word@def@test}{%
	\begin{tabular}{rl}
		Change bar:	& \if@star On\else Off\fi \\
		Section:	& \ifnum\value{word@core}=\valign{chapter}\thesection\else\thesubsection\fi \\
		Number:		& \word@num \\
		Sub Number:	& \word@sub \\
		Name:		& \word@name \\
		Wordlist:	& \word@list~\if@ext EXT\fi \\
		Proposal:	& \word@prop \\
		Label:		& \word@label \\
		English:	& \word@read \\
	\end{tabular}\par
}

% ==== Word Header ====
%
% Generate the word header based on the macros collected

\newcommand{\word@def@head}{%
	%
	% This is a good place to start a new page
	%
	\pagebreak[3]
	%
441 442 443 444 445
	% Define the hyper target before the glossary entry
	% So that a hyperlink will show the glossary line
	%
	\hyperdef{\word@list}{\word@label}{}
	%
446 447
	% Word number and name
	%
pknaggs's avatar
pknaggs committed
448 449 450 451 452 453 454
\@tempswbfalse
\ifrelease\else
	\ifx\empty\word@prop\else
		\cbstart\marginpar{\tiny{\color{white}c:b}}
		\@tempswbtrue
	\fi
\fi
455
	\makebox[0.5\textwidth][l]{%
pknaggs's avatar
pknaggs committed
456
		\makebox[6.0em][l]{% <== Magic Number, width of section number
457
			% Switch to a bold font
pknaggs's avatar
pknaggs committed
458
			\bfseries\sffamily
459 460 461 462 463 464 465 466
			%
			% Current section or subsection
			%
			\ifnum\value{word@core}=\value{chapter}
				% In the core wordset
				\thesection
			\else
				% In all other word sets
pknaggs's avatar
pknaggs committed
467
				\thesubsection
468 469 470 471 472 473 474
			\fi
			%
			% Word number
			%
			\ifx\empty\word@num
				% No word number given
				.\rule[.8ex]{2em}{.5pt}
pknaggs's avatar
pknaggs committed
475 476 477 478 479 480 481
			\else%
\if@tempswb%
				\uline{.\word@num}%
\else%
				.\word@num%
\fi%
			\fi%
482 483 484 485
			%
			% Sub division
			%
			\ifx\word@sub\empty
pknaggs's avatar
pknaggs committed
486
				~% No sub division
487
			\else
pknaggs's avatar
pknaggs committed
488 489 490
\if@tempswb
				\uline{.\word@sub}
\else
491
				.\word@sub
pknaggs's avatar
pknaggs committed
492
\fi
493 494 495 496 497
			\fi
		}
		%
		% Word Name
		%
pknaggs's avatar
pknaggs committed
498 499
		%\mdseries	% Back to a medium weight (normal) font
		\texttt{\textbf{\word@name}}
500
	}
pknaggs's avatar
pknaggs committed
501 502 503
\if@tempswb
		\cbend
\fi
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
	%
	% English pronunciation (if given)
	%
	\ifx\word@read\empty
		% No english pronunciation given
	\else
		``\word@read''
	\fi
	%
	% Wordlist
	%
	\hfill
	\MakeUppercase{\word@list}
	\if@ext EXT\fi
	%
	% Cross Reference
	%
pknaggs's avatar
pknaggs committed
521
	\ifshowref%
522 523 524 525 526 527
		\ifx\word@label\word@name
			% Word label is the word name
		\else
			% Label is different to name
			\hbox to 0pt{\textsf{\small ~~\word@label}}
		\fi
pknaggs's avatar
pknaggs committed
528
	\fi%
529
	%
pknaggs's avatar
pknaggs committed
530 531 532 533 534 535
	% Start change bar
	%
	\if@star%
		\cbstart\patch{\word@prop}%
	\fi%
	%
536 537
	% Proposal
	%
pknaggs's avatar
pknaggs committed
538
	\\*[-0.6ex]
539 540 541
	\ifx\word@prop\empty
		% No proposal - word must be from ANS Forth '94
	\else
pknaggs's avatar
pknaggs committed
542 543 544 545
		\ifrelease\else
			\mbox{} \hfill	% flush right (under the wordset name)
			\textsf{\small \word@prop}%
		\fi
546 547
	\fi
	%
548 549 550 551 552 553 554 555 556 557 558
	% Define the label for this word
	%
	\def\@currentlabel{%
		\ifnum\value{word@core}=\value{chapter}\thesection\else\thesubsection\fi%
		\ifx\empty\word@num .0\else.\word@num\fi%
		\ifx\empty\word@sub\else .\word@sub\fi
	}%
	\edef\@currentlabelname{\word@name}%
	\def\@currentHref{\word@list.\word@label}%
	\label{\word@list:\word@label}%
	%
559 560
	% End the header
	%
pknaggs's avatar
pknaggs committed
561 562 563 564
	\if@star\else
		\ifx\word@prop\empty\else\cbend\fi % Draft
	\fi
	\\*[-1.5\baselineskip]
565 566 567 568 569 570 571 572 573 574 575 576 577 578
	%
	% This is a very bad place for a page break
	%
	\pagebreak[0]
}

% ==== Word Body ====
%
% Define the macro which will be used to format items within the word
% definition. We right align the text which is output with a trailing
% colon.

\newcommand{\word@item}[1]{%
	\hfil
579
	\ifx#1\else #1:\fi
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
}

% For the main body of the definition we use a "simple" list
% environment. We need only set up the margins for environment.

\newcommand{\word@def@body}{
	\begin{list}{}{
		\setlength{\labelwidth}{6.8em}		% <== Magic number, width of indent
		\setlength{\leftmargin}{\labelwidth}
		\addtolength{\leftmargin}{\labelsep}
		\renewcommand{\makelabel}{\word@item}
	}
}

% ==== Word Footer ====
%
% This cleans up after the header and body

\newcommand{\word@def@end}{%
	%
	% Extend the normal "missing \item" error message to
	% tell us which word is in error.
	%
	\def\@noitemerr{\word@error{Something wrong here --- perhaps a
		missing \string\item}}
	%
	% End the list started by \word@def@body
	%
	\end{list}
	%
	% End the change bar, if it was enabled
	%
pknaggs's avatar
pknaggs committed
612
	\if@star\cbend\fi%
613 614 615
	%
	% Leave some extra space after the list
	%
pknaggs's avatar
pknaggs committed
616
	\vspace{3ex}
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
	%
	% This would be a fairly good place for a page break
	%
	\par\pagebreak[3]
}

% ==== Word Sections ====

% Define the sections found within a glossary entry.

\newcommand{\compile}{\item[Compilation]}
\newcommand{\execute}[1][\empty]{%
	\ifx#1\empty
		\item[Execution]
	\else
		\item[\emph{#1} Execution]
	\fi
}
\newcommand{\init}{\item[Initiation]}
\newcommand{\interpret}{\item[Interpretation]}
\newcommand{\note}[1][\empty]{\item[Note\ifx#1\empty\else\ #1\fi]}
\newcommand{\runtime}[1][]{\item[#1 Run-time]}
pknaggs's avatar
pknaggs committed
639
\newcommand{\see}{\pagebreak[0]\item[See]}
640 641 642 643


% ==== Stack Descriptions ====

pknaggs's avatar
pknaggs committed
644 645
% Okay, we are going for some very nasty low level TeX here.
% Check out the actionarg entry of the TeX FAQ for full details.
646
%
pknaggs's avatar
pknaggs committed
647
% First we define the functions which are going to be called by our
648 649
% special characters

pknaggs's avatar
pknaggs committed
650 651 652 653 654 655
\newcommand{\stack@sub}[1]{\raisebox{-0.4ex}{\scriptsize #1}}  % _
\newcommand{\stack@sup}[1]{\raisebox{0.8ex}{\scriptsize #1}}   % ^
\newcommand{\stack@mul}{\ensuremath{\mathbin\times}}           % *
\newcommand{\stack@bar}{~\textbar~}                            % |
\newcommand{\stack@opa}{\ensuremath{\langle}}                  % <
\newcommand{\stack@cla}{\ensuremath{\rangle}}                  % >
656 657

\newif\if@stack@quote\@stack@quotetrue
pknaggs's avatar
pknaggs committed
658
\newcommand{\stack@qot}{%                                      % "
659 660 661 662 663 664 665
	\if@stack@quote``\@stack@quotefalse\else''\@stack@quotetrue\fi}

% Now we have to activate the special characters we are going to
% define, so that we can define them! We do this inside a simple
% group so we don't screw up the rest of the system.

\begingroup
pknaggs's avatar
pknaggs committed
666 667 668 669 670 671
	\catcode`\_=\active  % Subscript:      _1 or _{12}
	\catcode`\*=\active  % Multiply:       1*2
	\catcode`\|=\active  % Alternative:    u|n
	\catcode`\<=\active  % Start text:     <ccc>
	\catcode`\>=\active  % End text:       <ccc>
	\catcode`\"=\active  % Syntax element: "name"
672 673

% Because we are inside a simple group, we have to use \gdef rather
pknaggs's avatar
pknaggs committed
674
% than \newcommand. The \stack@set command installs the new specials
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
% for the next function call.

\gdef\stack@set{%
	\catcode`\_=\active \let_=\stack@sub%
	\catcode`\*=\active \let*=\stack@mul%
	\catcode`\|=\active \let|=\stack@bar%
	\catcode`\<=\active \let<=\stack@opa%
	\catcode`\>=\active \let>=\stack@cla%
	\catcode`\"=\active \let"=\stack@qot%
}
\endgroup

% Now we can define the \stack command:
%
% \stack[<stack>}{<before>}{<after>}
%
% Where the <before> and <after> parameters are interpreted with the
% new specials. To do this we have to enable the new specials before
% processing the arguments with the support function \stack@sig. We
% do this inside a new group so we don't bugger up text outside of
% the parameter.
%
% The <before> and <after> parameters define a number of additional
% special characters as follows:
% _x or _{xx}	x or xx is a subscript
% x*y			becomes x multiplied by y ($x\times y$)
% x|y			becomes x or y ( x \textbar y )
% <xxx>			becomes an argument <xxx>
% "				becomes open or close double quote
%
% All other characters are typeset in italic.

\newcommand{\stack}[1][\empty]{% [<stack>]...
	(				% Mark the start of the signature
	\ifx#1\empty\else #1: \fi	% The stack name (if given)
	\begingroup		% Open a new restricted scope for new specials
	\itshape		% The signature is in italic
	\stack@set		% Enable the specials
	\stack@sig		% Parse the signature parameters
					% We have to do this in a separate macro as
					% the specials are not active when this macro
					% is executed
}

\newcommand{\stack@sig}[2]{% ...{<before>}{<after>}
	#1\ 			% Pre-condition (before)
721
	\texttt{-{}-}	% Mark the "execution point"
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
	\ #2			% Post-condition (after)
	\endgroup		% Close restricted scope
					% Disable new specials and \itshape
	)				% Close stack signature
}

% The \param{} command allows us to process its argument in exactly
% the same way as the <before> and <after> parameters. Thus we have
% to use the same trick of enabling the our specials inside of a new
% group before calling a helper word \param@arg which actually
% processes the argument.

\newcommand{\param}{% ...
	\begingroup		% Open a restricted scope for our specials
	\itshape		% A stack parameter is always given in italic
	\stack@set		% Enable the specials
	\param@arg		% Parse the parameter
}

\newcommand{\param@arg}[1]{% ...{<param>}
	#1%				% Parse the parameter with our specials enabled
	\endgroup		% Close restricted scope, we don't want our
					% specials buggering up anything else now do we,
					% this also cancels the \itshape command
}

748 749
% As part of the testing environment we also provide the \test
% macro to typeset the text of a test case.
pknaggs's avatar
pknaggs committed
750

751 752 753 754
% \test[<format>]{<pre>}{<post>}
\newcommand{\test}{\frenchspacing\obeyspaces\test@arg}
\newcommand{\test@arg}[3][]{%
	\texttt{T\{ #2 -> #3 #1\}T}%
pknaggs's avatar
pknaggs committed
755 756
	\nonfrenchspacing\catcode`\ =10}

757 758
% ==== Deferred Text ====
%
pknaggs's avatar
pknaggs committed
759 760 761 762
% \begin{rationale} ... \end{rationale}
% \begin{testing}   ... \end{testing}
%   \test{<pre>}{<post>}	A test case
% \begin{implement} ... \end{implement}
763
%
pknaggs's avatar
pknaggs committed
764 765 766 767
% Deferred text refers to those parts of a words definition that
% do not appear in the main normative definition.  Such informative
% text appears in a separate appendix.  Be in the Rationale, Test
% cases, or a reference implementation.
768
%
pknaggs's avatar
pknaggs committed
769
% Rather than defining sections as we have done for the different
770
% semantic descriptions, we have to define environments so that we
pknaggs's avatar
pknaggs committed
771 772 773 774
% can either include the text in with the normative definition as
% it is much easer to review the text in this way, or export the
% text to another file, which can then be included into the
% appropriate section of the appendix.
775
%
pknaggs's avatar
pknaggs committed
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
% We have to provide two separate versions of these environments.
% One is used when we are inlining (\inlinetrue) and the other when
% we are exporting (\inlinefalse).

\ifinline
	% We have to define the "inline" version of these environments.
	% These will simply show the text inline with the normative
	% description.
	
	% We define two helper macros.  The first of which will output
	% the section <title> and define a hyper target for the <title>
	% based on the current name <space>.
	\newcommand{\inline@section}[2]{% {<space>}{<title>}
		% In the review version of the document we change the font
		% for of the informative text to help distinguish it from
		% the normative text.  In the final version it will appear
792
		% in a separate appendix.
pknaggs's avatar
pknaggs committed
793 794 795
		\sffamily
		%
		% Output the section <title> and define an associated
796
		% hyper target in the given name <space>.
pknaggs's avatar
pknaggs committed
797 798
		\item[\hyperdef{#1.\word@list}{\word@label}{#2}]
	}
799

pknaggs's avatar
pknaggs committed
800 801 802 803
	% We need to fake a latex label for this section of the words
	% definition.  This macro will fake a label for the given
	% <annex> within a given name <space>.
	\newcommand{\inline@label}[2]{% {<space>}{<annex>}
pknaggs's avatar
pknaggs committed
804
		% We start by fakeing the current label value
pknaggs's avatar
pknaggs committed
805 806 807 808 809 810 811 812 813 814 815 816 817
		\def\@currentlabel{%
			#2.%
			\ifnum\value{word@core}=\value{chapter}\thesection\else\thesubsection\fi%
			\ifx\word@num\empty.0\else.\word@num\fi%
			\ifx\word@sub\empty\else.\word@sub\fi%
		}
		% The text of the label
		\edef\@currentlabelname{\word@name}
		% The hyper target for this label
		\def\@currentHref{#1.\word@list.\word@label}
		% Finally, the label itself
		\label{#1:\word@list:\word@label}
	}
818

pknaggs's avatar
pknaggs committed
819 820 821 822 823 824 825 826 827 828 829 830 831
	% \begin{rationale} ... \end{rationale}
	% The rationale environment must define a cross reference label
	% (and hyper link target) for use by \rref.

	\newenvironment{rationale}{%
		\inline@section{rat}{Rationale}
		\inline@label{rat}{\ref{annex:rationale}}
	}{
		% Switch back to the normal font
		\rmfamily
	}

	% \begin{testing} ... \end{testing}
832
	% Now we need to do something similar for the testing environment.
pknaggs's avatar
pknaggs committed
833 834 835 836 837 838 839 840 841 842 843
	\newenvironment{testing}{
		\inline@section{test}{Testing}
		\inline@label{test}{\ref{annex:test}}
	}{
		\rmfamily
	}

	% \begin{implment} ... \end{implment}
	% And the same again for the reference implementation.
	\newenvironment{implement}{%
		\inline@section{imp}{Implementation}
pknaggs's avatar
pknaggs committed
844
		\inline@label{imp}{\ref{annex:implement}}
pknaggs's avatar
pknaggs committed
845
		\ttfamily
846
	}{%
pknaggs's avatar
pknaggs committed
847
		\rmfamily
848 849
	}

pknaggs's avatar
pknaggs committed
850
	% Sometime we want "normal" text in the implementation and
851
	% testing sections.  We define a "Deferred Font" to hide the
pknaggs's avatar
pknaggs committed
852 853 854
	% sf/rm font switch.
	\newcommand{\textdf}[1]{\textsf{#1}}
	\newcommand{\dffamily}{\sffamily}
855
\else
pknaggs's avatar
pknaggs committed
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
	% We are not "inline," so we have to ship the informative text
	% out to their respective appendices.
	%
	% For this some knowledge of the answers package is required.
	% This package allows us to define an association between two
	% environments and a "solution" file:
	%
	% \Newassociation{defertext}{deferredtext}{deferred}
	%
	% When a <defertext> environment is encountered the text will
	% be written out to the associated solution file (<deferred> in
	% this case).  The text is placed in the <deferredtext>
	% environment, so that it may be processed correctly.
	%
	% The <deferredtext> environment is executed with a number of
	% parameters.  These are defined by the \deferredtextparams
	% macro.  This allows us to capture the environment in which the
	% defertext environment was found, and pass on any relevant
	% information to the deferred text environment.
	%
	% The command:
	%
	%	\Opensolutionfile{deferred}[filename]
	%
	% associates an actual file name (in this case <filename>) with
	% the solution file handle <deferred>.  This allows a single
	% solution file handle to be associated with multiple physical
	% files, one per wordlist.
	%
	% So that's the background, no on to the deferred environments!
886

pknaggs's avatar
pknaggs committed
887 888 889 890
	% Override the default file extension (.tex) for these support
	% files.  Making it something else (.sub) will make it easy to
	% delete them after a run.
	\renewcommand{\solutionextension}{sub}
891

pknaggs's avatar
pknaggs committed
892
	% Define a new solution handle for each of the informative
893
	% environments:
894

pknaggs's avatar
pknaggs committed
895 896 897
	\Newassociation{rationale}{worddefer}{rationale}
	\Newassociation{testing}{worddefer}{testing}
	\Newassociation{implement}{worddefer}{implementation}
898

pknaggs's avatar
pknaggs committed
899 900 901 902 903
	% The pre<x> macros are invoked before the text is shipped out to
	% the auxiliary file.  We use them to redirect the reader to the
	% appropriate appendix.

%	\newcommand{\prerationale}{%
pknaggs's avatar
pknaggs committed
904
%		\item[Rationale] See \rref{\word@list:\word@label}{\word@name}.
pknaggs's avatar
pknaggs committed
905
%	}
pknaggs's avatar
pknaggs committed
906

pknaggs's avatar
pknaggs committed
907
%	\newcommand{\pretesting}{%
pknaggs's avatar
pknaggs committed
908
%		\item[Testing] See \tref{\word@list:\word@label}{\word@name}.
pknaggs's avatar
pknaggs committed
909
%	}
pknaggs's avatar
pknaggs committed
910

pknaggs's avatar
pknaggs committed
911
%	\newcommand{\preimplement}{%
pknaggs's avatar
pknaggs committed
912
%		\item[Implementation] See \iref{\word@list:\word@label}{\word@name}.
pknaggs's avatar
pknaggs committed
913
%	}	
pknaggs's avatar
pknaggs committed
914 915 916 917 918

	% The text for all three environments will be processed by
	% the worddefer environment.  This will be given a number
	% of paramaters, which must capture the current environment
	% when the source environment was used.
919 920 921 922 923 924 925 926

	\renewcommand{\worddeferparams}{%
		{\ifnum\value{word@core}=\value{chapter}\thesection\else\thesubsection\fi}%	Section (or sub-section) number
		{\ifx\empty\word@num0\else\word@num\fi}%		2 Word number or \empty
		{\word@sub}%		3 Word sub-number
		{\word@list}%		4 The current word list
		{\word@label}%		5 The label for the word
		{\word@name}%		6 The LaTeX name for the word
pknaggs's avatar
pknaggs committed
927
		{\if@star\word@prop\fi}%	7 Proposal
928 929
	}

pknaggs's avatar
pknaggs committed
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
	% The exported text has to interact with the appendix which
	% includes the text.  It does this though the following
	% interface:

	% The appendix must define a namespace for itself.  This tells
	% worddefer which label to generate (rat, test or imp).

	\def\defer@space{%
		\@latex@error{No name space defined - Use the
			\protect\namespace command to define a namespace}\@ehc
	}

	\newcommand{\namespace}[1]{%
		\gdef\defer@space{#1}
	}

	% If the appendix generates a header for each section, there is
	% the potential for a header to appear with no body if there is
	% no exported text for the appendix in a given wordlist.  To
	% prevent this rather unsightly situation the appendix uses the
	% \defersection command to define the current section heading.

	\newcommand{\defersection}[1]{\gdef\defer@title{#1}}

954
	% deferword will output an appropriate section heading, and then
pknaggs's avatar
pknaggs committed
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
	% resets \defer@title to \empty so that it is only output once.

	% However, as we do not output a section header, we still need to
	% be able to increment the section number, so that the numbering
	% keeps in step with the wordlist definitions.  Thus we provide
	% a macro to increment the section number if the header was not
	% output.  This should be called after the support file has been
	% input into the document.

	\newcommand{\stepsection}{%
		\ifx\defer@title\empty\else
			\stepcounter{section}
		\fi
	}

	% Now we have set up the environment we can finally override the
971
	% default worddefer environment.  This takes six parameters which
pknaggs's avatar
pknaggs committed
972 973 974 975 976 977 978 979
	% where defined by \deferwordparams to be:
	%
	% #1	Section (or sub-section) number
	% #2	Word number or \empty
	% #3	Word sub-number
	% #4	The current word list
	% #5	The label for the word
	% #6	The LaTeX name for the word
pknaggs's avatar
pknaggs committed
980
	% #7  The proposal for the word
pknaggs's avatar
pknaggs committed
981

982 983 984
	% We redefine the standard worddefer environment to take account
	% of the parameters we have just defined.

pknaggs's avatar
pknaggs committed
985 986 987 988 989 990
%	\newcommand{\word@defer@error}[1]{%
%		\@latex@error{%
%			In rationale for \word@num\space "\word@name" of wordset
%			"\word@list" \MessageBreak #1}\@ehc
%	}

pknaggs's avatar
pknaggs committed
991 992 993 994 995
	% The \format@<x> commands are called by the general worddefer environment
	% to initialise the formatting for the section.  In the rationale and test
	% appendices this is the "normal" roman font, but in the implementation
	% appendix this is the type-type (courier) font.

pknaggs's avatar
pknaggs committed
996 997 998
	\let\format@rat\rmfamily
	\let\format@test\rmfamily
	\let\format@imp\ttfamily
999

pknaggs's avatar
pknaggs committed
1000
	\renewenvironment{worddefer}[7]{%
1001 1002 1003
		%
		% Output the section heading
		%
pknaggs's avatar
pknaggs committed
1004 1005 1006 1007 1008 1009 1010 1011 1012
		\ifx\defer@title\empty\else
			\section{The optional \defer@title{} word set}
			\label{\defer@space:\defer@title}
			\gdef\defer@title{}
		\fi
		%
		% Output the word header.
		% Mark the header as the target for the hyperlink.
		%
1013
		\par
pknaggs's avatar
pknaggs committed
1014
		\pagebreak[3]
pknaggs's avatar
pknaggs committed
1015
		%
pknaggs's avatar
pknaggs committed
1016 1017
		\hyperdef{\defer@space.#4}{#5}{%
			\textbf{\rmfamily\thechapter.#1%
1018 1019 1020 1021
				\ifnum#2=0\empty.\rule[.8ex]{2em}{.5pt}\else.#2\fi%
				\ifx#3\empty\else.#3\fi
				\quad \hyperref{}{}{#4.#5}{\texttt{#6}}
			}
pknaggs's avatar
pknaggs committed
1022
		} \\[-1.4\baselineskip]
1023
		%
pknaggs's avatar
pknaggs committed
1024 1025 1026 1027
		\ifx#7\empty\else%
			\@startrue%
			\cbstart\patch{#7}%
		\fi%
pknaggs's avatar
pknaggs committed
1028
		\pagebreak[1]
pknaggs's avatar
pknaggs committed
1029
		%
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
		% Start the body environment
		%
		\begin{list}{}{
			\setlength{\labelwidth}{2em}	% <== Magic number, width of indent
			\setlength{\leftmargin}{\labelwidth}
			\addtolength{\leftmargin}{\labelsep}
			\renewcommand{\makelabel}{\word@item}
		}
		\item\relax
		%
1040
		% Store a few values just in case there is an error
1041
		%
pknaggs's avatar
pknaggs committed
1042
		\def\word@num{\thechapter.#1%
1043 1044 1045 1046 1047 1048 1049 1050
			\ifx#2\empty.--\else.#2\fi%
			\ifx#3\empty\else.#3\fi}
		\def\word@list{#4}
		\def\word@label{#5}
		\def\word@name{#6}
		%
		% Create a few variables, used by \label
		%
pknaggs's avatar
pknaggs committed
1051
		\def\@currentlabel{\thechapter.#1%
1052 1053 1054 1055
			\ifx#2\empty.0\else.#2\fi%
			\ifx#3\empty\else .#3\fi
		}
		\edef\@currentlabelname{#6}
pknaggs's avatar
pknaggs committed
1056
		\def\@currentHref{\defer@space.#4.#5}
1057 1058 1059
		%
		% Record a cross reference label for the section
		%
pknaggs's avatar
pknaggs committed
1060
		\label{\defer@space:\word@list:\word@label}
pknaggs's avatar
pknaggs committed
1061
		\typeout{\ifnum#2=0----\else #2\fi: \defer@space:\word@list:\word@label}
1062
		%
pknaggs's avatar
pknaggs committed
1063
		% Format the section
1064
		%
pknaggs's avatar
pknaggs committed
1065
		\csname format@\defer@space\endcsname
1066 1067 1068
		%
		% Patch the error message to report "rationale"
		%
pknaggs's avatar
pknaggs committed
1069
%		\let\word@error=\word@defer@error
1070 1071 1072 1073
	}{
		%
		% Ignore the no \item error
		%
pknaggs's avatar
pknaggs committed
1074
%		\def\@noitemerr{}
1075 1076 1077 1078
		%
		% End the list environment
		%
		\end{list}
pknaggs's avatar
pknaggs committed
1079 1080 1081 1082 1083
		%
		\if@star%
			\cbend%
			\@starfalse%
		\fi%
pknaggs's avatar
pknaggs committed
1084 1085
		%
		\pagebreak[3]
1086
	}
1087

pknaggs's avatar
pknaggs committed
1088
	% Sometime we want "normal" text in the implementation and
1089
	% testing sections.  We define a "Deferred Font" to hide the
pknaggs's avatar
pknaggs committed
1090 1091 1092 1093
	% sf/rm font switch.
	\newcommand{\textdf}[1]{\textrm{#1}}
	\newcommand{\dffamily}{\rmfamily}
\fi
1094

pknaggs's avatar
pknaggs committed
1095 1096 1097
\newcommand{\proposal}[1]{%
	\ifrelease\else\strut\hfill\textsf{\small #1}\fi
}
1098

1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
% ========== Special Characters ==========

% \tab[n]   => extra horizontal space
\newlength{\tablength}
\setlength{\tablength}{1em}
\newcommand{\tab}[1][1]{\hspace*{#1\tablength}}

% \arg{x}   => <x>
\renewcommand{\arg}[1]{$\langle$\textit{#1}$\rangle$}

% \bs       => \
\newcommand{\bs}{\char"5C}

% \tilde    => ~
\renewcommand{\tilde}{\char"7E}

% \num		=> #
\newcommand{\num}{\char"23}

pknaggs's avatar
pknaggs committed
1118 1119 1120
% \brace		=> {
\renewcommand{\brace}{\char"7B}

1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
% ========================================



% ========== Extend Cross Referencing ==========

% Thanks to hyperref, when we execute the label it expands to four
% augments:
%
% 1: Number - the \@curentlabel when the label was defined
% 2: Page   - the page the label was defined on (\c@page)
% 3: Title  - The title of the label (\@currentlabelname)
% 4: Link   - The hyperdef associated with the label (\@currenHref)

% Output a word name. The name is given in courier-bold and hyper
% linked to its definition.
% If we are using the \showref flag we also underline it, show we can
% see which words are linked, in the dvi viewer and which are not.

\newcommand{\word@word}[4]{% {number}{page}{name}{link}
	\hyperref{}{}{#4}{%
		\textbf{\texttt{%
pknaggs's avatar
pknaggs committed
1143
			\frenchspacing%
1144 1145 1146 1147 1148
			\ifshowref
				\underline{#3}%
			\else%
				{#3}%
			\fi%
pknaggs's avatar
pknaggs committed
1149
			\nonfrenchspacing
1150 1151 1152 1153 1154 1155
		}}%
	}%
}

\ifshowref
	\newcommand{\@noword}[2]{% {<wordset>}{<word>}
pknaggs's avatar
pknaggs committed
1156
		\@latex@error{Can't find "#2" in "#1", in file \includefile}\@ehc%
1157 1158 1159
	}
\else
	\newcommand{\@noword}[2]{% {<wordset>}{<word>}
pknaggs's avatar
pknaggs committed
1160
		\@latex@warning{Can't find "#2" in "#1", in file \includefile}{}%
1161 1162 1163 1164
	}
\fi

% \word[<wordlist>]{<wordlabel>}
pknaggs's avatar
pknaggs committed
1165
% Typeset the word associated with the label <wordlabel>. The word is
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
% either in the current wordlist, the core word list or the optional
% <wordlist>. The word is hyperlinked back to its definition.
%
% If the word has not been defined, can not be found, it reports an
% error. The word is still typeset but with a line though it.

% Note that three \expandafter's are needed to call \word@word with
% the value held by the label. For example if we consider the core
% word ! (store), we would have three levels of expansion as follows:
%
% 1: expand \csname r@#1:#2\endcsname      to \r@core:store
% 2: execute \r@core:store                 to obtain {0010}{12}{!}{store}
% 3: call \word@word with those arguments

\newcommand{\word}[2][\word@list]{% [<wordlist>]{<wordlabel>}
	% Is label <wordlist>:<wordlabel> defined
	\expandafter\ifx\csname r@#1:#2\endcsname\relax%
		% No - try looking for the label core:<wordlabel>
		\expandafter\ifx\csname r@core:#2\endcsname\relax%
			% No - then its not a standard word
			\textbf{\texttt{\ifshowref\sout{#2}\else{#2}\fi}}%
			\@noword{#1}{#2}%
		\else%
			% word in core wordlist
			\expandafter\expandafter\expandafter\word@word\csname r@core:#2\endcsname%
		\fi%
	\else%
		% word in given wordlist
		\expandafter\expandafter\expandafter\word@word\csname r@#1:#2\endcsname%
	\fi%
}

% \xref[<text>]{<label>}
% Extended cross reference.
pknaggs's avatar
pknaggs committed
1200
%
1201 1202
% This was originally developed as a tool to help in the conversion of
% existing documents into LaTeX form. It relies on the extended \label
pknaggs's avatar
pknaggs committed
1203
% command provided by the hyperref package.  It will look up <label>
1204
% and places the section number followed by the section name as a
pknaggs's avatar
pknaggs committed
1205 1206 1207 1208 1209
% hyperlink to <label>.  Should <label> not be found it places <label>
% (between brackets) with the optional <text> along side.  The idea
% being that the user can see what was in the original document
% (<text>), and which <label> was not found.  If the <text> is not
% given, the traditional double question mark is used.
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
%
% Thus for the following example, the label "foo" refers to section
% 3.2.1 which has the name "Foo", the text:
%
%	section \xref[original text]{foo}.
%
% If the label foo is found this would produce:
%
%	section 3.2.1 Foo.
%
% where the "3.2.1 Foo" is a hyperlink to the label foo.
%
% If the label foo does not exist this would produce the text:
%
%	section [foo: original text].
%
pknaggs's avatar
pknaggs committed
1226 1227 1228
% where the "[foo: original text]" appears in bold. This is intended
% to indicate that the label foo was not found, but the original
% document had "original text" as the text which should appear here.
1229 1230

% We define a helper command which interprets the parameters generated
pknaggs's avatar
pknaggs committed
1231
% by executing the label.  It will output the section number (#1) and
1232 1233 1234
% title (#3)

\newcommand{\word@xref}[4]{% {number}{page}{name}{link}
1235
	\textbf{%
1236 1237 1238
		\hyperref{}{}{#4}{#1} \linebreak[3]
		\hyperref{}{}{#4}{#3}%
	}%
1239 1240 1241 1242 1243 1244 1245
}

\newcommand{\xref}[2][??]{% [<text>]{<label>}
	% Look for the label
	\expandafter\ifx\csname r@#2\endcsname\relax%
		% label is not found
		% Spit out a warning
1246
		\@latex@warning{Reference `#2' in file \includefile\space undefined}%
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
		% Tell the user the label and original text
		\textbf{[#2: #1]}%
	\else%
		% Label found so output a the section number and title
		\expandafter\expandafter\expandafter\word@xref\csname r@#2\endcsname
	\fi
}


% \wref{<label>}{<Name>} - Word reference
%	<label> will be of the form <wordlist>:<label> i.e., core:store
%	<name>	is the LaTeX which will be typeset for the word reference

pknaggs's avatar
pknaggs committed
1260
\newcommand{\word@ref}[4]{% <section> <page> <name> <label>
1261 1262 1263
	\hyperref{}{}{#4}{\textbf{#1}} \linebreak[3]
	\hyperref{}{}{#4}{\texttt{#3}}%
}
1264 1265 1266 1267 1268 1269

\newcommand{\wref}[2]{% {label}{name}
	% Look for the word's label
	\expandafter\ifx\csname r@#1\endcsname\relax%
		% Not found - output label and then name
		\textbf{[#1] #2}%
1270
		\@latex@warning{Reference `#1' to word `#2' in file \includefile\space undefined}%
1271 1272 1273 1274 1275 1276 1277 1278 1279
	\else%
		\expandafter\expandafter\expandafter\word@ref\csname r@#1\endcsname%
	\fi%
}

% \rref{<label>}{<name>} - Rationale reference
%	\rref is the same as \wref except it looks in the rationale (rat:)
%	name space

1280
\newcommand{\word@ref@inline}[4]{\word@ref{A.#1}{#2}{#3}{#4}}
1281 1282 1283 1284 1285 1286 1287 1288

\newcommand{\rref}[2]{% {<label>}{<name>}
	\expandafter\ifx\csname r@rat:#1\endcsname\relax%
		% Not found - output a warning, the label and the word
		\textbf{[rat:#1] #2}%
		\@latex@warning{Reference `#1' to rationale of `#2' on page
			\thepage\space undefined}%
	\else%
pknaggs's avatar
pknaggs committed
1289
		\ifinline%
1290
			\expandafter\expandafter\expandafter\word@ref@inline\csname r@#1\endcsname%
pknaggs's avatar
pknaggs committed
1291
		\else%
1292 1293 1294 1295 1296
			\expandafter\expandafter\expandafter\word@ref\csname r@rat:#1\endcsname%
		\fi%
	\fi%
}

pknaggs's avatar
pknaggs committed
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
% \tref{<label>}{<name>} - Testing

\newcommand{\word@test@inline}[4]{\word@ref{\ref{annex:test}.#1}{#2}{#3}{#4}}
\newcommand{\tref}[2]{% {<label>}{<name>}
	\expandafter\ifx\csname r@test:#1\endcsname\relax%
		\textbf{[test:#1] #2}%
		\@latex@warning{Reference '#1' to testing of '#2' on page
			\thepage\space undefined}%
	\else%
		\ifinline%
			\expandafter\expandafter\expandafter\word@test@inline\csname r@#1\endcsname%
		\else%
			\expandafter\expandafter\expandafter\word@ref\csname r@test:#1\endcsname%
		\fi%
	\fi%
}

% \iref{<label>}{<name>} - Implementation
\newcommand{\word@imp@inline}[4]{\word@ref{\ref{annex:implement}.#1}{#2}{#3}{#4}}
\newcommand{\iref}[2]{% {<label>}{<name>}
	\expandafter\ifx\csname r@imp:#1\endcsname\relax%
		\textbf{[imp:#1] #2}%
		\@latex@warning{Reference '#1' to implementation of '#2' on page
			\thepage\space undefined}%
	\else%
		\ifinline%
			\expandafter\expandafter\expandafter\word@imp@inline\csname r@#1\endcsname%
		\else%
			\expandafter\expandafter\expandafter\word@ref\csname r@imp:#1\endcsname%
		\fi%
	\fi%
}
1329 1330 1331 1332 1333 1334 1335 1336 1337
% =============================================


% ========== Format of Headings ==========

\setcounter{secnumdepth}{4}

\renewcommand{\chapter}{\@startsection
	{chapter}{0}{0pt}{1pt}{\baselineskip}
pknaggs's avatar
pknaggs committed
1338
	{\normalfont\LARGE\sffamily\bfseries}
1339 1340
}
\renewcommand{\chaptermark}[1]{
pknaggs's avatar
pknaggs committed
1341
	\markboth{\textsf{\thechapter. #1}}{}
1342 1343 1344
}
\renewcommand{\section}{\@startsection
	{section}{1}{0pt}{1pt}{1pt}
pknaggs's avatar
pknaggs committed
1345
	{\normalfont\Large\sffamily\bfseries}
1346 1347 1348
}
\renewcommand{\subsection}{\@startsection
	{subsection}{2}{0pt}{1pt}{1pt}
pknaggs's avatar
pknaggs committed
1349
	{\normalfont\large\sffamily\bfseries}
1350 1351 1352
}
\renewcommand{\subsubsection}{\@startsection
	{subsubsection}{3}{0pt}{1pt}{1pt}
pknaggs's avatar
pknaggs committed
1353
	{\normalfont\normalsize\sffamily\bfseries}
1354 1355
}

1356
\newcommand{\annex}[2][\empty]{%
1357 1358
	\refstepcounter{chapter}
	\begin{center}
pknaggs's avatar
pknaggs committed
1359
		\normalfont\Large\sffamily
1360 1361
		{\bfseries Annex \thechapter} \\
		(informative) \\
1362
		{\bfseries #2}
1363
	\end{center}
1364 1365 1366
	\ifx\empty#1 \def\tmp@a{#2}\else\def\tmp@a{#1}\fi
	\chaptermark{\tmp@a}
	\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}\tmp@a}
pknaggs's avatar
pknaggs committed
1367 1368 1369
	%
	% Set up variables for \label
	\def\@currentlabel{\thechapter}%
1370
	\edef\@currentlabelname{\tmp@a}%
1371 1372
}

pknaggs's avatar
pknaggs committed
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
\usepackage{environ}[2008/06/18]

\NewEnviron{editor}{%
	{\color{blue}\fbox{%
	\begin{minipage}{\linewidth}
		\slshape\textbf{Editor:} \par \BODY
	\end{minipage}}}
}


% \@history@label defined/used by history package
pknaggs's avatar
pknaggs committed
1384
\newcommand{\patch}[1]{% {<name>}
pknaggs's avatar
pknaggs committed
1385 1386 1387 1388 1389 1390 1391 1392 1393
	\edef\temp@b{\thepage.#1}
	\ifx\temp@b\@history@label
		% Label already used on this page
		\marginpar{\tiny{\color{white}c:b}}
	\else
		% New label for this page
		\marginpar{\tiny\textsf{#1}{\color{white}c:b}}
		\edef\@history@label{\temp@b}
	\fi
pknaggs's avatar
pknaggs committed
1394 1395
}

pknaggs's avatar
pknaggs committed
1396 1397 1398 1399 1400 1401 1402
\newcommand{\strike}[3][3]{% [<end-space>]{<height>}{<width>}
	\rule{-#3pt}{0pt}%
	\rule[#2pt]{#3pt}{.5pt}%
	\rule[#2pt]{3pt}{.5pt}%
	\rule{-#1pt}{0pt}%
}

1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425
% ========================================

% Modify itemize and enumerate environments

\renewcommand{\labelenumi}{\alph{enumi})}
\renewcommand{\labelenumii}{\arabic{enumii})}

\renewcommand{\labelitemi}{\bfseries --}
\renewcommand{\labelitemii}{\m@th\bullet}

% Reduce space between to \hline commands
\doublerulesep=1pt

\makeatother

% =======================================================
% ==========                                   ==========
% ========== Finally we can start the document ==========
% ==========                                   ==========
% =======================================================

\begin{document}

pknaggs's avatar
pknaggs committed
1426 1427 1428
% \nochangebars\rule{\linewidth}{1pt}\hspace*{-\linewidth}\rule[3pt]{\linewidth}{1pt}

\include{hyphenation}
1429 1430
\include{titlepage}
\thispagestyle{empty}
1431
\def\includefile{}
1432

pknaggs's avatar
pknaggs committed
1433 1434 1435 1436 1437 1438
% Change style of page numbering without changing the page number.
% What used to be \frontmatter is now this crap:

\makeatletter
\cleardoublepage
\@tempcnta = \c@page
1439
\frontmatter
pknaggs's avatar
pknaggs committed
1440 1441 1442
\c@page = \@tempcnta
\makeatother

1443
\setcounter{tocdepth}{2}
pknaggs's avatar
pknaggs committed
1444
{\parskip 0pt \tableofcontents}	\addcontentsline{toc}{chapter}{\contentsname}
pknaggs's avatar
pknaggs committed
1445 1446 1447
%%{\parskip 0pt \listoftables}	\addcontentsline{toc}{chapter}{\listtablename}
%%{\parskip 0pt \listoffigures}	\addcontentsline{toc}{chapter}{\listfigurename}
%%{\parskip 0pt \listofprograms}	\addcontentsline{toc}{chapter}{\listprogramname}
1448

pknaggs's avatar
pknaggs committed
1449
%\newpage
1450 1451
\include{foreword}
\include{foreword-ans}
1452 1453 1454 1455
\include{process}
\include{members-2x}
%\include{members-x3}

pknaggs's avatar
pknaggs committed
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465
% Because some people are unable to handle the concept of sheet
% numbers being different to page numbers we have to bastardise
% the page numbering by preserving the page number between
% the font and main matter, converting page number into sheet
% numbering.
% What used to be \mainmatter is now this crap:

\makeatletter
\cleardoublepage
\@tempcnta = \c@page
1466
\mainmatter
pknaggs's avatar
pknaggs committed
1467 1468
\c@page = \@tempcnta
\makeatother
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483

% Part I: Introduction

\include{intro}
\include{notation}
\include{usage}
\include{doc}
\include{label}

% Part II: Glossary

\raggedbottom
\cfoot{\collate}

\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
pknaggs's avatar
pknaggs committed
1484
\include{core}		% 6
pknaggs's avatar
pknaggs committed
1485
\include{block}		% 7
pknaggs's avatar
pknaggs committed
1486
\include{double}	% 8
pknaggs's avatar
pknaggs committed
1487 1488
\include{exception}	% 9
\include{facility}	% 10
pknaggs's avatar
pknaggs committed
1489
\include{file}		% 11
pknaggs's avatar
pknaggs committed
1490
\include{float}		% 12
pknaggs's avatar
pknaggs committed
1491 1492
\include{locals}	% 13
\include{memory}	% 14
pknaggs's avatar
pknaggs committed
1493
\include{tools}		% 15
pknaggs's avatar
pknaggs committed
1494 1495
\include{search}	% 16
\include{string}	% 17
pknaggs's avatar
pknaggs committed
1496 1497

\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
pknaggs's avatar
pknaggs committed
1498
\include{xchar}		% 18
pknaggs's avatar
pknaggs committed
1499

1500
% Close the deferred output files
pknaggs's avatar
pknaggs committed
1501 1502 1503
\Closesolutionfile{rationale}
\Closesolutionfile{testing}
\Closesolutionfile{implementation}
1504 1505 1506 1507 1508 1509 1510 1511

\flushbottom
\cfoot{}


% Part III: Rational

\appendix
pknaggs's avatar
pknaggs committed
1512
\include{rationale}		% A
1513 1514 1515

% Part IV: Informative background

pknaggs's avatar
pknaggs committed
1516 1517 1518 1519 1520 1521 1522 1523
\include{bib}			% B
%	\include{history}	% C
\include{diff}			% D
\include{port}			% E
\ifrelease\else
	\include{implement}	% F
	\include{testsuite}	% G
\fi
1524

pknaggs's avatar
pknaggs committed
1525 1526 1527
% Close the glossary file
\immediate\closeout\wordfile

1528 1529 1530
% Part V: Index

%\closehistory
pknaggs's avatar
pknaggs committed
1531 1532
\ifrelease\else
	\include{changelog}	% H
1533
\fi
pknaggs's avatar
pknaggs committed
1534
\include{alpha}			% I
1535 1536

\end{document}