summaryrefslogtreecommitdiff
path: root/pygments/formatters/latex.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-12-21 15:53:59 +0900
committerJean Abou-Samra <jean@abou-samra.fr>2022-03-02 10:02:28 +0100
commit231366c7106f66f67f3f27c86ee51434419fcda2 (patch)
tree3dcf9108278b6ed51b081be2178b559724fcefb8 /pygments/formatters/latex.py
parente0d15da721db1519d8017dc50379713e3d48f055 (diff)
downloadpygments-git-231366c7106f66f67f3f27c86ee51434419fcda2.tar.gz
Add nowrap option to LatexFormatter
Diffstat (limited to 'pygments/formatters/latex.py')
-rw-r--r--pygments/formatters/latex.py36
1 files changed, 23 insertions, 13 deletions
diff --git a/pygments/formatters/latex.py b/pygments/formatters/latex.py
index 9a9d02dc..d33b686d 100644
--- a/pygments/formatters/latex.py
+++ b/pygments/formatters/latex.py
@@ -159,6 +159,8 @@ class LatexFormatter(Formatter):
\PY{k}{pass}
\end{Verbatim}
+ Wrapping can be disabled using the `nowrap` option.
+
The special command used here (``\PY``) and all the other macros it needs
are output by the `get_style_defs` method.
@@ -171,6 +173,11 @@ class LatexFormatter(Formatter):
Additional options accepted:
+ `nowrap`
+ If set to ``True``, don't wrap the tokens at all, not even inside a
+ ``\begin{Verbatim}`` environment. This disables most other options
+ (default: ``False``).
+
`style`
The style to use, can be a string or a Style subclass (default:
``'default'``).
@@ -248,6 +255,7 @@ class LatexFormatter(Formatter):
def __init__(self, **options):
Formatter.__init__(self, **options)
+ self.nowrap = get_bool_opt(options, 'nowrap', False)
self.docclass = options.get('docclass', 'article')
self.preamble = options.get('preamble', '')
self.linenos = get_bool_opt(options, 'linenos', False)
@@ -334,18 +342,19 @@ class LatexFormatter(Formatter):
realoutfile = outfile
outfile = StringIO()
- outfile.write('\\begin{' + self.envname + '}[commandchars=\\\\\\{\\}')
- if self.linenos:
- start, step = self.linenostart, self.linenostep
- outfile.write(',numbers=left' +
- (start and ',firstnumber=%d' % start or '') +
- (step and ',stepnumber=%d' % step or ''))
- if self.mathescape or self.texcomments or self.escapeinside:
- outfile.write(',codes={\\catcode`\\$=3\\catcode`\\^=7'
- '\\catcode`\\_=8\\relax}')
- if self.verboptions:
- outfile.write(',' + self.verboptions)
- outfile.write(']\n')
+ if not self.nowrap:
+ outfile.write('\\begin{' + self.envname + '}[commandchars=\\\\\\{\\}')
+ if self.linenos:
+ start, step = self.linenostart, self.linenostep
+ outfile.write(',numbers=left' +
+ (start and ',firstnumber=%d' % start or '') +
+ (step and ',stepnumber=%d' % step or ''))
+ if self.mathescape or self.texcomments or self.escapeinside:
+ outfile.write(',codes={\\catcode`\\$=3\\catcode`\\^=7'
+ '\\catcode`\\_=8\\relax}')
+ if self.verboptions:
+ outfile.write(',' + self.verboptions)
+ outfile.write(']\n')
for ttype, value in tokensource:
if ttype in Token.Comment:
@@ -408,7 +417,8 @@ class LatexFormatter(Formatter):
else:
outfile.write(value)
- outfile.write('\\end{' + self.envname + '}\n')
+ if not self.nowrap:
+ outfile.write('\\end{' + self.envname + '}\n')
if self.full:
encoding = self.encoding or 'utf8'