
###########################################################################
#                                                                         #
#  @OrdinaryLayout extension to @DocumentLayout.                          #
#                                                                         #
#  Jeffrey H. Kingston                                                    #
#  August 1994                                                            #
#                                                                         #
#  This package extends DocumentLayout for ordinary documents.            #
#                                                                         #
###########################################################################

extend @DocumentLayout
export @Doc @Document @Text
def @OrdinaryLayout

    named @SectionNumbers            {  Arabic         }
    named @SubSectionNumbers         {  Arabic         }
    named @SubSubSectionNumbers      {  Arabic         }
    named @AppendixNumbers           {  UCAlpha        }
    named @SubAppendixNumbers        {  Arabic         }
    named @SubSubAppendixNumbers     {  Arabic         }

    named @SectionHeadingFont        {  Bold           }
    named @SubSectionHeadingFont     {  Bold           }
    named @SubSubSectionHeadingFont  {  Slope          }
    named @AppendixHeadingFont       {  Bold	       }
    named @SubAppendixHeadingFont    {  Bold           }
    named @SubSubAppendixHeadingFont {  Slope          }
    named @ReferencesHeadingFont     {  Bold           }
    named @IndexHeadingFont          {  Bold           }

    named @SectionGap                {  2.00v          }
    named @SubSectionGap             {  1.50v          }
    named @SubSubSectionGap          {  1.50v          }
    named @AppendixGap               {  2.00v          }
    named @SubAppendixGap            {  1.50v          }
    named @SubSubAppendixGap         {  1.50v          }

    named @SectionInContents         {  Yes            }
    named @SubSectionInContents      {  Yes            }
    named @SubSubSectionInContents   {  No             }
    named @AppendixInContents        {  Yes            }
    named @SubAppendixInContents     {  Yes            }
    named @SubSubAppendixInContents  {  No             }
    named @ReferencesInContents      {  Yes            }
    named @IndexInContents           {  Yes            }
@Begin

    #######################################################################
    #                                                                     #
    #  Lists of sections, sub(-sub)sections, appendices, etc.             #
    #                                                                     #
    #######################################################################

    def @TextPlace { @Galley }

    export num
    def @SectionList named @Tag {} right num
    {
	@Galley
        //@SectionGap	@SectionList @Next num
    }

    export num
    def @SubSectionList named @Tag {} right num
    {
	@Galley
        //@SubSectionGap    @SubSectionList @Next num
    }

    export num
    def @SubSubSectionList named @Tag {} right num
    {
	@Galley
        //@SubSubSectionGap @SubSubSectionList @Next num
    }

    export num
    def @AppendixList named @Tag {} right num
    {
	@Galley
        //@AppendixGap	@AppendixList @Next num
    }

    export num
    def @SubAppendixList named @Tag {} right num
    {
	@Galley
        //@SubAppendixGap   @SubAppendixList @Next num
    }

    export num
    def @SubSubAppendixList named @Tag {} right num
    {
	@Galley
        //@SubSubAppendixGap   @SubSubAppendixList @Next num
    }


    #######################################################################
    #                                                                     #
    #  @SendFull - send full-width text.                                  #
    #                                                                     #
    #######################################################################

    def @SendFull force into { @FullPlace&&following }
	right x
    {
	x
    }


    #######################################################################
    #                                                                     #
    #  Document.                                                          #
    #                                                                     #
    #######################################################################

    def @Document
        named @InitialFont { @InitialFont }
        named @InitialBreak { @InitialBreak }
        named @InitialLanguage { @InitialLanguage }
        named @PageHeaders { @PageHeaders }
        named @ColumnNumber { @ColumnNumber }
        named @FirstPageNumber { @FirstPageNumber }
    {
	def @ReferencesPart
	    named @Tag {}
	{
		ragged @Break @ReferencesHeadingFont @Font
		    @RefHeading @RefListTitle
	    //  @PageMarker&&preceding @Tagged @Tag
	    //  @ReferencesInContents @MajorContentsEntry
		    title { @RefHeading @RefListTitle }
		    pagenum { @PageOf @Tag }
	    //  NonStart @Runner @MajorTitle { @RefHeading @RefListTitle }
            //@RefListGap  @ReferencesSection
	    //  NonStart @Runner @MajorTitle { @RefHeading @RefListTitle }
	}

        def @IndexPart
	    named @Tag {}
        {
		@SendFull {
		       Start @Runner @MajorTitle { @Word&&index }
		    // ragged @Break @IndexHeadingFont @Font @Word&&index
		}
            //  @PageMarker&&preceding @Tagged @Tag
            //  @IndexInContents @MajorContentsEntry
		    title { @Word&&index }
		    pagenum { @PageOf @Tag }
            //  NonStart @Runner @MajorTitle { @Word&&index }
            //  @IndexSection {NonStart @Runner @MajorTitle {@Word&&index}}
        }

        def @DocumentBody force into { @ColPlace&&preceding }
        {
	    # this whole comment is now obsolete:
	    # It's important that the first component of @DocumentBody be
	    # indefinite.  If it was definite, then @DocumentBody would
	    # attach immediately to the first page.  This would prevent
	    # @FullWidth from attaching to that page, with the result that
	    # a document starting with @FullWidth would start on page 2!

	    //	@BeginFigures	{}
	    //  @BeginTables	{}
	    //  @BeginFootNotes	{}
	    //	@TextPlace
	    //@SectionGap @EndNoteList 1
	    //@SectionGap @MakeReferences @Then @ReferencesPart
	    //  @MakeIndex @Then @IndexPart
            //	NonStart @Runner
	    //  @EndFigures { NonStart @Runner }
	    //  @EndTables { NonStart @Runner }
	    //  @EndFootNotes { NonStart @Runner }
        }

        @InitialFont @Font @InitialBreak @Break @InitialLanguage @Language
	{ @ColourCommand @InitialColour } @SetColour
        {
            	@PageList
		    @ColumnNumber { @ColumnNumber }
		    @PageHeaders { @PageHeaders }
		    extra { Yes }
		    @FirstPageNumber
	    //  @DocumentBody
        }
    }

    macro @Doc { @Document // }


    #######################################################################
    #                                                                     #
    #  @Text containing sections, appendices, etc.                        #
    #                                                                     #
    #######################################################################

    export @FootNote @LongFootNote @EndNote @LongEndNote
	   @ContentsGoesHere @FullWidth
	   @BeginSections @EndSections @Section
	   @BeginAppendices @EndAppendices @Appendix
    def @Text force into { @TextPlace&&preceding }
        body @Body
    {
        macro @FootNote { @ColFootNote }
        macro @LongFootNote { @LongColFootNote }
        macro @EndNote { @ColEndNote }
	macro @LongEndNote { @LongColEndNote }

	def @ContentsGoesHere { @ContentsSection }

	export @FootNote @LongFootNote @EndNote @LongEndNote @ContentsGoesHere
	def @FullWidth body @Body
	{
            macro @FootNote { @FullFootNote }
            macro @LongFootNote { @LongFullFootNote }
            macro @EndNote { @ColEndNote }
            macro @LongEndNote { @LongColEndNote }

	    def @ContentsGoesHere {}

            @SendFull { Start @Runner // @Body }
	    & NonStart @Runner & &2.1b &
	}

        def @EndSectionsPlace { @Galley }

        def @EndSections force into { @EndSectionsPlace&&preceding }
	{}

        macro @BeginSections
	{   //@SectionGap @SectionList 1
	    // @EndSectionsPlace //
	}

        export @BeginSubSections @EndSubSections @SubSection
        def @Section force into { @SectionList&&preceding }
            named @Tag {}
            named @Title {}
            named @RunningTitle { dft }
	    named @InitialLanguage {}
	    named @BypassNumber { dft }
            body @Body
        {

            def @SectionNum
	    {
	      @BypassNumber @Dft {
		@SectionNumbers @Then {
		    @SectionNumbers @Num { @SectionList&&@Tag @Open { num } }
		}
	      }
	    }

            def @SectionTitle { @InitialLanguage @Language { @RunningTitle @Dft @Title } }

            def @EndSubSectionsPlace { @Galley }

            def @EndSubSections force into { @EndSubSectionsPlace&&preceding }
	    {}

            macro @BeginSubSections
            {	//@SubSectionGap @SubSectionList 1
		// @EndSubSectionsPlace //
	    }

	    export @BeginSubSubSections @EndSubSubSections @SubSubSection
            def @SubSection force into { @SubSectionList&&preceding }
		named @Tag {}
		named @Title {}
		named @RunningTitle { dft }
		named @InitialLanguage { @InitialLanguage }
		named @BypassNumber { dft }
		body @Body
            {

                def @SubSectionNum
		{
		  @BypassNumber @Dft {
		    @SubSectionNumbers @Then {
			@SectionNum @DotJoin @SubSectionNumbers @Num
			{ @SubSectionList&&@Tag @Open { num } }
		    }
		  }
		}

                def @EndSubSubSectionsPlace { @Galley }

                def @EndSubSubSections force into
		    { @EndSubSubSectionsPlace&&preceding }
		{}

                macro @BeginSubSubSections
                {   //@SubSubSectionGap @SubSubSectionList 1
		    // @EndSubSubSectionsPlace //
		}

		def @SubSubSection force into { @SubSubSectionList&&preceding }
		    named @Tag {}
		    named @Title {}
		    named @RunningTitle { dft }
		    named @InitialLanguage { @InitialLanguage }
		    named @BypassNumber { dft }
		    body @Body
		{

		    def @SubSubSectionNum
	            {
		      @BypassNumber @Dft {
		        @SubSubSectionNumbers @Then {
		            @SubSectionNum @DotJoin @SubSubSectionNumbers @Num
		            { @SubSubSectionList&&@Tag @Open { num } }
		        }
		      }
	            }

	                @InitialLanguage @Language
			@SubSubSectionHeadingFont @Font ragged @Break
			@Protect {@SubSubSectionNum @DotSep @Title}
	            //  @NumberMarker @Tag { @Tag } @SubSubSectionNum
	            //  @SubSubSectionList&&preceding @Tagged @Tag
	            //  @PageMarker&&preceding @Tagged @Tag
	            //  @SubSubSectionInContents @ContentsEntry
			    indent { 6f }
			    number { @SubSubSectionNum }
			    title { @InitialLanguage @Language @Title }
			    pagenum { @PageOf @Tag }
	            //  @InitialLanguage @Language @Body
	        }

		    @InitialLanguage @Language @SubSectionHeadingFont @Font
	            ragged @Break @Protect {@SubSectionNum @DotSep @Title}
	        //  @NumberMarker @Tag { @Tag } @SubSectionNum
	        //  @SubSectionList&&preceding @Tagged @Tag
	        //  @PageMarker&&preceding @Tagged @Tag
	        //  @SubSectionInContents @ContentsEntry
		        indent { 3f }
		        number { @SubSectionNum }
		        title { @InitialLanguage @Language @Title }
		        pagenum { @PageOf @Tag }
	        //  @InitialLanguage @Language @Body
            }

                @InitialLanguage @Language @SectionHeadingFont @Font
		ragged @Break @Protect { @SectionNum @DotSep @Title }
            //  @NumberMarker @Tag { @Tag } @SectionNum
            //  @SectionList&&preceding @Tagged @Tag
            //  @PageMarker&&preceding @Tagged @Tag
            //  @SectionInContents @MajorContentsEntry
		    number { @SectionNum }
		    title { @InitialLanguage @Language @Title }
		    pagenum { @PageOf @Tag }
            //  NonStart @Runner
	            @MajorNum { @SectionNum }
	            @MajorTitle { @SectionTitle }
            //  @InitialLanguage @Language @Body
            //  NonStart @Runner
	            @MajorNum { @SectionNum }
	            @MajorTitle { @SectionTitle }

        }

        def @EndAppendicesPlace { @Galley }

        def @EndAppendices force into { @EndAppendicesPlace&&preceding }
	{}

        macro @BeginAppendices
        {   //@AppendixGap @AppendixList 1
	    // @EndAppendicesPlace //
	}

	export @BeginSubAppendices @EndSubAppendices @SubAppendix
	def @Appendix force into { @AppendixList&&preceding }
            named @Tag {}
            named @Title {}
            named @RunningTitle { dft }
	    named @InitialLanguage {}
	    named @BypassNumber { dft }
            body @Body
	{
            def @EndSubAppendicesPlace { @Galley }

            def @EndSubAppendices force into
		{ @EndSubAppendicesPlace&&preceding }
	    {}

            macro @BeginSubAppendices
            {	//@SubAppendixGap @SubAppendixList 1
		// @EndSubAppendicesPlace //
	    }

            def @AppendixShortNum
            {
	      @BypassNumber @Dft {
		@AppendixNumbers @Num { @AppendixList&&@Tag @Open { num } }
	      }
            }

            def @AppendixLongNum
            {
		@AppendixNumbers @Then { @InitialLanguage @Language {
		    @Word&&appendix @AppendixShortNum
		} }
            }

            def @AppendixTitle
	    {
		@InitialLanguage @Language { @RunningTitle @Dft @Title }
	    }

            export @BeginSubSubAppendices @EndSubSubAppendices @SubSubAppendix
            def @SubAppendix force into { @SubAppendixList&&preceding }
		named @Tag {}
		named @Title {}
		named @RunningTitle { dft }
		named @InitialLanguage { @InitialLanguage }
		named @BypassNumber { dft }
		body @Body
            {

		def @SubAppendixNum
		{
		  @BypassNumber @Dft {
		    @SubAppendixNumbers @Then {
		        @AppendixShortNum @DotJoin @SubAppendixNumbers @Num
		        { @SubAppendixList&&@Tag @Open { num } }
		    }
		  }
		}

		def @EndSubSubAppendicesPlace { @Galley }

		def @EndSubSubAppendices force into
		    { @EndSubSubAppendicesPlace&&preceding }
		{}

		macro @BeginSubSubAppendices
		{   //@SubSubAppendixGap @SubSubAppendixList 1
		    // @EndSubSubAppendicesPlace //
		}

		def @SubSubAppendix force into {@SubSubAppendixList&&preceding}
		    named @Tag {}
		    named @Title {}
		    named @RunningTitle { dft }
		    named @InitialLanguage { @InitialLanguage }
		    named @BypassNumber { dft }
		    body @Body
		{

                    def @SubSubAppendixNum
		    {
		      @BypassNumber @Dft {
			@SubSubAppendixNumbers @Then {
			    @SubAppendixNum @DotJoin @SubSubAppendixNumbers
			    @Num { @SubSubAppendixList&&@Tag @Open { num } }
		        }
		      }
		    }

                    def @SubSubAppendixTitle { @RunningTitle @Dft @Title }

			@InitialLanguage @Language
			@SubSubAppendixHeadingFont @Font ragged @Break
			@Protect {@SubSubAppendixNum @DotSep @Title}
		    //  @NumberMarker @Tag { @Tag } @SubSubAppendixNum
		    //  @SubSubAppendixList&&preceding @Tagged @Tag
		    //  @PageMarker&&preceding @Tagged @Tag
		    //  @SubSubAppendixInContents @ContentsEntry
			    indent { 6f }
			    number { @SubSubAppendixNum }
			    title { @InitialLanguage @Language @Title }
			    pagenum { @PageOf @Tag }
		    //  @InitialLanguage @Language @Body
		}

                    @InitialLanguage @Language @SubAppendixHeadingFont @Font
		    ragged @Break @Protect { @SubAppendixNum @DotSep @Title }
		//  @NumberMarker @Tag { @Tag } @SubAppendixNum
		//  @SubAppendixList&&preceding @Tagged @Tag
		//  @PageMarker&&preceding @Tagged @Tag
		//  @SubAppendixInContents @ContentsEntry
			indent { 3f }
			number { @SubAppendixNum }
			title { @InitialLanguage @Language @Title }
			pagenum { @PageOf @Tag }
		//  @Body

	    }

		@InitialLanguage @Language @AppendixHeadingFont @Font 
		ragged @Break @Protect { @AppendixLongNum @DotSep @Title }
            //  @NumberMarker @Tag { @Tag } @AppendixShortNum
            //  @AppendixList&&preceding @Tagged @Tag
            //  @PageMarker&&preceding @Tagged @Tag
            //  @AppendixInContents @MajorContentsEntry
		    number { @AppendixLongNum }
		    title { @InitialLanguage @Language @Title }
		    pagenum { @PageOf @Tag }
            //  NonStart @Runner
	            @MajorNum { @AppendixLongNum }
	            @MajorTitle { @AppendixTitle }
	    //  @Body
            //  NonStart @Runner
	            @MajorNum { @AppendixLongNum }
	            @MajorTitle { @AppendixTitle }
	}

	//  Start @Runner
	//  @Body
	//  NonStart @Runner

    }

@End @OrdinaryLayout
