annotate MoinMoin/support/pygments/formatters/latex.py @ 6097:815981fad7fd

upgrade pygments from 1.6 to 2.1.3
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 05 Sep 2016 23:55:33 +0200
parents b48a69886ca4
children
rev   line source
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
2 """
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
3 pygments.formatters.latex
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
5
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
6 Formatter for LaTeX fancyvrb output.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
7
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
9 :license: BSD, see LICENSE for details.
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
10 """
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
11
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
12 from __future__ import division
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
13
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
14 from pygments.formatter import Formatter
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
15 from pygments.lexer import Lexer
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
16 from pygments.token import Token, STANDARD_TYPES
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
17 from pygments.util import get_bool_opt, get_int_opt, StringIO, xrange, \
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
18 iteritems
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
19
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
20
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
21 __all__ = ['LatexFormatter']
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
22
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
23
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
24 def escape_tex(text, commandprefix):
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
25 return text.replace('\\', '\x00'). \
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
26 replace('{', '\x01'). \
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
27 replace('}', '\x02'). \
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
28 replace('\x00', r'\%sZbs{}' % commandprefix). \
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
29 replace('\x01', r'\%sZob{}' % commandprefix). \
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
30 replace('\x02', r'\%sZcb{}' % commandprefix). \
5803
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
31 replace('^', r'\%sZca{}' % commandprefix). \
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
32 replace('_', r'\%sZus{}' % commandprefix). \
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
33 replace('&', r'\%sZam{}' % commandprefix). \
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
34 replace('<', r'\%sZlt{}' % commandprefix). \
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
35 replace('>', r'\%sZgt{}' % commandprefix). \
5803
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
36 replace('#', r'\%sZsh{}' % commandprefix). \
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
37 replace('%', r'\%sZpc{}' % commandprefix). \
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
38 replace('$', r'\%sZdl{}' % commandprefix). \
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
39 replace('-', r'\%sZhy{}' % commandprefix). \
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
40 replace("'", r'\%sZsq{}' % commandprefix). \
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
41 replace('"', r'\%sZdq{}' % commandprefix). \
5803
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
42 replace('~', r'\%sZti{}' % commandprefix)
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
43
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
44
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
45 DOC_TEMPLATE = r'''
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
46 \documentclass{%(docclass)s}
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
47 \usepackage{fancyvrb}
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
48 \usepackage{color}
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
49 \usepackage[%(encoding)s]{inputenc}
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
50 %(preamble)s
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
51
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
52 %(styledefs)s
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
53
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
54 \begin{document}
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
55
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
56 \section*{%(title)s}
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
57
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
58 %(code)s
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
59 \end{document}
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
60 '''
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
61
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
62 ## Small explanation of the mess below :)
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
63 #
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
64 # The previous version of the LaTeX formatter just assigned a command to
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
65 # each token type defined in the current style. That obviously is
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
66 # problematic if the highlighted code is produced for a different style
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
67 # than the style commands themselves.
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
68 #
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
69 # This version works much like the HTML formatter which assigns multiple
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
70 # CSS classes to each <span> tag, from the most specific to the least
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
71 # specific token type, thus falling back to the parent token type if one
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
72 # is not defined. Here, the classes are there too and use the same short
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
73 # forms given in token.STANDARD_TYPES.
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
74 #
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
75 # Highlighted code now only uses one custom command, which by default is
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
76 # \PY and selectable by the commandprefix option (and in addition the
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
77 # escapes \PYZat, \PYZlb and \PYZrb which haven't been renamed for
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
78 # backwards compatibility purposes).
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
79 #
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
80 # \PY has two arguments: the classes, separated by +, and the text to
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
81 # render in that style. The classes are resolved into the respective
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
82 # style commands by magic, which serves to ignore unknown classes.
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
83 #
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
84 # The magic macros are:
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
85 # * \PY@it, \PY@bf, etc. are unconditionally wrapped around the text
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
86 # to render in \PY@do. Their definition determines the style.
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
87 # * \PY@reset resets \PY@it etc. to do nothing.
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
88 # * \PY@toks parses the list of classes, using magic inspired by the
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
89 # keyval package (but modified to use plusses instead of commas
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
90 # because fancyvrb redefines commas inside its environments).
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
91 # * \PY@tok processes one class, calling the \PY@tok@classname command
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
92 # if it exists.
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
93 # * \PY@tok@classname sets the \PY@it etc. to reflect the chosen style
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
94 # for its class.
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
95 # * \PY resets the style, parses the classnames and then calls \PY@do.
5803
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
96 #
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
97 # Tip: to read this code, print it out in substituted form using e.g.
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
98 # >>> print STYLE_TEMPLATE % {'cp': 'PY'}
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
99
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
100 STYLE_TEMPLATE = r'''
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
101 \makeatletter
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
102 \def\%(cp)s@reset{\let\%(cp)s@it=\relax \let\%(cp)s@bf=\relax%%
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
103 \let\%(cp)s@ul=\relax \let\%(cp)s@tc=\relax%%
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
104 \let\%(cp)s@bc=\relax \let\%(cp)s@ff=\relax}
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
105 \def\%(cp)s@tok#1{\csname %(cp)s@tok@#1\endcsname}
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
106 \def\%(cp)s@toks#1+{\ifx\relax#1\empty\else%%
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
107 \%(cp)s@tok{#1}\expandafter\%(cp)s@toks\fi}
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
108 \def\%(cp)s@do#1{\%(cp)s@bc{\%(cp)s@tc{\%(cp)s@ul{%%
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
109 \%(cp)s@it{\%(cp)s@bf{\%(cp)s@ff{#1}}}}}}}
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
110 \def\%(cp)s#1#2{\%(cp)s@reset\%(cp)s@toks#1+\relax+\%(cp)s@do{#2}}
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
111
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
112 %(styles)s
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
113
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
114 \def\%(cp)sZbs{\char`\\}
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
115 \def\%(cp)sZus{\char`\_}
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
116 \def\%(cp)sZob{\char`\{}
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
117 \def\%(cp)sZcb{\char`\}}
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
118 \def\%(cp)sZca{\char`\^}
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
119 \def\%(cp)sZam{\char`\&}
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
120 \def\%(cp)sZlt{\char`\<}
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
121 \def\%(cp)sZgt{\char`\>}
5803
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
122 \def\%(cp)sZsh{\char`\#}
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
123 \def\%(cp)sZpc{\char`\%%}
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
124 \def\%(cp)sZdl{\char`\$}
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
125 \def\%(cp)sZhy{\char`\-}
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
126 \def\%(cp)sZsq{\char`\'}
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
127 \def\%(cp)sZdq{\char`\"}
5803
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
128 \def\%(cp)sZti{\char`\~}
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
129 %% for compatibility with earlier versions
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
130 \def\%(cp)sZat{@}
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
131 \def\%(cp)sZlb{[}
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
132 \def\%(cp)sZrb{]}
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
133 \makeatother
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
134 '''
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
135
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
136
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
137 def _get_ttype_name(ttype):
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
138 fname = STANDARD_TYPES.get(ttype)
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
139 if fname:
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
140 return fname
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
141 aname = ''
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
142 while fname is None:
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
143 aname = ttype[-1] + aname
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
144 ttype = ttype.parent
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
145 fname = STANDARD_TYPES.get(ttype)
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
146 return fname + aname
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
147
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
148
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
149 class LatexFormatter(Formatter):
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
150 r"""
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
151 Format tokens as LaTeX code. This needs the `fancyvrb` and `color`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
152 standard packages.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
153
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
154 Without the `full` option, code is formatted as one ``Verbatim``
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
155 environment, like this:
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
156
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
157 .. sourcecode:: latex
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
158
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
159 \begin{Verbatim}[commandchars=\\\{\}]
5803
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
160 \PY{k}{def }\PY{n+nf}{foo}(\PY{n}{bar}):
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
161 \PY{k}{pass}
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
162 \end{Verbatim}
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
163
5803
6446873d152f upgraded bundled pygments from 1.3.1 to 1.4
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5564
diff changeset
164 The special command used here (``\PY``) and all the other macros it needs
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
165 are output by the `get_style_defs` method.
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
166
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
167 With the `full` option, a complete LaTeX document is output, including
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
168 the command definitions in the preamble.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
169
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
170 The `get_style_defs()` method of a `LatexFormatter` returns a string
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
171 containing ``\def`` commands defining the macros needed inside the
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
172 ``Verbatim`` environments.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
173
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
174 Additional options accepted:
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
175
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
176 `style`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
177 The style to use, can be a string or a Style subclass (default:
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
178 ``'default'``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
179
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
180 `full`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
181 Tells the formatter to output a "full" document, i.e. a complete
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
182 self-contained document (default: ``False``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
183
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
184 `title`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
185 If `full` is true, the title that should be used to caption the
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
186 document (default: ``''``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
187
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
188 `docclass`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
189 If the `full` option is enabled, this is the document class to use
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
190 (default: ``'article'``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
191
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
192 `preamble`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
193 If the `full` option is enabled, this can be further preamble commands,
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
194 e.g. ``\usepackage`` (default: ``''``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
195
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
196 `linenos`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
197 If set to ``True``, output line numbers (default: ``False``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
198
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
199 `linenostart`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
200 The line number for the first line (default: ``1``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
201
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
202 `linenostep`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
203 If set to a number n > 1, only every nth line number is printed.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
204
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
205 `verboptions`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
206 Additional options given to the Verbatim environment (see the *fancyvrb*
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
207 docs for possible values) (default: ``''``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
208
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
209 `commandprefix`
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
210 The LaTeX commands used to produce colored output are constructed
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
211 using this prefix and some letters (default: ``'PY'``).
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
212
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
213 .. versionadded:: 0.7
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
214 .. versionchanged:: 0.10
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
215 The default is now ``'PY'`` instead of ``'C'``.
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
216
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
217 `texcomments`
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
218 If set to ``True``, enables LaTeX comment lines. That is, LaTex markup
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
219 in comment tokens is not escaped so that LaTeX can render it (default:
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
220 ``False``).
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
221
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
222 .. versionadded:: 1.2
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
223
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
224 `mathescape`
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
225 If set to ``True``, enables LaTeX math mode escape in comments. That
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
226 is, ``'$...$'`` inside a comment will trigger math mode (default:
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
227 ``False``).
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
228
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
229 .. versionadded:: 1.2
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
230
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
231 `escapeinside`
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
232 If set to a string of length 2, enables escaping to LaTeX. Text
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
233 delimited by these 2 characters is read as LaTeX code and
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
234 typeset accordingly. It has no effect in string literals. It has
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
235 no effect in comments if `texcomments` or `mathescape` is
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
236 set. (default: ``''``).
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
237
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
238 .. versionadded:: 2.0
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
239
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
240 `envname`
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
241 Allows you to pick an alternative environment name replacing Verbatim.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
242 The alternate environment still has to support Verbatim's option syntax.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
243 (default: ``'Verbatim'``).
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
244
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
245 .. versionadded:: 2.0
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
246 """
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
247 name = 'LaTeX'
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
248 aliases = ['latex', 'tex']
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
249 filenames = ['*.tex']
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
250
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
251 def __init__(self, **options):
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
252 Formatter.__init__(self, **options)
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
253 self.docclass = options.get('docclass', 'article')
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
254 self.preamble = options.get('preamble', '')
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
255 self.linenos = get_bool_opt(options, 'linenos', False)
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
256 self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
257 self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
258 self.verboptions = options.get('verboptions', '')
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
259 self.nobackground = get_bool_opt(options, 'nobackground', False)
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
260 self.commandprefix = options.get('commandprefix', 'PY')
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
261 self.texcomments = get_bool_opt(options, 'texcomments', False)
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
262 self.mathescape = get_bool_opt(options, 'mathescape', False)
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
263 self.escapeinside = options.get('escapeinside', '')
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
264 if len(self.escapeinside) == 2:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
265 self.left = self.escapeinside[0]
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
266 self.right = self.escapeinside[1]
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
267 else:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
268 self.escapeinside = ''
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
269 self.envname = options.get('envname', u'Verbatim')
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
270
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
271 self._create_stylesheet()
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
272
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
273 def _create_stylesheet(self):
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
274 t2n = self.ttype2name = {Token: ''}
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
275 c2d = self.cmd2def = {}
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
276 cp = self.commandprefix
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
277
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
278 def rgbcolor(col):
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
279 if col:
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
280 return ','.join(['%.2f' % (int(col[i] + col[i + 1], 16) / 255.0)
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
281 for i in (0, 2, 4)])
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
282 else:
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
283 return '1,1,1'
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
284
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
285 for ttype, ndef in self.style:
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
286 name = _get_ttype_name(ttype)
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
287 cmndef = ''
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
288 if ndef['bold']:
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
289 cmndef += r'\let\$$@bf=\textbf'
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
290 if ndef['italic']:
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
291 cmndef += r'\let\$$@it=\textit'
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
292 if ndef['underline']:
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
293 cmndef += r'\let\$$@ul=\underline'
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
294 if ndef['roman']:
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
295 cmndef += r'\let\$$@ff=\textrm'
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
296 if ndef['sans']:
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
297 cmndef += r'\let\$$@ff=\textsf'
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
298 if ndef['mono']:
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
299 cmndef += r'\let\$$@ff=\textsf'
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
300 if ndef['color']:
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
301 cmndef += (r'\def\$$@tc##1{\textcolor[rgb]{%s}{##1}}' %
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
302 rgbcolor(ndef['color']))
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
303 if ndef['border']:
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
304 cmndef += (r'\def\$$@bc##1{\setlength{\fboxsep}{0pt}'
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
305 r'\fcolorbox[rgb]{%s}{%s}{\strut ##1}}' %
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
306 (rgbcolor(ndef['border']),
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
307 rgbcolor(ndef['bgcolor'])))
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
308 elif ndef['bgcolor']:
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
309 cmndef += (r'\def\$$@bc##1{\setlength{\fboxsep}{0pt}'
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
310 r'\colorbox[rgb]{%s}{\strut ##1}}' %
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
311 rgbcolor(ndef['bgcolor']))
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
312 if cmndef == '':
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
313 continue
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
314 cmndef = cmndef.replace('$$', cp)
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
315 t2n[ttype] = name
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
316 c2d[name] = cmndef
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
317
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
318 def get_style_defs(self, arg=''):
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
319 """
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
320 Return the command sequences needed to define the commands
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
321 used to format text in the verbatim environment. ``arg`` is ignored.
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
322 """
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
323 cp = self.commandprefix
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
324 styles = []
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
325 for name, definition in iteritems(self.cmd2def):
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
326 styles.append(r'\expandafter\def\csname %s@tok@%s\endcsname{%s}' %
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
327 (cp, name, definition))
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
328 return STYLE_TEMPLATE % {'cp': self.commandprefix,
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
329 'styles': '\n'.join(styles)}
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
330
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
331 def format_unencoded(self, tokensource, outfile):
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
332 # TODO: add support for background colors
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
333 t2n = self.ttype2name
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
334 cp = self.commandprefix
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
335
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
336 if self.full:
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
337 realoutfile = outfile
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
338 outfile = StringIO()
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
339
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
340 outfile.write(u'\\begin{' + self.envname + u'}[commandchars=\\\\\\{\\}')
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
341 if self.linenos:
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
342 start, step = self.linenostart, self.linenostep
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
343 outfile.write(u',numbers=left' +
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
344 (start and u',firstnumber=%d' % start or u'') +
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
345 (step and u',stepnumber=%d' % step or u''))
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
346 if self.mathescape or self.texcomments or self.escapeinside:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
347 outfile.write(u',codes={\\catcode`\\$=3\\catcode`\\^=7\\catcode`\\_=8}')
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
348 if self.verboptions:
6009
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
349 outfile.write(u',' + self.verboptions)
b48a69886ca4 upgrade bundled pygments to 1.6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5803
diff changeset
350 outfile.write(u']\n')
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
351
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
352 for ttype, value in tokensource:
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
353 if ttype in Token.Comment:
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
354 if self.texcomments:
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
355 # Try to guess comment starting lexeme and escape it ...
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
356 start = value[0:1]
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
357 for i in xrange(1, len(value)):
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
358 if start[0] != value[i]:
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
359 break
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
360 start += value[i]
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
361
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
362 value = value[len(start):]
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
363 start = escape_tex(start, cp)
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
364
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
365 # ... but do not escape inside comment.
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
366 value = start + value
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
367 elif self.mathescape:
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
368 # Only escape parts not inside a math environment.
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
369 parts = value.split('$')
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
370 in_math = False
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
371 for i, part in enumerate(parts):
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
372 if not in_math:
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
373 parts[i] = escape_tex(part, cp)
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
374 in_math = not in_math
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
375 value = '$'.join(parts)
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
376 elif self.escapeinside:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
377 text = value
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
378 value = ''
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
379 while text:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
380 a, sep1, text = text.partition(self.left)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
381 if sep1:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
382 b, sep2, text = text.partition(self.right)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
383 if sep2:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
384 value += escape_tex(a, cp) + b
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
385 else:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
386 value += escape_tex(a + sep1 + b, cp)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
387 else:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
388 value += escape_tex(a, cp)
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
389 else:
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
390 value = escape_tex(value, cp)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
391 elif ttype not in Token.Escape:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
392 value = escape_tex(value, cp)
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
393 styles = []
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
394 while ttype is not Token:
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
395 try:
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
396 styles.append(t2n[ttype])
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
397 except KeyError:
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
398 # not in current style
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
399 styles.append(_get_ttype_name(ttype))
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
400 ttype = ttype.parent
5184
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
401 styleval = '+'.join(reversed(styles))
0970ed47d2cd updated pygments to 1.1.1+ ( http://dev.pocoo.org/hg/pygments-main/rev/948f8885af16 )
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4377
diff changeset
402 if styleval:
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
403 spl = value.split('\n')
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
404 for line in spl[:-1]:
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
405 if line:
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
406 outfile.write("\\%s{%s}{%s}" % (cp, styleval, line))
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
407 outfile.write('\n')
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
408 if spl[-1]:
5564
74fa6f714526 upgraded pygments to 1.2.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5184
diff changeset
409 outfile.write("\\%s{%s}{%s}" % (cp, styleval, spl[-1]))
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
410 else:
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
411 outfile.write(value)
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
412
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
413 outfile.write(u'\\end{' + self.envname + u'}\n')
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
414
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
415 if self.full:
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
416 encoding = self.encoding or 'utf8'
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
417 # map known existings encodings from LaTeX distribution
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
418 encoding = {
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
419 'utf_8': 'utf8',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
420 'latin_1': 'latin1',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
421 'iso_8859_1': 'latin1',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
422 }.get(encoding.replace('-', '_'), encoding)
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
423 realoutfile.write(DOC_TEMPLATE %
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
424 dict(docclass = self.docclass,
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
425 preamble = self.preamble,
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
426 title = self.title,
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
427 encoding = encoding,
4377
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
428 styledefs = self.get_style_defs(),
00b1307bd9c2 Adding Pygments to MoinMoin/support
Radomir Dopieralski <moindev@sheep.art.pl>
parents:
diff changeset
429 code = outfile.getvalue()))
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
430
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
431
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
432 class LatexEmbeddedLexer(Lexer):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
433 """
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
434 This lexer takes one lexer as argument, the lexer for the language
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
435 being formatted, and the left and right delimiters for escaped text.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
436
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
437 First everything is scanned using the language lexer to obtain
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
438 strings and comments. All other consecutive tokens are merged and
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
439 the resulting text is scanned for escaped segments, which are given
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
440 the Token.Escape type. Finally text that is not escaped is scanned
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
441 again with the language lexer.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
442 """
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
443 def __init__(self, left, right, lang, **options):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
444 self.left = left
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
445 self.right = right
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
446 self.lang = lang
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
447 Lexer.__init__(self, **options)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
448
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
449 def get_tokens_unprocessed(self, text):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
450 buf = ''
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
451 idx = 0
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
452 for i, t, v in self.lang.get_tokens_unprocessed(text):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
453 if t in Token.Comment or t in Token.String:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
454 if buf:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
455 for x in self.get_tokens_aux(idx, buf):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
456 yield x
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
457 buf = ''
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
458 yield i, t, v
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
459 else:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
460 if not buf:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
461 idx = i
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
462 buf += v
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
463 if buf:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
464 for x in self.get_tokens_aux(idx, buf):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
465 yield x
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
466
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
467 def get_tokens_aux(self, index, text):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
468 while text:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
469 a, sep1, text = text.partition(self.left)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
470 if a:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
471 for i, t, v in self.lang.get_tokens_unprocessed(a):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
472 yield index + i, t, v
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
473 index += len(a)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
474 if sep1:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
475 b, sep2, text = text.partition(self.right)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
476 if sep2:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
477 yield index + len(sep1), Token.Escape, b
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
478 index += len(sep1) + len(b) + len(sep2)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
479 else:
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
480 yield index, Token.Error, sep1
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
481 index += len(sep1)
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6009
diff changeset
482 text = b