Skip to content

Commit

Permalink
Merge branch '1.8'
Browse files Browse the repository at this point in the history
Conflicts:
	sphinx/writers/latex.py
	tests/test_build_latex.py

Also, modifications were needed in further files.

	modified:   CHANGES
	modified:   sphinx/templates/latex/sphinxmessages.sty_t
	modified:   sphinx/util/template.py
	modified:   sphinx/util/texescape.py
	modified:   sphinx/writers/latex.py
	modified:   tests/test_build_latex.py
  • Loading branch information
jfbu committed Jan 5, 2019
2 parents 833e5ef + e44f56a commit af2bb9f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 44 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ Features added

Bugs fixed
----------
* #3707: latex: no bold checkmark (✔) available.
* #5605: with the documentation language set to Chinese, English words could not
be searched.
* #5889: LaTeX: user ``numfig_format`` is stripped of spaces and may cause
build failure

Testing
--------
Expand Down
12 changes: 4 additions & 8 deletions sphinx/templates/latex/sphinxmessages.sty_t
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
\renewcommand{\sphinxnumbersname}{<%= _('Numbers') | e %>}
\def\pageautorefname{<%= _('page') | e %>}

<%= addtocaptions %>{\renewcommand{\figurename}{<%= figurename[0].strip() | e %>}}
<%- if figurename[1] %>
\def\fnum@figure{\figurename\thefigure\relax{}<%= figurename[1].strip() | e %>}
<%- endif %>
<%= addtocaptions %>{\renewcommand{\figurename}{<%= figurename[0] | e | eabbr %>}}
\def\fnum@figure{\figurename\thefigure{}<%= figurename[1] | e %>}

<%= addtocaptions %>{\renewcommand{\tablename}{<%= tablename[0].strip() %>}}
<%- if tablename[1] %>
\def\fnum@table{\tablename\thetable\relax{}<%= tablename[1].strip() | e %>}
<%- endif %>
<%= addtocaptions %>{\renewcommand{\tablename}{<%= tablename[0] | e | eabbr %>}}
\def\fnum@table{\tablename\thetable{}<%= tablename[1] | e %>}

<%= addtocaptions %>{\renewcommand{\literalblockname}{<%= literalblockname[0].strip() %>}}
1 change: 1 addition & 0 deletions sphinx/util/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self):
# use texescape as escape filter
self.env.filters['e'] = texescape.escape
self.env.filters['escape'] = texescape.escape
self.env.filters['eabbr'] = texescape.escape_abbr

# use JSP/eRuby like tagging instead because curly bracket; the default
# tagging of jinja2 is not good for LaTeX sources.
Expand Down
9 changes: 9 additions & 0 deletions sphinx/util/texescape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
:license: BSD, see LICENSE for details.
"""

import re

if False:
# For type annotation
from typing import Dict # NOQA
Expand Down Expand Up @@ -38,6 +40,7 @@
('→', r'\(\rightarrow\)'),
('‣', r'\(\rightarrow\)'),
('✓', r'\(\checkmark\)'),
('✔', r'\(\pmb{\checkmark}\)'),
# used to separate -- in options
('', r'{}'),
# map some special Unicode characters to similar ASCII ones
Expand Down Expand Up @@ -81,6 +84,12 @@ def escape(s):
return s.translate(tex_escape_map)


def escape_abbr(text):
# type: (str) -> str
"""Adjust spacing after abbreviations. Works with @ letter or other."""
return re.sub(r'\.(?=\s|$)', r'.\@{}', text)


def init():
# type: () -> None
for a, b in tex_replacements:
Expand Down
22 changes: 10 additions & 12 deletions sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2571,26 +2571,24 @@ def generate_numfig_format(self, builder):
ret.append('\\def\\fnum@figure{%s}\n' %
str(figure[0]).strip().translate(tex_escape_map))
else:
definition = str(figure[0]).strip().translate(tex_escape_map)
definition = escape_abbr(str(figure[0]).translate(tex_escape_map))
ret.append(self.babel_renewcommand('\\figurename', definition))
if figure[1]:
ret.append('\\makeatletter\n')
ret.append('\\def\\fnum@figure{\\figurename\\thefigure%s}\n' %
str(figure[1]).strip().translate(tex_escape_map))
ret.append('\\makeatother\n')
ret.append('\\makeatletter\n')
ret.append('\\def\\fnum@figure{\\figurename\\thefigure{}%s}\n' %
str(figure[1]).translate(tex_escape_map))
ret.append('\\makeatother\n')

table = self.builder.config.numfig_format['table'].split('%s', 1)
if len(table) == 1:
ret.append('\\def\\fnum@table{%s}\n' %
str(table[0]).strip().translate(tex_escape_map))
else:
definition = str(table[0]).strip().translate(tex_escape_map)
definition = escape_abbr(str(table[0]).translate(tex_escape_map))
ret.append(self.babel_renewcommand('\\tablename', definition))
if table[1]:
ret.append('\\makeatletter\n')
ret.append('\\def\\fnum@table{\\tablename\\thetable%s}\n' %
str(table[1]).strip().translate(tex_escape_map))
ret.append('\\makeatother\n')
ret.append('\\makeatletter\n')
ret.append('\\def\\fnum@table{\\tablename\\thetable{}%s}\n' %
str(table[1]).translate(tex_escape_map))
ret.append('\\makeatother\n')

codeblock = self.builder.config.numfig_format['code-block'].split('%s', 1)
if len(codeblock) == 1:
Expand Down
48 changes: 24 additions & 24 deletions tests/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ def test_numref(app, status, warning):
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.}}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table}}' in result
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table }}' in result
assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Listing}}' in result


Expand Down Expand Up @@ -276,7 +276,7 @@ def test_numref_with_prefix1(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab_}}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result
assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Code-}}' in result


Expand Down Expand Up @@ -318,9 +318,9 @@ def test_numref_with_prefix2(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result
assert r'\def\fnum@figure{\figurename\thefigure\relax{}.}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab_}}' in result
assert r'\def\fnum@table{\tablename\thetable\relax{}:}' in result
assert r'\def\fnum@figure{\figurename\thefigure{}.}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result
assert r'\def\fnum@table{\tablename\thetable{}:}' in result
assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Code-}}' in result


Expand Down Expand Up @@ -357,8 +357,8 @@ def test_numref_with_language_ja(app, status, warning):
# sphinxmessages.sty
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert '\n{\\renewcommand{\\figurename}{図}}' in result
assert '\n{\\renewcommand{\\tablename}{表}}' in result
assert '\n{\\renewcommand{\\figurename}{図 }}' in result
assert '\n{\\renewcommand{\\tablename}{表 }}' in result
assert '\n{\\renewcommand{\\literalblockname}{リスト}}' in result


Expand Down Expand Up @@ -441,8 +441,8 @@ def test_babel_with_no_language_settings(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{page}' in result
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.}}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.}}' in result
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.\@{} }}' in result


@pytest.mark.sphinx(
Expand All @@ -466,8 +466,8 @@ def test_babel_with_language_de(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{Seite}' in result
assert r'\addto\captionsngerman{\renewcommand{\figurename}{Fig.}}' in result
assert r'\addto\captionsngerman{\renewcommand{\tablename}{Table.}}' in result
assert r'\addto\captionsngerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsngerman{\renewcommand{\tablename}{Table.\@{} }}' in result


@pytest.mark.sphinx(
Expand All @@ -491,8 +491,8 @@ def test_babel_with_language_ru(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{страница}' in result
assert r'\addto\captionsrussian{\renewcommand{\figurename}{Fig.}}' in result
assert r'\addto\captionsrussian{\renewcommand{\tablename}{Table.}}' in result
assert r'\addto\captionsrussian{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsrussian{\renewcommand{\tablename}{Table.\@{} }}' in result


@pytest.mark.sphinx(
Expand All @@ -516,8 +516,8 @@ def test_babel_with_language_tr(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{sayfa}' in result
assert r'\addto\captionsturkish{\renewcommand{\figurename}{Fig.}}' in result
assert r'\addto\captionsturkish{\renewcommand{\tablename}{Table.}}' in result
assert r'\addto\captionsturkish{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsturkish{\renewcommand{\tablename}{Table.\@{} }}' in result


@pytest.mark.sphinx(
Expand All @@ -540,8 +540,8 @@ def test_babel_with_language_ja(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{ページ}' in result
assert '\n{\\renewcommand{\\figurename}{Fig.}}' in result
assert '\n{\\renewcommand{\\tablename}{Table.}}' in result
assert '\n{\\renewcommand{\\figurename}{Fig.\\@{} }}' in result
assert '\n{\\renewcommand{\\tablename}{Table.\\@{} }}' in result


@pytest.mark.sphinx(
Expand All @@ -567,8 +567,8 @@ def test_babel_with_unknown_language(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{page}' in result
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.}}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.}}' in result
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.\@{} }}' in result


@pytest.mark.sphinx(
Expand All @@ -593,8 +593,8 @@ def test_polyglossia_with_language_de(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{Seite}' in result
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.}}' in result
assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.}}' in result
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.\@{} }}' in result


@pytest.mark.sphinx(
Expand All @@ -619,8 +619,8 @@ def test_polyglossia_with_language_de_1901(app, status, warning):
result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8')
print(result)
assert r'\def\pageautorefname{page}' in result
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.}}' in result
assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.}}' in result
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result
assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.\@{} }}' in result


@pytest.mark.sphinx('latex')
Expand Down

0 comments on commit af2bb9f

Please sign in to comment.