% ITF.TeX - Interlinear Text Formatting macros for plain TeX
%   Copyright 1990, 1991 by the Summer Institute of Linguistics, Inc.
%
%   See ``Formatting Interlinear Text'' by Jonathan Kew and Stephen McConnel
%   for instructions on how to use the macros defined in this file.
%
\immediate\write16{%
Interlinear Text Formatter, Version 1.1.10 (March 27, 1991)}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	EDIT HISTORY of ITF.TeX
%
%	Jonathan F. Kew		November 1988 - June 1989
%	Stephen R. McConnel	December 1989 - October 1990
%
%	Version 1.0.0 (16 October 1990)
%		- finally ready to publish and release to the world!
%		  (modulo all the last-minute bug fixes...)
%
%	Version 1.0.6 (8 February 1991) [SRMc]
%		- fix alignment bug in TwoColumn (one free annotation),
%		  ThreeColumn, and MixedColumnFootnote--for \catenateunits{no},
%		  have to allow for space between units (\intlineskip) and
%		  for the difference between \intparskip and \freeparskip
%	Version 1.1.0 (14 February 1991) [SRMc]
%		- empty \F{} produces no output (this allows optional free
%		  annotation)
%	Version 1.1.1 (16 February 1991) [SRMc]
%		- add \showemptyfootnote{yes|no}, controlling whether or not
%		  to show the rule separating footnoted free annotations from
%		  the interlinear text above when they are empty
%	Version 1.1.2 (18 February 1991) [SRMc]
%		- add \freeBparskip and \freeBparindent to independently
%		  control paragraph spacing for the second free annotation
%	Version 1.1.3 (19 February 1991) [SRMc]
%		- fix bug in \setblock_ handling empty \F{}'s
%		- fix bug in applying \freeBparindent
%		- fix bug in \MixedColumnFootnotePageTotal_
%		- handle empty blocks better in \chopnewblocks_
%	Version 1.1.4 (20 February 1991) [SRMc]
%		- fiddle with setblocks_ to make it a bit cleaner
%		- define \addtotokenlist_, to simplify \F
%	Version 1.1.5 (27 February 1991) [SRMc]
%		- fix longstanding bug in alignment following a unit number
%	Version 1.1.6 (March 1, 1991) [SRMc]
%		- fix bug in \selectextrafont: check for valid \freenumber_
%	Version 1.1.7 (March 6, 1991) [SRMc]
%		- use \edef\unitno inside \superscriptnumber and \plainnumber,
%		  rather than \def\unitno.  This makes automatic numbering
%		  much easier.
%	Version 1.1.8 (March 18, 1991) [SRMc]
%		- improve check for (\showemptyfootnote) empty \freeblockX_
%		- parameterize \chopnewblocks_ with (undocumented) \maxperK_,
%		  \minperK_, and \ifrequiresomeofeach_ (defaults=1024,0,false)
%	Version 1.1.9 (March 19, 1991) [SRMc]
%		- handle overfull page resulting from inadequating column
%		  splitting in \chopnewblocks_ with new \overflow_ dimen,
%		  adding it temporarily to \vsize when necessary.  (a test case
%		  was producing 0.24pt too much, which is rather negligible.)
%		- merge \setmygoal_ into \setheights_
%	Version 1.1.10 (March 27, 1991 [SRMc]
%		- define \MyFixBadPageBreak_ and friends
%		- define \space_ and \newlinechar
%		- change \message to \immediate\write16 for all error messages
%		- replace \eject with \safeeject_ to simplify code
%		- revise \chopnewblocks_ again, removing \ifrequiresomeofeach_
%		  and moving page overflow checking to \safeeject_
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Internal variable and macro names all end with a _.  This should
%	prevent name collision with either plain TeX or user-defined macros.
%
\catcode`\_=11
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	REDEFINE SOME MACROS FROM PLAIN.TeX
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	On \bye, we may well need to flush out a partial page of text.
%
\outer\def\bye{\endparagraph\flush_\par\vfill\supereject\end}
%
%%%%%%%%%%%%%%%%%%%%
%
%	Redefine \makeheadline in order to allow variable spacing between the
%	headline and the body of the text.  \makefootline is also redefined.
%
\def\makeheadline{\vbox to 0pt{\vskip-\headergap
    \line{\vbox to 8.5pt{}\the\headline}\vss}\nointerlineskip}
\def\makefootline{\baselineskip\footergap\line{\the\footline}}
%
%%%%%%%%%%%%%%%%%%%%
%
%	\newskip and \newbox need to be non-\outer, because we want to use
%	them inside \setintlinespace_ and \setfreelinespace_
%
\catcode`\@=11
\def\newskip{\alloc@2\skip\skipdef\insc@unt}
\def\newbox{\alloc@4\box\chardef\insc@unt}
\catcode`\@=12
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	GLOBAL VARIABLES USED INTERNALLY BY ITF.TeX
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	\INTcount_ is the total number of interlinear lines declared by
%	the use of \aligning.
%
%	\intline_ is the number of the current interlinear line.
%	\interlinear starts the numbering at 1.
%	0 indicates that we're not handling interlinear text.
%
%	\restoreintline_ and \saveintline_ are used by \[, \], and \< to
%	preserve the value of \intline_ across possibly nested invocations.
%	The initial value of \restoreintline_ must match \interlinear's
%	setting of \intline_.
%	These are used by some of the more obscure TeX code produced by
%	Jonathan Kew.  I'm not sure whether or not having two variables
%	here limits nesting to a depth of two.	- Steve McConnel (?)
%
%	\bracketlevel_ is incremented by \[ and decremented by \] to keep track
%	of nesting depth.
%
%	\numberbracketlevel_ is used by \< and \dounitnumber_ to control the
%	output of unit numbers.	 The initial value is 1 to allow output at
%	the outermost level when \< is not used.
%
%	\firstvisible_ is the number of the first interlinear line that is
%	actually output.  The initial value should be an impossibly large
%	number.
%
%	\FREEcount_ is the total number of free annotation lines declared
%	by use of \freeform.
%
%	\enabledfree_ is the total number of free annotated lines that are
%	output. It must be less than or equal to 2.
%
%	\freeline_ is the number of the current free annotation line.
%	\free starts the numbering at 1.
%	0 means that we're not processing the free annotations.
%	The initial value must match \interlinear's setting.
%
%	\freeseen_ is used by \free, \F, and \checkfreevisibility_ to test
%	whether or not a particular free annotation line is output.
%
%	\freenumber_ is set by \frfontA_ and \frfontB_ and used by
%	\selectextrafont to control the fonts used in printing the free
%	annotation lines.
%
%	\ix_ is set by \aligning, \freeform, \styledfont, and \extrafont, and
%	used by \loadfont_, \setintlinespace_, \setfreelinespace_,
%	\loadstyledfont_, and \loadextrafont_ to create font names for
%	loading the fonts and setting the interline spacing.
%
%	\tmp_ is used as a temporary register by several macros.
%
\newcount\INTcount_ \INTcount_=0
\newcount\intline_ \intline_=0
\newcount\restoreintline_ \restoreintline_=1
\newcount\saveintline_ \saveintline_=0
\newcount\bracketlevel_ \bracketlevel_=0
\newcount\numberbracketlevel_ \numberbracketlevel_=1
\newcount\firstvisible_ \firstvisible_=9999
\newcount\FREEcount_ \FREEcount_=0
\newcount\enabledfree_ \enabledfree_=0
\newcount\freeline_ \freeline_=0
\newcount\freeseen_ \freeseen_=0
\newcount\freenumber_ \freenumber_=0
\newcount\ix_ \ix_=0
\countdef\tmp_=255  % must be \countdef, not \newcount
%
%%%%%%%%%%%%%%%%%%%%
%
%	\omitted_true indicates to \aligning or \free that the current line
%	is to be omitted from the output.  It is set by \loadfont_,
%	\loadfreefont_, \styledfont, and \extrafont.
%
%	\firstunit_true indicates that we're at the very first unit to be
%	output.	 It is reset by \interlinear.
%
%	\visible_true indicates to { and \F that the current line is output.
%	It is set by \checkvisibility_ and \checkfreevisibility_.
%
%	\parend_true is used by \setblock_ to handle the end of a paragraph.
%	It is set by \endparagraph.
%
%	\paragraphbegun_true indicates to \endparagraph that a paragraph has
%	actually been started.	It is set by \newparagraph.
%
%	\notsameordone_true indicates to \styledfont and \extrafont that the
%	desired interlinear or free annotation line has not been found, but
%	that there are still more lines to check.  It is set by \comparenames_.
%
%	\foundfield_true indicates to \styledfont and \extrafont that the
%	desired interlinear or free annotation line has been found.  It is
%	set by \comparenames_.
%
%	\lefthandpage_true indicates that the current output page should be
%	processed as a left-hand page.	It is set by \setleftright_ according
%	to the values of \pageno and \ifoddeven_.
%
%	\twofree_true indicates that two free annotation lines are being
%	output.	 It is set by \freeform.
%
%	\anyfree_true indicates that at least one free annotation line is
%	being output.  It is set by \freeform.
%
%	\catenateunits_true indicates that units are catenated to form
%	paragraphs.  Otherwise, each unit is treated as a ``paragraph'' in
%	its own right.
%
%	\switchfree_true indicates that (when two free annotation lines are
%	output) the free annotation lines switch their relative position
%	from the input to the output.
%
%	\oddeven_true indicates that odd and even pages are treated differently
%	in the output.	The default is to treat them all as right-hand pages.
%
%	\rulecentered_true indicates that the horizontal rule separating the
%	interlinear text from the free annotations should be centered rather
%	than flush left.  This also applies to a horizontal rule separating
%	two free annotation lines.
%
%	\showemptyfootnote_true indicates that the horizontal rule separating
%	the interlinear text from the footnoted free annotation(s) should be
%	shown even if the free annotations are empty for this page.
%
\newif\ifomitted_
\newif\iffirstunit_ \firstunit_true
\newif\ifvisible_
\newif\ifparend_
\newif\ifparagraphbegun_
\newif\ifnotsameordone_
\newif\iffoundfield_
\newif\iflefthandpage_
\newif\iftwofree_ \twofree_false
\newif\ifanyfree_ \anyfree_false
\newif\ifcatenateunits_
\newif\ifswitchfree_
\newif\ifoddeven_
\newif\ifrulecentered_
\newif\ifshowemptyfootnote_
%
%%%%%%%%%%%%%%%%%%%%
%
%	\intblock_ is used to accumulate one `block' of interlinear text.
%
%	\freeblockA_ is used to accumulate one `block' of the first free
%	annotation text, pulling tokens out of \freelistA_ in \setblock_.
%
%	\freeblockB_ is used to accumulate one `block' of the second free
%	annotation text, pulling tokens out of \freelistB_ in \setblock_.
%
%	\intcol_ is used to accumulate interlinear text from \intblock_ and
%	hold it until output.
%
%	\freecolA_ is used to accumulate interlinear text from freeblockA_
%	and hold it until output.
%
%	\freecolB_ is used to accumulate interlinear text from freeblockB_
%	and hold it until output.
%
\newbox\intblock_
\newbox\freeblockA_
\newbox\freeblockB_
\newbox\intcol_
\newbox\freecolA_
\newbox\freecolB_
%
%%%%%%%%%%%%%%%%%%%%
%
%  \freelistA_ is used to accumulate text for the first free annotation line.
%
%  \freelistB_ is used to accumulate text for the second free annotation line.
%
\newtoks\freelistA_
\newtoks\freelistB_
%
%%%%%%%%%%%%%%%%%%%%
%
%	\intwidth_ is the width (horizontal size) of the interlinear text
%	stored in \intblock_ and \intcol_.
%
%	\freewidthA_ is is the width (horizontal size) of the free annotation
%	text stored in \freeblockA_ and \freecolA_.
%
%	\freewidthB_ is is the width (horizontal size) of the free annotation
%	text stored in \freeblockB_ and \freecolB_.
%
%	\intht_ is the height of the interlinear text stored in \intcol_
%	and \intblock_.
%
%	\frAht_ is the height of the free annotation text stored in
%	\freecolA_ and \freeblockA_.
%
%	\frBht_ is the height of the free annotation text stored in
%	\freecolB_ and \freeblockB_.
%
%	\mygoal_ is the desired height of a full page of text to output.
%
%	\mytotal_ is the total height of everything stored thus far.
%	It depends on the page layout style.
%
%	\oldtotal_ is used by the various \...PageTotal_ commands in
%	calculating the current height of stored text.
%
%	\vgaphalf_ is used to hold approximately 0.5 times the value of \vgap.
%
%	\vrulelength_ is the length of the vertical rule that separates two
%	column of text.
%
\newdimen\intwidth_
\newdimen\freewidthA_
\newdimen\freewidthB_
\newdimen\intht_
\newdimen\frAht_
\newdimen\frBht_
\newdimen\mygoal_
\newdimen\mytotal_
\newdimen\oldtotal_
\newdimen\vgaphalf_
\newdimen\vrulelength_
\newdimen\morespaceforA_ \morespaceforA_=0pt
\newdimen\morespaceforB_ \morespaceforB_=0pt
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	MACROS USED INTERNALLY BY ITF.TeX
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Curly braces will be `active' within the interlinear text section
%	only---we want to use them for grouping elsewhere, so we need macros
%	to switch their meaning.  Note that these re-catcodings only happen
%	during actual processing of interlinear text; we can still use braces
%	freely in this file, even for the macros which will be called while
%	braces are active.
%
%	\activebraces_ does not have any arguments.
%	Neither does \groupingbraces_.
%
\def\activebraces_{\global\catcode`\{=\active\global\catcode`\}=\active}
\def\groupingbraces_{\global\catcode`\{=1 \global\catcode`\}=2 }
%
%	We redefine <RETURN> to be the same as a space within interlinear
%	text, so the user can't insert a \par just by leaving a blank line.
%	This should also help \ignorespaces to do the right thing.
%
%	\makereturnspace_ does not have any arguments.
%	Neither does \makereturnreturn_.
%
\def\makereturnspace_{\global\catcode`\^^M=10 }
\def\makereturnreturn_{\global\catcode`\^^M=5 }
%
%%%%%%%%%%%%%%%%%%%%
%
%	These are all used in \ifx tests for comparing against macro
%	parameter strings.
%
%	None of these has an argument.
%
\def\yes_{yes}
\def\no_{no}
\def\empty_{}
\def\OMIT_{OMIT}
%%%%%%%%%%%%%%%%%%%%
%
%	used in \message's and \write's following a macro name to give a space
%
\def\space_{ }
\newlinechar=`\^^J
%%%%%%%%%%%%%%%%%%%%
%
%	Add items to the end of a token list.
%
%	\addtotokenlist_ has two arguments:
%	     1. a token list (declared by \newtoks)
%	     2. stuff to add
%
%%%%	%%%%	%%%%	%%%%	%%%%	%%%%	%%%%	%%%%	%%%%	%%%%
%
%	NOTE: from Knuth, page 374 (Dirty Tricks appendix):
%
%	\expandafter\a\b 					=> \b\c
%
%	\expandafter\expandafter\expandafter\a\expandafter\b\c	=> \c\b\a
%
%	\expandafter\expandafter\expandafter\expandafter
%	\expandafter\expandafter\expandafter\a
%	\expandafter\expandafter\expandafter\b\expandafter\c\d	=> \d\c\b\a
%
%	I'm not sure this information helps, but it's the only thing I've
%	seen that even remotely resembles the code below, which is an
%	adaptation of what Jonathan left behind.  - Steve McConnel
%
%%%%	%%%%	%%%%	%%%%	%%%%	%%%%	%%%%	%%%%	%%%%	%%%%
%
\def\addtotokenlist_#1#2{\global#1=\expandafter
    \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
	{\expandafter\expandafter\expandafter\the\expandafter#1#2}%
}
%
%%%%%%%%%%%%%%%%%%%%
%
%	Load a font for an aligning (interlinear) annotation.
%
%	\loadfont_ has two arguments:
%	     1. the font name (for example, {cmr10} or {OMIT})
%	     2. the font size (for example, {at 10pt} or {scaled 1200})
%
\def\loadfont_#1#2{
    \def\temp{#1}
    \ifx\temp\OMIT_
	\expandafter\let\csname\the\ix_ INTFONT\endcsname\nullfont
	\omitted_true
    \else
	\expandafter\font\csname\the\ix_ INTFONT\endcsname=#1 #2
	\omitted_false
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Load a font for a free annotation.
%
%	\loadfreefont_ has two arguments:
%	     1. the font name (for example, {cmr10} or {OMIT})
%	     2. the type size (for example, {at 10pt} or {scaled 1200})
%
\def\loadfreefont_#1#2{
    \def\temp{#1}
    \ifx\temp\OMIT_
	\expandafter\let\csname\the\FREEcount_ FREEFONT\endcsname\nullfont
	\omitted_true
    \else
	\ifnum\enabledfree_>1
	    \immediate\write16{%
ITF error: no more than two freeform fields can be printed.^^J
Freeform field {\csname\the\FREEcount_ FREENAME\endcsname} (number \the\FREEcount_) will be ignored.}%
	    \expandafter\let\csname\the\FREEcount_ FREEFONT\endcsname\nullfont
	    \omitted_true
	\else
	    \expandafter\font\csname\the\FREEcount_ FREEFONT\endcsname=#1 #2
	    \omitted_false
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Load a "styled" font.
%
%	\loadstyledfont_ has four arguments:
%	     1. field type (either {INT} or {FREE})
%	     2. the style name (for example, {bold} or {large})
%	     3. the font name (for example, {cmr10} or {OMIT})
%	     4. the type size (for example, {at 10pt} or {scaled 1200})
%
\def\loadstyledfont_#1#2#3#4{%
    \expandafter\font\csname#2\the\ix_#1FONT\endcsname=#3 #4
}
%%%%%%%%%%%%%%%%%%%%
%
%	Load an "extra" font.
%
%	\loadextrafont_ has five arguments:
%	     1. field type (either {INT} or {FREE})
%	     2. the tag name of the extra font (for example, {ipa} or {asia})
%	     3. the style name (for example, {bold} or {})
%	     4. the font name (for example, {cmr10} or {OMIT})
%	     5. the type size (for example, {at 10pt} or {scaled 1200})
%
\def\loadextrafont_#1#2#3#4#5{%
    \expandafter\font\csname#3\the\ix_#1FONT#2\endcsname=#4 #5
}
%%%%%%%%%%%%%%%%%%%%
%
%	Define the internal field hook macros.
%
%	\sethooks_ has three arguments:
%	     1. either {INT} or {FREE}
%	     2. TeX code to execute when entering the field
%	     3. TeX code to execute at the end of the field
%
\def\sethooks_#1#2#3{%
    \expandafter\def\csname\the\ix_ Enter#1\endcsname{#2}%
    \expandafter\def\csname\the\ix_ Leave#1\endcsname{#3}%
}
%%%%%%%%%%%%%%%%%%%%
%
%	Set the line spacing for an aligning (interlinear) annotation.
%	Also set up some struts needed for this field.
%
%	\setintlinespace_ has two arguments:
%	     1. the line spacing for the font (for example, {15pt} or {})
%		If this is empty, then 1.2 times the font's quad width is used.
%	     2. style name (for example, {bold} or {})
%
\def\setintlinespace_#1#2{
    \ifomitted_\else
	\def\test{#1}
	\ifx\test\empty_
	    \dimen0=\fontdimen6\csname#2\the\ix_ INTFONT\endcsname
	    \multiply\dimen0 by 12 \divide\dimen0 by 10
	\else
	    \dimen0=#1
	\fi
	\dimen1=\dimen0
	\multiply\dimen0 by 7 \divide\dimen0 by 10
	\multiply\dimen1 by 3 \divide\dimen1 by 10
	\expandafter\newbox\csname#2\the\ix_ INTSTRUTBOX\endcsname
	\expandafter\setbox\csname#2\the\ix_ INTSTRUTBOX\endcsname=\vbox{%
				\hrule height \dimen0 depth \dimen1 width 0pt}%
	\expandafter\ht\csname#2\the\ix_ INTSTRUTBOX\endcsname=\dimen0
	\expandafter\dp\csname#2\the\ix_ INTSTRUTBOX\endcsname=\dimen1
	\expandafter\edef\csname#2\the\ix_ INTSTRUT\endcsname{\expandafter
				\copy\csname#2\the\ix_ INTSTRUTBOX\endcsname}%
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Set the line spacing for a free annotation.
%	Also set up some struts needed for this field.
%
%	\setfreelinespace_ has two arguments:
%	     1. the line spacing for the font (for example, {15pt} or {})
%		If this is empty, then 1.2 times the font's quad width is used.
%	     2. style name (for example, {bold} or {})
%
\def\setfreelinespace_#1#2{
    \ifomitted_\else
	\def\test{#1}
	\ifx\test\empty_
	    \dimen0=\fontdimen6\csname#2\the\ix_ FREEFONT\endcsname
	    \multiply\dimen0 by 12 \divide\dimen0 by 10
	\else
	    \dimen0=#1
	\fi
	\dimen1=\dimen0
	\dimen2=\dimen0
	\multiply\dimen0 by 7 \divide\dimen0 by 10
	\multiply\dimen1 by 3 \divide\dimen1 by 10
	\expandafter\newbox\csname#2\the\ix_ FREESTRUTBOX\endcsname
	\expandafter\setbox\csname#2\the\ix_ FREESTRUTBOX\endcsname=\vbox{%
			    \hrule height \dimen0 depth \dimen1 width 0pt}%
	\expandafter\ht\csname#2\the\ix_ FREESTRUTBOX\endcsname=\dimen0
	\expandafter\dp\csname#2\the\ix_ FREESTRUTBOX\endcsname=\dimen1
	\expandafter\edef\csname#2\the\ix_ FREESTRUT\endcsname{\expandafter
			    \copy\csname#2\the\ix_ FREESTRUTBOX\endcsname}%
	\expandafter\newskip\csname#2\the\ix_ frbaselineskip\endcsname
	\csname#2\the\ix_ frbaselineskip\endcsname=\dimen2
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	This odd-looking line spacing is used in the aligned blocks, because
%	we put struts of the appropriate size into all the boxes, so we really
%	do want them packed together.
%
%	\intlinespacing_ does not have any arguments.
%
\def\intlinespacing_{\baselineskip=0pt \lineskiplimit=1pt \lineskip=1pt}
%
%%%%%%%%%%%%%%%%%%%%
%
%	Insert the horizontal glue between two chunks of interlinear text.
%	The \skip register \interwordskip is the spacing used.	It defaults
%	to twice the word spacing of cmr10.  (See end of file and The
%	TeXbook, page 75.)
%
%	\intspace_ does not have any arguments.
%
\def\intspace_{\hskip\interwordskip}
%
%%%%%%%%%%%%%%%%%%%%
%
%	Check whether the current field of interlinear text is being
%	output or ignored, setting \ifvisible appropriately.
%
%	\checkvisibility_ does not have any arguments.
%
\def\checkvisibility_{% (required %)
    \expandafter\ifx\csname\the\intline_ INTFONT\endcsname\nullfont%
	\visible_false
    \else
	\visible_true
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Check whether the current field of free annotation is being
%	output or ignored, setting \ifvisible appropriately.
%
%	\checkfreevisibility_ does not have any arguments.
%
\def\checkfreevisibility_{% (required %)
    \expandafter\ifx\csname\the\freeseen_ FREEFONT\endcsname\nullfont
	\visible_false
    \else
	\visible_true
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Process a unit number if it's appropriate to do so.
%
%	\dounitnumber_ does not have any arguments.
%
\newdimen\unitnophantomwd_
\def\setunitnophantom_#1{\setbox0=\hbox{#1}\global\unitnophantomwd_=\wd0 }
\def\unitnophantom_{\setbox2=\null \wd2=\unitnophantomwd_ \box2 }
\def\dounitnumber_{% (required %)
    \ifnewnumber
	\ifnum\bracketlevel_=\numberbracketlevel_
	    \ifnum\intline_=\firstvisible_
		\unitno \setunitnophantom_{\unitno}%
	    \else
		\unitnophantom_
	    \fi
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Choose the correct font for the current line of the interlinear text,
%	and generate a strut associated with this font.
%	A warning is generated for undefined styles.
%
%	\selectfont_ does not have any arguments.
%
\def\selectfont_{%
    \expandafter\ifx\csname\itfontstyle\the\intline_ INTFONT\endcsname\relax
	\immediate\write16{%
ITF error: styled font {\itfontstyle} is not defined for aligning field {\csname\the\intline_ INTNAME\endcsname}.^^J
I'm substituting the plain style.}%
	\expandafter\gdef\csname\itfontstyle\the\intline_ INTFONT\endcsname{%
				\csname\the\intline_ INTFONT\endcsname}%
	\expandafter\gdef\csname\itfontstyle\the\intline_ INTSTRUT\endcsname{%
				\csname\the\intline_ INTSTRUT\endcsname}%
    \fi
    \csname\itfontstyle\the\intline_ INTFONT\endcsname
    \csname\itfontstyle\the\intline_ INTSTRUT\endcsname
}
%%%%%%%%%%%%%%%%%%%%
%
%	Set up for beginning a block (paragraph) of text.
%
%	\beginblock_ does not have any arguments.
%
\def\beginblock_{%
    \ifanyfree_
	\freelistA_={}%
	\iftwofree_\freelistB_={}\fi
    \fi
    \setbox\intblock_=\vbox\bgroup\intsize_
    \hrule height 0pt depth 0pt\vfil\hrule height 0pt depth 0pt
    \the\parstyle
}
%%%%%%%%%%%%%%%%%%%%
%
%	Finish off a block (paragraph) of text.
%	This is called prior to \setblock_.
%
%	\endblock_ does not have any arguments.
%
\def\endblock_{\egroup}
%
%%%%%%%%%%%%%%%%%%%%
%
%	Set the baseline skip for a free annotation line.
%
%	\frbaselineA_ and \frbaselineB_ do not have any arguments.
%	\frbaseline_ has one argument:
%		the index number of the current free annotation line
%
\def\frbaselineA_{\ifswitchfree_\frbaseline_{\frB}\else\frbaseline_{\frA}\fi}
\def\frbaselineB_{\ifswitchfree_\frbaseline_{\frA}\else\frbaseline_{\frB}\fi}
\def\frbaseline_#1{%
    \expandafter\ifx\csname\itfontstyle#1frbaselineskip\endcsname\relax
	\immediate\write16{%
ITF error: styled font {\itfontstyle} is not defined for freeform field {\csname#1FREENAME\endcsname}.^^J
I'm substituting the plain style.}%
	\expandafter\gdef\csname\itfontstyle#1frbaselineskip\endcsname{%
				\csname#1frbaselineskip\endcsname}%
    \fi
    \expandafter\baselineskip\csname\itfontstyle#1frbaselineskip\endcsname
}
%%%%%%%%%%%%%%%%%%%%
%
%	Set the paragraph indentation for a free annotation line.
%
%	\freeParindentA_ and \freeParindentB_ do not have any arguments.
%
\def\freeParindentA_{%
\ifswitchfree_\parindent=\freeBparindent\else\parindent=\freeparindent\fi
}
\def\freeParindentB_{%
\ifswitchfree_\parindent=\freeparindent\else\parindent=\freeBparindent\fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Select the field hooks for a free annotation line.
%
%	None of these macros have any arguments.
%
\def\freeEnterA_{%
    \ifswitchfree_
	\csname\frB EnterFREE\endcsname
    \else
	\csname\frA EnterFREE\endcsname
    \fi
}
\def\freeEnterB_{%
    \ifswitchfree_
	\csname\frA EnterFREE\endcsname
    \else
	\csname\frB EnterFREE\endcsname
    \fi
}
\def\freeLeaveA_{%
    \ifswitchfree_
	\csname\frB LeaveFREE\endcsname
    \else
	\csname\frA LeaveFREE\endcsname
    \fi
}
\def\freeLeaveB_{%
    \ifswitchfree_
	\csname\frA LeaveFREE\endcsname
    \else
	\csname\frB LeaveFREE\endcsname
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Select the font for a free annotation line.
%
%	\frfontA_ and \frfontB_ do not have any arguments.
%	\freefont_ has one argument:
%		the index number of the current free annotation line
%
\def\frfontA_{\ifswitchfree_\freefont_{\frB}\else\freefont_{\frA}\fi}
\def\frfontB_{\ifswitchfree_\freefont_{\frA}\else\freefont_{\frB}\fi}
\def\freefont_#1{%
    \freenumber_=#1
    \expandafter\ifx\csname\itfontstyle#1FREEFONT\endcsname\relax
	\expandafter\gdef\csname\itfontstyle#1FREEFONT\endcsname{%
				\csname#1FREEFONT\endcsname}%
    \fi
    \csname\itfontstyle#1FREEFONT\endcsname
}
%%%%%%%%%%%%%%%%%%%%
%
%	Select and place the strut used at the beginning and end of a block
%	of free annotation text.
%
%	\frstrutA_ and \frstrutB_ do not have any arguments.
%	\freestrut_ has one argument:
%		the index number of the current free annotation line
%
\def\frstrutA_{\ifswitchfree_\freestrut_{\frB}\else\freestrut_{\frA}\fi}
\def\frstrutB_{\ifswitchfree_\freestrut_{\frA}\else\freestrut_{\frB}\fi}
\def\freestrut_#1{%
    \expandafter\ifx\csname\itfontstyle#1FREESTRUT\endcsname\relax
	\expandafter\gdef\csname\itfontstyle#1FREESTRUT\endcsname{%
				\csname#1FREESTRUT\endcsname}%
    \fi
    \csname\itfontstyle#1FREESTRUT\endcsname
}
%%%%%%%%%%%%%%%%%%%%
%
%	If at the end of a paragraph, select and place the vertical glue used
%	to separate paragraphs of free annotation text.
%
%	\freeParskipA_ and \freeParskipB_ do not have any arguments.
%
\def\freeParskipA_{\ifparend_
    \ifswitchfree_\vskip\freeBparskip\else\vskip\freeparskip\fi
    \fi
}
\def\freeParskipB_{\ifparend_
    \ifswitchfree_\vskip\freeparskip\else\vskip\freeBparskip\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Set the \hsize and line spacing for the interlinear text, or for
%	text from one of the free annotation lines.
%
%	\intsize_, \freesizeA_, and \freesizeB_ do not have any arguments.
%
\def\intsize_{%
    \baselineskip=0pt\lineskiplimit=0pt\lineskip=\intlineskip\hsize=\intwidth_
}
\def\freesizeA_{\frbaselineA_\hsize=\freewidthA_}
\def\freesizeB_{\frbaselineB_\hsize=\freewidthB_}
%
%%%%%%%%%%%%%%%%%%%%
%
%	Check whether the field name stored in \fieldname matches the one
%	stored for the current line number (\ix_) and field type.
%
%	\comparenames_ has one argument:
%		the field type (either {INT} or {FREE}
%
\def\comparenames_#1{%
    \notsameordone_false
    \expandafter\ifx\csname\the\ix_#1NAME\endcsname\fieldname
	\foundfield_true
    \else
	\expandafter\ifnum\csname#1count_\endcsname=\ix_ \else
	    \notsameordone_true
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	This macro is called when we have a `block' of interlinear text in
%	\box\intblock_, and the token lists for the corresponding free fields
%	in \freelistA_ and \freelistB_.	 This macro must set the free blocks,
%	then measure everything and decide whether to do a page break.	The
%	real work is, of course, delegated to other macros.
%
%	\setblock_ does not have any arguments.
%
\def\setblock_{%
    \ifanyfree_
	%
	% if \freelistA_ is not empty, switch settings
	%  and add it to \freeblockA_
	%
	\setbox0=\hbox{\the\freelistA_}%
	\dimen0=\ht0 \advance \dimen0 by \dp0
	\advance \dimen0 by \wd0
	\ifdim\dimen0=0pt\else
	    \setbox\freeblockA_=\vbox{%
				    \freesizeA_
				    \freeParindentA_
				    \ifdim\morespaceforA_=0pt\else
					\vskip\morespaceforA_
					\global\morespaceforA_=0pt
				    \fi
				    \hrule height0pt depth0pt\vfil
				    \hrule height0pt depth0pt
				    \the\parstyle
				    \ifnewpar\indent\else\noindent\fi
				    \frfontA_
				    \freeEnterA_
				    \frstrutA_
				    \the\freelistA_\unskip
				    \frstrutA_
				    \freeLeaveA_
				    \freeParskipA_
				    }%
	\fi
	\iftwofree_
	    %
	    % if \freelistB_ is not empty, switch settings
	    %  and add it to \freeblockB_
	    %
	    \setbox0=\hbox{\the\freelistB_}%
	    \dimen0=\ht0 \advance \dimen0 by \dp0
	    \advance \dimen0 by \wd0
	    \ifdim\dimen0=0pt\else
		\setbox\freeblockB_=\vbox{%
				    \freesizeB_
				    \freeParindentB_
				    \ifdim\morespaceforB_=0pt\else
					\vskip\morespaceforB_
					\global\morespaceforB_=0pt
				    \fi
				    \hrule height0pt depth0pt\vfil
				    \hrule height0pt depth0pt
				    \the\parstyle
				    \ifnewpar\indent\else\noindent\fi
				    \frfontB_
				    \freeEnterB_
				    \frstrutB_
				    \the\freelistB_\unskip
				    \frstrutB_
				    \freeLeaveB_
				    \freeParskipB_
				    }%
	    \fi
	\fi
    \fi
    \let\beginlist=\relax
    \checkpage_
}
%%%%%%%%%%%%%%%%%%%%
%
%	Examine the amount of space remaining on the page, and the size of
%	the text collected so far, and decide if there is enough to fill the
%	page.  If not, the new blocks are appended to the columns; but if we
%	have a pagefull, then we need to try to break the new blocks at roughly
%	corresponding points.
%
%	\checkpage_ calls \setheights_ to find out how full the page is.  If
%	there is room for the entire new blocks, they are simply appended to
%	the columns.  Otherwise, it chops a proportion off them, and calls
%	\MyOutputPage_.  Note that both \MyPageTotal_ and \MyOutputPage_ are
%	defined by the various layouts to add components appropriately.
%
%	\checkpage_ does not have any arguments.
%
\def\checkpage_{%
    \setheights_
    \ifx\MyOutputPage_\InterMixedOutputPage_
	%
	%  InterMixed page layout is unique...
	%
	\MyOutputPage_
    \else
	%
	%  other layout styles are more complicated, even recursive
	%
	\ifdim\mytotal_>\mygoal_
	    \chopnewblocks_
	    \MyOutputPage_
	    \setbox\intcol_=\vbox{\intsize_}%
	    \ifanyfree_
		\setbox\freecolA_=\vbox{\freesizeA_}%
		\iftwofree_\setbox\freecolB_=\vbox{\freesizeB_}\fi
	    \fi
	    \checkpage_
	\fi
	\appendnewblocks_
	\MyEquateHeights_
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Set \intht_, \frAht_, and \frBht_ to the heights of the respective
%	blocks of text that have been processed and stored.
%	Set \mygoal_ to the additional amount of vertical fill that is
%	needed to complete the current page of output.
%
%	\setheights_ does not have any arguments.
%
\def\setheights_{%
    \intht_=\ht\intcol_ \advance\intht_ by \ht\intblock_
    \ifanyfree_
	\frAht_=\ht\freecolA_ \advance\frAht_ by \ht\freeblockA_
	\iftwofree_
	    \frBht_=\ht\freecolB_ \advance\frBht_ by \ht\freeblockB_
	\fi
    \fi
    \mygoal_=\vsize
    \ifdim\pagetotal=0pt\else
	\advance\mygoal_ by -\pagetotal
	\advance\mygoal_ by -\pagedepth
	\advance\mygoal_ by -\lastskip	% subtract last vertical skip, if any
    \fi
    \MyPageTotal_
}
%%%%%%%%%%%%%%%%%%%%
%
%	Add new blocks of text to the columns.
%
%	\appendnewblocks_ does not have any arguments.
%
\def\appendnewblocks_{%
    \setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\unvbox\intblock_}%
    \ifanyfree_
	\setbox\freecolA_=\vbox{\freesizeA_
				\unvbox\freecolA_\unvbox\freeblockA_}%
	\iftwofree_
	    \setbox\freecolB_=\vbox{\freesizeB_
				\unvbox\freecolB_\unvbox\freeblockB_}%
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Figure out the proportion of the new material which can be fitted on
%	the page, and cut the new blocks at the right places.  If one or more
%	of the chopped blocks has height zero, and the unchopped block does
%	not, we can't fit some of each on this page, so we put the blocks
%	back together and let the page be output `as is'.
%
%	\chopnewblocks_ does not have any arguments.
%
\newdimen\wanted_  % wanted_ = mygoal_ - oldtotal_
\newdimen\got_	   % got_    = mytotal_ - oldtotal_
\newcount\perK_	   % perK_   = wanted_ / (got / 1024)
\newcount\maxperK_ \maxperK_=1024
\newcount\minperK_ \minperK_=0
\newif\ifdidntfit_ % 
\def\chopnewblocks_{%
    \wanted_=\mygoal_\advance\wanted_ by -\oldtotal_
    \got_=\mytotal_\advance\got_ by -\oldtotal_
    \perK_=\wanted_
    \tmp_=\got_
    \divide\tmp_ by 1024
    \ifnum\tmp_>0
	\divide\perK_ by \tmp_
	\ifnum\perK_>\maxperK_\perK_=\maxperK_\fi
	%
	% Chop the blocks, but only if \perK_ > \minperK_
	%
	\ifnum\perK_>\minperK_
	    \intht_=\ht\intblock_
	    \divide\intht_ by 1024\multiply\intht_ by \perK_
	    \setbox3=\copy\intblock_
	    \setbox0=\vsplit\intblock_ to \intht_
	    \setbox0=\vbox{\intsize_\unvbox0}%
	    %
	    % Chop the first free block
	    %
	    \ifanyfree_
		\frAht_=\ht\freeblockA_
		\divide\frAht_ by 1024\multiply\frAht_ by \perK_
		\setbox4=\copy\freeblockA_
		\setbox1=\vsplit\freeblockA_ to \frAht_
		\setbox1=\vbox{\freesizeA_\unvbox1}%
		%
		% And also the second free block
		%
		\iftwofree_
		    \frBht_=\ht\freeblockB_
		    \divide\frBht_ by 1024\multiply\frBht_ by \perK_
		    \setbox5=\copy\freeblockB_
		    \setbox2=\vsplit\freeblockB_ to \frBht_
		    \setbox2=\vbox{\freesizeB_\unvbox2}%
		\fi
	    \fi
	    %
	    %  If we got something of all blocks that are non-empty, we'll
	    %  append them to the columns...  If not, we put them back
	    %  together and leave the columns as they were.
	    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	    % if we split nothing off \intblock_, then restore all the columns
	    % if we split nothing off \freeblockA_ but split everything off
	    %	\intblock_, then restore all the columns
	    % if we split nothing off \freeblockB_ but split everything off
	    %	\intblock_, then restore all the columns
	    %
	    \didntfit_false
	    \ifdim\ht0>0pt\else\ifdim\ht3>0pt \didntfit_true \fi\fi
	    \ifanyfree_ \ifdim\ht1>0pt\else\ifdim\ht4>0pt\ifdim\ht3>0pt\else
		\didntfit_true
	    \fi\fi\fi\fi
	    \iftwofree_ \ifdim\ht2>0pt\else\ifdim\ht5>0pt\ifdim\ht3>0pt\else
		\didntfit_true
	    \fi\fi\fi\fi
	    \ifdidntfit_	% restore blocks if *any* didn't fit at all
		%
		% the blocks MUST be restored EXACTLY, without losing glue
		% at the outer level.  that's why we \copy earlier
		%
		\setbox\intblock_=\box3 \setbox0=\box3
		\ifanyfree_
		    \setbox\freeblockA_=\box4 \setbox1=\box4
		    \iftwofree_ \setbox\freeblockB_=\box5 \setbox2=\box5 \fi
		\fi
	    \else
		%
		% Add what you can to each of the output columns from the
		% temporary holding vboxes 0-2.
		%
		\setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\unvbox0}%
		\ifanyfree_
		    \setbox\freecolA_=\vbox{%
				\freesizeA_\unvbox\freecolA_\unvbox1}%
		    \iftwofree_
			\setbox\freecolB_=\vbox{%
				\freesizeB_\unvbox\freecolB_\unvbox2}%
		    \fi
		    \MyFixBadPageBreak_
		\fi
		%
		% erase box contents we won't be needing
		%
		\setbox6=\box3 \setbox6=\box3 % second time it's void
		\ifanyfree_ \setbox4=\box3 \iftwofree_ \setbox5=\box3 \fi \fi
	    \fi
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Check for special processing of left-hand pages.
%	(Left-hand pages are different only if \oddeven{yes} is set.)
%
%	\setleftright_ does not have any arguments.
%
\def\setleftright_{
    \lefthandpage_false
    \ifoddeven_ \ifodd\pageno\else \lefthandpage_true \fi \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Optionally produce an optionally centered horizontal rule just above
%	the footnote style free annotation(s)
%
%	\intseparationrule_ does not have any arguments.
%
\def\intseparationrule_{%
    \offinterlineskip
    \vskip\vgap%		always have a minimal gap
    \ifdim\hrulewidth>0pt%	produce rule only if nonzero thickness
	\ifdim\hrulelength>0pt
	    \ifrulecentered_
		\hbox to \hsize{\hss%
		    \vbox{\hrule height\hrulewidth width\hrulelength}%
		    \hss}
	    \else
		\hrule height\hrulewidth width\hrulelength
	    \fi
	\else%			"zero" length rule => full width of page
	    \hrule height\hrulewidth
	\fi
	\vskip\vgap%	need gap between rule and free annotation
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Optionally produce an optionally centered horizontal rule between
%	the (footnote style) free annotation(s)
%
%	\freeseparationrule_ does not have any arguments.
%
\def\freeseparationrule_{%
    \ifdim\hfrulewidth>0pt
	\vgaphalf_=\vgap
	\advance\vgaphalf_ by -\hfrulewidth
	\divide\vgaphalf_ by 2
	\vskip\vgaphalf_
	\ifdim\hfrulelength>0pt
	    \ifrulecentered_
		\hbox to \hsize{
			    \hss
			    \vbox{\hrule height\hfrulewidth width\hfrulelength}
			    \hss
			    }
	    \else
		\hrule height\hfrulewidth width\hfrulelength
	    \fi
	\else		    % "zero" length rule => full width of page
	    \hrule height\hfrulewidth
	\fi
	\vskip\vgaphalf_
    \else
	\vskip\vgap
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Keep the blocks in sync for TwoColumn page layout mode.
%	This is only invoked when there is exactly one free annotation.
%
%	\TwoColumnEquateHeights_ does not have any arguments.
%
\def\TwoColumnEquateHeights_{%
    %
    %  find the height of the taller column
    %  if necessary, add glue to \intcol_
    %  otherwise, if necessary, add glue to \freecolA_
    %
    \dimen0=\ht\intcol_
    \ifdim\ht\freecolA_>\dimen0 \dimen0=\ht\freecolA_ \fi
    \ifdim\dimen0>\ht\intcol_
	\dimen1=\dimen0
	\advance\dimen1 by -\ht\intcol_
	\setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\vskip\dimen1}%
    \else\ifdim\dimen0>\ht\freecolA_
	\dimen1=\dimen0
	\advance\dimen1 by -\ht\freecolA_
	\setbox\freecolA_=\vbox{\freesizeA_\unvbox\freecolA_\vskip\dimen1}%
    \fi\fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Keep the blocks in sync for MixedColumnFootnote page layout mode.
%	This applies only the columns, not to the footnote, of course.
%
%	\MixedColumnFootnoteEquateHeights_ does not have any arguments.
%
\def\MixedColumnFootnoteEquateHeights_{%
    %
    %  find the height of the taller column
    %  if necessary, add glue to \intcol_
    %  otherwise, if necessary, add glue to \freecolA_
    %
    \dimen0=\ht\intcol_
    \ifswitchfree_
	\ifdim\ht\freecolB_>\dimen0 \dimen0=\ht\freecolB_ \fi
	\ifdim\dimen0>\ht\intcol_
	    \dimen1=\dimen0
	    \advance\dimen1 by -\ht\intcol_
	    \setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\vskip\dimen1}%
	\else\ifdim\dimen0>\ht\freecolB_
	    \dimen1=\dimen0
	    \advance\dimen1 by -\ht\freecolB_
	    \setbox\freecolB_=\vbox{\freesizeB_\unvbox\freecolB_\vskip\dimen1}%
	\fi\fi
    \else
	\ifdim\ht\freecolA_>\dimen0 \dimen0=\ht\freecolA_ \fi
	\ifdim\dimen0>\ht\intcol_
	    \dimen1=\dimen0
	    \advance\dimen1 by -\ht\intcol_
	    \setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\vskip\dimen1}%
	\else\ifdim\dimen0>\ht\freecolA_
	    \dimen1=\dimen0
	    \advance\dimen1 by -\ht\freecolA_
	    \setbox\freecolA_=\vbox{\freesizeA_\unvbox\freecolA_\vskip\dimen1}%
	\fi\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Keep the blocks in sync for ThreeColumn page layout mode.
%	This means that enough vertical glue is added to each of the two
%	shorter columns to make them as tall as the tallest column.
%
%	\ThreeColumnEquateHeights_ does not have any arguments.
%
\def\ThreeColumnEquateHeights_{%
    %
    %  find the height of the tallest column
    %
    \dimen0=\ifdim\ht\intcol_>\ht\freecolA_ \ht\intcol_ \else \ht\freecolA_ \fi
    \ifdim\ht\freecolB_>\dimen0 \dimen0=\ht\freecolB_ \fi
    %
    %  if necessary, add glue to \intcol_
    %
    \ifdim\dimen0>\ht\intcol_
	    \dimen1=\dimen0
	    \advance\dimen1 by -\ht\intcol_
	\setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\vskip\dimen1}%
    \fi
    %
    %  if necessary, add glue to \freecolA_
    %
    \ifdim\dimen0>\ht\freecolA_
	\dimen1=\dimen0
	\advance\dimen1 by -\ht\freecolA_
	\setbox\freecolA_=\vbox{\freesizeA_\unvbox\freecolA_\vskip\dimen1}%
    \fi
    %
    %  if necessary, add glue to \freecolB_
    %
    \ifdim\dimen0>\ht\freecolB_
	\dimen1=\dimen0
	\advance\dimen1 by -\ht\freecolB_
	\setbox\freecolB_=\vbox{\freesizeB_\unvbox\freecolB_\vskip\dimen1}%
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%  Fix a bad page break/column split for MixedColumnFootnote page layout
%
\def\MixedColumnFootnoteFixBreak_{%
    \ifdim\ht\intblock_=0pt
	\ifdim\ht\freeblockA_>0pt
	    %  all of \intblock_ was added to \intcol_, but not all of
	    %  \freeblockA_ was added to \freecolA_
	    \dimen0=\ht\intcol_ \advance\dimen0 by -\ht\freecolA_
	    \ifdim\dimen0>\ht\freeblockA_
		% there's room, so add rest of \freeblockA_ to \freecolA_
		\setbox\freecolA_=\vbox{\freesizeA_
					\unvbox\freecolA_\unvbox\freeblockA_}%
	    \fi
	\fi
    \else
	\ifdim\ht\freeblockA_=0pt
	    %  all of \freeblockA_ was added to \freecolA_, but not all of
	    %  \intblock_ was added to \intcol_
	    \dimen0=\ht\freecolA_ \advance\dimen0 by -\ht\intcol_
	    \ifdim\dimen0>\ht\intblock_
		% there's room, so add rest of \intblock_ to \intcol_
		\setbox\intcol_=\vbox{\intsize_
					\unvbox\intcol_\unvbox\intblock_}%
	    \fi
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%  Fix a bad page break/column split for TwoColumnFootnote page layout
%
\def\TwoColumnFootnoteFixBreak_{%
    \ifdim\ht\freeblockA_=0pt
	\ifdim\ht\freeblockB_>0pt
	    %  all of \freeblockA_ was added to \freecolA_, but not all of
	    %  \freeblockB_ was added to \freecolB_
	    \dimen0=\ht\freecolA_ \advance\dimen0 by -\ht\freecolB_
	    \ifdim\dimen0>\ht\freeblockB_
		% there's room, so add rest of \freeblockB_ to \freecolB_
		\setbox\freecolB_=\vbox{\freesizeB_
					\unvbox\freecolB_\unvbox\freeblockB_}%
	    \fi
	\fi
    \else
	\ifdim\ht\freeblockB_=0pt
	    %  all of \freeblockB_ was added to \freecolB_, but not all of
	    %  \freeblockA_ was added to \freecolA_
	    \dimen0=\ht\freecolB_ \advance\dimen0 by -\ht\freecolA_
	    \ifdim\dimen0>\ht\freeblockA_
		% there's room, so add rest of \freeblockA_ to \freecolA_
		\setbox\freecolA_=\vbox{\intsize_
					\unvbox\freecolA_\unvbox\freeblockA_}%
	    \fi
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%  Fix a bad page break/column split for ThreeColumn page layout
%
\def\ThreeColumnFixBreak_{%
    \ifdim\ht\intblock_=0pt
	%  all of \intblock_ was added to \intcol_, see how much room we have
	%  to add stuff to \freecolA_ and/or \freecolB_
	\dimen0=\mygoal_ \advance\dimen0 by -\ht\freecolA_
	\ifdim\dimen0<0pt \dimen0=0.01pt \fi
	\dimen1=\mygoal_ \advance\dimen1 by -\ht\freecolB_
	\ifdim\dimen1<0pt \dimen1=0.01pt \fi
	\ifdim\ht\freeblockA_<\dimen0 \ifdim\ht\freeblockB_<\dimen1
	    % add the rest of \freeblockA_ to \freecolA_
	    \ifdim\ht\freeblockA_>0pt
		\setbox\freecolA_=\vbox{\freesizeA_
					\unvbox\freecolA_\unvbox\freeblockA_}%
	    \fi
	    % add the rest of \freeblockB_ to \freecolB_
	    \ifdim\ht\freeblockB_>0pt
		\setbox\freecolB_=\vbox{\freesizeB_
					\unvbox\freecolB_\unvbox\freeblockB_}%
	    \fi
	\fi\fi
    \else\ifdim\ht\freeblockA_=0pt
	%  all of \freeblockA_ was added to \freecolA_, see how much room we
	%  have to add stuff to \intcol_ and/or \freecolB_
	\dimen0=\mygoal_ \advance\dimen0 by -\ht\intcol_
	\ifdim\dimen0<0pt \dimen0=0.01pt \fi
	\dimen1=\mygoal_ \advance\dimen1 by -\ht\freecolB_
	\ifdim\dimen1<0pt \dimen1=0.01pt \fi
	\ifdim\ht\intblock_<\dimen0 \ifdim\ht\freeblockB_<\dimen1
	    % add the rest of \intblock_ to \intcol_
	    \ifdim\ht\intblock_>0pt
		\setbox\intcol_=\vbox{\intsize_
					\unvbox\intcol_\unvbox\intblock_}%
	    \fi
	    % add the rest of \freeblockB_ to \freecolB_
	    \ifdim\ht\freeblockB_>0pt
		\setbox\freecolB_=\vbox{\freesizeB_
					\unvbox\freecolB_\unvbox\freeblockB_}%
	    \fi
	\fi\fi
    \else\ifdim\ht\freeblockB_=0pt
	%  all of \freeblockB_ was added to \freecolB_, see how much room we
	%  have to add stuff to \intcol_ and/or \freecolA_
	\dimen0=\mygoal_ \advance\dimen0 by -\ht\intcol_
	\ifdim\dimen0<0pt \dimen0=0.01pt \fi
	\dimen1=\mygoal_ \advance\dimen1 by -\ht\freecolA_
	\ifdim\dimen1<0pt \dimen1=0.01pt \fi
	\ifdim\ht\intblock_<\dimen0 \ifdim\ht\freeblockA_<\dimen1
	    % add the rest of \intblock_ to \intcol_
	    \ifdim\ht\intblock_>0pt
		\setbox\intcol_=\vbox{\intsize_
					\unvbox\intcol_\unvbox\intblock_}%
	    \fi
	    % add the rest of \freeblockA_ to \freecolA_
	    \ifdim\ht\freeblockA_>0pt
		\setbox\freecolA_=\vbox{\freesizeA_
					\unvbox\freecolA_\unvbox\freeblockA_}%
	    \fi
	\fi\fi
    \fi\fi\fi
}
%%%%%%%%%%%%%%%%%%%%
%
%  Fix a bad page break/column split for FacingPages page layout
%
\def\FacingPagesFixBreak_{%
    \ifdim\ht\intblock_=0pt
	%  all of \intblock_ was added to \intcol_, see how much room we have
	%  to add stuff to \freecolA_ and/or \freecolB_
	\dimen0=\vsize \advance\dimen0 by -\ht\freecolA_
	\ifdim\dimen0<0pt \dimen0=0.01pt \fi
	\dimen1=\vsize \advance\dimen1 by -\ht\freecolB_
	\ifdim\dimen1<0pt \dimen1=0.01pt \fi
	\ifdim\ht\freeblockA_<\dimen0 \ifdim\ht\freeblockB_<\dimen1
	    % add the rest of \freeblockA_ to \freecolA_
	    \ifdim\ht\freeblockA_>0pt
		\setbox\freecolA_=\vbox{\freesizeA_
					\unvbox\freecolA_\unvbox\freeblockA_}%
	    \fi
	    % add the rest of \freeblockB_ to \freecolB_
	    \ifdim\ht\freeblockB_>0pt
		\setbox\freecolB_=\vbox{\freesizeB_
					\unvbox\freecolB_\unvbox\freeblockB_}%
	    \fi
	\fi\fi
    \else\ifdim\ht\freeblockA_=0pt
	%  all of \freeblockA_ was added to \freecolA_, see how much room we
	%  have to add stuff to \intcol_ and/or \freecolB_
	\dimen0=\vsize \advance\dimen0 by\vsize \advance\dimen0 by -\ht\intcol_
	\ifdim\dimen0<0pt \dimen0=0.01pt \fi
	\dimen1=\vsize \advance\dimen1 by -\ht\freecolB_
	\ifdim\dimen1<0pt \dimen1=0.01pt \fi
	\ifdim\ht\intblock_<\dimen0 \ifdim\ht\freeblockB_<\dimen1
	    % add the rest of \intblock_ to \intcol_
	    \ifdim\ht\intblock_>0pt
		\setbox\intcol_=\vbox{\intsize_
					\unvbox\intcol_\unvbox\intblock_}%
	    \fi
	    % add the rest of \freeblockB_ to \freecolB_
	    \ifdim\ht\freeblockB_>0pt
		\setbox\freecolB_=\vbox{\freesizeB_
					\unvbox\freecolB_\unvbox\freeblockB_}%
	    \fi
	\fi\fi
    \else\ifdim\ht\freeblockB_=0pt
	%  all of \freeblockB_ was added to \freecolB_, see how much room we
	%  have to add stuff to \intcol_ and/or \freecolA_
	\dimen0=\vsize \advance\dimen0 by\vsize \advance\dimen0 by -\ht\intcol_
	\ifdim\dimen0<0pt \dimen0=0.01pt \fi
	\dimen1=\vsize \advance\dimen1 by -\ht\freecolA_
	\ifdim\dimen1<0pt \dimen1=0.01pt \fi
	\ifdim\ht\intblock_<\dimen0 \ifdim\ht\freeblockA_<\dimen1
	    % add the rest of \intblock_ to \intcol_
	    \ifdim\ht\intblock_>0pt
		\setbox\intcol_=\vbox{\intsize_
					\unvbox\intcol_\unvbox\intblock_}%
	    \fi
	    % add the rest of \freeblockA_ to \freecolA_
	    \ifdim\ht\freeblockA_>0pt
		\setbox\freecolA_=\vbox{\freesizeA_
					\unvbox\freecolA_\unvbox\freeblockA_}%
	    \fi
	\fi\fi
    \fi\fi\fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Flush whatever is left over on the last page at the end of the file.
%
%	\flush_ does not have any arguments.
%
\def\flush_{%
    \dimen0=\ht\intcol_
    \ifanyfree_
	\advance\dimen0 by \ht\freecolA_
	\iftwofree_ \advance\dimen0 by \ht\freecolB_ \fi
    \fi
    \ifdim\dimen0>0pt
	\ifx\MyOutputPage_\InterMixedOutputPage_
	    \InterMixedFlush_
	\else
	    \MyOutputPage_
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	If necessary, adjust the free translation column(s) to keep aligned
%	with the interlinear column.  This is called from \interlinear.
%	if TwoColumn layout and one free translation,
%		add vertical space to free block A
%	if MixedColumnFootnote layout,
%		if switchfree_, add vertical space to free block B
%		otherwise, add vertical space to free block A
%	if ThreeColumn layout,
%		add vertical space to both free block A and free block B
%
%	\fixfreecolumns_ has one argument:
%		the amount of vertical space being added to the interlinear
%		column.
%		
\def\fixfreecolumns_#1{%
\ifx\MyEquateHeights_\TwoColumnEquateHeights_
    \iftwofree_\else \global\morespaceforA_=#1 \fi
\fi
\ifx\MyEquateHeights_\MixedColumnFootnoteEquateHeights_
    \ifswitchfree_ \global\morespaceforB_=#1\else \global\morespaceforA_=#1\fi
\fi
\ifx\MyEquateHeights_\ThreeColumnEquateHeights_
    \global\morespaceforA_=#1 \global\morespaceforB_=#1
\fi
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	PAGE LAYOUT STYLES
%
%	ITF.TeX supports several page layouts.	The available options vary
%	according to the number of free annotations.  The layouts currently
%	implemented are:
%
%	For NO (ZERO) freeform annotations:
%		OneColumn
%
%	For ONE freeform annotation:
%		InterMixed
%		OneColumnFootnote
%		TwoColumn
%
%	For TWO freeform annotations:
%		InterMixed
%		OneColumnFootnote
%		TwoColumn
%		TwoColumnFootnote
%		ThreeColumn
%		MixedColumnFootnote
%		FacingPages
%
%	These are selected by the user with the \pagelayout{...} macro.
%
%	Each page layout style requires three macros to be defined:
%
%	\...PageTotal_
%		Calculate how much has accumulated on this page.
%		\MyPageTotal_ will be set to the appropriate macro.
%
%	\...OutputPage_
%		Actually output a page in the desired style.
%		\MyOutputPage_ will be set the appropriate macro.
%
%	\...Style_
%		Define parameters for the desired style.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	PageTotal_ MACROS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	PageTotal_ macro for \pagelayout{OneColumn}
%
\def\OneColumnPageTotal_{%
    \mytotal_=\intht_
    \oldtotal_=\ht\intcol_
}
%%%%%%%%%%%%%%%%%%%%
%
%	PageTotal_ macro for \pagelayout{InterMixed}
%
\def\InterMixedPageTotal_{}
%
%%%%%%%%%%%%%%%%%%%%
%
%	PageTotal_ macro for \pagelayout{OneColumnFootnote}
%
\def\OneColumnFootnotePageTotal_{%
    \mytotal_=\intht_
    \ifdim\hrulewidth>0pt
	\advance\mytotal_ by \vgap \advance\mytotal_ by \hrulewidth
    \fi
    \advance\mytotal_ by \vgap \advance\mytotal_ by \frAht_
    \iftwofree_
	\advance\mytotal_ by \vgap \advance\mytotal_ by \frBht_
    \fi
    \oldtotal_=\ht\intcol_
    \ifdim\hrulewidth>0pt
	\advance\oldtotal_ by \vgap \advance\oldtotal_ by \hrulewidth
    \fi
    \advance\oldtotal_ by \vgap \advance\oldtotal_ by \ht\freecolA_
    \iftwofree_
	\advance\oldtotal_ by \vgap \advance\oldtotal_ by \ht\freecolB_
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	PageTotal_ macro for \pagelayout{TwoColumn}
%
\def\TwoColumnPageTotal_{%
    \iftwofree_
	\mytotal_=\frAht_
	\advance\mytotal_ by \frBht_
	\advance\mytotal_ by \vgap
	\advance\mytotal_ by \vgap
	\advance\mytotal_ by \hfrulewidth
	\ifdim\intht_>\mytotal_ \mytotal_=\intht_ \fi
	\oldtotal_=\ht\freecolA_
	\advance\oldtotal_ by \ht\freecolB_
	\advance\oldtotal_ by \vgap
	\advance\oldtotal_ by \vgap
	\advance\oldtotal_ by \hfrulewidth
	\ifdim\ht\intcol_>\oldtotal_ \oldtotal_=\ht\intcol_ \fi
    \else
	\mytotal_=\ifdim\frAht_>\intht_ \frAht_ \else \intht_ \fi
	\oldtotal_=\ifdim\ht\freecolA_>\ht\intcol_
		\ht\freecolA_ \else \ht\intcol_ \fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	PageTotal_ macro for \pagelayout{ThreeColumn}
%
\def\ThreeColumnPageTotal_{%
    \mytotal_=\ifdim\frAht_>\frBht_ \frAht_ \else \frBht_ \fi
    \ifdim\intht_>\mytotal_ \mytotal_=\intht_ \fi
    \oldtotal_=\ifdim\ht\freecolA_>\ht\freecolB_
		\ht\freecolA_ \else\ht\freecolB_\fi
    \ifdim\ht\intcol_>\oldtotal_ \oldtotal_=\ht\intcol_ \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	PageTotal_ macro for \pagelayout{TwoColumnFootnote}
%
\def\TwoColumnFootnotePageTotal_{%
    \mytotal_=\ifdim\frAht_>\frBht_ \frAht_ \else \frBht_ \fi
    \advance\mytotal_ by \intht_ \advance\mytotal_ by \vgap
    \ifdim\hrulewidth>0pt
	\advance\mytotal_ by \vgap \advance\mytotal_ by \hrulewidth
    \fi
    \oldtotal_=\ifdim\ht\freecolA_>\ht\freecolB_
		\ht\freecolA_ \else\ht\freecolB_\fi
    \advance\oldtotal_ by \ht\intcol_ \advance\oldtotal_ by \vgap
    \ifdim\hrulewidth>0pt
	\advance\oldtotal_ by \vgap \advance\oldtotal_ by \hrulewidth
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	PageTotal_ macro for \pagelayout{MixedColumnFootnote}
%
\def\MixedColumnFootnotePageTotal_{%
    \mytotal_=\ifdim\intht_>\frAht_ \intht_ \else \frAht_ \fi
    \ifdim\hrulewidth>0pt
	\advance\mytotal_ by \vgap \advance\mytotal_ by \hrulewidth
    \fi
    \advance\mytotal_ by \vgap
    \advance\mytotal_ by \frBht_
    \oldtotal_=\ifdim\ht\intcol_>\ht\freecolA_
			\ht\intcol_ \else \ht\freecolA_ \fi
    \ifdim\hrulewidth>0pt
	\advance\oldtotal_ by \vgap \advance\oldtotal_ by \hrulewidth
    \fi
    \advance\oldtotal_ by \vgap
    \advance\oldtotal_ by \ht\freecolB_
}
%%%%%%%%%%%%%%%%%%%%
%
%	PageTotal_ macro for \pagelayout{FacingPages}
%
\def\FacingPagesPageTotal_{%
    \mytotal_=\ifdim\frAht_>\frBht_ \frAht_ \else \frBht_ \fi
    \dimen0=\intht_ \divide\dimen0 by 2
    \ifdim\dimen0>\mytotal_ \mytotal_=\dimen0 \fi
    \oldtotal_=\ifdim\ht\freecolA_>\ht\freecolB_
		\ht\freecolA_ \else \ht\freecolB_ \fi
    \dimen0=\ht\intcol_ \divide\dimen0 by 2
    \ifdim\dimen0>\oldtotal_ \oldtotal_=\dimen0 \fi
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	OutputPage_ MACROS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	OutputPage_ macro for \pagelayout{OneColumn}
%
\def\OneColumnOutputPage_{%
    {\offinterlineskip\box\intcol_\vfil}%
    \safeeject_
}
%%%%%%%%%%%%%%%%%%%%
%
%	OutputPage_ macro for \pagelayout{InterMixed}
%	This is different in that it outputs stuff directly rather than
%	building up a page and splitting off stuff when enough accumulates.
%
\newif\iffirstparagraph_ \firstparagraph_true
\def\InterMixedOutputPage_{%
    \bgroup
    \offinterlineskip
    \vgaphalf_=\vgap \divide\vgaphalf_ by 2
    \iffirstparagraph_
        \global\firstparagraph_false
    \else
	\InterMixedGap_{\vgap}{\hrulewidth}{\hrulelength}
    \fi
    \intsize_\unvbox\intblock_
    \ifanyfree_
	\InterMixedGap_{\vgaphalf_}{\hfrulewidth}{\hfrulelength}
	\freesizeA_\unvbox\freeblockA_
    \fi
    \iftwofree_
	\InterMixedGap_{\vgaphalf_}{\hfrulewidth}{\hfrulelength}
	\freesizeB_\unvbox\freeblockB_
    \fi
    \egroup
}
%%%%%%%%%%%%%%%%%%%%
%
%	Produce an appropriate gap and rule for InterMixed output.
%
%	\InterMixedGap_ has three arguments:
%	     1. half the total amount of vertical whitespace wanted
%	     2. thickness of horizontal rule (0pt means none)
%	     3. length of horizontal rule (0pt means width of the page)
%
\def\InterMixedGap_#1#2#3{%
    \nointerlineskip
    \ifdim#2>0pt%	   produce rule only if nonzero thickness
	%
	%  add spacing between the two sections
	%
	\vskip#1
	\ifdim#3>0pt
	    \ifrulecentered_
		\hbox to \hsize{\hss\vbox{\hrule height#2 width#3}\hss}
	    \else
		\hrule height#2 width#3
	    \fi
	\else%		    "zero" length rule => full width of page
	    \hrule height#2
	\fi
	\vskip#1%    need gap between rule and free annotation
    \else
	%
	%  add spacing between the two sections without a rule
	%
	\dimen0=#1
	\multiply\dimen0 by 2
	\vskip\dimen0
    \fi
    \nointerlineskip
}
%%%%%%%%%%%%%%%%%%%%
%
%	Flush the final page of output for InterMixed layout style.
%
\def\InterMixedFlush_{%
    \vfill
    \safeeject_
}
%%%%%%%%%%%%%%%%%%%%
%
%	OutputPage_ macro for \pagelayout{OneColumnFootnote}
%
\def\OneColumnFootnoteOutputPage_{{%  (need both braces)
    \offinterlineskip
    \box\intcol_
    \vfill
    %
    %  if either the height+depth OR the width of the free column(s)
    %	equals zero, then the free column(s) is(are) effectively empty
    %
    \dimen0=\ht\freecolA_ \advance \dimen0 by \dp\freecolA_
    \iftwofree_
	\advance \dimen0 by \ht\freecolB_ \advance \dimen0 by \dp\freecolB_
    \fi
    \ifdim\dimen0=0pt\else\ifdim\wd\freecolA_=0pt
	\iftwofree_
	    \ifdim\wd\freecolB_=0pt
		% empty out \freecolA_ and \freecolB_
		\setbox0=\box\freecolA_\setbox0=\box\freecolA_
		\setbox\freecolA_=\box0
		\setbox\freecolB_=\box0
		\dimen0=0pt
	    \fi
	\else
	    % empty out \freecolA_
	    \setbox0=\box\freecolA_\setbox0=\box\freecolA_
	    \setbox\freecolA_=\box0
	    \dimen0=0pt
	\fi
    \fi\fi
    \ifdim\dimen0=0pt
	\ifshowemptyfootnote_ \intseparationrule_ \fi
    \else
	\intseparationrule_
	\box\freecolA_
	\iftwofree_
	    \dimen0=\ht\freecolB_
	    \advance \dimen0 by \dp\freecolB_
	    \advance \dimen0 by \wd\freecolB_
	    \ifdim\dimen0=0pt
		\ifshowemptyfootnote_ \freeseparationrule_ \fi
	    \else
		\freeseparationrule_
		\box\freecolB_
	    \fi
	\fi
    \fi
    }%
    \safeeject_
}
%%%%%%%%%%%%%%%%
%
%	box up the free column(s) for TwoColumn page layout
%
\def\TwoColumnBoxFree_{%
    \freesizeA_
    \box\freecolA_
    \vfill
    \iftwofree_
	\ifdim\hfrulewidth>0pt
	    \ifdim\hfrulelength>0pt
		\ifrulecentered_
		    \hbox to \freewidthA_{%
			\hss
			\vbox{\hrule height\hfrulewidth width\hfrulelength}%
			\hss }%
		\else
		    \hrule height\hfrulewidth width\hfrulelength
		\fi
	    \else	  % "zero" length rule => full width of column
		\hrule height\hrulewidth width\freewidthA_
	    \fi
	\fi
	\vfill
	\box\freecolB_
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	OutputPage_ macro for \pagelayout{TwoColumn}
%
\def\TwoColumnOutputPage_{{%  (need both braces)
    \offinterlineskip
    \setleftright_
    %
    %  remove any glue at the bottom
    %
    \setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\unskip}%
    \setbox\freecolA_=\vbox{\freesizeA_\unvbox\freecolA_\unskip}%
    \vrulelength_=\ht\freecolA_
    \iftwofree_
	\setbox\freecolB_=\vbox{\freesizeB_\unvbox\freecolB_\unskip}%
	\advance\vrulelength_ by \ht\freecolB_
	\advance\vrulelength_ by \vgap
	\advance\vrulelength_ by \vgap
	\advance\vrulelength_ by \hfrulewidth
    \fi
    \ifdim\ht\intcol_>\vrulelength_ \vrulelength_=\ht\intcol_ \fi
    \iflefthandpage_
	\hbox to \hsize{%
	    \vbox to\mygoal_{\hbox{\vbox to\vrulelength_{%
				\TwoColumnBoxFree_
				}}\vfill}%
	    \hfill
	    \vbox to\mygoal_{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
	    \hfill
	    \vbox to\mygoal_{\hbox{\vbox to\vrulelength_{%
				\intsize_\box\intcol_\vfill
				}}\vfill}%
	    }%
    \else
	\hbox to \hsize{%
	    \vbox to\mygoal_{\hbox{\vbox to\vrulelength_{%
				\intsize_\box\intcol_\vfill
				}}\vfill}%
	    \hfill
	    \vbox to \mygoal_{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
	    \hfill
	    \vbox to\mygoal_{\hbox{\vbox to\vrulelength_{%
				\TwoColumnBoxFree_
				}}\vfill}%
	    }%
    \fi
    \vfill
    }%	       closes brace for \offinterlineskip
    \safeeject_
}
%%%%%%%%%%%%%%%%%%%%
%
%	OutputPage_ macro for \pagelayout{ThreeColumn}
%
\def\ThreeColumnOutputPage_{{%	(need both braces)
    \offinterlineskip
    \setleftright_
    %
    %  remove any glue at the bottom
    %
    \setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\unskip}%
    \setbox\freecolA_=\vbox{\freesizeA_\unvbox\freecolA_\unskip}%
    \setbox\freecolB_=\vbox{\freesizeB_\unvbox\freecolB_\unskip}%
    %
    %  find the median column height for vertical rule length
    %
    \dimen0=\ht\intcol_ \dimen1=\ht\freecolA_ \dimen2=\ht\freecolB_
    \tmp_=0
    \loop
        \advance\tmp_ by 1
        \ifnum\tmp_<3
            \ifdim\dimen0>\dimen\tmp_
                \dimen3=\dimen0 \dimen0=\dimen\tmp_ \dimen\tmp_=\dimen3
            \fi
    \repeat
    \tmp_=1
    \loop
        \advance\tmp_ by 1
        \ifnum\tmp_<3
            \ifdim\dimen1>\dimen\tmp_
                \dimen3=\dimen1 \dimen1=\dimen\tmp_ \dimen\tmp_=\dimen3
            \fi
    \repeat
    \vrulelength_=\dimen1 % median value of three column heights
    \iflefthandpage_
	\hbox to \hsize{%
		\vbox to \mygoal_{\freesizeB_\box\freecolB_\vfill}%
		\hfill
		\vbox to \mygoal_{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
		\hfill
		\vbox to \mygoal_{\freesizeA_\box\freecolA_\vfill}%
		\hfill
		\vbox to \mygoal_{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
		\hfill
		\vbox to \mygoal_{\intsize_\box\intcol_\vfill}%
		}%
    \else
	\hbox to \hsize{%
		\vbox to \mygoal_{\intsize_\box\intcol_\vfill}%
		\hfill
		\vbox to \mygoal_{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
		\hfill
		\vbox to \mygoal_{\freesizeA_\box\freecolA_\vfill}
		\hfill
		\vbox to \mygoal_{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
		\hfill
		\vbox to \mygoal_{\freesizeB_\box\freecolB_\vfill}%
		}%
    \fi
    \vfill
    }%
    \safeeject_
}
%%%%%%%%%%%%%%%%%%%%
%
%	OutputPage_ macro for \pagelayout{TwoColumnFootnote}
%
\def\TwoColumnFootnoteOutputPage_{{%  (need both braces)
    \offinterlineskip
    \setleftright_
    %
    %  remove any glue at the bottoms of the three columns
    %
    \setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\unskip}%
    \setbox\freecolA_=\vbox{\freesizeA_\unvbox\freecolA_\unskip}%
    \setbox\freecolB_=\vbox{\freesizeB_\unvbox\freecolB_\unskip}%
    %
    %  set \dimen0 to the height of the free columns
    %  if either the height+depth OR the width of the free columns
    %	equals zero, then the free columns are effectively empty
    %
    \dimen0=\ht\freecolA_             \advance \dimen0 by \ht\freecolB_
    \advance \dimen0 by \dp\freecolA_ \advance \dimen0 by \dp\freecolB_
    \ifdim\dimen0=0pt\else\ifdim\wd\freecolA_=0pt\ifdim\wd\freecolB_=0pt
	% empty out \freecolA_ and \freecolB_
	\setbox0=\box\freecolA_\setbox0=\box\freecolA_
	\setbox\freecolA_=\box0
	\setbox\freecolB_=\box0
	\dimen0=0pt
    \fi\fi\fi
    \box\intcol_ \vfill
    \ifdim\dimen0=0pt
	\ifshowemptyfootnote_ \intseparationrule_ \fi
    \else
	\intseparationrule_
	\frAht_=\ht\freecolA_ \advance\frAht_ by -\ht\freecolB_
	\frBht_=\ht\freecolB_ \advance\frBht_ by -\ht\freecolA_
	\iflefthandpage_
	    \hbox to \hsize{%
		\vbox{\freesizeB_\box\freecolB_
			\ifdim\frAht_>0pt \kern\frAht_ \fi}%
		\hfill \vrule width \vrulewidth \hfill
		\vbox{\freesizeA_\box\freecolA_
			\ifdim\frBht_>0pt \kern\frBht_ \fi}%
		}%
	\else
	    \hbox to \hsize{%
		\vbox{\freesizeA_\box\freecolA_
			\ifdim\frBht_>0pt \kern\frBht_ \fi}%
		\hfill \vrule width \vrulewidth \hfill
		\vbox{\freesizeB_\box\freecolB_
			\ifdim\frAht_>0pt \kern\frAht_ \fi}%
		}%
	\fi
    \fi
    }%
    \safeeject_
}
%%%%%%%%%%%%%%%%%%%%
%
%	OutputPage_ macro for \pagelayout{MixedColumnFootnote}
%
\def\MixedColumnFootnoteOutputPage_{{%	(need both braces)
    \offinterlineskip
    \setleftright_
    %
    %  remove any glue at the bottoms of the three columns
    %
    \setbox\intcol_=\vbox{\intsize_\unvbox\intcol_\unskip}%
    \setbox\freecolA_=\vbox{\freesizeA_\unvbox\freecolA_\unskip}%
    \setbox\freecolB_=\vbox{\freesizeB_\unvbox\freecolB_\unskip}%
    \ifdim\ht\intcol_>\ht\freecolA_ \intht_=\ht\intcol_
    \else			    \intht_=\ht\freecolA_
    \fi
    %
    %  if either the height+depth OR the width of free column B
    %	equals zero, then free column B is effectively empty
    %
    \dimen0=\ht\freecolB_ \advance \dimen0 by \dp\freecolB_
    \ifdim\dimen0=0pt\else\ifdim\wd\freecolB_=0pt
	% empty out \freecolA_ and \freecolB_
	\setbox0=\box\freecolB_\setbox0=\box\freecolB_
	\setbox\freecolB_=\box0
	\dimen0=0pt
    \fi\fi
    \dimen1=\intht_ \advance\dimen1 by \dimen0
    \ifdim\dimen1>0pt
	%
	%  set the vrule length and output the page
	%
	\vrulelength_=\ht\intcol_
	\ifdim\ht\freecolA_>\vrulelength_\vrulelength_=\ht\freecolA_\fi
	\iflefthandpage_
	    \hbox to \hsize{%
		\vbox to \intht_{\freesizeA_\box\freecolA_\vfill}%
		\hfill
		\vbox to \intht_{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
		\hfill
		\vbox to \intht_{\intsize_\box\intcol_\vfill}%
		}%
	\else
	    \hbox to \hsize{%
		\vbox to \intht_{\intsize_\box\intcol_\vfill}%
		\hfill
		\vbox to \intht_{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
		\hfill
		\vbox to \intht_{\freesizeA_\box\freecolA_\vfill}%
		}%
	\fi
	\vfill
	%
	\ifdim\dimen0=0pt
	    \ifshowemptyfootnote_ \intseparationrule_ \fi
	\else
	    \intseparationrule_
	    \freesizeB_\box\freecolB_
	\fi
    \fi
    }%
    \safeeject_
}
%%%%%%%%%%%%%%%%%%%%
%
%	OutputPage_ macro for \pagelayout{FacingPages}
%
%	This has to be a bit smarter:  it must chop the interlinear block in
%	two.
%
\def\FacingPagesOutputPage_{%
    %
    %  make sure we start on an even page
    %
    \ifdim\pagetotal>0pt \vfill\eject \fi
    \ifodd\the\pageno \line{\hfill}\vfill\eject \fi
    %
    %  try to balance the two pages of aligning annotations
    %
    \mygoal_=\vsize
    \multiply\mygoal_ by 2
    \ifdim\ht\intcol_>\mygoal_
	\setbox0=\vsplit\intcol_ to \vsize
	\setbox1=\vsplit\intcol_ to \vsize  %  maybe a line of overflow?
	\setbox\intblock_=\vbox{\intsize_\unvbox\intcol_\unvbox\intblock_}
    \else
	\mygoal_=\ht\intcol_	% balance the two pages if possible
	\divide\mygoal_ by 2
	\setbox0=\vsplit\intcol_ to \mygoal_
	\setbox1=\vsplit\intcol_ to \mygoal_  %  maybe a line of overflow?
	\setbox\intblock_=\vbox{\intsize_\unvbox\intcol_\unvbox\intblock_}
    \fi
    %
    %  remove any glue at the bottom
    %
    \setbox0=\vbox{\intsize_\unvbox0\unskip}%
    \setbox1=\vbox{\intsize_\unvbox1\unskip}%
    \dimen0=\ht0 \advance\dimen0 by \ht1
    \setbox\freecolA_=\vbox{\freesizeA_\unvbox\freecolA_\unskip}%
    \setbox\freecolB_=\vbox{\freesizeB_\unvbox\freecolB_\unskip}%
    %
    %  set the vrule length and output the first (even) page
    %
    \vrulelength_=\ht0
    \ifdim\ht\freecolA_>\vrulelength_\vrulelength_=\ht\freecolA_\fi
    \hbox to \hsize{%
		\vbox to \vsize{\freesizeA_\box\freecolA_\vfill}%
		\hfill
		\vbox to \vsize{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
		\hfill
		\vbox to \vsize{\intsize_\box0\vfill}%
		}%
    \ifdim\dimen0>0pt \safeeject_ \fi
    %
    %  set the vrule length and output the second (odd) page
    %
    \vrulelength_=\ht1
    \ifdim\ht\freecolB_>\vrulelength_\vrulelength_=\ht\freecolB_\fi
    \hbox to \hsize{%
		\vbox to \vsize{\intsize_\box1\vfill}%
		\hfill
		\vbox to \vsize{\hbox{%
			\vrule width \vrulewidth height \vrulelength_}\vfill}%
		\hfill
		\vbox to \vsize{\freesizeB_\box\freecolB_\vfill}%
		}%
    \ifdim\dimen0>0pt \safeeject_ \fi
}
%%%%%%%%%%%%%%%%%%%%%%%%
%
%  check \pagetotal to decide whether or not a \eject is needed
%  if so, and \pagetotal > \pagegoal, then temporarily adjust \vsize and
%  \pagegoal to fit.  warn the user if more than 1pt of adjustment needed
%
\newdimen\overflow_% amount by which \pagetotal overflows \pagegoal
\def\safeeject_{%
    \ifdim\pagetotal>0pt
	% check that the page fits okay, warn the user if it doesn't
	\global\overflow_=\pagetotal
	\global\advance\overflow_ by -\pagegoal
	\ifdim\overflow_>1pt   % allow up to 1 pt of slop silently
	    \immediate\write16{%
ITF warning: page \the\pageno\space_ is too tall by \the\overflow_}%
	\fi
	\bgroup
	\ifdim\overflow_>0pt \advance\vsize by\overflow_ \pagegoal=\vsize \fi
	\eject
	\egroup
    \fi
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Style_ MACROS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Style_ definition macro for \pagelayout{OneColumn}
%
\def\OneColumnStyle_{%
    \ifanyfree_
	\immediate\write16{%
ITF error: OneColumn page layout cannot handle free translations.^^J
I'm substituting OneColumnFootnote page layout.}%
	\OneColumnFootnoteStyle_
    \else
	\intwidth_=\hsize
	\freewidthA_=0pt
	\freewidthB_=0pt
	\let\MyPageTotal_=\OneColumnPageTotal_
	\let\MyOutputPage_=\OneColumnOutputPage_
	\let\MyEquateHeights_\relax
	\let\MyFixBadPageBreak_=\relax % default is to do nothing
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Style_ definition macro for \pagelayout{InterMixed}
%
\def\InterMixedStyle_{%
    \ifanyfree_
	\intwidth_=\hsize
	\freewidthA_=\hsize
	\freewidthB_=\hsize
	\let\MyPageTotal_=\InterMixedPageTotal_
	\let\MyOutputPage_=\InterMixedOutputPage_
	\let\MyEquateHeights_\relax
	\let\MyFixBadPageBreak_=\relax % default is to do nothing
    \else
	\immediate\write16{%
ITF error: InterMixed page layout requires a free translation.^^J
I'm substituting OneColumn page layout.}%
	\OneColumnStyle_
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Style_ definition macro for \pagelayout{OneColumnFootnote}
%
\def\OneColumnFootnoteStyle_{%
    \ifanyfree_
	\intwidth_=\hsize
	\freewidthA_=\hsize
	\freewidthB_=\hsize
	\let\MyPageTotal_=\OneColumnFootnotePageTotal_
	\let\MyOutputPage_=\OneColumnFootnoteOutputPage_
	\let\MyEquateHeights_\relax
	\let\MyFixBadPageBreak_=\relax % default is to do nothing
    \else
	\immediate\write16{%
ITF error: OneColumnFootnote page layout requires a free translation.^^J
I'm substituting OneColumn page layout.}%
	\OneColumnStyle_
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Style_ definition macro for \pagelayout{TwoColumn}
%
\def\TwoColumnStyle_{%
    \ifanyfree_
	\intwidth_=\hsize
	\divide\intwidth_ by 100
	\multiply\intwidth_ by \intpercent
	\freewidthA_=\hsize
	\advance\freewidthA_ by -\intwidth_
	\advance\freewidthA_ by -\hgap
	\freewidthB_=\freewidthA_
	\let\MyPageTotal_=\TwoColumnPageTotal_
	\let\MyOutputPage_=\TwoColumnOutputPage_
	\iftwofree_
	    \let\MyEquateHeights_\relax
	\else
	    \let\MyEquateHeights_\TwoColumnEquateHeights_
	\fi
	\let\MyFixBadPageBreak_=\relax % default is to do nothing
    \else
	\immediate\write16{%
ITF error: TwoColumn page layout requires a free translation.^^J
I'm substituting OneColumn page layout.}%
	\OneColumnStyle_
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Style_ definition macro for \pagelayout{ThreeColumn}
%
\def\ThreeColumnStyle_{%
    \iftwofree_
	\intwidth_=\hsize
	\divide\intwidth_ by 100
	\multiply\intwidth_ by \intpercent
	\freewidthA_=\hsize
	\advance\freewidthA_ by -\intwidth_
	\divide\freewidthA_ by 2
	\advance\freewidthA_ by -\hgap
	\freewidthB_=\freewidthA_
	\let\MyPageTotal_=\ThreeColumnPageTotal_
	\let\MyOutputPage_=\ThreeColumnOutputPage_
	\let\MyEquateHeights_\ThreeColumnEquateHeights_
	\let\MyFixBadPageBreak_=\ThreeColumnFixBreak_
    \else
	\immediate\write16{%
ITF error: ThreeColumn page layout requires two free translations.}%
	\ifanyfree_
	    \immediate\write16{I'm substituting OneColumnFootnote page layout.}%
	    \OneColumnFootnoteStyle_
	\else
	    \immediate\write16{I'm substituting OneColumn page layout.}%
	    \OneColumnStyle_
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Style_ definition macro for \pagelayout{TwoColumnFootnote}
%
\def\TwoColumnFootnoteStyle_{%
    \iftwofree_
	\intwidth_=\hsize
	\freewidthA_=\hsize
	\advance\freewidthA_ by -\hgap
	\divide\freewidthA_ by 2
	\freewidthB_=\freewidthA_
	\let\MyPageTotal_=\TwoColumnFootnotePageTotal_
	\let\MyOutputPage_=\TwoColumnFootnoteOutputPage_
	\let\MyEquateHeights_\relax
	\let\MyFixBadPageBreak_=\TwoColumnFootnoteFixBreak_
    \else
	\immediate\write16{%
ITF error: TwoColumnFootnote page layout requires two free translations.}%
	\ifanyfree_
	    \immediate\write16{I'm substituting OneColumnFootnote page layout.}%
	    \OneColumnFootnoteStyle_
	\else
	    \immediate\write16{I'm substituting OneColumn page layout.}%
	    \OneColumnStyle_
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Style_ definition macro for \pagelayout{MixedColumnFootnote}
%
\def\MixedColumnFootnoteStyle_{%
    \iftwofree_
	\intwidth_=\hsize
	\divide\intwidth_ by 100
	\multiply\intwidth_ by \intpercent
	\freewidthA_=\hsize
	\advance\freewidthA_ by -\intwidth_
	\advance\freewidthA_ by -\hgap
	\freewidthB_=\hsize
	\let\MyPageTotal_=\MixedColumnFootnotePageTotal_
	\let\MyOutputPage_=\MixedColumnFootnoteOutputPage_
	\let\MyEquateHeights_\MixedColumnFootnoteEquateHeights_
	\let\MyFixBadPageBreak_=\MixedColumnFootnoteFixBreak_
    \else
	\immediate\write16{%
ITF error: MixedColumnFootnote page layout requires two free translations.}%
	\ifanyfree_
	    \immediate\write16{I'm substituting OneColumnFootnote page layout.}%
	    \OneColumnFootnoteStyle_
	\else
	    \immediate\write16{I'm substituting OneColumn page layout.}%
	    \OneColumnStyle_
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Style_ definition macro for \pagelayout{FacingPages}
%
\def\FacingPagesStyle_{%
    \iftwofree_
	\intwidth_=\hsize
	\divide\intwidth_ by 100
	\multiply\intwidth_ by \intpercent
	\freewidthA_=\hsize
	\advance\freewidthA_ by -\intwidth_
	\advance\freewidthA_ by -\hgap
	\freewidthB_=\freewidthA_
	\let\MyPageTotal_=\FacingPagesPageTotal_
	\let\MyOutputPage_=\FacingPagesOutputPage_
	\let\MyEquateHeights_\relax
	\let\MyFixBadPageBreak_=\FacingPagesFixBreak_
    \else
	\immediate\write16{%
ITF error: FacingPages page layout requires two free translations.}%
	\ifanyfree_
	    \immediate\write16{I'm substituting OneColumnFootnote page layout.}%
	    \OneColumnFootnoteStyle_
	\else
	    \immediate\write16{I'm substituting OneColumn page layout.}%
	    \OneColumnStyle_
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	MACROS AND GLOBAL VARIABLES USED BY \ref AND \extr.
%
%	The user might want to rewrite those two macros, so these names are
%	purely alphabetic, rather than ending with an underscore.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	\newnumbertrue indicates to \dounitnumber_ that a unit number is
%	available for output.  It is set by \superscriptnumber and
%	\plainnumber, and reset by \].
%
\newif\ifnewnumber
%
%%%%%%%%%%%%%%%%%%%%
%
%	\newpartrue indicates that the current unit starts a new paragraph.
%	It is set by \extr and reset by \endunit.
%
\newif\ifnewpar
%
%%%%%%%%%%%%%%%%%%%%
%
%	\parstyle is used to build dynamic macro definitions for altering the
%	output styles of various kinds of paragraphs.
%
\newtoks\parstyle \parstyle={}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Start a paragraph of text.
%
%	\newparagraph does not have any arguments.
%
\def\newparagraph{%
    \ifparagraphbegun_
	\errmessage{%
ITF internal error: in \string\newparagraph -- already inside paragraph}%
    \fi
    \the\parstyle
    \global\paragraphbegun_true
    \ifcatenateunits_ \beginblock_ \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Finish a paragraph of text, formatting the paragraph and inserting
%	the extra glue between paragraphs.
%
%	\endparagraph does not have any arguments.
%
\def\endparagraph{%
    \ifparagraphbegun_
	\ifcatenateunits_
	    \vskip \intparskip \endblock_ \parend_true \setblock_ \parend_false
	\else
	    \ifanyfree_
		\ifdim\ht\freecolA_>0pt
			\setbox\freecolA_=\vbox{\freesizeA_\unvbox\freecolA_
				  \ifswitchfree_\vskip\freeBparskip\else
						\vskip\freeparskip\fi}%
		\fi
		\iftwofree_
		    \ifdim\ht\freecolB_>0pt
			\setbox\freecolB_=\vbox{\freesizeB_\unvbox\freecolB_
				  \ifswitchfree_\vskip\freeparskip\else
						\vskip\freeBparskip\fi}%
		    \fi
		\fi
	    \fi
	\fi
    \fi
    \global\paragraphbegun_false
}
%%%%%%%%%%%%%%%%%%%%
%
%	Prepare for centered text.
%
%	\centered does not have any arguments.
%
\def\centered{%
    \leftskip=0pt plus 1fil \rightskip=\leftskip
    \parfillskip=0pt \hyphenpenalty=10000
}
%%%%%%%%%%%%%%%%%%%%
%
%	Prepare for justified text.
%
%	\justified does not have any arguments.
%
\def\justified{%
    \leftskip=0pt \rightskip=\leftskip
    \parfillskip=0pt plus1fil \hyphenpenalty=50
}
%%%%%%%%%%%%%%%%%%%%
%
%	Prepare for ragged right text.
%
%	\unjustified does not have any arguments.
%
\def\unjustified{%
    \leftskip=0pt \rightskip=0pt plus 0.5in
    \parfillskip=0pt plus1fil \hyphenpenalty=50
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  GLOBAL VARIABLES VISIBLE TO (EXPLICITLY SETTABLE BY) THE USER
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	\intpercent is the percentage of the width of the page used for the
%	interlinear text
%
\newcount\intpercent
%
%%%%%%%%%%%%%%%%%%%%
%
%	\intparskip is the amount of extra vertical glue between paragraphs
%	in the interlinear text.
%
%	\interwordskip is the amount of extra horizontal glue between the
%	words (``bundles'') of the interlinear text.
%
%	\intlineskip is the amount of extra vertical glue between the
%	horizontal lines of boxes of interlinear text.
%
%	\freeparskip is the amount of extra vertical glue between paragraphs
%	in the first free annotation.
%
%	\freeBparskip is the amount of extra vertical glue between paragraphs
%	in the second free annotation.
%
\newskip\intparskip
\newskip\interwordskip
\newskip\intlineskip
\newskip\freeparskip
\newskip\freeBparskip
%
%%%%%%%%%%%%%%%%%%%%
%
%	\vrulewidth is the thickness of the vertical rule that separates a
%	column of interlinear text from a column of free annotation.  zero
%	thickness indicates no rule.
%
%	\hrulewidth is the thickness of the horizontal rule that separates a
%	block of interlinear text from the free annotations.  zero thickness
%	indicates no rule.
%
%	\hrulelength is the length of the horizontal rule that separates a
%	block of interlinear text from the free annotations.  zero length
%	indicates the full width of the page.
%
%	\hfrulewidth is the thickness of the horizontal rule that separates
%	two blocks of free annotations in OneColumnFootnote or TwoColumn.
%	zero thickness indicates no rule.
%
%	\hfrulelength is the length of the horizontal rule that separates
%	two blocks of free annotations in OneColumnFootnote or TwoColumn.
%	zero length indicates the full width of the page.
%
%	\headergap is the distance between the baseline of the header and the
%	baseline of the top line of the main body of text on the page.
%
%	\footergap is the distance between the baseline of the footer and the
%	baseline of the bottom line of the main body of text on the page.
%
%	\hgap is the horizontal distance between adjacent columns of text in
%	column page layout styles.
%
%	\vgap is the vertical distance between adjacent blocks of text in
%	footnote page layout styles.
%
%	\intparindent is the paragraph indentation for the interlinear text.
%
%	\freeparindent is the paragraph indentation for the first free
%	annotation.
%
%	\freeBparindent is the paragraph indentation for the seconde free
%	annotation.
%
\newdimen\vrulewidth
\newdimen\hrulewidth
\newdimen\hrulelength
\newdimen\hfrulewidth
\newdimen\hfrulelength
\newdimen\headergap
\newdimen\footergap
\newdimen\hgap
\newdimen\vgap
\newdimen\intparindent
\newdimen\freeparindent
\newdimen\freeBparindent
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	MACROS VISIBLE TO THE OUTSIDE WORLD
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	STYLE CONTROL MACROS
%
%	These would typically be used in an Interlinear Text Style (.ITS)
%	file to control the overall appearance of the output.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Define an aligning (interlinear) annotation line.
%
%	\aligning has six arguments:
%	     1. the name of the aligning annotation field
%	     2. the font name (for example, {cmr10} or {OMIT})
%	     3. the font size (for example, {at 10pt} or {scaled 1200})
%	     4. the line spacing (for example, {15pt} or {})
%	     5. TeX code to invoke when entering the aligning annotation field
%		(for example, {} or {\beginGreek})
%	     6. TeX code to invoke when leaving the aligning annotation field
%		(for example, {} or {\endGreek})
%
\def\aligning#1#2#3#4#5#6{%
    \advance\INTcount_ by 1
    \expandafter\def\csname\the\INTcount_ INTNAME\endcsname{#1}
    \ix_=\INTcount_
    \loadfont_{#2}{#3}
    \sethooks_{INT}{#5}{#6}
    \ifomitted_\else\ifnum\ix_<\firstvisible_ \firstvisible_=\ix_ \fi\fi
    \setintlinespace_{#4}{}
}
%%%%%%%%%%%%%%%%%%%%
%
%	Define a freeform annotation line.
%
%	\freeform has six arguments:
%	     1. the name of the free annotation field
%	     2. the font name (for example, {cmr10} or {OMIT})
%	     3. the font size (for example, {at 10pt} or {scaled 1200})
%	     4. the line spacing (for example, {15pt} or {})
%	     5. TeX code to invoke when entering the free annotation field
%		(for example, {\beginGreek} or {})
%	     6. TeX code to invoke when leaving the free annotation field
%		(for example, {\endGreek} or {})
%
\def\freeform#1#2#3#4#5#6{%
    \advance\FREEcount_ by 1
    \expandafter\def\csname\the\FREEcount_ FREENAME\endcsname{#1}%
    \ix_=\FREEcount_
    \loadfreefont_{#2}{#3}%
    \sethooks_{FREE}{#5}{#6}
    \setfreelinespace_{#4}{}%
    \ifomitted_\else
	\advance\enabledfree_ by 1
	\ifnum\enabledfree_=2
	    \twofree_true
	    \edef\frB{\the\ix_}%
	\else
	    \anyfree_true
	    \edef\frA{\the\ix_}%
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Specify the font (and size) to be used for a particular field in a
%	particular paragraph style.  For this to work, the extraneous field
%	which indicates the paragraph style must define \itfontstyle to be
%	the name of the desired font style; the default is nothing.
%
%	\styledfont has five arguments:
%	     1. the style name
%	     2. the field name this applies to
%	     3. the font to use
%	     4. the size to load the font at
%	     5. the line spacing
%
\def\styledfont#1#2#3#4#5{%
    %
    %  First, search the list of interlinear and free fields to find this
    %  field.  It is an error for it not to exist.
    %
    \omitted_false
    \def\fieldname{#2}%
    \ix_=0\foundfield_false
    \loop \comparenames_{INT}\ifnotsameordone_\advance\ix_ by 1 \repeat
    \iffoundfield_
	\loadstyledfont_{INT}{#1}{#3}{#4}%
	\setintlinespace_{#5}{#1}%
    \else
	\ix_=0
	\loop \comparenames_{FREE}\ifnotsameordone_\advance\ix_ by 1 \repeat
	\iffoundfield_
	    \loadstyledfont_{FREE}{#1}{#3}{#4}%
	    \setfreelinespace_{#5}{#1}%
	\else
	    \immediate\write16{%
ITF error: field {#2} for \string\styledfont{#1} has not been defined by either an \string\aligning{#2} or a \string\freeform{#2} command.^^J
I'm ignoring this \string\styledfont{#1} command.}%
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Set the ITF font style to empty (the default).
%
%	\itfontstyle does not have any arguments.
%
%
\def\itfontstyle{}
%
%%%%%%%%%%%%%%%%%%%%
%
%	Specify the font (and size) to be used for characters borrowed from
%	another font for use with a particular field in a particular style.
%	For this to work, macros must be defined elsewhere by the user to use
%	the extra font to print characters.
%
%	\extrafont has five arguments:
%	     1. the extrafont name
%	     2. the style name
%	     3. the field name this applies to
%	     4. the font to use
%	     5. the size to load the font at
%		(line spacing should already covered by \aligning, \freeform,
%		or \styledfont)
%
\def\extrafont#1#2#3#4#5{%
    %
    %  First, search the list of interlinear and free fields to find this
    %  field.  It is an error for it not to exist.
    %
    \omitted_false
    \def\fieldname{#3}%
    \ix_=0
    \foundfield_false
    \loop \comparenames_{INT}\ifnotsameordone_\advance\ix_ by 1 \repeat
    \iffoundfield_
	\loadextrafont_{INT}{#2}{#1}{#4}{#5}%
    \else
	\ix_=0
	\loop\comparenames_{FREE}\ifnotsameordone_\advance\ix_ by 1 \repeat
	\iffoundfield_
	    \loadextrafont_{FREE}{#2}{#1}{#4}{#5}%
	\else
	    \immediate\write16{%
ITF error: field {#3} for \string\extrafont{#1}{#2} has not been defined by either an \string\aligning{#3} or a \string\freeform{#3} command.^^J
I'm ignoring this \string\extrafont{#1}{#2} command.}%
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Select a font for access to special characters not found in the
%	standard font for the current field.  This handles both "normal" and
%	"styled" paragraphs.
%
%	\selectextrafont has one argument:
%		the extrafont name defined by a prior \extrafont macro.
%
\def\selectextrafont#1{%
    \ifnum\intline_>0
	%
	%  check for the font of an aligning field
	%
	\expandafter
	\ifx\csname\the\intline_ INTFONT\endcsname\nullfont\else
	    \expandafter
	    \ifx\csname#1\the\intline_ INTFONT\itfontstyle\endcsname\relax
		\immediate\write16{%
ITF error: extra font {#1}{\itfontstyle} is not defined for aligning field {\csname\the\intline_ INTNAME\endcsname}.^^J
I'm substituting the plain style.}%
		\expandafter
		\ifx\csname#1\the\intline_ INTFONT\endcsname\relax
		    \immediate\write16{I'm also substituting the normal font.}%
		    \expandafter
		    \gdef\csname#1\the\intline_ INTFONT\itfontstyle\endcsname{%
				\csname\the\intline_ INTFONT\endcsname}%
		\else
		    \expandafter
		    \gdef\csname#1\the\intline_ INTFONT\itfontstyle\endcsname{%
				\csname#1\the\intline_ INTFONT\endcsname}%
		\fi
	    \fi
	    \csname#1\the\intline_ INTFONT\itfontstyle\endcsname
	\fi
    \else\ifnum\freenumber_>0
	%
	%  check for the font of a free annotation field
	%
	\expandafter
	\ifx\csname\the\freenumber_ FREEFONT\endcsname\nullfont\else
	    \expandafter
	    \ifx\csname#1\the\freenumber_ FREEFONT\itfontstyle\endcsname\relax
		\immediate\write16{%
ITF error: extra font {#1}{\itfontstyle} is not defined for freeform field {\csname\the\freenumber_ FREENAME\endcsname}.^^J
I'm substituting the plain style.}%
		\expandafter
		\ifx\csname#1\the\freenumber_ FREEFONT\endcsname\relax
		    \immediate\write16{I'm also substituting the normal font.}%
		    \expandafter
		    \gdef
		    \csname#1\the\freenumber_ FREEFONT\itfontstyle\endcsname{%
				\csname\the\freenumber_ FREEFONT\endcsname}%
		\else
		    \expandafter
		    \gdef
		    \csname#1\the\freenumber_ FREEFONT\itfontstyle\endcsname{%
				\csname#1\the\freenumber_ FREEFONT\endcsname}%
		\fi
	    \fi
	    \csname#1\the\freenumber_ FREEFONT\itfontstyle\endcsname
	\fi
    \fi\fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Select a font set up by prior \aligning, \freeform, and \styledfont
%	commands.  This allows users easy access to switching \itfontstyle
%	temporarily, for example, for typesetting reference numbers.
%
%	\selectitffont does not have any arguments
%
\def\selectitffont{%
    \ifnum\intline_>0 \selectfont_
    \else \ifnum\freenumber_>0 \freefont_{\the\freenumber_}\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Make the values of \intline_ and \freenumber_ visible to the user.
%
%	Neither of these macros has any arguments.
%
\def\intline{\the\intline_}
\def\freeline{\the\freenumber_}
%
%%%%%%%%%%%%%%%%%%%%
%
%	\catenateunits_true indicates that units are catenated to form
%	paragraphs.  Otherwise, each unit is treated as a ``paragraph'' in
%	its own right.
%
%	\catenateunits has one argument:
%		either {yes} or {no}
%
\def\catenateunits#1{
    \def\temp{#1}
    \ifx\temp\yes_ \catenateunits_true \else \catenateunits_false
	\ifx\temp\no_\else
	    \immediate\write16{%
ITF error: Either {yes} or {no} was expected for \string\catenateunits{#1}.^^J
I'll pretend you said {no}.}%
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	\switchfree_true indicates that (when two free annotation lines are
%	output) the free annotation lines switch their relative position
%	from the input to the output.
%
%	\switchfree has one argument:
%		either {yes} or {no}
%
\def\switchfree#1{
    \def\temp{#1}
    \ifx\temp\yes_ \switchfree_true \else \switchfree_false
	\ifx\temp\no_\else
	    \immediate\write16{%
ITF error: Either {yes} or {no} was expected for \string\switchfree{#1}.^^J
I'll pretend you said {no}.}%
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	\oddeven_true indicates that odd and even pages are treated differently
%	in the output.	The default is to treat them all as right-hand pages.
%
%	\oddeven has one argument:
%		either {yes} or {no}
%
\def\oddeven#1{
    \def\temp{#1}
    \ifx\temp\yes_ \oddeven_true \else \oddeven_false
	\ifx\temp\no_\else
	    \immediate\write16{%
ITF error: Either {yes} or {no} was expected for \string\oddeven{#1}.^^J
I'll pretend you said {no}.}%
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	\rulecentered_true indicates that the horizontal rule separating the
%	interlinear text from the free annotations should be centered rather
%	than flush left.  This also applies to a horizontal rule separating
%	two free annotation lines.
%
%	\rulecentered has one argument:
%		either {yes} or {no}
%
\def\rulecentered#1{
    \def\temp{#1}
    \ifx\temp\yes_ \rulecentered_true \else \rulecentered_false
	\ifx\temp\no_\else
	    \immediate\write16{%
ITF error: Either {yes} or {no} was expected for \string\rulecentered{#1}.^^J
I'll pretend you said {no}.}%
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	\showemptyfootnote_true indicates that the horizontal rule separating
%	the interlinear text from the footnoted free annotation(s) should be
%	shown even if the free annotations are empty for this page.
%
%	\showemptyfootnote has one argument:
%		either {yes} or {no}
%
\def\showemptyfootnote#1{
    \def\temp{#1}
    \ifx\temp\yes_ \showemptyfootnote_true \else \showemptyfootnote_false
	\ifx\temp\no_\else
	    \immediate\write16{%
ITF error: Either {yes} or {no} was expected for \string\showemptyfootnote{#1}.^^J
I'll pretend you said {no}.}%
	\fi
    \fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Set the overall page layout style.
%
%	\pagelayout has one argument:
%		the name of the page layout style (for example, {OneColumn}
%		or {FacingPages})
%
\def\pagelayout#1{
    \expandafter\ifx\csname#1Style_\endcsname\relax
	\immediate\write16{%
ITF error: page layout style {#1} is unknown.  Valid styles are:^^J
OneColumn InterMixed OneColumnFootnote TwoColumn TwoColumnFootnote ThreeColumn^^J
MixedColumnFootnote FacingPages}%
	\ifanyfree_
	    \immediate\write16{I'm substituting OneColumnFootnote page layout.}%
	    \OneColumnFootnoteStyle_
	\else
	    \immediate\write16{I'm substituting OneColumn page layout.}%
	    \OneColumnStyle_
	\fi
    \else
	\csname#1Style_\endcsname
    \fi
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	LOW LEVEL INTERLINEAR TEXT MACROS
%
%	These macros are used to mark the actual interlinear and free
%	annotation text.  They may be easier to deal with if generated
%	automatically from some other format by a computer program such
%	as ITFPREP or AMPITF.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Mark the beginning of a unit of text.  If \catenateunits{no}, this
%	starts a block of text to be typeset.  Otherwise, this doesn't do a
%	whole lot.
%
%	\unit does not have any arguments.
%
\def\unit{%
    \makereturnspace_
    \edef\unitno{}%
    \ifcatenateunits_\else\beginblock_\fi
}
%%%%%%%%%%%%%%%%%%%%
%
%	Mark the beginning of the interlinear section of a unit of text.
%
%	\interlinear does not have any arguments.
%
\def\interlinear{%
    \global\intline_=1 \global\freeline_=0
    \global\parindent=\intparindent
    \activebraces_
    \ifnewpar
	\ifcatenateunits_\else\iffirstunit_\else
	    \vskip\intparskip
	    \ifswitchfree_
		\dimen0=\intparskip\advance\dimen0 by -\freeBparskip
	    \else
		\dimen0=\intparskip\advance\dimen0 by -\freeparskip
	    \fi
	    \fixfreecolumns_{\dimen0}\fi\fi
	\indent
    \else
	\ifcatenateunits_\else\iffirstunit_\else
	    \vskip\intlineskip\fixfreecolumns_{\intlineskip}\fi\fi
	\noindent
	\unskip
    \fi
    \ignorespaces
}
%%%%%%%%%%%%%%%%%%%%
%
%	Mark the beginning of a vertically-aligned fragment of interlinear
%	text.
%
%	\[ does not have any arguments.
%
\def\[{%
    \advance\bracketlevel_ by1
    \begingroup
    \intline_=\restoreintline_
    \saveintline_=\intline_
    %
    %  this vbox is closed by the \egroup in \]
    %
    \vbox\bgroup\intlinespacing_\ignorespaces
}
%%%%%%%%%%%%%%%%%%%%
%
%	Mark the beginning of a vertically-aligned fragment within a fragment
%	of vertically-aligned interlinear text.
%
%	\< does not have any arguments.
%
\def\<{%
    \restoreintline_=\intline_
    %
    % this hbox is closed by the \egroup in \>
    %
    \hbox\bgroup
	\interwordskip=0pt
	\numberbracketlevel_=\bracketlevel_ \advance\numberbracketlevel_ by 1
	\ignorespaces
}
%%%%%%%%%%%%%%%%%%%%
%
%	Mark the beginning of a single piece of text from one of the
%	interlinear annotations.
%
%	To define the { and } macros, we need to make braces temporarily
%	active, and use another pair of characters for grouping ... let's
%	use < and >.
%
%	{ does not have any arguments.
%
\begingroup
\catcode`\{=\active \catcode`\}=\active \catcode`\<=1 \catcode`\>=2
\gdef{<%
    \checkvisibility_
    \ifvisible_
	\hbox\bgroup \selectfont_ \dounitnumber_
    \else
	\setbox0=\hbox\bgroup
    \fi
    \ignorespaces
    \ifvisible_ \csname\the\intline_ EnterINT\endcsname \fi
>
%%%%%%%%%%%%%%%%%%%%
%
%	Mark the end of a single piece of text from one of the interlinear
%	annotations.
%
%	} does not have any arguments.
%
\gdef}<%
    \ifvisible_ \csname\the\intline_ LeaveINT\endcsname \fi
    \egroup\ignorespaces
    \global\advance\intline_ by 1
>
\endgroup			% braces/wedges are back to normal
%
%%%%%%%%%%%%%%%%%%%%
%
%	If \+ follows a column, it causes the column to be joined to the
%	following, by removing the intervening space.  This is intended
%	for use in subalignments and for leading punctuation.
%
%	\+ does not have any arguments.
%
\def\+{\unskip\ignorespaces}
%
%%%%%%%%%%%%%%%%%%%%
%
%	Mark the end of a vertically-aligned fragment within a fragment of
%	vertically-aligned interlinear text.
%
%	\> does not have any arguments.
%
\def\>{%
    \egroup%		closes hbox opened in \<
    \ignorespaces
}
%%%%%%%%%%%%%%%%%%%%
%
%	Mark the end of a vertically-aligned fragment of interlinear text.
%
%	\] does not have any arguments.
%
\def\]{%
    %
    %  this closes the vbox opened in \[
    %
    \egroup
    \global\restoreintline_=\saveintline_
    \endgroup
    \advance\bracketlevel_ by-1
    \newnumberfalse
    \intspace_
    \ignorespaces
}
%%%%%%%%%%%%%%%%%%%%
%
%	Mark the end of the interlinear text within a unit, and the beginning
%	of the free annotation text.
%
%	\free does not have any arguments.
%
\def\free{%
    \global\intline_=0 \global\freeline_=1
    \groupingbraces_
    \freeseen_=\freeline_
}
%%%%%%%%%%%%%%%%%%%%
%
%	Accumulate text for the `freeform' fields in token lists freelistA_
%	and freelistB_.	 We can accumulate across several units to form a
%	single paragraph, while interlinear stuff is being accumulated in the
%	\box\intblock_.
%
%	\F has one argument:
%		the text for the unit of a free annotation field.
%
\def\F#1{
    \def\test{#1}%
    \checkfreevisibility_
    \ifvisible_
	\ifnum\freeline_=1
	    \iftwofree_
		\ifswitchfree_
		    \ifx\test\empty_\else
			\addtotokenlist_\freelistB_{\unitno#1}%
		    \fi
		\else
		    \ifx\test\empty_\else
			\addtotokenlist_\freelistA_{\unitno#1}%
		    \fi
		\fi
	    \else
		\ifx\test\empty_\else
		    \addtotokenlist_\freelistA_{\unitno#1}%
		\fi
	    \fi
	\else\ifnum\freeline_=2
	    \iftwofree_
		\ifswitchfree_
		    \ifx\test\empty_\else
			\addtotokenlist_\freelistA_{\unitno#1}%
		    \fi
		\else
		    \ifx\test\empty_\else
			\addtotokenlist_\freelistB_{\unitno#1}
		    \fi
		\fi
	    \else
		\errmessage{%
ITF internal error: in \string\F{} -- too many enabled freeform fields}%
	    \fi
	\else
	    \errmessage{%
ITF internal error: in \string\F{} -- too many enabled freeform fields}%
	\fi\fi
	\advance\freeline_ by 1
    \fi
    \global\advance\freeseen_ by 1
    \ignorespaces
}
%%%%%%%%%%%%%%%%%%%%
%
%	Mark the end of a unit of text.	 If \catenateunits{no}, this ends a
%	block of text to be typeset.  Otherwise, this doesn't do a whole lot.
%
%	\endunit does not have any arguments.
%
\def\endunit{%
    \global\firstunit_false
    \makereturnreturn_
    \ifcatenateunits_\intspace_\else\endblock_\setblock_\fi
    \newparfalse
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	SPECIAL FORMATTING MACROS
%
%	Users may want to rewrite \ref and \extr to fit their texts.
%	This is not for the faint of heart, but neither is it impossible.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Define the default types of reference numbers that are recognized
%	by the \ref macro.
%
%	None of these macros has an argument.
%
\def\chapterref{c}
\def\verseref{v}
\def\unitref{u}
\def\sentenceref{sentence}
%
%%%%%%%%%%%%%%%%%%%%
%
%	The unit reference field (possibly generated from \ref fields in an
%	ITX file) may be used to typeset unit numbers in the text.  The style
%	of number depends on the first argument to the \ref macro.  If the
%	reference type is unrecognized, no number is typeset.
%
%	\ref has two arguments:
%	     1. reference type (for example {v}, {u}, or {sentence})
%	     2. reference number (for example, {1} or {9.7})
%
\def\ref#1#2{%
    \global\let\unitno=\relax
    \def\refmark{#1}%
    \ifx\refmark\chapterref
	\message{#1:#2}\plainnumber{#2.\enspace}%
    \fi
    \ifx\refmark\verseref
	\message{#1:#2}\superscriptnumber{#2}%
    \fi
    \ifx\refmark\unitref
	\message{#1:#2}\plainnumber{#2.\enspace}%
    \fi
    \ifx\refmark\sentenceref
	\message{#1:#2}\plainnumber{[#2]\enspace}%
    \fi
    \ignorespaces
}
%%%%%%%%%%%%%%%%%%%%
%
%	Process the various types of unit reference numbers.
%
%	Each of these macros has one argument:
%		the unit reference number.
%
\def\superscriptnumber#1{\edef\unitno{${}^{#1}$}\newnumbertrue}
\def\plainnumber#1{\edef\unitno{#1}\newnumbertrue}
%
%%%%%%%%%%%%%%%%%%%%
%
%	Define the default types of extraneous field markers that are
%	recognized by the \extr macro.
%
%	None of these macros has an argument.
%
\def\extrp{p}	 % standard paragraph
\def\extrmt{mt}	 % main title
\def\extrst{st}	 % secondary title
\def\extrs{s}	 % section head
\def\extrid{id}	 % ID line --> footer
%
%%%%%%%%%%%%%%%%%%%%
%
%	Paragraphing (\catenateunits{yes}) is possible only if the text
%	includes paragraph markers in extraneous (\extr) fields.  Various
%	types of \extr fields may be recognized, and used to begin different
%	styles of paragraph.
%
%	Unrecognized extraneous fields are totally ignored.
%
%	\extr has two arguments:
%	     1. field type (for example {p}, {nr}, or {id})
%	     2. contents of the extraneous field, if any (for example, {} or
%		{<filename>, <date>, <short description>}
%
\def\extr#1#2{%
    \def\extrmark{#1}%
    \ifx\extrmark\extrmt
	\message{MT}%
	\endparagraph
	\parstyle={\def\itfontstyle{large}\centered}%
	\newparagraph
    \fi
    \ifx\extrmark\extrst
	\message{ST}%
	\endparagraph
	\parstyle={\def\itfontstyle{bold}\centered}%
	\newparagraph
    \fi
    \ifx\extrmark\extrs
	\message{S}%
	\endparagraph
	\parstyle={\def\itfontstyle{bold}\unjustified}%
	\newparagraph
    \fi
    \ifx\extrmark\extrp
	\message{P}%
	\endparagraph
	\parstyle={\def\itfontstyle{}\unjustified}%
	\newpartrue
	\newparagraph
    \fi
%
%	Plain TeX defaults to page numbers centered at the bottom of the
%	page.  We change this if \extr{id} is found.
%
    \ifx\extrmark\extrid
	\message{ID}%
	\footline={\tenrm #2\hfill Page \folio}%
    \fi
%
%	anything else is *truly* extraneous...
%
    \ignorespaces
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	DEFAULT VARIABLE SETTINGS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Set a number of plain TeX parameters to the initial values we want
%
\hsize=6.5in
\vsize=8.9in
\hoffset=0pt
\voffset=0pt
\pretolerance=100
\tolerance=10000
\hbadness=5000
\vbadness=1000
\hyphenpenalty=50
\exhyphenpenalty=50
\clubpenalty=0
\widowpenalty=0
\brokenpenalty=0
\doublehyphendemerits=0
\finalhyphendemerits=0
\adjdemerits=0
\hfuzz=0.1pt
\vfuzz=0.1pt
\overfullrule=5pt
\boxmaxdepth=0pt
\leftskip=0pt plus 0pt minus 0pt
\rightskip=0pt plus 0pt minus 0pt
\topskip=0pt plus 0pt minus 0pt
\showboxbreadth=0
\showboxdepth=0
\tracingstats=1			% find out how close to the limits we are
\unjustified			% set up for ragged-right by default
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Set the default ITF layout parameters.
%
\intpercent=70
\catenateunits{no}
\switchfree{no}
\oddeven{no}
\rulecentered{no}
\showemptyfootnote{yes}
\interwordskip=6.66666pt plus 3.33333pt minus 2.22222pt
\intlineskip=8pt plus 0pt minus 0pt
\intparskip=12pt plus 0pt minus 0pt
\intparindent=20pt
\freeparskip=2pt plus 0pt minus 0pt
\freeBparskip=2pt plus 0pt minus 0pt
\freeparindent=20pt
\freeBparindent=20pt
\vgap=1pc
\vrulewidth=0.4pt
\hgap=1pc
\hrulewidth=0.4pt
\hrulelength=0pt
\hfrulewidth=0pt
\hfrulelength=0pt
\headergap=22.5pt
\footergap=24.0pt
%
\anyfree_true \pagelayout{TwoColumn} \anyfree_false
\catcode`\_=8
