
###########################################################################
#                                                                         #
#  @OverheadSetup extension to @DocumentSetup.                            #
#                                                                         #
#  Jeffrey H. Kingston                                                    #
#                                                                         #
#  This package extends DocumentSetup with definitions for overheads.     #
#                                                                         #
#  This program is free software; you can redistribute it and/or modify   #
#  it under the terms of the GNU General Public License as published by   #
#  the Free Software Foundation; either Version 3, or (at your option)    #
#  any later version.                                                     #
#                                                                         #
#  This program is distributed in the hope that it will be useful,        #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of         #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          #
#  GNU General Public License for more details.                           #
#                                                                         #
#  You should have received a copy of the GNU General Public License      #
#  along with this program; if not, write to the Free Software            #
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA #
#                                                                         #
#  As a special exception, when this file is read by Lout when processing #
#  a Lout source document, you may use the result without restriction.    #
#                                                                         #
###########################################################################

extend @BasicSetup @DocumentSetup
export @OverheadTransparencies @Lecture @Overhead
def @OverheadSetup
    named @DateLine			{ No			}
    named @ContentsWord			{ contents		}
    named @LectureWord			{ lecture		}
    named @OverheadWord			{ 			}
    named @LectureNumbers		{ Arabic		}
    named @FirstLectureNumber		{ 1			}
    named @OverheadNumbers		{ Arabic		}
    named @FirstOverheadNumber		{ 1			}
    named @TitlePageFont		{ Helvetica Base      	}
    named @TitleFormat
            right title                 { @Center clines @Break title }
    named @AuthorFormat
            right author                { @Center clines @Break author }
    named @InstitutionFormat
            right institution           { @Center clines @Break @I institution }
    named @DateLineFormat
            right date                  { @Center date          }
    named @AboveTitleGap		{ 0.5i			}
    named @AboveAuthorGap		{ 1.0i			}
    named @AboveInstitutionGap		{ 0.5i			}
    named @AboveDateLineGap		{ 0.5i			}
    named @LectureHeadingFont		{ Bold 1.2f		}
    named @LectureHeadingBreak		{ 1.2fx nohyphen	}
    named @LectureHeadingFormat
	    left number right title	{ @Centre number @DP @Centre title @DP }
    named @AboveLectureGap              { 3.0f                  }
    named @OverheadHeadingFont		{ Bold			}
    named @OverheadHeadingBreak		{ 1.2fx nohyphen	}
    named @OverheadHeadingFormat
	    left number right title	{ @Centre title @DP }
    named @OverheadFormat
	named @II right x { |@DisplayIndent x |               }
	named @QQ right x { |@DisplayIndent x |@DisplayIndent }
	named @CC right x { |0.5rt x          |               }
	named @RR right x { |1.0rt x          |               }
	right @Body
					{ @Body }
    named @AboveOverheadGap             { 1.0f                  }
    named @LectureInContents		{ Yes			}
    named @OverheadInContents		{ No			}
    named @ReferencesInContents		{ Yes			}
    named @LectureContentsIndent	{ 0f			}
    named @OverheadContentsIndent	{ 0f			}
    named @OverheadInLectureContentsIndent { 2f			}
    named @ReferencesContentsIndent	{ 0f			}
    named @LectureNumInTheorems		{ Yes			}
    named @OverheadNumInTheorems	{ No			}
    named @LectureNumInDisplays		{ Yes			}
    named @OverheadNumInDisplays	{ No			}
    named @LectureNumInFigures		{ Yes			}
    named @OverheadNumInFigures		{ No			}
    named @LectureNumInTables		{ Yes			}
    named @OverheadNumInTables		{ No			}
    named @LectureNumInFloaters		{ Yes			}
    named @OverheadNumInFloaters	{ No			}
    named @LectureNumInRunners		{ Yes			}
    named @OverheadNumInRunners		{ Yes			}
    named @LecturePrefix		{			}
    named @OverheadPrefix		{			}
@Begin

    #######################################################################
    #                                                                     #
    #  Symbols for passing full title to running headers.                 #
    #                                                                     #
    #######################################################################

    export @Val
    def @StoreTitle left @Tag named @Val {} { @Null }

    def @SaveTitle right x { save @StoreTitle @Val { x } }

    def @GetTitle { @StoreTitle&&save @Open { @Val } }


    #######################################################################
    #                                                                     #
    #  Lists of lectures and overheads.                                   #
    #                                                                     #
    #######################################################################

    export num
    def @LectureList named @Tag {} named num {}
    {
		@Galley
        //1.1b  @LectureList num { @Next num }
    }

    export num
    def @OverheadsList named @Tag {} named num {}
    {
		@Galley
        //1.1b	@OverheadsList num { @Next num }
    }

    export num
    def @LecOverheadsList named @Tag {} right num
    {
		@Galley
        //1.1b	@LecOverheadsList @Next num
    }


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

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


    #######################################################################
    #                                                                     #
    #  @OverheadTransparencies.                                           #
    #                                                                     #
    #######################################################################

    def @OverheadTransparencies
        named @Title {}
        named @RunningTitle { dft }
        named @Author {}
        named @Institution {}
        named @DateLine { @DateLine }
        named @InitialFont { @InitialFont }
        named @InitialBreak { @InitialBreak }
        named @InitialOutdent { @InitialOutdent }
        named @InitialSpace { @InitialSpace }
        named @InitialLanguage { @InitialLanguage }
	named @PageOrientation { @PageOrientation }
        named @PageHeaders { @PageHeaders }
        named @FirstPageNumber { @FirstPageNumber }
        named @FirstOverheadNumber { @FirstOverheadNumber }
        named @FirstLectureNumber { @FirstLectureNumber }
	named @OptimizePages { @OptimizePages }
    {

	def @DatePart
	{
	    @DateLine @Case {
		No	@Yield { @Null	    }
		Yes	@Yield { @Date      }
		else	@Yield { @DateLine  }
	    }
	}

	def @TitlePart
	{
	    @TitlePageFont @Font @InitialBreak @Break
	    @InitialSpace @Space clines @Break {
		//0.5i
               //@AboveTitleGap   1.5f @Font @InitialBreak @Break
                                  @InitialSpace @Space @TitleFormat @Title |
               //@AboveAuthorGap      @AuthorFormat @Author |
               //@AboveInstitutionGap @InstitutionFormat @Institution |
               //@AboveDateLineGap    @DateLineFormat @DatePart |
	    }
	}

	def @ContentsPart
	{
	    @DP	|0.5rt @LectureHeadingFont @Font @LectureHeadingBreak @Break
		       @LectureHeadingFormat { contents @WordVal @ContentsWord } |
	    @DP	@ContentsSection
	}

	def @ReferencesPart
	    named @Tag {}
	{
	    @DP	|0.5rt @LectureHeadingFont @Font @LectureHeadingBreak @Break
		       @LectureHeadingFormat { @RefHeading @RefListTitle } |
	    //  @PageMark @Tag
	    //  @ReferencesInContents @ContentsEntry
	            indent { @ReferencesContentsIndent }
		    title { @RefHeading @RefListTitle }
		    pagenum { @PageOf @Tag }
	    //  Start @Runner @MajorTitle { @GetTitle }
            @DP @ReferencesSection
	    //  NonStart @Runner @MajorTitle { @GetTitle }
	}

	def @OverheadsBody force into { @ColPlace&&preceding }
	    named @Optimize { @OptimizePages }
	{
		    @Title @Case {
			""	@Yield @Null
			else	@Yield @TitlePart
		    }
	    //1.1b  @MakeContents @Case {
			{ Yes Bypass }	@Yield @ContentsPart
			else		@Yield @Null
		    }
	    //      Start @Runner @MajorTitle { @GetTitle }
	    //1.1b  @OverheadsList num { @FirstOverheadNumber }
	    //1.1b  @LectureList num { @FirstLectureNumber }
	    //1.1b  @ReferencesPart
	}

        @InitialFont @Font { @InitialBreak setoutdent @InitialOutdent } @Break
	@InitialLanguage @Language @InitialSpace @Space
	{ @ColourCommand @InitialColour } @SetColour
        {
		@SaveTitle {
		    @InitialLanguage @Language { @RunningTitle @Dft @Title }
		}

	    //  Yes @BeginAllCounters {}
	    //  Yes @BeginDisplayCounter {}
	    //  Yes @BeginFigureCounter {}
	    //  Yes @BeginFigureCounter {}
            //	@PageList
		    @ColumnNumber { 1 }
		    @PageHeaders { @PageHeaders }
		    @Orient { @PageOrientation }
		    extra { Yes }
		    @FirstPageNumber
            //	@OverheadsBody
            //	Start @Runner
        }
    }


    #######################################################################
    #                                                                     #
    #  Overheads.                                                         #
    #                                                                     #
    #######################################################################

    def @Overhead force into { @OverheadsList&&preceding }
	named @Tag {}
	named @Title {}
	named @RunningTitle { dft }
	named @Format
            named @II right x { |@DisplayIndent x |               }
            named @QQ right x { |@DisplayIndent x |@DisplayIndent }
            named @CC right x { |0.5rt x          |               }
            named @RR right x { |1.0rt x          |               }
                right @Body { @OverheadFormat @Body }
	named @InitialLanguage {}
	named @BypassNumber { dft }
	body @Body
    {

	@LargeScaleStructure
	    tag { @Tag }
	    type { Major }
	    initiallanguage { @InitialLanguage }
	    title { @Title }
	    majortitle { @GetTitle }
	    runningtitle { @RunningTitle }
	    aboveheadinggap { @AboveOverheadGap }
	    headingfont { @OverheadHeadingFont }
	    headingbreak { @OverheadHeadingBreak }
	    headingformat { @Num @OverheadHeadingFormat @Body }
	    incontents { @OverheadInContents }
	    contentsindent { @OverheadContentsIndent }
	    numbers { @OverheadNumbers }
	    attachnum { @OverheadsList&&preceding @Tagged @Tag }
	    retrievenum { @OverheadsList&&@Tag @Open { num } }
	    bypassnumber { @BypassNumber }
	    pnprefix { @OverheadPrefix }
	    intheorems { @OverheadNumInTheorems }
            indisplays { @OverheadNumInDisplays }
            infigures { @OverheadNumInFigures }
            intables { @OverheadNumInTables }
            infloaters { @OverheadNumInFloaters }
	    sendheader { @Full @Body }
	    innergap { @DisplayGap }
            inrunners { @OverheadNumInRunners }
	    @Format @Body
    }


    #######################################################################
    #                                                                     #
    #  Lectures containing overheads.                                     #
    #                                                                     #
    #######################################################################

    export @BeginOverheads @EndOverheads @Overhead
    def @Lecture force into { @LectureList&&preceding }
        named @Tag {}
        named @Title {}
        named @RunningTitle { dft }
	named @InitialLanguage {}
	named @BypassNumber { dft }
        body @Body
    {
	def @SaveTitle { @Title }

        def @EndOverheadsPlace { @Galley }

        def @EndOverheads force into { @EndOverheadsPlace&&preceding }
	{}

        macro @BeginOverheads
	{   //1.1b @LecOverheadsList 1
	    // @EndOverheadsPlace //
	}

        def @LectureNum
        {
	    @LectureNumbers @Then {
		@BypassNumber @Dft {
		    @LectureNumbers @Num @LectureList&&@Tag @Open { num }
		}
	    }
        }

        def @Overhead force into { @LecOverheadsList&&preceding }
            named @Tag {}
            named @Title {}
            named @RunningTitle { dft }
	    named @Format
                named @II right x { |@DisplayIndent x |               }
                named @QQ right x { |@DisplayIndent x |@DisplayIndent }
                named @CC right x { |0.5rt x          |               }
                named @RR right x { |1.0rt x          |               }
		    right @Body { @OverheadFormat @Body }
	    named @InitialLanguage { @InitialLanguage }
	    named @BypassNumber { dft }
            body @Body
        {

	    @LargeScaleStructure
		tag { @Tag }
		type { Minor }
		initiallanguage { @InitialLanguage }
		title { @Title }
		runningtitle { @RunningTitle }
		headingfont { @OverheadHeadingFont }
		headingbreak { @OverheadHeadingBreak }
		headingformat { @Num @OverheadHeadingFormat @Body }
		incontents { @OverheadInContents }
		contentsindent { @OverheadInLectureContentsIndent }
		numbers { @OverheadNumbers }
		attachnum { @LecOverheadsList&&preceding @Tagged @Tag }
		retrievenum { @LecOverheadsList&&@Tag @Open { num } }
		bypassnumber { @BypassNumber }
		prefix { @LectureNum }
		majornum { @LectureNum }
		majortitle { @GetTitle }
		minortitle { @SaveTitle }
		intheorems { @OverheadNumInTheorems }
		indisplays { @OverheadNumInDisplays }
		infigures { @OverheadNumInFigures }
		inrunners { @OverheadNumInRunners }
		@Format @Body

        }

	@LargeScaleStructure
	    tag { @Tag }
	    type { Major }
	    initiallanguage { @InitialLanguage }
	    title { @Title }
	    runningtitle { @RunningTitle }
	    aboveheadinggap { @AboveLectureGap }
	    headingfont { @LectureHeadingFont }
	    headingbreak { @LectureHeadingBreak }
	    headingformat { @Num @LectureHeadingFormat @Body }
	    incontents { @LectureInContents }
	    contentsindent { @LectureContentsIndent }
	    word { lecture @WordVal @LectureWord }
	    numbers {  @LectureNumbers }
	    attachnum { @LectureList&&preceding @Tagged @Tag }
	    retrievenum { @LectureList&&@Tag @Open { num } }
	    bypassnumber { @BypassNumber }
	    pnprefix { @LecturePrefix }
	    majortitle { @GetTitle }
	    intheorems { @LectureNumInTheorems }
	    indisplays { @LectureNumInDisplays }
	    infigures { @LectureNumInFigures }
	    intables { @LectureNumInTables }
	    infloaters { @LectureNumInFloaters }
	    sendheader { @Full @Body }
	    innergap { @DisplayGap }
	    inrunners { @LectureNumInRunners }
	    @Body
	    
    }

@End @OverheadSetup
