merge stable to default

This commit is contained in:
Georg Brandl 2015-12-18 21:42:55 +01:00
commit 8232707a12
12 changed files with 92 additions and 25 deletions

View File

@ -47,6 +47,7 @@ Bugs fixed
* #2134: Fix figure caption with reference causes latex build error * #2134: Fix figure caption with reference causes latex build error
* #2094: Fix rubric with reference not working in Latex * #2094: Fix rubric with reference not working in Latex
* #2147: Fix literalinclude code in latex does not break in pages
Release 1.3.3 (released Dec 2, 2015) Release 1.3.3 (released Dec 2, 2015)
@ -103,10 +104,7 @@ Bugs fixed
* #1942: Fix a KeyError in websupport. * #1942: Fix a KeyError in websupport.
* #1903: Fix strange id generation for glossary terms. * #1903: Fix strange id generation for glossary terms.
* #1796, On py3, automated .mo building cause UnicodeDecodeError * #1796, On py3, automated .mo building cause UnicodeDecodeError
* Fix: ``make text`` will crush if a definition list item has more than 1 classifiers as:
* #1796: On py3, automated .mo building cause UnicodeDecodeError
* ``make text`` will crush if a definition list item has more than 1 classifiers as: * ``make text`` will crush if a definition list item has more than 1 classifiers as:
* Fixed #1855: make gettext generates broken po file for definition lists with classifier.
``term : classifier1 : classifier2``. ``term : classifier1 : classifier2``.
* #1855: make gettext generates broken po file for definition lists with classifier. * #1855: make gettext generates broken po file for definition lists with classifier.
* #1869: Fix problems when dealing with files containing non-ASCII characters. Thanks to * #1869: Fix problems when dealing with files containing non-ASCII characters. Thanks to
@ -121,6 +119,8 @@ Bugs fixed
* #1994: More supporting non-standard parser (like recommonmark parser) for Translation and * #1994: More supporting non-standard parser (like recommonmark parser) for Translation and
WebSupport feature. Now node.rawsource is fall backed to node.astext() during docutils WebSupport feature. Now node.rawsource is fall backed to node.astext() during docutils
transforming. transforming.
* #1989: "make blahblah" on Windows indicate help messages for sphinx-build every time.
It was caused by wrong make.bat that generated by Sphinx-1.3.0/1.3.1.
* On Py2 environment, conf.py that is generated by sphinx-quickstart should have u prefixed * On Py2 environment, conf.py that is generated by sphinx-quickstart should have u prefixed
config value for 'version' and 'release'. config value for 'version' and 'release'.
* #2102: On Windows + Py3, using ``|today|`` and non-ASCII date format will raise * #2102: On Windows + Py3, using ``|today|`` and non-ASCII date format will raise

View File

@ -1432,6 +1432,8 @@ These options influence LaTeX output.
'floated' into the next page but may be preceded by any other text. 'floated' into the next page but may be preceded by any other text.
If you don't like this behavior, use 'H' which will disable floating If you don't like this behavior, use 'H' which will disable floating
and position figures strictly in the order they appear in the source. and position figures strictly in the order they appear in the source.
.. versionadded:: 1.3
``'footer'`` ``'footer'``
Additional footer content (before the indices), default empty. Additional footer content (before the indices), default empty.

View File

@ -525,11 +525,18 @@
\fi \fi
% Define literal-block environment % Define literal-block environment
\RequirePackage{float} \RequirePackage{newfloat}
\floatstyle{plaintop} \DeclareFloatingEnvironment{literal-block}
\ifx\thechapter\undefined \ifx\thechapter\undefined
\newfloat{literal-block}{htbp}{loc}[section] \SetupFloatingEnvironment{literal-block}{within=section,placement=h}
\else \else
\newfloat{literal-block}{htbp}{loc}[chapter] \SetupFloatingEnvironment{literal-block}{within=chapter,placement=h}
\fi \fi
\floatname{literal-block}{List} \SetupFloatingEnvironment{literal-block}{name=List}
% control caption around literal-block
\RequirePackage{capt-of}
\RequirePackage{needspace}
% if the left page space is less than \literalblockneedsapce, insert page-break
\newcommand{\literalblockneedspace}{5\baselineskip}
% margin before the caption of literal-block
\newcommand{\literalblockcaptiontopvspace}{0.5\baselineskip}

View File

@ -296,6 +296,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.in_production_list = 0 self.in_production_list = 0
self.in_footnote = 0 self.in_footnote = 0
self.in_caption = 0 self.in_caption = 0
self.in_container_literal_block = 0
self.first_document = 1 self.first_document = 1
self.this_is_the_title = 1 self.this_is_the_title = 1
self.literal_whitespace = 0 self.literal_whitespace = 0
@ -400,7 +401,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
if len(codeblock) == 1: if len(codeblock) == 1:
pass # FIXME pass # FIXME
else: else:
ret.append('\\floatname{literal-block}{%s}\n' % ret.append('\\SetupFloatingEnvironment{literal-block}{name=%s}\n' %
text_type(codeblock[0]).translate(tex_escape_map)) text_type(codeblock[0]).translate(tex_escape_map))
if table[1]: if table[1]:
pass # FIXME pass # FIXME
@ -749,8 +750,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
raise nodes.SkipNode raise nodes.SkipNode
self.body.append('\\paragraph{') self.body.append('\\paragraph{')
self.context.append('}\n') self.context.append('}\n')
self.in_title = 1
def depart_rubric(self, node): def depart_rubric(self, node):
self.in_title = 0
self.body.append(self.context.pop()) self.body.append(self.context.pop())
def visit_footnote(self, node): def visit_footnote(self, node):
@ -1179,7 +1182,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
options = '' options = ''
if include_graphics_options: if include_graphics_options:
options = '[%s]' % ','.join(include_graphics_options) options = '[%s]' % ','.join(include_graphics_options)
self.body.append('\\includegraphics%s{%s}' % (options, uri)) base, ext = path.splitext(uri)
self.body.append('\\includegraphics%s{{%s}%s}' % (options, base, ext))
self.body.extend(post) self.body.extend(post)
def depart_image(self, node): def depart_image(self, node):
@ -1220,6 +1224,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_caption(self, node): def visit_caption(self, node):
self.in_caption += 1 self.in_caption += 1
if self.in_container_literal_block:
self.body.append('\\needspace{\\literalblockneedspace}')
self.body.append('\\vspace{\\literalblockcaptiontopvspace}')
self.body.append('\\captionof{literal-block}{')
return
self.body.append('\\caption{') self.body.append('\\caption{')
def depart_caption(self, node): def depart_caption(self, node):
@ -1381,8 +1390,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
raise nodes.SkipNode raise nodes.SkipNode
def visit_reference(self, node): def visit_reference(self, node):
if not self.in_title:
for id in node.get('ids'): for id in node.get('ids'):
self.body += self.hypertarget(id, anchor=True) anchor = not self.in_caption
self.body += self.hypertarget(id, anchor=anchor)
uri = node.get('refuri', '') uri = node.get('refuri', '')
if not uri and node.get('refid'): if not uri and node.get('refid'):
uri = '%' + self.curfilestack[-1] + '#' + node['refid'] uri = '%' + self.curfilestack[-1] + '#' + node['refid']
@ -1770,17 +1781,19 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_container(self, node): def visit_container(self, node):
if node.get('literal_block'): if node.get('literal_block'):
self.in_container_literal_block += 1
ids = '' ids = ''
for id in self.next_literal_ids: for id in self.next_literal_ids:
ids += self.hypertarget(id, anchor=False) ids += self.hypertarget(id, anchor=False)
if node['ids']: if node['ids']:
ids += self.hypertarget(node['ids'][0]) ids += self.hypertarget(node['ids'][0])
self.next_literal_ids.clear() self.next_literal_ids.clear()
self.body.append('\n\\begin{literal-block}\n') self.body.append('\n')
self.context.append(ids + '\n\\end{literal-block}\n') self.context.append(ids + '\n')
def depart_container(self, node): def depart_container(self, node):
if node.get('literal_block'): if node.get('literal_block'):
self.in_container_literal_block -= 1
self.body.append(self.context.pop()) self.body.append(self.context.pop())
def visit_decoration(self, node): def visit_decoration(self, node):

View File

@ -26,3 +26,6 @@ Sphinx image handling
.. an SVG image (for HTML at least) .. an SVG image (for HTML at least)
.. image:: svgimg.* .. image:: svgimg.*
.. an image with more than 1 dot in its file name
.. image:: img.foo.png

BIN
tests/root/img.foo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
master_doc = 'index'
html_theme = 'classic'

View File

@ -0,0 +1,22 @@
==============
test-reference
==============
The section with a reference to [AuthorYear]_
=============================================
.. figure:: rimg.png
This is the figure caption with a reference to [AuthorYear]_.
.. list-table:: The table title with a reference to [AuthorYear]_
:header-rows: 1
* - Header1
- Header2
* - Content
- Content
.. rubric:: The rubric title with a reference to [AuthorYear]_
.. [AuthorYear] Author, Title, Year

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

View File

@ -168,7 +168,7 @@ def test_numref(app, status, warning):
print(warning.getvalue()) print(warning.getvalue())
assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig. }}' in result assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig. }}' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table }}' in result assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table }}' in result
assert '\\floatname{literal-block}{Listing }' in result assert '\\SetupFloatingEnvironment{literal-block}{name=Listing }' in result
assert '\\hyperref[index:fig1]{Fig. \\ref{index:fig1}}' in result assert '\\hyperref[index:fig1]{Fig. \\ref{index:fig1}}' in result
assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
assert '\\hyperref[index:table-1]{Table \\ref{index:table-1}}' in result assert '\\hyperref[index:table-1]{Table \\ref{index:table-1}}' in result
@ -190,7 +190,7 @@ def test_numref_with_prefix1(app, status, warning):
print(warning.getvalue()) print(warning.getvalue())
assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Figure:}}' in result assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Figure:}}' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Tab\\_}}' in result assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Tab\\_}}' in result
assert '\\floatname{literal-block}{Code-}' in result assert '\\SetupFloatingEnvironment{literal-block}{name=Code-}' in result
assert '\\ref{index:fig1}' in result assert '\\ref{index:fig1}' in result
assert '\\ref{baz:fig22}' in result assert '\\ref{baz:fig22}' in result
assert '\\ref{index:table-1}' in result assert '\\ref{index:table-1}' in result
@ -220,7 +220,7 @@ def test_numref_with_prefix2(app, status, warning):
assert '\\def\\fnum@figure{\\figurename\\thefigure.}' in result assert '\\def\\fnum@figure{\\figurename\\thefigure.}' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Tab\\_}}' in result assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Tab\\_}}' in result
assert '\\def\\fnum@table{\\tablename\\thetable:}' in result assert '\\def\\fnum@table{\\tablename\\thetable:}' in result
assert '\\floatname{literal-block}{Code-}' in result assert '\\SetupFloatingEnvironment{literal-block}{name=Code-}' in result
assert '\\hyperref[index:fig1]{Figure:\\ref{index:fig1}.}' in result assert '\\hyperref[index:fig1]{Figure:\\ref{index:fig1}.}' in result
assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
assert '\\hyperref[index:table-1]{Tab\\_\\ref{index:table-1}:}' in result assert '\\hyperref[index:table-1]{Tab\\_\\ref{index:table-1}:}' in result
@ -239,7 +239,7 @@ def test_numref_with_language_el(app, status, warning):
print(warning.getvalue()) print(warning.getvalue())
assert '\\addto\\captionsgreek{\\renewcommand{\\figurename}{Fig. }}' in result assert '\\addto\\captionsgreek{\\renewcommand{\\figurename}{Fig. }}' in result
assert '\\addto\\captionsgreek{\\renewcommand{\\tablename}{Table }}' in result assert '\\addto\\captionsgreek{\\renewcommand{\\tablename}{Table }}' in result
assert '\\floatname{literal-block}{Listing }' in result assert '\\SetupFloatingEnvironment{literal-block}{name=Listing }' in result
assert '\\hyperref[index:fig1]{Fig. \\ref{index:fig1}}' in result assert '\\hyperref[index:fig1]{Fig. \\ref{index:fig1}}' in result
assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
assert '\\hyperref[index:table-1]{Table \\ref{index:table-1}}' in result assert '\\hyperref[index:table-1]{Table \\ref{index:table-1}}' in result
@ -258,7 +258,7 @@ def test_numref_with_language_ja(app, status, warning):
print(warning.getvalue()) print(warning.getvalue())
assert u'\\renewcommand{\\figurename}{\u56f3 }' in result assert u'\\renewcommand{\\figurename}{\u56f3 }' in result
assert '\\renewcommand{\\tablename}{TABLE }' in result assert '\\renewcommand{\\tablename}{TABLE }' in result
assert '\\floatname{literal-block}{LIST }' in result assert '\\SetupFloatingEnvironment{literal-block}{name=LIST }' in result
assert u'\\hyperref[index:fig1]{\u56f3 \\ref{index:fig1}}' in result assert u'\\hyperref[index:fig1]{\u56f3 \\ref{index:fig1}}' in result
assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result assert '\\hyperref[baz:fig22]{Figure\\ref{baz:fig22}}' in result
assert '\\hyperref[index:table-1]{TABLE \\ref{index:table-1}}' in result assert '\\hyperref[index:table-1]{TABLE \\ref{index:table-1}}' in result
@ -318,3 +318,17 @@ def test_footnote(app, status, warning):
assert ('\\end{threeparttable}\n\n' assert ('\\end{threeparttable}\n\n'
'\\footnotetext[4]{\nfootnotes in table caption\n}' '\\footnotetext[4]{\nfootnotes in table caption\n}'
'\\footnotetext[5]{\nfootnotes in table\n}' in result) '\\footnotetext[5]{\nfootnotes in table\n}' in result)
@with_app(buildername='latex', testroot='references-in-caption')
def test_reference_in_caption(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'Python.tex').text(encoding='utf8')
print(result)
print(status.getvalue())
print(warning.getvalue())
assert ('\\caption{This is the figure caption with a reference to \\label{index:id2}'
'{\\hyperref[index:authoryear]{\\emph{{[}AuthorYear{]}}}}.}' in result)
assert '\\chapter{The section with a reference to {[}AuthorYear{]}}' in result
assert '\\caption{The table title with a reference to {[}AuthorYear{]}}' in result
assert '\\paragraph{The rubric title with a reference to {[}AuthorYear{]}}' in result

View File

@ -64,7 +64,7 @@ def test_code_block_caption_html(app, status, warning):
def test_code_block_caption_latex(app, status, warning): def test_code_block_caption_latex(app, status, warning):
app.builder.build_all() app.builder.build_all()
latex = (app.outdir / 'Python.tex').text(encoding='utf-8') latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
caption = '\\caption{caption \\emph{test} rb}' caption = '\\captionof{literal-block}{caption \\emph{test} rb}'
assert caption in latex assert caption in latex
@ -205,5 +205,5 @@ def test_literalinclude_caption_html(app, status, warning):
def test_literalinclude_caption_latex(app, status, warning): def test_literalinclude_caption_latex(app, status, warning):
app.builder.build('index') app.builder.build('index')
latex = (app.outdir / 'Python.tex').text(encoding='utf-8') latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
caption = '\\caption{caption \\textbf{test} py}' caption = '\\captionof{literal-block}{caption \\textbf{test} py}'
assert caption in latex assert caption in latex

View File

@ -63,9 +63,10 @@ def test_images():
image_uri_message = remove_unicode_literals(image_uri_message) image_uri_message = remove_unicode_literals(image_uri_message)
assert image_uri_message in app._warning.content[-1] assert image_uri_message in app._warning.content[-1]
assert set(htmlbuilder.images.keys()) == \ assert set(htmlbuilder.images.keys()) == \
set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg']) set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg',
'img.foo.png'])
assert set(htmlbuilder.images.values()) == \ assert set(htmlbuilder.images.values()) == \
set(['img.png', 'img1.png', 'simg.png', 'svgimg.svg']) set(['img.png', 'img1.png', 'simg.png', 'svgimg.svg', 'img.foo.png'])
app._warning.reset() app._warning.reset()
latexbuilder = LaTeXBuilder(app) latexbuilder = LaTeXBuilder(app)
@ -73,9 +74,10 @@ def test_images():
assert image_uri_message in app._warning.content[-1] assert image_uri_message in app._warning.content[-1]
assert set(latexbuilder.images.keys()) == \ assert set(latexbuilder.images.keys()) == \
set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf', set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf',
'svgimg.pdf']) 'svgimg.pdf', 'img.foo.png'])
assert set(latexbuilder.images.values()) == \ assert set(latexbuilder.images.values()) == \
set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf']) set(['img.pdf', 'img.png', 'img1.png', 'simg.png',
'svgimg.pdf', 'img.foo.png'])
def test_second_update(): def test_second_update():