ThirdParty/Pygments/pygments/formatters/latex.py

changeset 4697
c2e9bf425554
parent 4172
4f20dba37ab6
child 5072
aab59042fefb
equal deleted inserted replaced
4696:bf4d19a7cade 4697:c2e9bf425554
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-2014 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2015 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 __future__ import division
13 13
358 if start[0] != value[i]: 358 if start[0] != value[i]:
359 break 359 break
360 start += value[i] 360 start += value[i]
361 361
362 value = value[len(start):] 362 value = value[len(start):]
363 start = escape_tex(start, self.commandprefix) 363 start = escape_tex(start, cp)
364 364
365 # ... but do not escape inside comment. 365 # ... but do not escape inside comment.
366 value = start + value 366 value = start + value
367 elif self.mathescape: 367 elif self.mathescape:
368 # Only escape parts not inside a math environment. 368 # Only escape parts not inside a math environment.
369 parts = value.split('$') 369 parts = value.split('$')
370 in_math = False 370 in_math = False
371 for i, part in enumerate(parts): 371 for i, part in enumerate(parts):
372 if not in_math: 372 if not in_math:
373 parts[i] = escape_tex(part, self.commandprefix) 373 parts[i] = escape_tex(part, cp)
374 in_math = not in_math 374 in_math = not in_math
375 value = '$'.join(parts) 375 value = '$'.join(parts)
376 elif self.escapeinside: 376 elif self.escapeinside:
377 text = value 377 text = value
378 value = '' 378 value = ''
379 while len(text) > 0: 379 while text:
380 a, sep1, text = text.partition(self.left) 380 a, sep1, text = text.partition(self.left)
381 if len(sep1) > 0: 381 if sep1:
382 b, sep2, text = text.partition(self.right) 382 b, sep2, text = text.partition(self.right)
383 if len(sep2) > 0: 383 if sep2:
384 value += escape_tex(a, self.commandprefix) + b 384 value += escape_tex(a, cp) + b
385 else: 385 else:
386 value += escape_tex(a + sep1 + b, self.commandprefix) 386 value += escape_tex(a + sep1 + b, cp)
387 else: 387 else:
388 value = value + escape_tex(a, self.commandprefix) 388 value += escape_tex(a, cp)
389 else: 389 else:
390 value = escape_tex(value, self.commandprefix) 390 value = escape_tex(value, cp)
391 elif ttype not in Token.Escape: 391 elif ttype not in Token.Escape:
392 value = escape_tex(value, self.commandprefix) 392 value = escape_tex(value, cp)
393 styles = [] 393 styles = []
394 while ttype is not Token: 394 while ttype is not Token:
395 try: 395 try:
396 styles.append(t2n[ttype]) 396 styles.append(t2n[ttype])
397 except KeyError: 397 except KeyError:
421 styledefs = self.get_style_defs(), 421 styledefs = self.get_style_defs(),
422 code = outfile.getvalue())) 422 code = outfile.getvalue()))
423 423
424 424
425 class LatexEmbeddedLexer(Lexer): 425 class LatexEmbeddedLexer(Lexer):
426 r""" 426 """
427
428 This lexer takes one lexer as argument, the lexer for the language 427 This lexer takes one lexer as argument, the lexer for the language
429 being formatted, and the left and right delimiters for escaped text. 428 being formatted, and the left and right delimiters for escaped text.
430 429
431 First everything is scanned using the language lexer to obtain 430 First everything is scanned using the language lexer to obtain
432 strings and comments. All other consecutive tokens are merged and 431 strings and comments. All other consecutive tokens are merged and

eric ide

mercurial