6.14.9.5. Lout Prolog and Epilog

This introduces the document and establishes the appropriate environment for the resulting Lout document. Optional keyword parameters aid in the selection of options to direct Lout in the style of document to be produced.

There are three basic styles to choose from: book (the default), report, and doc. Associated with each of these is a set of keywords used to customize the layout of that style. Since there are so many parameters that can be passed to most of the Lout styles, it is easier to rely upon the user having some understanding of this and accept what he provides verbatim.

Because the style or document class controls other details of the document, we remember what class was selected. It should be noted that the code below only works with the standard document styles that are in the Lout distribution.

The following summarizes the keyword options that can be passed to the prolog and hence to the constructor of the lout_weaver. Note that all these options take @I raw Lout text. No transformation of any sort is performed.

Include
This specifies a list of additional packages to included in addition to the standard document style. These includes will appear @B before the one for the document style.
InitialFont
The initial font specification for the document. This becomes the default font of the document.
InitialLanguage
The default language in which the document is written.
OptimizePages
Either Yes or No. If yes, page layout is optimized in a manner similar to TeX.
PageHeaders
Information about the appropriate headers. This is specific to the document style selected.
InitialSpace
How Lout should treat spaces.
Author
The author of the document if the style is other than doc.
Title
The title of the document.
Institution
The institution of the author.
DateLine
What to specify for the date. If simply Yes, then the date when the document was typeset will be included in the standard format specified by the document style.
CoverSheet
Yes if a cover sheet is desired and No otherwise. This is valid only if the document style is report.
Publisher
The publisher of the book (valid only if the document style is book.
Start python section to interscript/weavers/lout.py[3 /34 ] Next Prev First Last
    48: #line 153 "lout_weaver.ipk"
    49:     def prolog(self,kwds):
    50:         if kwds.has_key('Include'):
    51:             includes = kwds['Include']
    52:             if type(includes) != type([]):
    53:                 includes = [includes]
    54: 
    55:             for i in includes:
    56:                 self._writeline("@Include{%s}" % i)
    57: 
    58:         self.documentClass = 'book'
    59:         if kwds.has_key('documentclass'):
    60:             self.documentClass = kwds['documentclass']
    61: 
    62:         self._writeline("@Include{ " + self.documentClass + "}")
    63:         if self.documentClass == 'book':
    64:             self._writeline("@Book")
    65:         elif self.documentClass == 'report':
    66:             self._writeline("@Report")
    67:         else:
    68:             self._writeline("@Document")
End python section to interscript/weavers/lout.py[3]

Now that we have the very beginnings of the prolog started, we search through our keywords looking for options to control the layout. docOptions contains the set of standard options available in all three styles augmented as specified by the currently selected style.

A very explicit assumption is that the user does not have his own document style. If so, we cannot accurately manage headings. Perhaps we can find some way of generalizing this?

Start python section to interscript/weavers/lout.py[4 /34 ] Next Prev First Last
    69: #line 187 "lout_weaver.ipk"
    70:         docOptions = ['InitialFont', 'InitialLanguage',
    71:                       'OptimizePages', 'PageHeaders', 'InitialSpace']
    72: 
    73:         if self.documentClass == 'report':
    74:             docOptions = docOptions + ['Author', 'Title',
    75:                                        'Institution', 'DateLine',
    76:                                        'CoverSheet'
    77:                                        ]
    78:         elif self.documentClass == 'book':
    79:             docOptions = docOptions + ['Title' , 'Author',
    80:                                        'Publisher', 'DateLine'
    81:                                        ]
    82: 
    83:         for k in docOptions:
    84:             if kwds.has_key(k):
    85:                 self._writeline("    @%s{%s}" % (k, kwds[k]))
    86: 
    87:         if kwds.has_key("heading_level_offset"):
    88:             self.heading_level_offset = int(kwds["heading_level_offset"])
    89:         else:
    90:             self.heading_level_offset = 0
End python section to interscript/weavers/lout.py[4]

Now all we need to do is end the parameter section and start the document body. Only the basic document style needs anything else.

Start python section to interscript/weavers/lout.py[5 /34 ] Next Prev First Last
    91: #line 213 "lout_weaver.ipk"
    92:         self._writeline("//")
    93: 
    94:         if self.documentClass == 'doc':
    95:             self._writeline("@Text @Begin")
End python section to interscript/weavers/lout.py[5]

We have to keep track of some state as we attempt to build sections and subsections. Lout requires that each sequence of subsections within a section be bracketed by @BeginSubSections and @EndSubSections. The same is true of sections in the doc and book styles but not in the report style. In addition, we set self.sectionLevels to the list of section levels available in the current style.

Start python section to interscript/weavers/lout.py[6 /34 ] Next Prev First Last
    96: #line 229 "lout_weaver.ipk"
    97:         self.inSubSubSection = 0
    98:         self.inSubSection = 0
    99:         if self.documentClass == 'report':
   100:             self.inSection = 1
   101:             self.sectionLevels = ['Section',
   102:                                   'SubSection',
   103:                                   'SubSubSection']
   104:         elif self.documentClass == 'book':
   105:             self.inSection = 0
   106:             self.sectionLevels = ['Chapter' ,
   107:                                   'Section',
   108:                                   'SubSection',
   109:                                   'SubSubSection']
   110:         else:
   111:             self.inSection = 0
   112:             self.sectionLevels = ['Section',
   113:                                   'SubSection',
   114:                                   'SubSubSection']
   115: 
   116:         self.maxSectionLevels = len(self.sectionLevels)
End python section to interscript/weavers/lout.py[6]

The epilog depends upon the document type...

Start python section to interscript/weavers/lout.py[7 /34 ] Next Prev First Last
   117: #line 253 "lout_weaver.ipk"
   118:     def epilog(self):
   119:         self.closeLevels(0)
   120:         if self.documentClass == 'doc':
   121:             self._writeline("@End @Text")
End python section to interscript/weavers/lout.py[7]