;
;    $Id: report2html1.xom 1.8 1996/09/04 18:23:19 rwm Exp $
;
down-translate
;
include "library.xom"
;
;   Global Shelf Declarations
;
global counter acrocount variable
global stream acrodefn variable
global stream acronyms variable
global stream acrostream
global switch articleswitch
global switch authorswitch
global switch bookswitch
global counter chapterfilenumber
global switch citedpgnoswitch
global switch collectionswitch
global stream collectiontitle
global switch collectiontitleswitch
global counter cols
global switch commaspaceswitch
global switch confprocswitch
global switch congressswitch
global switch committeeswitch
global switch communicationswitch
global counter curcol
global counter curftnote
global switch dateswitch
global switch docnumswitch
global stream doctitle
global switch editionswitch
global switch editorswitch
global switch emediaswitch
global counter figurenumber
global stream figurestream
global counter ftnotenumber
global stream ftnotestream
global switch incluspgnosswitch
global switch issueswitch
global switch journalswitch
global switch numswitch
global switch partswitch
global switch placeswitch
global switch publisherswitch
global stream referelem variable
global counter refernumber
global switch refererror
global stream referfile
global stream referstream variable
global switch repseriesswitch
global switch reptswitch
global stream rulerow
global switch sect1author
global stream sect1authors variable
global counter sect1number
global counter sect2number
global counter sect3number
global counter sect4number
global counter sect5number
global counter sect6number
global stream sectionstream
global stream sourcestream variable
global switch spannedrules
global switch statusfinal
global stream tabalign variable
global stream tabbodyvalign
global stream tabchar variable
global stream tabcolname variable
global counter tabcolnum variable
global stream tabcolsep variable
global stream tabcolwidth variable
global stream tabfootvalign
global stream tabframe variable
global stream tabheadvalign
global counter tabhspan variable
global counter tableftnotenumber
global stream tableftnotestream variable
global stream tableftnotereferencestream variable
global counter tablenumber
global stream tablestream
global stream taborient variable
global stream tabpgwide variable
global stream tabrotate variable
global stream tabrowsep variable
global stream tabvalign variable
global counter tabvspan variable
global counter tgroupnumber
global switch thesisswitch
global switch titleswitch
global switch univswitch
global switch volumeswitch
;
translate "%n"        ; Make all carriage returns dependent upon output
    output "%/%s_"     ;   statements
;
break-width 72
;
replacement-break "%_" "%n"
;
macro
    add-refer-element(
arg
    pretext,
arg
    elem,
arg
    posttext,
arg
    elemswitch)
is
    do when stream referelem has key elem
        put referstream ", " when active commaspaceswitch
            put referstream pretext
        using stream referelem key elem
            put referstream "%g(referelem)"
            put referstream posttext
        activate commaspaceswitch
        deactivate elemswitch
    done
macro-end
;
macro
    copy-table-attributes(
arg
    previous)
is
    new stream tabalign
    set buffer tabalign to stream tabalign item previous
    new stream tabchar
    set buffer tabchar to stream tabchar item previous
    new stream tabcolname
    set buffer tabcolname to stream tabcolname item previous
    new counter tabcolnum
    reset tabcolnum to counter tabcolnum item previous
    new stream tabcolsep
    set buffer tabcolsep to stream tabcolsep item previous
    new stream tabcolwidth
    set buffer tabcolwidth to stream tabcolwidth item previous
    new stream tabframe
    set buffer tabframe to stream tabframe item previous
    new counter tabhspan
    reset tabhspan to counter tabhspan item previous
    new stream taborient
    set buffer taborient to stream taborient item previous
    new stream tabpgwide
    set buffer tabpgwide to stream tabpgwide item previous
    new stream tabrotate
    set buffer tabrotate to stream tabrotate item previous
    new stream tabrowsep
    set buffer tabrowsep to stream tabrowsep item previous
    new stream tabvalign
    set buffer tabvalign to stream tabvalign item previous
    new counter tabvspan
    reset tabvspan to counter tabvspan item previous
macro-end
;
macro
    load-referelem(
arg
    elem)
is
    do when stream referelem has key elem
     ;   using referelem key elem om3632 if want to fix this
     ;   do
            reopen referelem key elem as buffer
            put referelem key elem ", %c"
            close referelem key elem
      ;  done
    else
        new stream referelem key elem
        set buffer referelem to "%c"
    done
macro-end
;
macro
    process-refer
is
    do
;when attribute style is equal ul "chicagob"
        do when active (articleswitch and collectionswitch)
            reopen referstream as buffer
            add-refer-element("","author","",authorswitch)
            add-refer-element("","title","",titleswitch)
            add-refer-element("","collectiontitle","",collectiontitleswitch)
            add-refer-element("","editor","",editorswitch)
            add-refer-element("","publisher","",publisherswitch)
            add-refer-element("","place","",placeswitch)
            add-refer-element("","incluspgnos","",incluspgnosswitch)
            add-refer-element("","date","",dateswitch)
            deactivate articleswitch
            deactivate collectionswitch
            close referstream
        done
        do when active bookswitch
            reopen referstream as buffer
            add-refer-element("","author","",authorswitch)
            add-refer-element("","title","",titleswitch)
            add-refer-element("","edition","",editionswitch)
            add-refer-element("","editor","",editorswitch)
            add-refer-element("","publisher","",publisherswitch)
            add-refer-element("","place","",placeswitch)
            add-refer-element("","date","",dateswitch)
            deactivate bookswitch
            close referstream
        done
        do when active communicationswitch
            reopen referstream as buffer
            add-refer-element("","communication","",communicationswitch)
            deactivate communicationswitch
            close referstream
        done
        do
;when active reptswitch
            reopen referstream as buffer
            add-refer-element("","author","",authorswitch)
            deactivate commaspaceswitch when active dateswitch
            add-refer-element(" ","date",". ",dateswitch)
            deactivate commaspaceswitch when active titleswitch
            add-refer-element("<i>","title","</i>",titleswitch)
            add-refer-element("","docnum","",docnumswitch)
            add-refer-element("","publisher","",publisherswitch)
            add-refer-element("","place","",placeswitch)
            deactivate reptswitch
            close referstream
        done
    done
    deactivate refererror
    do when active refererror
        halt
    done
macro-end
;
macro
    remove-table-attributes
is
    remove stream tabalign
    remove stream tabchar
    remove stream tabcolname
    remove counter tabcolnum
    remove stream tabcolsep
    remove stream tabcolwidth
    remove stream tabframe
    remove counter tabhspan
    remove stream taborient
    remove stream tabpgwide
    remove stream tabrotate
    remove stream tabrowsep
    remove stream tabvalign
    remove counter tabvspan
macro-end
;
macro
    remove-table-colspec-attributes
is
    repeat
        remove-table-attributes
    exit when number of stream tabalign is equal 2
    again
macro-end
;
document-start
    open acrostream as "ac.htm" 
    open ftnotestream with referents-allowed as "ftnotes.htm"
    put ftnotestream "<html><head><title>Footnotes</title></head><body><DL>%n"
;
    clear stream referstream
    clear stream tableftnotestream
    clear stream tableftnotereferencestream
    activate statusfinal
;
;   Set table default attributes
;
    set buffer tabalign to "left"
    set buffer tabchar to "."
    set buffer tabcolname to ""
    reset tabcolnum to 0
    set buffer tabcolsep to "no"
    set buffer tabcolwidth to "0pt"
    set buffer tabframe to "none"
    reset tabhspan to 1
    set buffer taborient to "portrait"
    set buffer tabpgwide to "no"
    set buffer tabrotate to "no"
    set buffer tabrowsep to "no"
    set buffer tabvalign to "top"
    reset tabvspan to 0
;
document-end
    close acrostream
;
;   Handle the footnote listing
;
    put ftnotestream "</DL>%n<PRE><a HREF = %"<instancename>.htm%">%n"
    put ftnotestream
        "<img SRC =%n%"/library/icons/butn2_menu.gif%">%n"
    put ftnotestream "</a></PRE>%n"
    put ftnotestream "</body></html>%n"
    close ftnotestream
;
element abstract when parent is front
    set referent "cfn%d(chapterfilenumber)" to
        "<a HREF = %"abstract.htm%">" _
        "<img SRC = %"/library/icons/blueball.gif%"> ABSTRACT </a><br>%n"
    output "<a HREF = %"abstract.htm%"  NAME = " _
        "%"preface%">ABSTRACT</a><p>%n"
;
;   Open stream to contain the whole abstract.htm file
;
    open sectionstream with referents-allowed as
        "abstract.htm" 
    put sectionstream "<html><head>"
    put sectionstream "<a NAME=%"abstract%"><title>ABSTRACT</title>%n"
    put sectionstream "<h1>ABSTRACT</h1>"
    increment chapterfilenumber
    put sectionstream "%c"
    put sectionstream referent "cfn%d(chapterfilenumber)"
    set referent "cfn%d(chapterfilenumber)" to "<br>"
    put sectionstream "<a HREF = %"<instancename>.htm#abstract%">%n"
    put sectionstream
        "<img SRC =%"/library/icons/blueball.gif%"> Contents "
    put sectionstream "</a><p>%n"
    put sectionstream "</body></html>%n"
    close sectionstream
    reset figurenumber to 1
    reset tablenumber to 1
;
element abstract when parent is sect1
    local counter temp
    do when active sect1author
        output "<p>%g(sect1authors)</p>%n"
            when number of stream sect1authors is equal 1
        do when number of stream sect1authors is equal 2
            using stream sect1authors item 1
                output "<p>%g(sect1authors) and "
            output "%g(sect1authors)</p>"
        done
        do when number of stream sect1authors is greater-than 2
            reset temp to 2
            output "<p>"
            repeat over stream sect1authors
                output "%g(sect1authors)"
                output ", "
                    when counter temp is less-than number of stream sect1authors
                output ", and "
                    when counter temp is equal number of stream sect1authors
                output "</p>%n"
                    when counter temp is greater-than number of stream sect1authors
                increment temp
            again
        done
        deactivate sect1author
    done
    output "<h3>ABSTRACT</h3><p>%n"
    output "%c"
;
element acknowl
    set referent "cfn%d(chapterfilenumber)" to
        "<a HREF = %"acknowl.htm%">" _
        "<img SRC = %"/library/icons/blueball.gif%"> ACKNOWLEDGMENTS </a><br>%n"
    output "<a HREF = %"acknowl.htm%"  NAME = " _
        "%"preface%">ACKNOWLEDGMENTS</a><p>%n"
;
;   Open stream to contain the whole acknowl.htm file
;
    open sectionstream with referents-allowed as
        "acknowl.htm" 
    put sectionstream "<html><head>"
    put sectionstream "<a NAME=%"acknowl%"><title>ACKNOWLEDGMENTS</title>%n"
    put sectionstream "<h1>ACKNOWLEDGMENTS</h1>"
    increment chapterfilenumber
    put sectionstream "%c"
    put sectionstream referent "cfn%d(chapterfilenumber)"
    set referent "cfn%d(chapterfilenumber)" to "<br>"
    put sectionstream "<a HREF = %"<instancename>.htm#acknowl%">%n"
    put sectionstream
        "<img SRC =%"/library/icons/blueball.gif%"> Contents "
    put sectionstream "</a><p>%n"
    put sectionstream "</body></html>%n"
    close sectionstream
    reset figurenumber to 1
    reset tablenumber to 1
;
element acro-defn
    new stream acronyms key "%v(ID)"
    new stream acrodefn key "%v(ID)"
    new counter acrocount key "%v(ID)"
    reset acrocount to 0
    output "%c"
    put acrostream "<1>%10fv(ID)<2>%10fg(acronyms)<3>%g(acrodefn)<4>%n"
;
element acro-ref when ancestor isnt table
    suppress
        using counter acrocount key "%v(idref)"
            do
                increment acrocount
                output "<A HREF=%"ac.htm#%v(IDREF)%" TARGET = %"acros%">"
                    when counter acrocount is equal 1
                using stream acronyms key "%v(idref)"
                    output "%g(acronyms)"
                output "</a>" when counter acrocount is equal 1
            done
;
element acro-ref when ancestor is table
    suppress
    using stream acronyms key "%v(idref)"
        output "%g(acronyms)"
;
element acrolist
    output "%c"
;
element acronym
    set buffer acronyms to "%c"
;
element appendix when parent is back
;
; The previous chapter put out a reference to its successor when it didn't
;  know its successor's name.  so it used a referent.  Now we know what the
;  successor is--we are processing it--so fill in the referent.
;
    set referent "cfn%d(chapterfilenumber)" to
        "<a HREF = %"ap-%ua(sect1number).htm%">%n" _
        " <img SRC = %"/library/icons/blueball.gif%"> Appendix %ua(sect1number) </a><br>%n"
;
;   Reset acronyms
;
    repeat over counter acrocount
        reset acrocount to 0 
    again
;
;   Open stream to contain the whole <chapter>.htm file
;
    do when attribute ID is specified
        set referent "%lv(ID)" to "%lv(ID)"
        set referent "f-%lv(ID)" to "ap-%ua(sect1number).htm#"
        set referent "ap-%lv(ID)" to "%ua(sect1number). "
    done
    open sectionstream with referents-allowed as
        "ap-%ua(sect1number).htm" 
    put sectionstream "<html><head>"
    do when counter chapterfilenumber is greater-equal 1000
        reset chapterfilenumber to 0
    done
    increment chapterfilenumber
    put sectionstream "%c"
;
; Put out the reference to the succeeding chapter even though we don't know
;  what it is yet.
;
    put sectionstream referent "cfn%d(chapterfilenumber)"
    set referent "cfn%d(chapterfilenumber)" to "<br>"
    put sectionstream "<a HREF = %"<instancename>.htm#ap-%ua(sect1number)%">%n"
    put sectionstream
        "<img SRC =%"/library/icons/blueball.gif%"> Contents "
    put sectionstream "</a><p>%n"
    put sectionstream "</body></html>%n"
    close sectionstream
    increment sect1number
    reset sect2number
    reset figurenumber
    reset tablenumber
;
element article when parent is refer
    activate articleswitch
    output "%c"
;
element author when ancestor is refer
    activate authorswitch
    load-referelem("author")
;
element author when parent is sect1
    activate sect1author
    new stream sect1authors
    set buffer sect1authors to "%c"
;
element author when parent is titleblk
    output "<h2>%c</h2><p>"
;
element back
    reset sect1number
    output "%c"
;
element bibliog
    set referent "cfn%d(chapterfilenumber)" to
        "<a HREF = %"bibliog.htm%">" _
        "<img SRC = %"/library/icons/blueball.gif%"> BIBLIOGRAPHY </a><br>%n"
    output "<a HREF = %"bibliog.htm%"  NAME = " _
        "%"preface%">BIBLIOGRAPHY</a><p>%n"
;
;   Open stream to contain the whole bibliog.htm file
;
    open sectionstream with referents-allowed as
        "bibliog.htm" 
    put sectionstream "<html><head>"
    put sectionstream "<a NAME=%"bibliog%"><title>BIBLIOGRAPHY</title>%n"
    put sectionstream "<h1>BIBLIOGRAPHY</h1>"
    increment chapterfilenumber
    put sectionstream "%c"
    put sectionstream referent "cfn%d(chapterfilenumber)"
    set referent "cfn%d(chapterfilenumber)" to "<br>"
    put sectionstream "<a HREF = %"<instancename>.htm#bibliog%">%n"
    put sectionstream
        "<img SRC =%"/library/icons/blueball.gif%"> Contents "
    put sectionstream "</a><p>%n"
    put sectionstream "</body></html>%n"
    close sectionstream
    reset figurenumber to 1
    reset tablenumber to 1
;
element body
    output "%c"
    set referent "cfn%d(chapterfilenumber)" to
        "<a HREF = %"rf.htm%">" _
        "<img SRC = %"/library/icons/blueball.gif%"> REFERENCES </a><br>%n"
    output "<a HREF = %"rf.htm%"  NAME = " _
        "%"preface%">REFERENCES</a><p>%n"
    open referfile with referents-allowed as "rf.htm" 
    put referfile "<html><head>"
    put referfile "<a NAME=%"rf%"><title>REFERENCES</title>%n"
    put referfile "<h1>REFERENCES</h1>"
    increment chapterfilenumber
    repeat over stream referstream
        put referfile "%g(referstream)%n" 
    again
    put referfile referent "cfn%d(chapterfilenumber)"
    set referent "cfn%d(chapterfilenumber)" to "<br>"
    put referfile "<a HREF = %"tcnew.htm#c-%d(sect1number)%" TARGET=%"main%">%n"
    put referfile
        "<img SRC =%"/library/icons/blueball.gif%"> Contents "
    put referfile "</a><p>%n"
    put referfile "</body></html>%n"
    close referfile
    reset figurenumber to 1
    reset tablenumber to 1
;
element book when parent is refer
    activate bookswitch
    output "%c"
;
element caption
    output "<p>%c<p>%n"
;
element caution
;    suppress
;    do when attribute id is specified
;        set referent "%lv(ID)" to
;            "%d(sect1number).%d(figurenumber)" 
;        set referent "a-%lv(ID)" to
;            "<a HREF = %"fg-ch-%d(sect1number)-%d(figurenumber).htm%">" _
;                "%d(sect1number).%d(figurenumber)</a>"
;        increment figurenumber
;    done

    do when attribute ID is specified
        open figurestream with referents-allowed
            as "fg-ch-%d(sect1number)-%d(figurenumber).htm"
            when ancestor isnt appendix
        open figurestream with referents-allowed
            as "fg-ap-%ua(sect1number)-%d(figurenumber).htm"
            when ancestor is appendix
        put figurestream "<a NAME = %"%lv(ID)%">%c</a>"
        set referent "a-%lv(ID)" to
            "<a HREF = %"fg-ch-%d(sect1number)-%d(figurenumber).htm%">" _
            "%d(sect1number).%d(figurenumber)</a>" when ancestor isnt appendix
        set referent "a-%lv(ID)" to
            "<a HREF = %"fg-ap-%ua(sect1number)-%d(figurenumber).htm%">" _
            "%ua(sect1number).%d(figurenumber)</a>" when ancestor is appendix
        set referent "%lv(ID)" to
            "%d(sect1number).%d(figurenumber)" when ancestor isnt appendix
        set referent "%lv(ID)" to
            "%ua(sect1number).%d(figurenumber)" when ancestor is appendix
        increment figurenumber
        close figurestream
    done

;
element citation
    output "<i>%c</i>"
;
element citedpgno when ancestor is refer
    activate citedpgnoswitch
    load-referelem("citedpgno")
;
element collection when ancestor is refer
    activate collectionswitch
    output "%c"
;
element colspec
    suppress
;
;   Set colspec table attributes
;
    copy-table-attributes(3)
;
;   Change any of the attributes set by colspec.  Note that rowsep is ignored
;   if set here.
;
    do when counter tgroupnumber is equal 1
        set buffer tabalign to "%v(align)" when attribute align is specified
        set buffer tabchar to "%v(char)" when attribute char is specified
        set buffer tabcolname to "%v(colname)"
            when attribute colname is specified
        remove counter tabcolnum
        new counter tabcolnum key "%lv(colname)"
        reset tabcolnum to "%d(curcol)"
        set buffer tabcolsep to "%v(colsep)" when attribute colsep is specified
        set buffer tabcolwidth to "%v(colwidth)"
            when attribute colwidth is specified
    done
    increment curcol
;
element committee when ancestor is refer
    activate committeeswitch
    load-referelem("committee")
;
element communication when ancestor is refer
    activate communicationswitch
    load-referelem("communication")
;
element confproc when ancestor is refer
    activate confprocswitch
    load-referelem("confproc")
;
element congress when ancestor is refer
    activate congressswitch
    load-referelem("congress")
;
element contract
    suppress    ;  elem is EMPTY
;
element contrib
    output "%c"
;
element date when ancestor is refer
    activate dateswitch
    load-referelem("date")
;
element date when parent is titleblk
    output "%c<p>%n"
;
element def when parent is acro-defn
    set buffer acrodefn to "%c"
;
element def when parent is deflist
    output "<DD>%c%n"
;
element deflist
    output "<DL>%c</DL>%n"
;
element distrib
    suppress
;
element division
    output "%c<p>%n"
;
element docnum when ancestor is refer
    activate docnumswitch
    load-referelem("docnum")
;
element docnum when parent is titleblk
    output "%c<p>%n"
;
element edition when ancestor is refer
    activate editionswitch
    load-referelem("edition")
;
element editor when ancestor is refer
    activate editorswitch
    load-referelem("editor")
;
element editor-comment
    output "<h1>editor comment</h1>%c<p>%n" when not active statusfinal
    suppress when active statusfinal
;
element emedia when parent is refer
    activate emediaswitch
    load-referelem("emedia")
;
element emphasis
    output "%c%n" when attribute TYPE isnt specified
    do when attribute TYPE is specified
        output "%c%n" when attribute TYPE is equal "CANCEL"
        output "<i>%c</i>%n" when attribute TYPE is equal ("1" or "ITALIC")
        output "<b>%c</b>%n" when attribute TYPE is equal ("2" or "BOLD")
        output "<b>%c</b>%n" when attribute TYPE is equal "3"
        output "<b>%c</b>%n" when attribute TYPE is equal "4"
    done
    put #error "EMPHASIS type is %v(type)%n"
        when attribute type isnt equal
        ("1" or "2" or "3" or "4" or "BOLD" or "CANCEL" or "ITALIC")
;
element entry
    local counter itemno
    reset itemno to counter curcol
    increment itemno by 3
;
;   First, are we in an entry which was vertically spanned from above?
;   If so, get out now!
;
    repeat
    exit when counter curcol is greater-than counter cols
    exit when counter tabvspan item "%d(itemno)" is equal 0
        increment curcol
        increment itemno
    again
;
    do when counter curcol isnt greater-than counter cols
;
;   Set entry table attributes
;
        copy-table-attributes("%d(itemno)")
;
;   Change any of the attributes set by entry.  Note that rowsep is ignored.
;
        set buffer tabalign to "%v(align)" when attribute align is specified
        set buffer tabchar to "%v(char)" when attribute char is specified
        set buffer tabcolsep to "%v(colsep)" when attribute colsep is specified
        set buffer tabrotate to "%v(rotate)" when attribute rotate is specified
        set buffer tabvalign to "%g(tabheadvalign)" when ancestor is thead
        set buffer tabvalign to "%g(tabbodyvalign)" when ancestor is tbody
        set buffer tabvalign to "%v(valign)" when attribute valign is specified
;
;   Set tabhspan and tabvspan if needed
;
        do when attribute namest is specified
            using counter tabcolnum key "%lv(nameend)"
                reset tabhspan to counter tabcolnum
            using counter tabcolnum key "%lv(namest)"
                decrement tabhspan by counter tabcolnum
            increment tabhspan
        done
        reset tabvspan item "%d(itemno)" to "%v(morerows)"
            when attribute morerows is specified
        increment tabvspan item "%d(itemno)"
    done
;
    output "<th" when ancestor is thead
    put rulerow "<th" when ancestor is thead
    output "<td" when ancestor is tbody
    output " align = %"left%""
        when stream tabalign is equal ul "LEFT"
    output " align = %"right%""
        when stream tabalign is equal ul "RIGHT"
    output " align = %"center%""
        when stream tabalign is equal ul "CENTER"
    output " align = %"left%""
        when stream tabalign is equal ul "JUSTIFY"
    output " align = %"center%""
        when stream tabalign is equal ul "CHAR"
;
    put rulerow " align = %"left%""
        when stream tabalign is equal ul "LEFT"
    put rulerow " align = %"right%""
        when stream tabalign is equal ul "RIGHT"
    put rulerow " align = %"center%""
        when stream tabalign is equal ul "CENTER"
    put rulerow " align = %"left%""
        when stream tabalign is equal ul "JUSTIFY"
    put rulerow " align = %"center%""
        when stream tabalign is equal ul "CHAR"
;
    output " valign = %"%g(tabvalign)%""
    put rulerow " valign = %"%g(tabvalign)%""
    output " colspan = %"%d(tabhspan)%"" when attribute namest is specified
    put rulerow " colspan = %"%d(tabhspan)%""
        when attribute namest is specified
    activate spannedrules when attribute namest is specified
    using counter tabvspan item "%d(itemno)"
        output " rowspan = %d(tabvspan)"
            when attribute morerows is specified
    using counter tabvspan item "%d(itemno)"
        put rulerow " rowspan = %d(tabvspan)"
            when attribute morerows is specified
    output ">"
    put rulerow ">"
    output "&nbsp;&nbsp;&nbsp;"
        when counter curcol is greater-than 1
    output "%c"
    output "&nbsp;&nbsp;&nbsp;"
        when counter curcol is less-than "%d(cols)"
    put rulerow "<hr noshade>" when attribute namest is specified
    output "</td>" when ancestor isnt thead
    output "</th>" when ancestor is thead
    put rulerow "</th>" when ancestor is thead
    increment curcol
;
element execsum
    set referent "cfn%d(chapterfilenumber)" to
        "<a HREF = %"ex.htm%">" _
        "<img SRC = %"/library/icons/blueball.gif%"> EXECUTIVE SUMMARY </a><br>%n"
    output "<a HREF = %"ex.htm%"  NAME = " _
        "%"ex%">EXECUTIVE SUMMARY</a><p>%n"
;
;   Open stream to contain the whole ex.htm file
;
    open sectionstream with referents-allowed as
        "ex.htm" 
    put sectionstream "<html><head>"
    put sectionstream "<a NAME=%"ex%"><title>EXECUTIVE SUMMARY</title>%n"
    put sectionstream "<h1>EXECUTIVE SUMMARY</h1>"
    increment chapterfilenumber
    put sectionstream "%c"
    put sectionstream referent "cfn%d(chapterfilenumber)"
    set referent "cfn%d(chapterfilenumber)" to "<br>"
    put sectionstream "<a HREF = %"<instancename>.htm#ex%">%n"
    put sectionstream
        "<img SRC =%"/library/icons/blueball.gif%"> Contents "
    put sectionstream "</a><p>%n"
    put sectionstream "</body></html>%n"
    close sectionstream
    reset figurenumber to 1
    reset tablenumber to 1
;
element figref when ancestor isnt (figure or sidebar)
    suppress
;
;  Output the href version of the figure reference
;
    output referent "a-%lv(IDREF)"
;
element figref when ancestor is figure
    suppress
;
;  Output the non-href version of the figure reference
;
    output referent "%lv(IDREF)"
;
element figure
    do when attribute ID isnt specified
        output "%c"
    done
    do when attribute ID is specified
        open figurestream with referents-allowed
            as "fg-ch-%d(sect1number)-%d(figurenumber).htm"
            when ancestor isnt appendix
        open figurestream with referents-allowed
            as "fg-ap-%ua(sect1number)-%d(figurenumber).htm"
            when ancestor is appendix
        put figurestream "<a NAME = %"%lv(ID)%">%c</a>"
        set referent "a-%lv(ID)" to
            "<a HREF = %"fg-ch-%d(sect1number)-%d(figurenumber).htm%">" _
            "%d(sect1number).%d(figurenumber)</a>" when ancestor isnt appendix
        set referent "a-%lv(ID)" to
            "<a HREF = %"fg-ap-%ua(sect1number)-%d(figurenumber).htm%">" _
            "%ua(sect1number).%d(figurenumber)</a>" when ancestor is appendix
        set referent "%lv(ID)" to
            "%d(sect1number).%d(figurenumber)" when ancestor isnt appendix
        set referent "%lv(ID)" to
            "%ua(sect1number).%d(figurenumber)" when ancestor is appendix
        increment figurenumber
        close figurestream
    done
;
element foreword
    set referent "cfn%d(chapterfilenumber)" to
        "<a HREF = %"foreword.htm%">" _
        "<img SRC = %"/library/icons/blueball.gif%"> FOREWORD </a><br>%n"
    output "<a HREF = %"foreword.htm%"  NAME = " _
        "%"preface%">FOREWORD</a><p>%n"
;
;   Open stream to contain the whole foreword.htm file
;
    open sectionstream with referents-allowed as "foreword.htm" 
    put sectionstream "<html><head>"
    put sectionstream "<a NAME=%"foreword%"><title>FOREWORD</title>%n"
    put sectionstream "<h1>FOREWORD</h1>"
    increment chapterfilenumber
    put sectionstream "%c"
    put sectionstream referent "cfn%d(chapterfilenumber)"
    set referent "cfn%d(chapterfilenumber)" to "<br>"
    put sectionstream "<a HREF = %"<instancename>.htm#foreword%">%n"
    put sectionstream
        "<img SRC =%"/library/icons/blueball.gif%"> Contents "
    put sectionstream "</a><p>%n"
    put sectionstream "</body></html>%n"
    close sectionstream
    reset figurenumber to 1
    reset tablenumber to 1
;
element front
    output "%c"
;
element ftnote when ancestor isnt (multilist or table)
    put ftnotestream "<A NAME = %"%lv(ID)%">%d(ftnotenumber). </A>%c<P>%n"
    set referent "%lv(ID)" to "%"ftnotes.htm#%lv(ID)%">Note %d(ftnotenumber). "
    increment ftnotenumber
;
element ftnote when ancestor is (multilist or table)
    increment tableftnotenumber
    new stream tableftnotestream key "%d(tableftnotenumber)"
    set buffer tableftnotestream to
        "<sup><i>%la(tableftnotenumber)</i></sup>%c"
    put #error "Processing Footnote with attribute %lv(id)%n"
    new stream tableftnotereferencestream key "%lv(id)"
    set buffer tableftnotereferencestream to
        "<sup><i>%la(tableftnotenumber)</i></sup>"
;
element ftnref when ancestor isnt (multilist or table)
    suppress
    output "<A HREF = "
    output referent "%lv(IDREF)"
    output "</A>"
;
element ftnref when ancestor is (multilist or table)
    suppress
    using stream tableftnotereferencestream key "%lv(idref)"
        output "%g(tableftnotereferencestream)"
;
element graphic
    suppress    ;  elem is EMPTY
    output "<img src = %"%v(FILENAME).gif%"><p>%n" when attribute FORMAT isnt
        specified
    output file "hardcopy.htm" when attribute format is specified
    output "<A HREF = %"%v(FILENAME).pdf%">%n"
    output "<IMG src=%"blueball.gif%"> Printable Version of this Graph "
    output "</A><P>%n"
;
element incluspgnos when ancestor is refer
    activate incluspgnosswitch
    load-referelem("incluspgnos")
;
element issue when ancestor is refer
    activate issueswitch
    load-referelem("issue")
;
element item
    output "%c<br>%n" when attribute prefix of parent isnt specified
    do when attribute prefix of parent is specified
        output "<li>%c" when attribute prefix of parent isnt equal "NONE"
        output "%c<br>%n" when attribute prefix of parent is equal "NONE"
    done
;
element journal when ancestor is refer
    activate journalswitch
    load-referelem("journal")
;
element list
    output "<ul>%c</ul>" when attribute prefix isnt specified
    do when attribute prefix is specified
        output "<ul>%c</ul>" when attribute prefix is equal ("BULLET" or
            "DASH")
        output "<p>%n%c<p>%n" when attribute prefix is equal "NONE"
        output "<ol>%c</ol>" when attribute prefix is equal ("ALPHA" or
            "NUMERIC")
    done
;
element note
    output "<center><b>NOTE</b></center><p>"
    output "%c<p>"
;
element notice
    output "%c<p>%n"
;
element num when ancestor is refer
    activate numswitch
    load-referelem("num")
;
element p
    output "%c<p>%n"
;
element part when ancestor is refer
    activate partswitch
    load-referelem("part")
;
element place when ancestor is refer
    activate placeswitch
    load-referelem("place")
;
element publisher when ancestor is refer
    activate publisherswitch
    load-referelem("publisher")
;
element q
    output "``%c''"
;
element refer when parent isnt referlist
    output "%c"
    process-refer
    output ".<p>%n"
;
element refer when parent is referlist
    deactivate commaspaceswitch
    deactivate articleswitch
    deactivate authorswitch
    deactivate bookswitch
    deactivate citedpgnoswitch
    deactivate collectionswitch
    deactivate collectiontitleswitch
    deactivate confprocswitch
    deactivate congressswitch
    deactivate committeeswitch
    deactivate communicationswitch
    deactivate dateswitch
    deactivate docnumswitch
    deactivate editionswitch
    deactivate editorswitch
    deactivate emediaswitch
    deactivate incluspgnosswitch
    deactivate issueswitch
    deactivate journalswitch
    deactivate numswitch
    deactivate partswitch
    deactivate placeswitch
    deactivate publisherswitch
    deactivate repseriesswitch
    deactivate reptswitch
    deactivate thesisswitch
    deactivate titleswitch
    deactivate univswitch
    deactivate volumeswitch
;
    new stream referstream key "%lv(ID)"
    clear stream referelem
    new stream referelem key "first"
    set buffer referelem to ""
    open referstream as buffer
    put referstream "<A NAME = %"%lv(id)%">%c"
    close referstream
    process-refer
    reopen referstream as buffer
    put referstream ".</A>%n<P>%n"
    close referstream
    increment refernumber
;
element referef
    reset refernumber to item of stream referstream key "%lv(idref)"
    output "<a href = %"rf.htm#%lv(IDREF)%" TARGET = %"acros%">%c"
    output "</a>%n"
;
element referlist
    reset refernumber
    output "%c"
;
element report
    output "%c"
;
element repseries when ancestor is refer
    activate repseriesswitch
    load-referelem("repseries")
;
element rept when parent is refer
    activate reptswitch
    output "%c"
;
element row
    reset curcol
    deactivate spannedrules
    open rulerow as buffer
    output "<tr>%c</tr>%n"
    close rulerow
    output "<tr>%g(rulerow)</tr>%n"
        when (active spannedrules and ancestor is thead)
    repeat over counter tabvspan
        decrement tabvspan when counter tabvspan isnt equal 0
    again
;   Handle rowsep here later
;
element sect1 when parent is body
;
; The previous chapter put out a reference to its successor when it didn't
;  know its successor's name.  so it used a referent.  Now we know what the
;  successor is--we are processing it--so fill in the referent.
;
    set referent "cfn%d(chapterfilenumber)" to
        "<a HREF = %"ch-%d(sect1number).htm%">%n" _
        " <img SRC = %"/library/icons/blueball.gif%"> Chapter %d(sect1number) </a><br>%n"
;
;   Open stream to contain the whole <chapter>.htm file
;
    do when attribute ID is specified
        set referent "%lv(ID)" to "%lv(ID)"
        set referent "f-%lv(ID)" to "ch-%d(sect1number).htm#"
        set referent "a-%lv(ID)" to "%d(sect1number). "
    done
    clear stream sect1authors
    open sectionstream with (referents-allowed and break-width 72) as
        "ch-%d(sect1number).htm" 
    put #error "Processing ch-%d(sect1number).htm%n"
    put sectionstream "<html><head>"
    do when counter chapterfilenumber is greater-equal 1000
        reset chapterfilenumber to 0
    done
    increment chapterfilenumber
    put sectionstream "%c"
;
; Put out the reference to the succeeding chapter even though we don't know
;  what it is yet.
;
    put sectionstream "<a HREF = %"tcnew.htm#ch-%d(sect1number)%" TARGET=%"main%">%n"
    put sectionstream
        "<img SRC =%"/library/icons/blueball.gif%"> Contents "
    put sectionstream referent "cfn%d(chapterfilenumber)"
    set referent "cfn%d(chapterfilenumber)" to "<br>"
    put sectionstream "</a><p>%n"
    put sectionstream "</body></html>%n"
    close sectionstream
    increment sect1number
    reset sect2number to 1
    reset figurenumber to 1
    reset tablenumber to 1
;
element sect2
    local stream sectnumber
    set buffer sectnumber to "%ua(sect1number)" when ancestor is appendix
    set buffer sectnumber to "%d(sect1number)" when ancestor is sect1
;
;   Reset acronyms
;
    repeat over counter acrocount
        reset acrocount to 0 
    again
    do when attribute ID is specified
        set referent "%lv(ID)" to "%lv(ID)"
        set referent "f-%lv(ID)" to "ch-%g(sectnumber).htm#"
            when ancestor isnt appendix
        set referent "f-%lv(ID)" to "ap-%g(sectnumber).htm#"
            when ancestor is appendix
        set referent "a-%lv(ID)" to "%g(sectnumber).%d(sect2number) "
    done
    output "%c"
    increment sect2number
    reset sect3number to 1
;
element sect3 when parent is sect2
    do when attribute ID is specified
        set referent "%lv(ID)" to "%lv(ID)"
        set referent "f-%lv(ID)" to "ch-%d(sect1number).htm#"
            when ancestor isnt appendix
        set referent "f-%lv(ID)" to "ap-%ua(sect1number).htm#"
            when ancestor is appendix
        set referent "a-%lv(ID)" to "%d(sect1number).%d(sect2number)." _
            "%d(sect3number) " when ancestor isnt appendix
        set referent "a-%lv(ID)" to "%ua(sect1number).%d(sect2number)." _
            "%d(sect3number) " when ancestor is appendix
    done
    output "%c"
    increment sect3number
    reset sect4number to 1
;
element sect4 when parent is sect3
    do when attribute ID is specified
        set referent "%lv(ID)" to "%lv(ID)"
        set referent "f-%lv(ID)" to "ch-%d(sect1number).htm#"
            when ancestor isnt appendix
        set referent "f-%lv(ID)" to "ap-%ua(sect1number).htm#"
            when ancestor is appendix
        set referent "a-%lv(ID)" to "%d(sect1number).%d(sect2number)." _
            "%d(sect3number).%d(sect4number) " when ancestor isnt appendix
        set referent "a-%lv(ID)" to "%ua(sect1number).%d(sect2number)." _
            "%d(sect3number).%d(sect4number) " when ancestor is appendix
    done
    output "%c"
    increment sect4number
    reset sect5number to 1
;
element sect5 when parent is sect4
    do when attribute ID is specified
        set referent "%lv(ID)" to "%lv(ID)"
        set referent "f-%lv(ID)" to "ch-%d(sect1number).htm#"
            when ancestor isnt appendix
        set referent "f-%lv(ID)" to "ap-%ua(sect1number).htm#"
            when ancestor is appendix
        set referent "a-%lv(ID)" to "%d(sect1number).%d(sect2number)." _
            "%d(sect3number).%d(sect4number).%d(sect5number) "
            when ancestor isnt appendix
        set referent "a-%lv(ID)" to "%ua(sect1number).%d(sect2number)." _
            "%d(sect3number).%d(sect4number).%d(sect5number) "
            when ancestor is appendix
    done
    output "%c"
    increment sect5number
    reset sect6number to 1
;
element sect6 when parent is sect5
    do when attribute ID is specified
        set referent "%lv(ID)" to "%lv(ID)"
        set referent "f-%lv(ID)" to "ch-%d(sect1number).htm#"
            when ancestor isnt appendix
        set referent "f-%lv(ID)" to "ap-%ua(sect1number).htm#"
            when ancestor is appendix
        set referent "a-%lv(ID)" to "%d(sect1number).%d(sect2number)." _
            "%d(sect3number).%d(sect4number).%d(sect5number).%d(sect6number) "
            when ancestor isnt appendix
        set referent "a-%lv(ID)" to "%ua(sect1number).%d(sect2number)." _
            "%d(sect3number).%d(sect4number).%d(sect5number).%d(sect6number) "
            when ancestor is appendix
    done
    output "%c"
    increment sect6number
;
element sectref
    suppress
    output "<a href = %""
    output referent "f-%lv(IDREF)"
    output referent "%lv(IDREF)"
    output "%">"
    output referent "a-%lv(IDREF)"
    output "</a> "
;
element sidebar
    suppress
;
element source when parent is figure
    output "<i>Source:</i> %c<p>%n"
;
element source when parent is table
    new stream sourcestream
    set buffer sourcestream to "Source: %c<p>%n"
;
element specialtext
    reopen referelem as buffer
    put referelem "%c"
    close referelem
;
element subscrpt
    output "<sub>%c</sub>"
;
element supscrpt
    output "<sup>%c</sup>"
;
element table
;
;   Set table table attributes
;
    copy-table-attributes(1)
;
;   Change any of the attributes set by table
;
    set buffer tabcolsep to "%v(colsep)" when attribute colsep is specified
    set buffer tabframe to "%v(frame)" when attribute frame is specified
    set buffer taborient to "%v(orient)" when attribute orient is specified
    set buffer tabpgwide to "%v(pgwide)" when attribute pgwide is specified
    set buffer tabrowsep to "%v(rowsep)" when attribute rowsep is specified
;
    reset tgroupnumber
    reset tableftnotenumber to 0
    clear stream tableftnotestream
    clear stream tableftnotereferencestream
    clear stream sourcestream
    do when attribute ID is specified
        do when ancestor is appendix
            put #error "Processing Table %ua(sect1number).%d(tablenumber)%n"
            set referent "%lv(ID)" to
                "%ua(sect1number).%d(tablenumber)" 
            set referent "a-%lv(ID)" to
                "<a HREF = %"tb-ap-%ua(sect1number)-%d(tablenumber).htm%">" _
                "%ua(sect1number).%d(tablenumber)</a>"
        done
        do when ancestor is execsum
            put #error "Processing Table ex.%d(tablenumber)%n"
            set referent "%lv(ID)" to
                "ex.%d(tablenumber)" 
            set referent "a-%lv(ID)" to
                "<a HREF = %"tb-ex-%d(tablenumber).htm%">" _
                    "ex.%d(tablenumber)</a>"
        done
        do when ancestor is sect1
            put #error "Processing Table %d(sect1number).%d(tablenumber)%n"
            set referent "%lv(ID)" to
                "%d(sect1number).%d(tablenumber)" 
            set referent "a-%lv(ID)" to
                "<a HREF = %"tb-%d(sect1number)-%d(tablenumber).pdf%">" _
                    "%d(sect1number).%d(tablenumber)</a>"
        done
        output "<a NAME = %"%lv(ID)%">%n"
    done
    do when attribute id isnt specified
        output "<p><br><p><br>%n"
        output "<center><table border=0>%c"
        output "<tr><td colspan = %"%d(cols)%"><hr noshade></td></tr>%n"
        reset curftnote to 0
        repeat over stream tableftnotestream
            output "<tr><td colspan = %"%d(cols)%">" _
            "%g(tableftnotestream)</td></tr>%n"
        again
        repeat over stream sourcestream
            output "<tr><td colspan = %"%d(cols)%">%g(sourcestream)</td></tr>%n"
        again
        output "</table></center>%n"
    done
    do when attribute id is specified
        open tablestream with referents-allowed
            as "tb-ap-%ua(sect1number)-%d(tablenumber).htm"
            when ancestor is appendix
        open tablestream with referents-allowed
            as "tb-ex-%d(sect1number)-%d(tablenumber).htm"
            when ancestor is execsum
        open tablestream with referents-allowed
            as "tb-ch-%d(sect1number)-%d(tablenumber).htm"
            when ancestor is sect1
        put tablestream "<p><br><p><br>%n"
        put tablestream "<center><table border=0>%c"
        put tablestream "<tr><td colspan = %"%d(cols)%"><hr noshade></td></tr>%n"
        reset curftnote to 0
        repeat over stream tableftnotestream
            put tablestream "<tr><td colspan = %"%d(cols)%">" _
            "%g(tableftnotestream)</td></tr>%n"
        again
        repeat over stream sourcestream
            put tablestream "<tr><td colspan = %"%d(cols)%">%g(sourcestream)</td></tr>%n"
        again
        put tablestream "</table></center>%n"
    done
    put tablestream "</a>%n" when attribute ID is specified
    put tablestream "<p><br><p><br>%n"
    increment tablenumber when attribute ID is specified
    remove-table-attributes
;
element tabref when ancestor isnt table
    suppress
;
;  Output the href version of the table reference
;
    output referent "a-%lv(IDREF)"
;
element tabref when ancestor is table
    suppress
;
;  Output the non-href version of the table reference
;
    output referent "%lv(IDREF)"
;
element tbody
    set buffer tabbodyvalign to stream tabvalign item 1
    set buffer tabbodyvalign to "%v(valign)" when attribute valign is specified
    output "%c"
;
element term when ancestor is deflist
    output "<DT>%c"
;
element tgroup
;
;   Set table table attributes
;
    copy-table-attributes(2)
;
;   Change any of the attributes set by tgroup
;
    set buffer tabalign to "%v(align)" when attribute align is specified
    set buffer tabchar to "%v(char)" when attribute char is specified
    set buffer tabcolsep to "%v(colsep)" when attribute colsep is specified
    set buffer tabrowsep to "%v(rowsep)" when attribute rowsep is specified
;
    reset cols to "%v(cols)"
    reset curcol
    output "<tr><td colspan = %"%d(cols)%"><hr noshade></td></tr>%n"
    output "%c"
    increment tgroupnumber by 1
    remove-table-colspec-attributes
;
element thead
    set buffer tabheadvalign to stream tabvalign item 1
    set buffer tabheadvalign to "%v(valign)" when attribute valign is specified
    output "%c"
    output "<tr><td colspan = %"%d(cols)%"><hr noshade></td></tr>%n"
;
element thesis when parent is refer
    activate thesisswitch
    output "%c"
;
element title when parent is appendix
    local stream contents
    set buffer contents to "%c"
;
;   Output intended for the menu file
;
    put output "<a HREF = %"ap-%ua(sect1number).htm%"%n    NAME = " _
        "%"ap-%ua(sect1number)%">%ua(sect1number). " _
        "%g(contents)</a><p>%n"
;
;   Output for the section file
;
    output "<title>%ua(sect1number). %g(contents)</title>" _
        "</head>%n<body>%n"
    do when attribute ID of parent is specified
        output "<a NAME = %""
        using attribute ID of parent
            output referent "%lv(ID)"
        output "%">"
    done
    output "<h1>%ua(sect1number). %g(contents)</h1>"
    output "</a>" when attribute ID of parent is specified
    output "<p>%n"
    do when attribute rev-date of parent is specified
        using attribute rev-date of parent
            output "<I>%v(rev-date)</I><P>%n"
    done
;
;   Put out the next chapter button.
;
    output referent "cfn%d(chapterfilenumber)"
;
;   Output the table of contents button.
    output "<A HREF=%"tcnew.htm#ap-%ua(sect1number)%" TARGET=%"main%">"
    output "<img SRC=%"/library/icons/blueball.gif%"> Contents </a><P>"
;
element title when parent is bibliog
    local stream contents
    set buffer contents to "%c"
;
;   Output intended for the menu file
;
    put output "<a HREF = %"ap-%ua(sect1number).htm%"%n    NAME = " _
        "%"ap-%ua(sect1number)%">Appendix %ua(sect1number). " _
        "%g(contents)</a><p>%n"
;
;   Output for the section file
;
    output "<title>Appendix %ua(sect1number). %g(contents)</title>" _
        "</head>%n<body>%n"
    do when attribute ID of parent is specified
        output "<a NAME = %""
        using attribute ID of parent
            output referent "%lv(ID)"
        output "%">"
    done
    output "<h1>Appendix %ua(sect1number). %g(contents)</h1>"
    output "</a>" when attribute ID of parent is specified
    output "<p>%n"
    do when attribute rev-date of parent is specified
        using attribute rev-date of parent
            output "<I>%v(rev-date)</I><P>%n"
    done
;
;   Put out the next chapter button.
;
    output referent "cfn%d(chapterfilenumber)"
;
;   Output the table of contents button.
;
    output "<A HREF=%"<instancename>.htm#ap-%ua(sect1number)%">"
    output "<img SRC=%"/library/icons/blueball.gif%"> Contents </a><P>"
;
element title when (ancestor is refer and parent isnt collection)
    activate titleswitch
    load-referelem("title")
;
element title when (ancestor is refer and parent is collection)
    activate collectiontitleswitch
    load-referelem("collectiontitle")
;
element title when parent is sect1
    local stream contents
    set buffer contents to "%c"
;
;   Output intended for the menu file
;
    put output "<a HREF = %"ch-%d(sect1number).htm%"%n    NAME = " _
        "%"ch-%d(sect1number)%">    %d(sect1number). %g(contents)</a><p>%n"
;
;   Output for the section file
;
    output "<title>%d(sect1number). %g(contents)</title></head>%n<body>%n"
    do when attribute ID of parent is specified
        output "<a NAME = %""
        using attribute ID of parent
            output referent "%lv(ID)"
        output "%">"
    done
    output "<h2>%d(sect1number). %g(contents)</h2>"
    output "</a>" when attribute ID of parent is specified
    output "<p>%n"
    do when attribute rev-date of parent is specified
        using attribute rev-date of parent
            output "<I>%v(rev-date)</I><P>%n"
    done
;
;   Output the table of contents button.
;
    output "<A HREF=%"tcnew.htm#ch-%d(sect1number)%" TARGET=%"main%">"
    output "<img SRC=%"/library/icons/blueball.gif%"> Contents </a>"
;
;    Put out the previous chapter button.
;
    do when counter sect1number is greater-than 1
        decrement sect1number
        output "<A HREF=%"ch-%d(sect1number).htm%">"
        output "<img SRC=%"/library/icons/blueball.gif%"> Chapter %d(sect1number) </a>"
        increment sect1number
    done
    output "<a HREF = %"ac.htm%">%n"
    output
        "<img SRC =%"/library/icons/blueball.gif%"> Acronyms </a><p>"
;
element title when parent is sect2
    local stream contents
    set buffer contents to "%c"
;
;   Output intended for the menu file
;
    using attribute ID of parent
        put output "&nbsp;&nbsp;&nbsp;&nbsp;" _
            "<a HREF = %"ch-%d(sect1number).htm#%lv(ID)%"%n    NAME = " _
            "%"ch-%d(sect1number).%d(sect2number)%"> " _
            "%d(sect1number).%d(sect2number) %g(contents)</a><p>%n"
;
    do when attribute ID of parent is specified
        output "<a NAME = %""
        using attribute ID of parent
            output referent "%lv(ID)"
        output "%">"
    done
    output "<h3>"
    output "%ua(sect1number)" when ancestor is appendix
    output "%d(sect1number)" when ancestor is sect1
    output ".%d(sect2number) %g(contents)</h3>"
    output "</a>" when attribute ID of parent is specified
    output "<p>%n"
;
element title when parent is sect3
    local stream contents
    set buffer contents to "%c"
;
;   Output intended for the menu file
;
    using attribute ID of parent
        put output "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" _
            "<a HREF = %"ch-%d(sect1number).htm#%lv(ID)%"%n    NAME = " _
            "%"ch-%d(sect1number).%d(sect2number).%d(sect3number)%"> " _
            "%d(sect1number).%d(sect2number).%d(sect3number) " _
            "%g(contents)</a><p>%n"
;
    do when attribute ID of parent is specified
        output "<a NAME = %""
        using attribute ID of parent
            output referent "%lv(ID)"
        output "%">"
    done
    output "<h4>"
    output "%ua(sect1number)" when ancestor is appendix
    output "%d(sect1number)" when ancestor is sect1
    output ".%d(sect2number).%d(sect3number) %g(contents)</h4>"
    output "</a>" when attribute ID of parent is specified
    output "%n"
;
element title when parent is sect4
    do when attribute ID of parent is specified
        output "<a NAME = %""
        using attribute ID of parent
            output referent "%lv(ID)"
        output "%">"
    done
    output "<h4>"
    output "%ua(sect1number)" when ancestor is appendix
    output "%d(sect1number)" when ancestor is sect1
    output ".%d(sect2number).%d(sect3number).%d(sect4number) %c</h4>"
    output "</a>" when attribute ID of parent is specified
    output "%n"
;
element title when parent is sect5
    do when attribute ID of parent is specified
        output "<a NAME = %""
        using attribute ID of parent
            output referent "%lv(ID)"
        output "%">"
    done
    output "<h4><i><b>%c</b></i></h4>"
    output "</a>" when attribute ID of parent is specified
    output "%n"
;
element title when parent is sect6
    do when attribute ID of parent is specified
        output "<a NAME = %""
        using attribute ID of parent
            output referent "%lv(ID)"
        output "%">"
    done
    output "<i>%c</i><p>"
    output "</a>" when attribute ID of parent is specified
    output "%n"
;
element title when parent is table
    output "<caption><strong><font size = 4>%c</font></strong></caption>%n"
;
element title when parent is titleblk
    set buffer doctitle to "%c"
    output "<title>%g(doctitle)</title>%n"
    output "<h1>%g(doctitle)</h1>%n"
;
element titleblk
    output "%c"
;
element univ when ancestor is refer
    activate univswitch
    load-referelem("univ")
;
element volume when ancestor is refer
    activate volumeswitch
    load-referelem("volume")
;
element warning
    suppress
    do when attribute id is specified
        set referent "%lv(ID)" to
            "%d(sect1number).%d(tablenumber)" 
        set referent "a-%lv(ID)" to
            "<a HREF = %"tb-%d(sect1number)-%d(tablenumber).pdf%">" _
                "%d(sect1number).%d(tablenumber)</a>"
        increment tablenumber
    done
;
element #IMPLIED
    output "%n<NOTDONEYET--%q>%n%c%n"