Wrap float environment on writing literal_block to latex

This commit is contained in:
tk0miya 2014-09-19 11:08:07 +09:00
parent 007a15454f
commit 447c8c1d37
3 changed files with 12 additions and 7 deletions

View File

@ -522,3 +522,9 @@
\gdef\@chappos{}
}
\fi
% Define literal-block environment
\RequirePackage{float}
\floatstyle{plaintop}
\newfloat{literal-block}{htbp}{loc}[chapter]
\floatname{literal-block}{List}

View File

@ -1347,9 +1347,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
linenos = node['linenos']
caption = node.get('caption')
if caption:
self.body.append('\n{\\colorbox[rgb]{0.9,0.9,0.9}'
'{\\makebox[\\textwidth][l]'
'{\\small\\texttt{%s}}}}\n' % (caption,))
self.body.append('\n\\begin{literal-block}\caption{%s}\n' %
(caption,))
def warner(msg):
self.builder.warn(msg, (self.curfilestack[-1], node.line))
hlcode = self.highlighter.highlight_block(code, lang, warn=warner,
@ -1367,6 +1366,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
hlcode = hlcode.rstrip() + '\n'
self.body.append('\n' + hlcode + '\\end{%sVerbatim}\n' %
(self.table and 'Original' or ''))
if caption:
self.body.append('\n\\end{literal-block}\n')
raise nodes.SkipNode
def depart_literal_block(self, node):
self.body.append('\n\\end{alltt}\n')

View File

@ -93,8 +93,7 @@ def test_code_block_caption_html(app):
def test_code_block_caption_latex(app):
app.builder.build('index')
latex = (app.outdir / 'Python.tex').text()
caption = ('{\\colorbox[rgb]{0.9,0.9,0.9}{\\makebox[\\textwidth][l]'
'{\\small\\texttt{caption-test.rb}}}}')
caption = '\\caption{caption-test.rb}'
assert caption in latex
@ -168,6 +167,5 @@ def test_literalinclude_caption_html(app):
def test_literalinclude_caption_latex(app):
app.builder.build('index')
latex = (app.outdir / 'Python.tex').text()
caption = ('{\\colorbox[rgb]{0.9,0.9,0.9}{\\makebox[\\textwidth][l]'
'{\\small\\texttt{caption-test.py}}}}')
caption = '\\caption{caption-test.py}'
assert caption in latex