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-2017 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2019 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 __future__ import division |
12 from io import StringIO |
13 |
13 |
14 from pygments.formatter import Formatter |
14 from pygments.formatter import Formatter |
15 from pygments.lexer import Lexer |
15 from pygments.lexer import Lexer |
16 from pygments.token import Token, STANDARD_TYPES |
16 from pygments.token import Token, STANDARD_TYPES |
17 from pygments.util import get_bool_opt, get_int_opt, StringIO, xrange, \ |
17 from pygments.util import get_bool_opt, get_int_opt |
18 iteritems |
|
19 |
18 |
20 |
19 |
21 __all__ = ['LatexFormatter'] |
20 __all__ = ['LatexFormatter'] |
22 |
21 |
23 |
22 |
320 Return the command sequences needed to define the commands |
319 Return the command sequences needed to define the commands |
321 used to format text in the verbatim environment. ``arg`` is ignored. |
320 used to format text in the verbatim environment. ``arg`` is ignored. |
322 """ |
321 """ |
323 cp = self.commandprefix |
322 cp = self.commandprefix |
324 styles = [] |
323 styles = [] |
325 for name, definition in iteritems(self.cmd2def): |
324 for name, definition in self.cmd2def.items(): |
326 styles.append(r'\expandafter\def\csname %s@tok@%s\endcsname{%s}' % |
325 styles.append(r'\expandafter\def\csname %s@tok@%s\endcsname{%s}' % |
327 (cp, name, definition)) |
326 (cp, name, definition)) |
328 return STYLE_TEMPLATE % {'cp': self.commandprefix, |
327 return STYLE_TEMPLATE % {'cp': self.commandprefix, |
329 'styles': '\n'.join(styles)} |
328 'styles': '\n'.join(styles)} |
330 |
329 |
352 for ttype, value in tokensource: |
351 for ttype, value in tokensource: |
353 if ttype in Token.Comment: |
352 if ttype in Token.Comment: |
354 if self.texcomments: |
353 if self.texcomments: |
355 # Try to guess comment starting lexeme and escape it ... |
354 # Try to guess comment starting lexeme and escape it ... |
356 start = value[0:1] |
355 start = value[0:1] |
357 for i in xrange(1, len(value)): |
356 for i in range(1, len(value)): |
358 if start[0] != value[i]: |
357 if start[0] != value[i]: |
359 break |
358 break |
360 start += value[i] |
359 start += value[i] |
361 |
360 |
362 value = value[len(start):] |
361 value = value[len(start):] |