6.14.7.8. Latex Preamble

This is a very complex section that provides the latex preamble and document front matter. The basic command is like: @w = latex_weaver(sink,documentclass='book', documentclass_options=['a4paper','11pt'],topmargin='4pt'). [Typeset this as a display .. when the code is done for that feature]
Start python section to interscript/weavers/latex.py[9 /19 ] Next Prev First Last
   117: #line 137 "latex_weaver.ipk"
   118:   def prolog(self,kwds):
   119:     # this bit handles lambda translation process
   120:     # to convert interscript generated UTF-8 to unicode
   121:     if kwds.has_key('llambda'):
   122:       self._writeline('\\ocp\\inutf=inutf8')
   123:       self._writeline('\\inputTranslation\\inutf8')
   124:       self.omega=1
   125:     else:
   126:       self.omega=0
   127: 
   128:     # see Kopka pp25-27
   129:     # the default document class is for a book
   130:     # other standard classes include:
   131:     #   article report letter
   132: 
   133:     documentclass = 'book'
   134:     if kwds.has_key('documentclass'):
   135:       documentclass=kwds['documentclass']
   136: 
   137:     # the options are a python list of words
   138:     # for the standard book class they're from the set:
   139:     #   10pt 11pt 12pt
   140:     #   letterpaper legalpaper executivepaper
   141:     #   a4paper a5paper b5paper
   142:     #   landscape
   143:     #   onecolumn twocolumn
   144:     #   oneside twoside
   145:     #   openright openany
   146:     #   notitlepage titlepage
   147: 
   148:     # note: the default paper size Latex uses is
   149:     # american letterpaper. Don't count on this,
   150:     # I intend to make the ISO Standard A4 that everyone
   151:     # else uses the default!
   152: 
   153:     docopts = []
   154:     if kwds.has_key('documentclass_options'):
   155:       docopts =kwds['documentclass']
   156:     docoptstr=''
   157:     if docopts: docoptstr = docopts[0]
   158:     for opt in range(1,len(docopts)):
   159:      docoptstr = dosoptstr + ', ' + opt
   160:     self._writeline('\\documentclass['+docoptstr+']{'+documentclass+'}')
   161: 
   162:     if kwds.has_key('heading_level_offset'):
   163:       self.heading_level_offset = kwds['heading_level_offset']
   164: 
   165:     # page heading control
   166:     pagestyle = 'headings'
   167:     if kwds.has_key('pagestyle'):
   168:       pagestyle=kwds['pagestyle']
   169:     self._writeline('\\pagestyle{'+pagestyle+'}')
   170: 
   171:     pagenumbering= 'arabic'
   172:     if kwds.has_key('pagenumbering'):
   173:       pagenumbering=kwds['pagenumbering']
   174:     self._writeline('\\pagenumbering{'+pagenumbering+'}')
   175: 
   176:     # page layout
   177:     page_format_params = [
   178:       'topmargin','headheight','headsep','topskip','textheight','footskip',
   179:       'oddsidemargin','evensidemargin',
   180:       'textwidth']
   181:     for p in page_format_params:
   182:       if kwds.has_key(p):
   183:         param=kwds[p]
   184:         self._writeline('\\setlength{\\'+p+'}{'+param+'}')
   185: 
   186:     # lines and paragraphs
   187: 
   188:     # Note: we do _not_ permit indented paragraphs AT ALL.
   189:     # Don't even try it. FAR FAR too many things are broken
   190:     # by indentation.
   191: 
   192:     baselinestretch= 1
   193:     if kwds.has_key('baselinestretch'):
   194:       baselinestretch=kwds['baselinestretch']
   195:     self._writeline('\\renewcommand{\\baselinestretch}{'+str(baselinestretch)+'}')
   196: 
   197:     self._writeline('\\setlength{\\parskip 2mm plus 0.5mm minus 1mm}')
   198:     self._writeline('\\setlength{\\parindent 0mm}')
   199: 
   200:     self._writeline( '\\begin{document}')
   201:     if kwds.has_key('title'):
   202:       title=kwds['title']
   203:     else:
   204:       title = self.sink.pass_frame.master.filename
   205:     self._writeline('\\title{'+cvt_text(title)+'}')
   206:     if kwds.has_key('author'):
   207:       author =kwds['author']
   208:       self._writeline('\\author{'+cvt_text(author)+'}')
   209: 
   210:     self._writeline( '\\maketitle')
   211: 
   212:   def epilog(self):
   213:     self._writeline('\\end{document}')
   214: 
End python section to interscript/weavers/latex.py[9]