Merge pull request #2652 from jfbu/jfbu_sphinxverbatim

latex: keep Verbatim under same name, use SphinxVerbatim for own
This commit is contained in:
Jean-François B 2016-06-11 17:20:01 +02:00 committed by GitHub
commit 8043f6406f
5 changed files with 21 additions and 18 deletions

View File

@ -7,6 +7,7 @@ Incompatible changes
* LaTeX package fancybox is not longer a dependency of sphinx.sty * LaTeX package fancybox is not longer a dependency of sphinx.sty
* Use ``'locales'`` as a default value of `locale_dirs` * Use ``'locales'`` as a default value of `locale_dirs`
* LaTeX package ifthen is not any longer a dependency of sphinx.sty * 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 Features added
-------------- --------------

View File

@ -159,11 +159,10 @@
% Support large numbered footnotes in minipage (cf. admonitions) % Support large numbered footnotes in minipage (cf. admonitions)
\def\thempfootnote{\arabic{mpfootnote}} \def\thempfootnote{\arabic{mpfootnote}}
% Redefine the Verbatim environment to allow border and background colors % Preparations for SphinxVerbatim environment, which is a wrapper of fancyvrb
% and to handle the top caption in a non separable by pagebreak way. % Verbatim with framing allowing pagebreaks, with border and background colors
% The original environment is still used for verbatims within tables. % and possibly also a top caption, non separable by pagebreak. The original
\let\OriginalVerbatim=\Verbatim % fancyvrb Verbatim is still used within tables.
\let\endOriginalVerbatim=\endVerbatim
\newcommand\Sphinx@colorbox [2]{% \newcommand\Sphinx@colorbox [2]{%
% #1 will be \fcolorbox or, for first part of frame: \Sphinx@fcolorbox % #1 will be \fcolorbox or, for first part of frame: \Sphinx@fcolorbox
@ -279,7 +278,7 @@
\lccode`\~`\~ \lccode`\~`\~
} }
\renewcommand{\Verbatim}[1][1]{% \newenvironment{SphinxVerbatim}[1][1]{%
% quit horizontal mode if we are still in a paragraph % quit horizontal mode if we are still in a paragraph
\par \par
% list starts new par, but we don't want it to be set apart vertically % list starts new par, but we don't want it to be set apart vertically
@ -328,8 +327,10 @@
\discretionary{\copy\Sphinxvisiblespacebox}{\Sphinxafterbreak} \discretionary{\copy\Sphinxvisiblespacebox}{\Sphinxafterbreak}
{\kern\fontdimen2\font}% {\kern\fontdimen2\font}%
}% }%
% go around fancyvrb's check of @currenvir (for case of minipage below) % go around fancyvrb's check of \@currenvir
\renewcommand*{\VerbatimEnvironment}{\gdef\FV@EnvironName{Verbatim}}% \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. % Allow breaks at special characters using \PYG... macros.
\Sphinxbreaksatspecials \Sphinxbreaksatspecials
% The list environment is needed to control perfectly the vertical space. % The list environment is needed to control perfectly the vertical space.
@ -354,10 +355,10 @@
% For grid placement from \strut's in \FancyVerbFormatLine % For grid placement from \strut's in \FancyVerbFormatLine
\lineskip\z@skip \lineskip\z@skip
% Breaks at punctuation characters . , ; ? ! and / need catcode=\active % Breaks at punctuation characters . , ; ? ! and / need catcode=\active
\OriginalVerbatim[#1,codes*=\Sphinxbreaksatpunct]% \Verbatim[#1,codes*=\Sphinxbreaksatpunct]%
} }
\renewcommand{\endVerbatim}{% {%
\endOriginalVerbatim \endVerbatim
\par\unskip\@minipagefalse\endMakeFramed \par\unskip\@minipagefalse\endMakeFramed
\ifSphinx@inframed\end{minipage}\fi \ifSphinx@inframed\end{minipage}\fi
\endtrivlist \endtrivlist

View File

@ -1899,14 +1899,15 @@ class LaTeXTranslator(nodes.NodeVisitor):
hlcode = hlcode.replace(u'', u'@texteuro[]') hlcode = hlcode.replace(u'', u'@texteuro[]')
# must use original Verbatim environment and "tabular" environment # must use original Verbatim environment and "tabular" environment
if self.table: if self.table:
hlcode = hlcode.replace('\\begin{Verbatim}',
'\\begin{OriginalVerbatim}')
self.table.has_problematic = True self.table.has_problematic = True
self.table.has_verbatim = True self.table.has_verbatim = True
else:
hlcode = hlcode.replace('\\begin{Verbatim}',
'\\begin{SphinxVerbatim}')
# get consistent trailer # get consistent trailer
hlcode = hlcode.rstrip()[:-14] # strip \end{Verbatim} hlcode = hlcode.rstrip()[:-14] # strip \end{Verbatim}
self.body.append('\n' + hlcode + '\\end{%sVerbatim}\n' % self.body.append('\n' + hlcode + '\\end{%sVerbatim}\n' %
(self.table and 'Original' or '')) ((not self.table) and 'Sphinx' or ''))
if ids: if ids:
self.body.append('\\let\\SphinxLiteralBlockLabel\empty\n') self.body.append('\\let\\SphinxLiteralBlockLabel\empty\n')
raise nodes.SkipNode raise nodes.SkipNode

View File

@ -228,11 +228,11 @@ def test_literalinclude_file_whole_of_emptyline(app, status, warning):
app.builder.build_all() app.builder.build_all()
latex = (app.outdir / 'Python.tex').text(encoding='utf-8').replace('\r\n', '\n') latex = (app.outdir / 'Python.tex').text(encoding='utf-8').replace('\r\n', '\n')
includes = ( includes = (
'\\begin{Verbatim}[commandchars=\\\\\\{\\},numbers=left,firstnumber=1,stepnumber=1]\n' '\\begin{SphinxVerbatim}[commandchars=\\\\\\{\\},numbers=left,firstnumber=1,stepnumber=1]\n'
'\n' '\n'
'\n' '\n'
'\n' '\n'
'\\end{Verbatim}\n') '\\end{SphinxVerbatim}\n')
assert includes in latex assert includes in latex

View File

@ -137,9 +137,9 @@ def test_latex_escaping():
r'\(\Gamma\)\textbackslash{}\(\infty\)\$') r'\(\Gamma\)\textbackslash{}\(\infty\)\$')
# in verbatim code fragments # in verbatim code fragments
yield (verify, u'::\n\n\\∞${}', None, 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'@\\(\\Gamma\\)\\PYGZbs{}\\(\\infty\\)\\PYGZdl{}\\PYGZob{}\\PYGZcb{}\n'
u'\\end{Verbatim}') u'\\end{SphinxVerbatim}')
# in URIs # in URIs
yield (verify_re, u'`test <http://example.com/~me/>`_', None, yield (verify_re, u'`test <http://example.com/~me/>`_', None,
r'\\href{http://example.com/~me/}{test}.*') r'\\href{http://example.com/~me/}{test}.*')