Back to index

moin  1.9.0~rc2
Classes | Functions | Variables Namespace Reference


class  LatexFormatter


def escape_tex
def _get_ttype_name


list __all__ = ['LatexFormatter']
string DOC_TEMPLATE = r''
string STYLE_TEMPLATE = r''
 Small explanation of the mess below :)

Function Documentation

Definition at line 102 of file

00103 def _get_ttype_name(ttype):
00104     fname = STANDARD_TYPES.get(ttype)
00105     if fname:
00106         return fname
00107     aname = ''
00108     while fname is None:
00109         aname = ttype[-1] + aname
00110         ttype = ttype.parent
00111         fname = STANDARD_TYPES.get(ttype)
00112     return fname + aname

Here is the caller graph for this function:

def (   text,

Definition at line 20 of file

00021 def escape_tex(text, commandprefix):
00022     return text.replace('@', '\x00').    \
00023                 replace('[', '\x01').    \
00024                 replace(']', '\x02').    \
00025                 replace('\x00', '@%sZat[]' % commandprefix).\
00026                 replace('\x01', '@%sZlb[]' % commandprefix).\
00027                 replace('\x02', '@%sZrb[]' % commandprefix)

Here is the caller graph for this function:

Variable Documentation

Definition at line 17 of file

Definition at line 29 of file

Small explanation of the mess below :)

The previous version of the LaTeX formatter just assigned a command to each token type defined in the current style. That obviously is problematic if the highlighted code is produced for a different style than the style commands themselves.

This version works much like the HTML formatter which assigns multiple CSS classes to each tag, from the most specific to the least specific token type, thus falling back to the parent token type if one is not defined. Here, the classes are there too and use the same short forms given in token.STANDARD_TYPES.

Highlighted code now only uses one custom command, which by default is and selectable by the commandprefix option (and in addition the escapes , and which haven't been renamed for backwards compatibility purposes).

has two arguments: the classes, separated by +, and the text to render in that style. The classes are resolved into the respective style commands by magic, which serves to ignore unknown classes.

The magic macros are:

  • , , etc. are unconditionally wrapped around the text to render in . Their definition determines the style.
  • resets etc. to do nothing.
  • parses the list of classes, using magic inspired by the keyval package (but modified to use plusses instead of commas because fancyvrb redefines commas inside its environments).
  • processes one class, calling the command if it exists.
  • sets the etc. to reflect the chosen style for its class.
  • resets the style, parses the classnames and then calls .

Definition at line 81 of file