Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
MoinMoin.support.pygments.formatters.latex.LatexFormatter Class Reference
Inheritance diagram for MoinMoin.support.pygments.formatters.latex.LatexFormatter:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.pygments.formatters.latex.LatexFormatter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_style_defs
def format_unencoded

Public Attributes

 docclass
 preamble
 linenos
 linenostart
 linenostep
 verboptions
 nobackground
 commandprefix
 ttype2name
 cmd2def

Static Public Attributes

string name = 'LaTeX'
list aliases = ['latex', 'tex']
list filenames = ['*.tex']

Private Member Functions

def _create_stylesheet

Detailed Description

Definition at line 114 of file latex.py.


Constructor & Destructor Documentation

Definition at line 185 of file latex.py.

00185 
00186     def __init__(self, **options):
00187         Formatter.__init__(self, **options)
00188         self.docclass = options.get('docclass', 'article')
00189         self.preamble = options.get('preamble', '')
00190         self.linenos = get_bool_opt(options, 'linenos', False)
00191         self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
00192         self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
00193         self.verboptions = options.get('verboptions', '')
00194         self.nobackground = get_bool_opt(options, 'nobackground', False)
00195         self.commandprefix = options.get('commandprefix', 'PY')
00196 
00197         self._create_stylesheet()
00198 


Member Function Documentation

Definition at line 199 of file latex.py.

00199 
00200     def _create_stylesheet(self):
00201         t2n = self.ttype2name = {Token: ''}
00202         c2d = self.cmd2def = {}
00203         cp = self.commandprefix
00204 
00205         def rgbcolor(col):
00206             if col:
00207                 return ','.join(['%.2f' %(int(col[i] + col[i + 1], 16) / 255.0)
00208                                  for i in (0, 2, 4)])
00209             else:
00210                 return '1,1,1'
00211 
00212         for ttype, ndef in self.style:
00213             name = _get_ttype_name(ttype)
00214             cmndef = ''
00215             if ndef['bold']:
00216                 cmndef += r'\let\$$@bf=\textbf'
00217             if ndef['italic']:
00218                 cmndef += r'\let\$$@it=\textit'
00219             if ndef['underline']:
00220                 cmndef += r'\let\$$@ul=\underline'
00221             if ndef['roman']:
00222                 cmndef += r'\let\$$@ff=\textrm'
00223             if ndef['sans']:
00224                 cmndef += r'\let\$$@ff=\textsf'
00225             if ndef['mono']:
00226                 cmndef += r'\let\$$@ff=\textsf'
00227             if ndef['color']:
00228                 cmndef += (r'\def\$$@tc##1{\textcolor[rgb]{%s}{##1}}' %
00229                            rgbcolor(ndef['color']))
00230             if ndef['border']:
00231                 cmndef += (r'\def\$$@bc##1{\fcolorbox[rgb]{%s}{%s}{##1}}' %
00232                            (rgbcolor(ndef['border']),
00233                             rgbcolor(ndef['bgcolor'])))
00234             elif ndef['bgcolor']:
00235                 cmndef += (r'\def\$$@bc##1{\colorbox[rgb]{%s}{##1}}' %
00236                            rgbcolor(ndef['bgcolor']))
00237             if cmndef == '':
00238                 continue
00239             cmndef = cmndef.replace('$$', cp)
00240             t2n[ttype] = name
00241             c2d[name] = cmndef

Definition at line 254 of file latex.py.

00254 
00255     def format_unencoded(self, tokensource, outfile):
00256         # TODO: add support for background colors
00257         t2n = self.ttype2name
00258         cp = self.commandprefix
00259 
00260         if self.full:
00261             realoutfile = outfile
00262             outfile = StringIO()
00263 
00264         outfile.write(r'\begin{Verbatim}[commandchars=@\[\]')
00265         if self.linenos:
00266             start, step = self.linenostart, self.linenostep
00267             outfile.write(',numbers=left' +
00268                           (start and ',firstnumber=%d' % start or '') +
00269                           (step and ',stepnumber=%d' % step or ''))
00270         if self.verboptions:
00271             outfile.write(',' + self.verboptions)
00272         outfile.write(']\n')
00273 
00274         for ttype, value in tokensource:
00275             value = escape_tex(value, self.commandprefix)
00276             styles = []
00277             while ttype is not Token:
00278                 try:
00279                     styles.append(t2n[ttype])
00280                 except KeyError:
00281                     # not in current style
00282                     styles.append(_get_ttype_name(ttype))
00283                 ttype = ttype.parent
00284             styleval = '+'.join(reversed(styles))
00285             if styleval:
00286                 spl = value.split('\n')
00287                 for line in spl[:-1]:
00288                     if line:
00289                         outfile.write("@%s[%s][%s]" % (cp, styleval, line))
00290                     outfile.write('\n')
00291                 if spl[-1]:
00292                     outfile.write("@%s[%s][%s]" % (cp, styleval, spl[-1]))
00293             else:
00294                 outfile.write(value)
00295 
00296         outfile.write('\\end{Verbatim}\n')
00297 
00298         if self.full:
00299             realoutfile.write(DOC_TEMPLATE %
00300                 dict(docclass  = self.docclass,
00301                      preamble  = self.preamble,
00302                      title     = self.title,
00303                      encoding  = self.encoding or 'latin1',
00304                      styledefs = self.get_style_defs(),
00305                      code      = outfile.getvalue()))

Here is the call graph for this function:

Here is the caller graph for this function:

Return the command sequences needed to define the commands
used to format text in the verbatim environment. ``arg`` is ignored.

Definition at line 242 of file latex.py.

00242 
00243     def get_style_defs(self, arg=''):
00244         """
00245         Return the command sequences needed to define the commands
00246         used to format text in the verbatim environment. ``arg`` is ignored.
00247         """
00248         cp = self.commandprefix
00249         styles = []
00250         for name, definition in self.cmd2def.iteritems():
00251             styles.append(r'\def\%s@tok@%s{%s}' % (cp, name, definition))
00252         return STYLE_TEMPLATE % {'cp': self.commandprefix,
00253                                  'styles': '\n'.join(styles)}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 182 of file latex.py.

Definition at line 201 of file latex.py.

Definition at line 194 of file latex.py.

Definition at line 187 of file latex.py.

Definition at line 183 of file latex.py.

Definition at line 189 of file latex.py.

Definition at line 190 of file latex.py.

Definition at line 191 of file latex.py.

Definition at line 181 of file latex.py.

Definition at line 193 of file latex.py.

Definition at line 188 of file latex.py.

Definition at line 200 of file latex.py.

Definition at line 192 of file latex.py.


The documentation for this class was generated from the following file: