6.14.9.14. Headings

Lout provides us with fewer levels of headings than does LaTeX so we try to make do with what we have. Further, the levels of headings differ between the various styles of document. We always have section, subsection and subsubsection available. With the book style we gain chapter as the uppermost heading.

Our first step is to determine what the heading level really requested is based on the offset that was specified when this instance was created and the level requested by the user. In addition we check to see if this heading has an anchor or in Lout terminology, a tag. We use anchor if that is specified and atext if not.

Start python section to interscript/weavers/lout.py[19 /34 ] Next Prev First Last
   280: #line 582 "lout_weaver.ipk"
   281:     def head(self,level, text, **kwds):
   282:       atext=kwds.get('short_text')
   283:       anchor=kwds.get('key','')
   284:         level = level + self.heading_level_offset
   285:         if level > self.maxSectionLevels:
   286:             level = self.maxSectionLevels
   287: 
   288:         if anchor == '':
   289:             anchor = atext
   290: 
End python section to interscript/weavers/lout.py[19]

The first thing that we have to figure out is whether we need to end any lower level sections. If, for instance, this is a request to start a new level 1 section and we are in the middle of a level 3 section, we have to emit the appropriate sequence of closure commands. For this reason, we keep track of the current level in self.currentLevel.

Start python section to interscript/weavers/lout.py[20 /34 ] Next Prev First Last
   291: #line 604 "lout_weaver.ipk"
   292:         if self.currentLevel > level:
   293:             self.closeLevels(level)
End python section to interscript/weavers/lout.py[20]

Now that we are closed off to the appropriate level we need to emit the appropriate openings.

Start python section to interscript/weavers/lout.py[21 /34 ] Next Prev First Last
   294: #line 612 "lout_weaver.ipk"
   295:         sectionType = self.sectionLevels[level-1]
   296:         if self.currentLevel == level:
   297:             # End the previous entity
   298:             self._writeline("@End @%s" % sectionType)
   299:         elif self.currentLevel < level:
   300:             self.openLevels(level)
End python section to interscript/weavers/lout.py[21]

Now we can generate the appropriate heading text. Remember that heading levels are 1-origin while Python indexing is 0-origin.

Start python section to interscript/weavers/lout.py[22 /34 ] Next Prev First Last
   301: #line 624 "lout_weaver.ipk"
   302:         self._writeline("@%s @Title{%s}" % (sectionType,
   303:                                             self.cvt_text(text)))
   304:         if anchor != '':
   305:             self._writeline("    @Tag{%s}" % anchor)
   306:         self._writeline("@Begin")
   307:         self.currentLevel = level
   308: 
End python section to interscript/weavers/lout.py[22]


6.14.9.14.1. Heading Helper openLevels
6.14.9.14.2. Heading Helper closeLevels