summaryrefslogtreecommitdiff
path: root/pygments/formatters/latex.py
diff options
context:
space:
mode:
Diffstat (limited to 'pygments/formatters/latex.py')
-rw-r--r--pygments/formatters/latex.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/pygments/formatters/latex.py b/pygments/formatters/latex.py
index 352684b0..4b22215f 100644
--- a/pygments/formatters/latex.py
+++ b/pygments/formatters/latex.py
@@ -236,6 +236,13 @@ class LatexFormatter(Formatter):
set. (default: ``''``).
.. versionadded:: 2.0
+
+ `envname`
+ Allows you to pick an alternative environment name replacing Verbatim.
+ The alternate environment still has to support Verbatim's option syntax.
+ (default: ``'Verbatim'``).
+
+ .. versionadded:: 2.0
"""
name = 'LaTeX'
aliases = ['latex', 'tex']
@@ -254,16 +261,15 @@ class LatexFormatter(Formatter):
self.texcomments = get_bool_opt(options, 'texcomments', False)
self.mathescape = get_bool_opt(options, 'mathescape', False)
self.escapeinside = options.get('escapeinside', '')
-
if len(self.escapeinside) == 2:
self.left = self.escapeinside[0]
self.right = self.escapeinside[1]
else:
self.escapeinside = ''
+ self.envname = options.get('envname', u'Verbatim')
self._create_stylesheet()
-
def _create_stylesheet(self):
t2n = self.ttype2name = {Token: ''}
c2d = self.cmd2def = {}
@@ -271,7 +277,7 @@ class LatexFormatter(Formatter):
def rgbcolor(col):
if col:
- return ','.join(['%.2f' %(int(col[i] + col[i + 1], 16) / 255.0)
+ return ','.join(['%.2f' % (int(col[i] + col[i + 1], 16) / 255.0)
for i in (0, 2, 4)])
else:
return '1,1,1'
@@ -331,7 +337,7 @@ class LatexFormatter(Formatter):
realoutfile = outfile
outfile = StringIO()
- outfile.write(u'\\begin{Verbatim}[commandchars=\\\\\\{\\}')
+ outfile.write(u'\\begin{' + self.envname + u'}[commandchars=\\\\\\{\\}')
if self.linenos:
start, step = self.linenostart, self.linenostep
outfile.write(u',numbers=left' +
@@ -371,9 +377,9 @@ class LatexFormatter(Formatter):
text = value
value = ''
while len(text) > 0:
- a,sep1,text = text.partition(self.left)
+ a, sep1, text = text.partition(self.left)
if len(sep1) > 0:
- b,sep2,text = text.partition(self.right)
+ b, sep2, text = text.partition(self.right)
if len(sep2) > 0:
value += escape_tex(a, self.commandprefix) + b
else:
@@ -404,7 +410,7 @@ class LatexFormatter(Formatter):
else:
outfile.write(value)
- outfile.write(u'\\end{Verbatim}\n')
+ outfile.write(u'\\end{' + self.envname + u'}\n')
if self.full:
realoutfile.write(DOC_TEMPLATE %
@@ -436,6 +442,7 @@ class LatexEmbeddedLexer(Lexer):
def get_tokens_unprocessed(self, text):
buf = ''
+ idx = 0
for i, t, v in self.lang.get_tokens_unprocessed(text):
if t in Token.Comment or t in Token.String:
if buf:
@@ -467,4 +474,3 @@ class LatexEmbeddedLexer(Lexer):
yield index, Token.Error, sep1
index += len(sep1)
text = b
-