Skip to content

Commit

Permalink
latex: keep original Verbatim under same name, use SphinxVerbatim for…
Browse files Browse the repository at this point in the history
… own
  • Loading branch information
jfbu committed Jun 10, 2016
1 parent de070a3 commit f9880bf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Incompatible changes
* LaTeX package fancybox is not longer a dependency of sphinx.sty
* Use ``'locales'`` as a default value of `locale_dirs`
* LaTeX package ifthen is not any longer a dependency of sphinx.sty
* LaTeX writer produces source not modifying original fancyvrb's Verbatim but using new name SphinxVerbatim for its custom wrapper

Features added
--------------
Expand Down
23 changes: 12 additions & 11 deletions sphinx/texinputs/sphinx.sty
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@
% Support large numbered footnotes in minipage (cf. admonitions)
\def\thempfootnote{\arabic{mpfootnote}}

% Redefine the Verbatim environment to allow border and background colors
% and to handle the top caption in a non separable by pagebreak way.
% The original environment is still used for verbatims within tables.
\let\OriginalVerbatim=\Verbatim
\let\endOriginalVerbatim=\endVerbatim
% Preparations for SphinxVerbatim environment, which is a wrapper of fancyvrb
% Verbatim with framing allowing pagebreaks, with border and background colors
% and possibly also a top caption, non separable by pagebreak. The original
% fancyvrb Verbatim is still used within tables.

\newcommand\Sphinx@colorbox [2]{%
% #1 will be \fcolorbox or, for first part of frame: \Sphinx@fcolorbox
Expand Down Expand Up @@ -279,7 +278,7 @@
\lccode`\~`\~
}

\renewcommand{\Verbatim}[1][1]{%
\newenvironment{SphinxVerbatim}[1][1]{%
% quit horizontal mode if we are still in a paragraph
\par
% list starts new par, but we don't want it to be set apart vertically
Expand Down Expand Up @@ -328,8 +327,10 @@
\discretionary{\copy\Sphinxvisiblespacebox}{\Sphinxafterbreak}
{\kern\fontdimen2\font}%
}%
% go around fancyvrb's check of @currenvir (for case of minipage below)
\renewcommand*{\VerbatimEnvironment}{\gdef\FV@EnvironName{Verbatim}}%
% go around fancyvrb's check of \@currenvir
\renewcommand*{\VerbatimEnvironment}{\gdef\FV@EnvironName{SphinxVerbatim}}%
% go around fancyvrb's check of current list depth
\def\@toodeep {\advance\@listdepth\@ne}%
% Allow breaks at special characters using \PYG... macros.
\Sphinxbreaksatspecials
% The list environment is needed to control perfectly the vertical space.
Expand All @@ -354,10 +355,10 @@
% For grid placement from \strut's in \FancyVerbFormatLine
\lineskip\z@skip
% Breaks at punctuation characters . , ; ? ! and / need catcode=\active
\OriginalVerbatim[#1,codes*=\Sphinxbreaksatpunct]%
\Verbatim[#1,codes*=\Sphinxbreaksatpunct]%
}
\renewcommand{\endVerbatim}{%
\endOriginalVerbatim
{%
\endVerbatim
\par\unskip\@minipagefalse\endMakeFramed
\ifSphinx@inframed\end{minipage}\fi
\endtrivlist
Expand Down
7 changes: 4 additions & 3 deletions sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1899,14 +1899,15 @@ def warner(msg):
hlcode = hlcode.replace(u'€', u'@texteuro[]')
# must use original Verbatim environment and "tabular" environment
if self.table:
hlcode = hlcode.replace('\\begin{Verbatim}',
'\\begin{OriginalVerbatim}')
self.table.has_problematic = True
self.table.has_verbatim = True
else:
hlcode = hlcode.replace('\\begin{Verbatim}',
'\\begin{SphinxVerbatim}')
# get consistent trailer
hlcode = hlcode.rstrip()[:-14] # strip \end{Verbatim}
self.body.append('\n' + hlcode + '\\end{%sVerbatim}\n' %
(self.table and 'Original' or ''))
((not self.table) and 'Sphinx' or ''))
if ids:
self.body.append('\\let\\SphinxLiteralBlockLabel\empty\n')
raise nodes.SkipNode
Expand Down
4 changes: 2 additions & 2 deletions tests/test_directive_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ def test_literalinclude_file_whole_of_emptyline(app, status, warning):
app.builder.build_all()
latex = (app.outdir / 'Python.tex').text(encoding='utf-8').replace('\r\n', '\n')
includes = (
'\\begin{Verbatim}[commandchars=\\\\\\{\\},numbers=left,firstnumber=1,stepnumber=1]\n'
'\\begin{SphinxVerbatim}[commandchars=\\\\\\{\\},numbers=left,firstnumber=1,stepnumber=1]\n'
'\n'
'\n'
'\n'
'\\end{Verbatim}\n')
'\\end{SphinxVerbatim}\n')
assert includes in latex


Expand Down
4 changes: 2 additions & 2 deletions tests/test_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def test_latex_escaping():
r'\(\Gamma\)\textbackslash{}\(\infty\)\$')
# in verbatim code fragments
yield (verify, u'::\n\n\\∞${}', None,
u'\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n'
u'\\begin{SphinxVerbatim}[commandchars=\\\\\\{\\}]\n'
u'@\\(\\Gamma\\)\\PYGZbs{}\\(\\infty\\)\\PYGZdl{}\\PYGZob{}\\PYGZcb{}\n'
u'\\end{Verbatim}')
u'\\end{SphinxVerbatim}')
# in URIs
yield (verify_re, u'`test <http://example.com/~me/>`_', None,
r'\\href{http://example.com/~me/}{test}.*')
Expand Down

0 comments on commit f9880bf

Please sign in to comment.