ThirdParty/Pygments/pygments/formatters/latex.py

changeset 1705
b0fbc9300f2b
parent 808
8f85926125ef
child 2426
da76c71624de
equal deleted inserted replaced
1704:02ae6c55b35b 1705:b0fbc9300f2b
3 pygments.formatters.latex 3 pygments.formatters.latex
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Formatter for LaTeX fancyvrb output. 6 Formatter for LaTeX fancyvrb output.
7 7
8 :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 from pygments.formatter import Formatter 12 from pygments.formatter import Formatter
13 from pygments.token import Token, STANDARD_TYPES 13 from pygments.token import Token, STANDARD_TYPES
24 replace('\x00', r'\%sZbs{}' % commandprefix). \ 24 replace('\x00', r'\%sZbs{}' % commandprefix). \
25 replace('\x01', r'\%sZob{}' % commandprefix). \ 25 replace('\x01', r'\%sZob{}' % commandprefix). \
26 replace('\x02', r'\%sZcb{}' % commandprefix). \ 26 replace('\x02', r'\%sZcb{}' % commandprefix). \
27 replace('^', r'\%sZca{}' % commandprefix). \ 27 replace('^', r'\%sZca{}' % commandprefix). \
28 replace('_', r'\%sZus{}' % commandprefix). \ 28 replace('_', r'\%sZus{}' % commandprefix). \
29 replace('&', r'\%sZam{}' % commandprefix). \
30 replace('<', r'\%sZlt{}' % commandprefix). \
31 replace('>', r'\%sZgt{}' % commandprefix). \
29 replace('#', r'\%sZsh{}' % commandprefix). \ 32 replace('#', r'\%sZsh{}' % commandprefix). \
30 replace('%', r'\%sZpc{}' % commandprefix). \ 33 replace('%', r'\%sZpc{}' % commandprefix). \
31 replace('$', r'\%sZdl{}' % commandprefix). \ 34 replace('$', r'\%sZdl{}' % commandprefix). \
32 replace('~', r'\%sZti{}' % commandprefix) 35 replace('~', r'\%sZti{}' % commandprefix)
33 36
104 \def\%(cp)sZbs{\char`\\} 107 \def\%(cp)sZbs{\char`\\}
105 \def\%(cp)sZus{\char`\_} 108 \def\%(cp)sZus{\char`\_}
106 \def\%(cp)sZob{\char`\{} 109 \def\%(cp)sZob{\char`\{}
107 \def\%(cp)sZcb{\char`\}} 110 \def\%(cp)sZcb{\char`\}}
108 \def\%(cp)sZca{\char`\^} 111 \def\%(cp)sZca{\char`\^}
112 \def\%(cp)sZam{\char`\&}
113 \def\%(cp)sZlt{\char`\<}
114 \def\%(cp)sZgt{\char`\>}
109 \def\%(cp)sZsh{\char`\#} 115 \def\%(cp)sZsh{\char`\#}
110 \def\%(cp)sZpc{\char`\%%} 116 \def\%(cp)sZpc{\char`\%%}
111 \def\%(cp)sZdl{\char`\$} 117 \def\%(cp)sZdl{\char`\$}
112 \def\%(cp)sZti{\char`\~} 118 \def\%(cp)sZti{\char`\~}
113 %% for compatibility with earlier versions 119 %% for compatibility with earlier versions
256 cmndef += r'\let\$$@ff=\textsf' 262 cmndef += r'\let\$$@ff=\textsf'
257 if ndef['color']: 263 if ndef['color']:
258 cmndef += (r'\def\$$@tc##1{\textcolor[rgb]{%s}{##1}}' % 264 cmndef += (r'\def\$$@tc##1{\textcolor[rgb]{%s}{##1}}' %
259 rgbcolor(ndef['color'])) 265 rgbcolor(ndef['color']))
260 if ndef['border']: 266 if ndef['border']:
261 cmndef += (r'\def\$$@bc##1{\fcolorbox[rgb]{%s}{%s}{##1}}' % 267 cmndef += (r'\def\$$@bc##1{\setlength{\fboxsep}{0pt}'
268 r'\fcolorbox[rgb]{%s}{%s}{\strut ##1}}' %
262 (rgbcolor(ndef['border']), 269 (rgbcolor(ndef['border']),
263 rgbcolor(ndef['bgcolor']))) 270 rgbcolor(ndef['bgcolor'])))
264 elif ndef['bgcolor']: 271 elif ndef['bgcolor']:
265 cmndef += (r'\def\$$@bc##1{\colorbox[rgb]{%s}{##1}}' % 272 cmndef += (r'\def\$$@bc##1{\setlength{\fboxsep}{0pt}'
273 r'\colorbox[rgb]{%s}{\strut ##1}}' %
266 rgbcolor(ndef['bgcolor'])) 274 rgbcolor(ndef['bgcolor']))
267 if cmndef == '': 275 if cmndef == '':
268 continue 276 continue
269 cmndef = cmndef.replace('$$', cp) 277 cmndef = cmndef.replace('$$', cp)
270 t2n[ttype] = name 278 t2n[ttype] = name
276 used to format text in the verbatim environment. ``arg`` is ignored. 284 used to format text in the verbatim environment. ``arg`` is ignored.
277 """ 285 """
278 cp = self.commandprefix 286 cp = self.commandprefix
279 styles = [] 287 styles = []
280 for name, definition in self.cmd2def.items(): 288 for name, definition in self.cmd2def.items():
281 styles.append(r'\def\%s@tok@%s{%s}' % (cp, name, definition)) 289 styles.append(r'\expandafter\def\csname %s@tok@%s\endcsname{%s}' %
290 (cp, name, definition))
282 return STYLE_TEMPLATE % {'cp': self.commandprefix, 291 return STYLE_TEMPLATE % {'cp': self.commandprefix,
283 'styles': '\n'.join(styles)} 292 'styles': '\n'.join(styles)}
284 293
285 def format_unencoded(self, tokensource, outfile): 294 def format_unencoded(self, tokensource, outfile):
286 # TODO: add support for background colors 295 # TODO: add support for background colors

eric ide

mercurial