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.
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")
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?
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
Now all we need to do is end the parameter section and start the document body. Only the basic document style needs anything else.
91: #line 213 "lout_weaver.ipk" 92: self._writeline("//") 93: 94: if self.documentClass == 'doc': 95: self._writeline("@Text @Begin")
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.
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)
The epilog depends upon the document type...
117: #line 253 "lout_weaver.ipk" 118: def epilog(self): 119: self.closeLevels(0) 120: if self.documentClass == 'doc': 121: self._writeline("@End @Text")