
###########################################################################
#                                                                         #
#  @BookLayout extension to @DocumentLayout.                              #
#                                                                         #
#  Jeffrey H. Kingston                                                    #
#  August 1994                                                            #
#                                                                         #
#  This package extends DocumentLayout with definitions for books.        #
#                                                                         #
###########################################################################

extend @DocumentLayout
export @Book @Preface @Introduction @Chapter @Appendix
def @BookLayout
    named @TitlePageFont		{  Helvetica Base		}
    named @SeparateIntroNumbering	{  Yes				}
    named @ChapterStartPages		{  Any				}
    named @ReferencesBeforeAppendices	{  No				}

    named @PrefaceWord			{  preface			}
    named @ContentsWord			{  contents			}
    named @FigureListWord		{  figurelist			}
    named @TableListWord		{  tablelist			}
    named @IntroductionWord		{  introduction			}
    named @ChapterWord			{  chapter			}
    named @AppendixWord			{  appendix			}
    named @IndexWord			{  index			}
    named @IndexAWord			{  index			}
    named @IndexBWord			{  index			}

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

    named @PartHeadingFont		{  Helvetica Base 2.50f		}
    named @PartHeadingBreak		{  clines 1.2fx nohyphen	}
    named @PartHeadingFormat
	left number right title		{  @CD number @DP @CD title	}

    named @ChapterHeadingFont		{  Bold 2.00f			}
    named @ChapterHeadingBreak		{  ragged 1.2fx nohyphen   	}
    named @ChapterHeadingFormat
	left number right title		{  number @DotSep title    	}

    named @SectionHeadingFont		{  Bold				}
    named @SectionHeadingBreak		{  ragged 1.2fx nohyphen	}
    named @SectionHeadingFormat
	left number right title		{  number @DotSep title    	}

    named @SubSectionHeadingFont	{  Bold				}
    named @SubSectionHeadingBreak	{  ragged 1.2fx nohyphen	}
    named @SubSectionHeadingFormat
	left number right title		{  number @DotSep title    	}

    named @SubSubSectionHeadingFont	{  Slope			}
    named @SubSubSectionHeadingBreak	{  ragged 1.2fx nohyphen	}
    named @SubSubSectionHeadingFormat
	left number right title		{  number @DotSep title    	}

    named @AppendixHeadingFont		{  Bold 2.00f			}
    named @AppendixHeadingBreak		{  ragged 1.2fx nohyphen   	}
    named @AppendixHeadingFormat
	left number right title		{  number @DotSep title    	}

    named @SubAppendixHeadingFont	{  Bold				}
    named @SubAppendixHeadingBreak	{  ragged 1.2fx nohyphen   	}
    named @SubAppendixHeadingFormat
	left number right title		{  number @DotSep title    	}

    named @SubSubAppendixHeadingFont	{  Slope			}
    named @SubSubAppendixHeadingBreak	{  ragged 1.2fx nohyphen   	}
    named @SubSubAppendixHeadingFormat
	left number right title		{  number @DotSep title    	}

    named @AbovePartGap			{  4.00f			}
    named @AboveChapterGap		{  3.00f			}
    named @SectionGap			{  2.00v			}
    named @SubSectionGap		{  1.50v			}
    named @SubSubSectionGap		{  1.50v			}
    named @SubAppendixGap		{  2.00v			}
    named @SubSubAppendixGap		{  1.50v			}

    named @IntroductionInContents	{  Yes				}
    named @PartInContents		{  Yes				}
    named @ChapterInContents		{  Yes				}
    named @SectionInContents		{  Yes				}
    named @SubSectionInContents		{  Yes				}
    named @SubSubSectionInContents	{  No				}
    named @AppendixInContents		{  Yes				}
    named @SubAppendixInContents	{  Yes				}
    named @SubSubAppendixInContents	{  No				}
    named @ReferencesInContents		{  Yes				}
    named @IndexInContents		{  Yes				}
    named @IndexAInContents		{  Yes				}
    named @IndexBInContents		{  Yes				}

    named @ChapterNumInTheorems		{  Yes				}
    named @SectionNumInTheorems		{  No				}
    named @SubSectionNumInTheorems	{  No				}
    named @SubSubSectionNumInTheorems	{  No				}
    named @AppendixNumInTheorems	{  Yes				}
    named @SubAppendixNumInTheorems	{  No				}
    named @SubSubAppendixNumInTheorems	{  No				}

    named @ChapterNumInDisplays		{  Yes				}
    named @SectionNumInDisplays		{  Yes				}
    named @SubSectionNumInDisplays	{  No				}
    named @SubSubSectionNumInDisplays	{  No				}
    named @AppendixNumInDisplays	{  Yes				}
    named @SubAppendixNumInDisplays	{  Yes				}
    named @SubSubAppendixNumInDisplays	{  No				}

    named @ChapterNumInFigures		{  Yes				}
    named @SectionNumInFigures		{  No				}
    named @SubSectionNumInFigures	{  No				}
    named @SubSubSectionNumInFigures	{  No				}
    named @AppendixNumInFigures		{  Yes				}
    named @SubAppendixNumInFigures	{  No				}
    named @SubSubAppendixNumInFigures	{  No				}

    named @ChapterNumInTables		{  Yes				}
    named @SectionNumInTables		{  No				}
    named @SubSectionNumInTables	{  No				}
    named @SubSubSectionNumInTables	{  No				}
    named @AppendixNumInTables		{  Yes				}
    named @SubAppendixNumInTables	{  No				}
    named @SubSubAppendixNumInTables	{  No				}

    named @PartContentsIndent		{  0.5rt			}
@Begin

    #######################################################################
    #                                                                     #
    #  Lists of chapters, sections, sub(-sub)sections, and appendices.    #
    #                                                                     #
    #######################################################################

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

    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
        //	@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
    }

    def @PrefacePlace { @Galley }
    def @IntroductionPlace { @Galley }


    #######################################################################
    #                                                                     #
    #  @Full - this sends text to a full-width place.                     #
    #                                                                     #
    #######################################################################

    def @Full right x
    {
	def @Any  force into { @FullPlace&&following     } right x { x }
	def @Odd  force into { @OddFullPlace&&following  } right x { x }
	def @Even force into { @EvenFullPlace&&following } right x { x }

	@ChapterStartPages @Case {
	    Any  @Yield @Any  x
	    Odd  @Yield @Odd  x
	    Even @Yield @Even x
	}
    }


    #######################################################################
    #                                                                     #
    #  @IntroFull - this sends text to a full-width intro place.          #
    #                                                                     #
    #######################################################################

    def @IntroFull right x
    {
	def @Any  force into { @IntroFullPlace&&following     } right x { x }
	def @Odd  force into { @IntroOddFullPlace&&following  } right x { x }
	def @Even force into { @IntroEvenFullPlace&&following } right x { x }

	@ChapterStartPages @Case {
	    Any  @Yield @Any  x
	    Odd  @Yield @Odd  x
	    Even @Yield @Even x
	}
    }


    #######################################################################
    #                                                                     #
    #  @ChooseFull - this sends either to introfull or ordinary full      #
    #                                                                     #
    #######################################################################

    def @ChooseFull right x
    {
	@SeparateIntroNumbering @Case {
	    No  @Yield @Full x
	    Yes @Yield @IntroFull x
	}
    }


    #######################################################################
    #                                                                     #
    #   @ChapRefSection                                                   #
    #                                                                     #
    #######################################################################

    def @ChapRefSection
    {
	@Heading @RefHeading @ChapRefListTitle
	@DP
	@ChapReferencesSection
    }


    #######################################################################
    #                                                                     #
    #  Book.                                                              #
    #                                                                     #
    #######################################################################

    def @Book
        named @Title {}
        named @Author {}
        named @Edition {}
        named @Publisher {}
        named @BeforeTitlePage {}
        named @AfterTitlePage {}
        named @InitialFont { @InitialFont }
        named @InitialBreak { @InitialBreak }
        named @InitialSpace { @InitialSpace }
        named @InitialLanguage { @InitialLanguage }
        named @PageHeaders { @PageHeaders }
        named @ColumnNumber { @ColumnNumber }
        named @FirstPageNumber { @FirstPageNumber }
        named @IntroFirstPageNumber { @IntroFirstPageNumber }
	named @OptimizePages { @OptimizePages }
    {
	def @Before
	{
	    @BeforeTitlePage @Case {
		""   @Yield @Null
		else @Yield {
		    //1i   |0.5rt @TitlePageFont @Font 2.0f @Font
				{ 1.2fx clines } @Break @Title |
		    //1.1b @BeforeTitlePage
		}
	    }
	}

	def @After
	{
	    @AfterTitlePage @Case {
		""   @Yield @Null
		else @Yield @AfterTitlePage
	    }
	}

	def @ContentsPart
	{
	    //	@ChooseFull {
		  //@AboveChapterGap
		  @ChapterHeadingFont @Font @ChapterHeadingBreak @Break
		  { {} @ChapterHeadingFormat contents @WordVal @ContentsWord }
		}
	    //
            //  @ContentsSection
	}

	def @FigureContentsPart
	{
	    //	@ChooseFull {
		  //@AboveChapterGap
		  @ChapterHeadingFont @Font @ChapterHeadingBreak @Break
		  { {} @ChapterHeadingFormat figurelist @WordVal @FigureListWord }
		}
	    //
            //  @FigureContentsSection
	}

	def @TableContentsPart
	{
	    //	@ChooseFull {
		  //@AboveChapterGap
		  @ChapterHeadingFont @Font @ChapterHeadingBreak @Break
		  {{} @ChapterHeadingFormat tablelist @WordVal @TableListWord }
		}
	    //
            //  @TableContentsSection
	}

        def @BookIntro force into { @IntroColPlace&&preceding }
	    named @Optimize { @OptimizePages }
        {
		    @Before
            //1.1b  @TitlePageFont @Font
		    {	//1i    |0.5rt 2.5f @Font {1.2fx clines} @Break @Title |
			//2i    |0.5rt clines @Break @Author |
			//1i    |0.5rt clines @Break @Edition |
			//1rt   @OneRow @Publisher
		    }
            //1.1b  @After
            //	    Start @Runner
            //1.1b  @PrefacePlace
            //      @MakeContents @Case {
			{ Yes Bypass }	@Yield @ContentsPart
			else		@Yield @Null
		    }
            //      @MakeFigureContents @Case {
			{ Yes Bypass }	@Yield @FigureContentsPart
			else		@Yield @Null
		    }
            //      @MakeTableContents @Case {
			{ Yes Bypass }	@Yield @TableContentsPart
			else		@Yield @Null
		    }
        }

	def @ReferencesPart
	    named @Tag {}
	{
            @Full {
		//@AboveChapterGap
		@ChapterHeadingFont @Font @ChapterHeadingBreak @Break
		{ {} @ChapterHeadingFormat @RefHeading @RefListTitle }
	    }
	    //
            //  @PageMarker&&preceding @Tagged @Tag
	    //  @FootNoteThrough @Do @BeginFootNoteCounter
            //  @ReferencesInContents @MajorContentsEntry
		    title { @RefHeading @RefListTitle }
		    pagenum { @PageOf @Tag }
            //  Start @Runner @MajorTitle { @RefHeading @RefListTitle }
            //  @ReferencesSection
	    //  NonStart @Runner @MajorTitle { @RefHeading @RefListTitle }
	}

	def @IndexPart
	    named @Tag {}
	{
	    @Full
	    {
		//@AboveChapterGap
		@ChapterHeadingFont @Font @ChapterHeadingBreak @Break
		{ {} @ChapterHeadingFormat index @WordVal @IndexWord }
		//  @PageMarker&&preceding @Tagged @Tag
		//  @FootNoteThrough @Do @BeginFootNoteCounter
		//  @IndexInContents @MajorContentsEntry
		    title { index @WordVal @IndexWord }
		    pagenum { @PageOf @Tag }
		//  Start @Runner @MajorTitle { index @WordVal @IndexWord }
	        //  @IndexSection {
		    NonStart @Runner @MajorTitle { index @WordVal @IndexWord }
		    }
	    }
	}

	def @IndexAPart
	    named @Tag {}
	{
	    @Full
	    {
		//@AboveChapterGap
		@ChapterHeadingFont @Font @ChapterHeadingBreak @Break
		{ {} @ChapterHeadingFormat index @WordVal @IndexAWord }
	    }
	    //  @PageMarker&&preceding @Tagged @Tag
	    //  @FootNoteThrough @Do @BeginFootNoteCounter
	    //  @IndexAInContents @MajorContentsEntry
		    title { index @WordVal @IndexAWord }
		    pagenum { @PageOf @Tag }
	    //  Start @Runner @MajorTitle { index @WordVal @IndexAWord }
	    //  @IndexASection {
		    NonStart @Runner @MajorTitle { index @WordVal @IndexAWord }
		}
	}

	def @IndexBPart
	    named @Tag {}
	{
	    @Full
	    {
		//@AboveChapterGap
		@ChapterHeadingFont @Font @ChapterHeadingBreak @Break
		{ {} @ChapterHeadingFormat index @WordVal @IndexBWord }
	    }
	    //  @PageMarker&&preceding @Tagged @Tag
	    //  @FootNoteThrough @Do @BeginFootNoteCounter
	    //  @IndexBInContents @MajorContentsEntry
		    title { index @WordVal @IndexBWord }
		    pagenum { @PageOf @Tag }
	    //  Start @Runner @MajorTitle { index @WordVal @IndexBWord }
	    //  @IndexBSection {
		    NonStart @Runner @MajorTitle { index @WordVal @IndexBWord }
		}
	}

        def @BookBody force into { @ColPlace&&preceding }
	    named @Optimize { @OptimizePages }
        {
	    # The first component of @BookBody must be indefinite, so that
	    # its flushing is delayed until we reach the body galleys, either
	    # @Introduction or @Chapter.  If not, @BookBody will free up
	    # @PrefacePlace etc. too soon, producing a "no @PrefacePlace
	    # precedes this @PrefacePLace&&preceding" error message.

	        @IntroductionPlace
	    //	@ChapterList 1
	    //	@ReferencesBeforeAppendices @Do {
		    @MakeReferences @Do @ReferencesPart
		}
            //	@AppendixList 1
	    //	@ReferencesBeforeAppendices @NoDo {
		    @MakeReferences @Do @ReferencesPart
		}
	    //	@MakeIndexA @Do @IndexAPart
	    //  @MakeIndexA @Case {
		  Bypass  @Yield @BypassBeginIndexAPlace
		  else    @Yield @Null
		}
	    //	@MakeIndexB @Do @IndexBPart
	    //  @MakeIndexB @Case {
		  Bypass  @Yield @BypassBeginIndexBPlace
		  else    @Yield @Null
		}
	    //	@MakeIndex  @Do @IndexPart
	    //  @MakeIndex @Case {
		  Bypass  @Yield @BypassBeginIndexPlace
		  else    @Yield @Null
		}
        }

	def @BookCombined force into { @ColPlace&&preceding }
	    named @Optimize { @OptimizePages }
	{
		    @Before
            //1.1b  @TitlePageFont @Font
		    {	//1i    |0.5rt 2.5f @Font {1.2fx clines} @Break @Title |
			//2i    |0.5rt clines @Break @Author |
			//1i    |0.5rt clines @Break @Edition |
			//1rt   @OneRow @Publisher
		    }
            //1.1b  @After
            //	    Start @Runner
            //1.1b  @PrefacePlace
            //      @MakeContents @Case {
			{ Yes Bypass }	@Yield @ContentsPart
			else		@Yield @Null
		    }
            //      @MakeFigureContents @Case {
			{ Yes Bypass }	@Yield @FigureContentsPart
			else		@Yield @Null
		    }
            //      @MakeTableContents @Case {
			{ Yes Bypass }	@Yield @TableContentsPart
			else		@Yield @Null
		    }
	    //  @IntroductionPlace
	    //	@ChapterList 1
	    //	@ReferencesBeforeAppendices @Do {
		    @MakeReferences @Do @ReferencesPart
		}
            //	@AppendixList 1
	    //	@ReferencesBeforeAppendices @NoDo {
		    @MakeReferences @Do @ReferencesPart
		}
	    //	@MakeIndexA @Do @IndexAPart
	    //  @MakeIndexA @Case {
		  Bypass  @Yield @BypassBeginIndexAPlace
		  else    @Yield @Null
		}
	    //	@MakeIndexB @Do @IndexBPart
	    //  @MakeIndexB @Case {
		  Bypass  @Yield @BypassBeginIndexBPlace
		  else    @Yield @Null
		}
	    //	@MakeIndex  @Do @IndexPart
	    //  @MakeIndex @Case {
		  Bypass  @Yield @BypassBeginIndexPlace
		  else    @Yield @Null
		}
	}

        @InitialFont @Font @InitialBreak @Break @InitialLanguage @Language
	@InitialSpace @Space { @ColourCommand @InitialColour } @SetColour
        {

	    @SeparateIntroNumbering @Case {

		No  @Yield {
		        Yes @BeginAllCounters {}
		        Yes @BeginDisplayCounter {}
		        Yes @BeginFigureCounter {}
		        Yes @BeginTableCounter {}
		    //	@PageList
			    @ColumnNumber { @ColumnNumber }
			    @PageHeaders { @PageHeaders }
			    @FirstPageNumber
		    //	@BookCombined
		    //	NonStart @Runner
		}

		Yes @Yield {
		        Yes @BeginAllCounters {}
		        Yes @BeginDisplayCounter {}
		        Yes @BeginFigureCounter {}
		        Yes @BeginTableCounter {}
		    //  @IntroPageList
			    @ColumnNumber { 1 }
			    @PageHeaders { @PageHeaders }
			    @IntroFirstPageNumber
		    //	NonStart @Runner
		    //	@PageList
			    @ColumnNumber { @ColumnNumber }
			    @PageHeaders { @PageHeaders }
			    extra { Yes }
			    @FirstPageNumber
		    //	@BookIntro
		    //	@BookBody
		    //	NonStart @Runner
		}
	    }
        }
    }


    #######################################################################
    #                                                                     #
    #  Preface.                                                           #
    #                                                                     #
    #######################################################################

    def @Preface force into { @PrefacePlace&&preceding }
        named @Tag {}
        named @Title { preface @WordVal @PrefaceWord }
        named @RunningTitle { dft }
	named @InitialLanguage {}
        body @Body
    {

	def @RunTitle { @InitialLanguage @Language { @RunningTitle @Dft @Title } }
        def @ER { NonStart @Runner @MajorTitle { @RunTitle } }

        @ChooseFull {
	    //@AboveChapterGap
	    @InitialLanguage @Language @ChapterHeadingFont @Font
	    @ChapterHeadingBreak @Break { {} @ChapterHeadingFormat @Title }
        }
	//
	//  Start @Runner @MajorTitle { @RunTitle }
	//  @PageMarker&&preceding @Tagged @Tag
        //  @FootNoteThrough @Do @BeginFootNoteCounter
	//
        //  @InitialLanguage @Language @Body
        //@SectionGap @InitialLanguage @Language @EndNoteList 1
        //@SectionGap @InitialLanguage @Language @ChapRefSection
        //  @ER
    }


    #######################################################################
    #                                                                     #
    #  Introduction.                                                      #
    #                                                                     #
    #######################################################################

    def @Introduction force into { @IntroductionPlace&&preceding }
        named @Tag {}
        named @Title { introduction @WordVal @IntroductionWord }
        named @RunningTitle { dft }
	named @InitialLanguage {}
        body @Body
    {
	def @RunTitle { @InitialLanguage @Language { @RunningTitle @Dft @Title } }
        def @ER { NonStart @Runner @MajorTitle { @RunTitle } }

        @Full {
	    //@AboveChapterGap
	        @InitialLanguage @Language @ChapterHeadingFont @Font
		@ChapterHeadingBreak @Break { {} @ChapterHeadingFormat @Title }
        }
	//
	//  Start @Runner @MajorTitle { @RunTitle }
	//  @PageMarker&&preceding @Tagged @Tag
	//  @IntroductionInContents @MajorContentsEntry
		title { @InitialLanguage @Language @Title }
		pagenum { @PageOf @Tag }
        //  @FootNoteThrough @Do @BeginFootNoteCounter
	//
        //  @InitialLanguage @Language @Body
        //@SectionGap @InitialLanguage @Language @EndFigureList
        //@SectionGap @InitialLanguage @Language @EndNoteList 1
        //@SectionGap @InitialLanguage @Language @ChapRefSection
        //  @ER
    }


    #######################################################################
    #                                                                     #
    #  Chapters containing sections and subsections.                      #
    #                                                                     #
    #######################################################################

    export @BeginSections @EndSections @Section
    def @Chapter force into { @ChapterList&&preceding }
        named @Tag {}
        named @Title {}
        named @RunningTitle { dft }
	named @InitialLanguage {}
	named @PartNumber {}
	named @PartTitle {}
	named @PartText {}
        named @BypassNumber { dft }
        body @Body
    {

        def @EndSectionsPlace { @Galley }

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

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

        def @ChapterShortNum
        {
	    @BypassNumber @Dft {
	        @ChapterNumbers @Num { @ChapterList&&@Tag @Open { num } }
	    }
        }

        def @ChapterLongNum
        {
	    @ChapterNumbers @Then {
	        @InitialLanguage @Language {
		    chapter @WordVal @ChapterWord @ChapterShortNum
		}
	    }
        }

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

        def @ER
        {
	    NonStart @Runner
	        @MajorNum { @ChapterLongNum }
	        @MajorTitle { @ChapterTitle }
        }

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

            def @SectionNum
	    {
		@BypassNumber @Dft {
		    @SectionNumbers @Then {
			@ChapterShortNum @DotJoin @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 ragged @Break
			@SubSubSectionHeadingFont @Font
			@SubSubSectionHeadingBreak @Break @Protect
			  { @SubSubSectionNum @SubSubSectionHeadingFormat @Title}
	            //  @NumberMarker @Tag { @Tag } @Value { @SubSubSectionNum }
	            //  @SubSubSectionList&&preceding @Tagged @Tag
	            //  @PageMarker&&preceding @Tagged @Tag
		    //  @SubSubSectionNumInTheorems @BeginAllCounters @SubSubSectionNum
		    //  @SubSubSectionNumInDisplays @BeginDisplayCounter @SubSubSectionNum
		    //  @SubSubSectionNumInFigures @BeginFigureCounter @SubSubSectionNum
		    //  @SubSubSectionNumInTables @BeginTableCounter @SubSubSectionNum
	            //  @SubSubSectionInContents @ContentsEntry
			    indent { 9f }
			    number { @SubSubSectionNum }
			    title { @InitialLanguage @Language @Title }
			    pagenum { @PageOf @Tag }
	            //  @InitialLanguage @Language @Body
	        }

	            @InitialLanguage @Language @SubSectionHeadingFont @Font
		    @SubSectionHeadingBreak @Break @Protect
		      { @SubSectionNum @SubSectionHeadingFormat @Title}
	        //  @NumberMarker @Tag { @Tag } @Value { @SubSectionNum }
	        //  @SubSectionList&&preceding @Tagged @Tag
	        //  @PageMarker&&preceding @Tagged @Tag
	        //  @SubSectionInContents @ContentsEntry
		        indent { 6f }
		        number { @SubSectionNum }
		        title { @InitialLanguage @Language @Title }
		        pagenum { @PageOf @Tag }
		//  @SubSectionNumInTheorems @BeginAllCounters @SubSectionNum
		//  @SubSectionNumInDisplays @BeginDisplayCounter @SubSectionNum
		//  @SubSectionNumInFigures @BeginFigureCounter @SubSectionNum
		//  @SubSectionNumInTables @BeginTableCounter @SubSectionNum
	        //  @InitialLanguage @Language @Body
            }

                @InitialLanguage @Language @SectionHeadingFont @Font
		@SectionHeadingBreak @Break @Protect
		  { @SectionNum @SectionHeadingFormat @Title }
            //  @NumberMarker @Tag { @Tag } @Value { @SectionNum }
            //  @SectionList&&preceding @Tagged @Tag
            //  @PageMarker&&preceding @Tagged @Tag
            //  @SectionInContents @ContentsEntry
		    indent { 3f }
		    number { @SectionNum }
		    title { @InitialLanguage @Language @Title }
		    pagenum { @PageOf @Tag }
	    //  @SectionNumInTheorems @BeginAllCounters @SectionNum
	    //  @SectionNumInDisplays @BeginDisplayCounter @SectionNum
	    //  @SectionNumInFigures @BeginFigureCounter @SectionNum
	    //  @SectionNumInTables @BeginTableCounter @SectionNum
            //  @InitialLanguage @Language @Body
            //  NonStart @Runner
	            @MajorNum { @ChapterLongNum }
	            @MajorTitle { @ChapterTitle }
	            @MinorNum { @SectionNum }
	            @MinorTitle { @SectionTitle }

        }

	def @Part right x
	{
	    //@AbovePartGap
		    @InitialLanguage @Language @PartHeadingFont @Font
		    @PartHeadingBreak @Break { @PartNumber @PartHeadingFormat @PartTitle }
	    //      @PartInContents @VeryMajorContentsEntry
			indent { @PartContentsIndent }
			title { @PartNumber @DotSep {@InitialLanguage @Language @PartTitle}}
	    //1.1b  @InitialLanguage @Language @PartText
	    //      None @Runner
	    //1.1b
	}

	@InitialLanguage @Language {
	    @Full {
	        @PartTitle @Case {
		    ""	@Yield ""
		    else	@Yield @Part
	        }
	        //@AboveChapterGap
		    @ChapterHeadingFont @Font @ChapterHeadingBreak @Break
		    { @ChapterLongNum @ChapterHeadingFormat @Title }
	    }
	    //
            //  @NumberMarker @Tag { @Tag } @Value { @ChapterShortNum }
            //  @ChapterList&&preceding  @Tagged @Tag
            //  @PageMarker&&preceding   @Tagged @Tag
            //  @ChapterInContents @MajorContentsEntry
		    number { @ChapterLongNum }
		    title { @InitialLanguage @Language @Title }
		    pagenum { @PageOf @Tag }
            //  Start @Runner
		    @MajorNum { @ChapterLongNum }
		    @MajorTitle { @ChapterTitle }
	    //  @ChapterNumInTheorems @BeginAllCounters @ChapterShortNum
	    //  @ChapterNumInDisplays @BeginDisplayCounter @ChapterShortNum
	    //  @ChapterNumInFigures @BeginFigureCounter @ChapterShortNum
	    //  @ChapterNumInTables @BeginTableCounter @ChapterShortNum
            //  @FootNoteThrough @Do @BeginFootNoteCounter
	    //
            //  @Body
	    //@SectionGap @EndFigureList
            //@SectionGap @EndNoteList 1
            //@SectionGap @ChapRefSection
            //  @ER
	}
    }


    #######################################################################
    #                                                                     #
    #  Appendices.                                                        #
    #                                                                     #
    #######################################################################

    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 {
		    appendix @WordVal @AppendixWord @AppendixShortNum
		}
	    }
        }

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

        def @ER
        {
	    NonStart @Runner
	        @MajorNum { @AppendixLongNum }
	        @MajorTitle { @AppendixTitle }
        }

        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 @SubAppendixTitle
	    { @InitialLanguage @Language { @RunningTitle @Dft @Title } }

            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 } }
		    }
		  }
		}

	            @InitialLanguage @Language @SubSubAppendixHeadingFont @Font
		    @SubSubAppendixHeadingBreak @Break @Protect
		      { @SubSubAppendixNum @SubSubAppendixHeadingFormat @Title}
	        //  @NumberMarker @Tag { @Tag } @Value { @SubSubAppendixNum }
	        //  @SubSubAppendixList&&preceding @Tagged @Tag
	        //  @PageMarker&&preceding @Tagged @Tag
	        //  @SubSubAppendixInContents @ContentsEntry
		        indent { 6f }
		        number { @SubSubAppendixNum }
		        title { @InitialLanguage @Language @Title }
		        pagenum { @PageOf @Tag }
		//  @SubSubAppendixNumInTheorems @BeginAllCounters @SubSubAppendixNum
		//  @SubSubAppendixNumInDisplays @BeginDisplayCounter @SubSubAppendixNum
		//  @SubSubAppendixNumInFigures @BeginFigureCounter @SubSubAppendixNum
		//  @SubSubAppendixNumInTables @BeginTableCounter @SubSubAppendixNum
	        //  @InitialLanguage @Language @Body
            }

                @InitialLanguage @Language @SubAppendixHeadingFont @Font
		@SubAppendixHeadingBreak @Break @Protect
		  { @SubAppendixNum @SubAppendixHeadingFormat @Title }
            //  @NumberMarker @Tag { @Tag } @Value { @SubAppendixNum }
            //  @SubAppendixList&&preceding @Tagged @Tag
            //  @PageMarker&&preceding @Tagged @Tag
            //  @SubAppendixInContents @ContentsEntry
		    indent { 3f }
		    number { @SubAppendixNum }
		    title { @InitialLanguage @Language @Title }
		    pagenum { @PageOf @Tag }
	    //  @SubAppendixNumInTheorems @BeginAllCounters @SubAppendixNum
	    //  @SubAppendixNumInDisplays @BeginDisplayCounter @SubAppendixNum
	    //  @SubAppendixNumInFigures @BeginFigureCounter @SubAppendixNum
	    //  @SubAppendixNumInTables @BeginTableCounter @SubAppendixNum
            //  @InitialLanguage @Language @Body
            //  NonStart @Runner
	            @MajorNum { @AppendixLongNum }
	            @MajorTitle { @AppendixTitle }
	            @MinorNum { @SubAppendixNum }
	            @MinorTitle { @SubAppendixTitle }

        }

	@InitialLanguage @Language {
	    @Full {
	        //@AboveChapterGap
		    @AppendixHeadingFont @Font @AppendixHeadingBreak @Break
		    { @AppendixLongNum @AppendixHeadingFormat @Title }
	    }
	    //
            //  @NumberMarker @Tag { @Tag } @Value { @AppendixShortNum }
            //  @AppendixList&&preceding @Tagged @Tag
            //  @PageMarker&&preceding @Tagged @Tag
            //  @AppendixInContents @MajorContentsEntry
		    number { @AppendixLongNum }
		    title { @InitialLanguage @Language @Title }
		    pagenum { @PageOf @Tag }
            //  Start @Runner
		    @MajorNum { @AppendixLongNum }
		    @MajorTitle { @AppendixTitle }
	    //  @AppendixNumInTheorems @Do @BeginAllCounters @AppendixShortNum
	    //  @AppendixNumInDisplays @Do @BeginDisplayCounter @AppendixShortNum
	    //  @AppendixNumInFigures @Do @BeginFigureCounter @AppendixShortNum
	    //  @AppendixNumInTables @Do @BeginTableCounter @AppendixShortNum
            //  @FootNoteThrough @Do @BeginFootNoteCounter
	    //
            //  @Body
	    //@SubAppendixGap @EndFigureList
            //@SubAppendixGap @EndNoteList 1
            //@SubAppendixGap @ChapRefSection
            //  @ER
	}
    }

@End @BookLayout
