Merge pull request #5891 from jfbu/latex_5889

LaTeX: obey spaces from `numfig_format` (figure and table only)
This commit is contained in:
Jean-François B 2019-01-05 10:03:11 +01:00 committed by GitHub
commit e44f56a871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 34 deletions

View File

@ -18,6 +18,8 @@ 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
--------

View File

@ -792,12 +792,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
ret.append('\\def\\fnum@figure{%s}\n' %
text_type(figure[0]).strip().translate(tex_escape_map))
else:
definition = text_type(figure[0]).strip().translate(tex_escape_map)
definition = escape_abbr(text_type(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' %
text_type(figure[1]).strip().translate(tex_escape_map))
ret.append('\\def\\fnum@figure{\\figurename\\thefigure{}%s}\n' %
text_type(figure[1]).translate(tex_escape_map))
ret.append('\\makeatother\n')
table = self.builder.config.numfig_format['table'].split('%s', 1)
@ -805,12 +804,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
ret.append('\\def\\fnum@table{%s}\n' %
text_type(table[0]).strip().translate(tex_escape_map))
else:
definition = text_type(table[0]).strip().translate(tex_escape_map)
definition = escape_abbr(text_type(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' %
text_type(table[1]).strip().translate(tex_escape_map))
ret.append('\\def\\fnum@table{\\tablename\\thetable{}%s}\n' %
text_type(table[1]).translate(tex_escape_map))
ret.append('\\makeatother\n')
codeblock = self.builder.config.numfig_format['code-block'].split('%s', 1)

View File

@ -206,7 +206,7 @@ def test_numref(app, status, warning):
print(result)
print(status.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{\\literalblockname}{Listing}}' in result
assert ('\\hyperref[\\detokenize{index:fig1}]'
@ -289,9 +289,9 @@ def test_numref_with_prefix2(app, status, warning):
print(status.getvalue())
print(warning.getvalue())
assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Figure:}}' in result
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 '\\def\\fnum@table{\\tablename\\thetable:}' in result
assert '\\def\\fnum@table{\\tablename\\thetable{}:}' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\literalblockname}{Code-}}' in result
assert ('\\hyperref[\\detokenize{index:fig1}]'
'{Figure:\\ref{\\detokenize{index:fig1}}.\\@}') in result
@ -422,8 +422,8 @@ def test_babel_with_no_language_settings(app, status, warning):
assert '\\usepackage[Bjarne]{fncychap}' in result
assert ('\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of content}}\n'
in result)
assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result
assert '\\addto\\extrasenglish{\\def\\pageautorefname{page}}\n' in result
assert '\\shorthandoff' not in result
@ -443,8 +443,8 @@ def test_babel_with_language_de(app, status, warning):
assert '\\usepackage[Sonny]{fncychap}' in result
assert ('\\addto\\captionsngerman{\\renewcommand{\\contentsname}{Table of content}}\n'
in result)
assert '\\addto\\captionsngerman{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsngerman{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\captionsngerman{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result
assert '\\addto\\captionsngerman{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result
assert '\\addto\\extrasngerman{\\def\\pageautorefname{Seite}}\n' in result
assert '\\shorthandoff{"}' in result
@ -464,8 +464,8 @@ def test_babel_with_language_ru(app, status, warning):
assert '\\usepackage[Sonny]{fncychap}' in result
assert ('\\addto\\captionsrussian{\\renewcommand{\\contentsname}{Table of content}}\n'
in result)
assert '\\addto\\captionsrussian{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsrussian{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\captionsrussian{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result
assert '\\addto\\captionsrussian{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result
assert (u'\\addto\\extrasrussian{\\def\\pageautorefname'
u'{\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430}}\n' in result)
assert '\\shorthandoff{"}' in result
@ -486,8 +486,8 @@ def test_babel_with_language_tr(app, status, warning):
assert '\\usepackage[Sonny]{fncychap}' in result
assert ('\\addto\\captionsturkish{\\renewcommand{\\contentsname}{Table of content}}\n'
in result)
assert '\\addto\\captionsturkish{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsturkish{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\captionsturkish{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result
assert '\\addto\\captionsturkish{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result
assert '\\addto\\extrasturkish{\\def\\pageautorefname{sayfa}}\n' in result
assert '\\shorthandoff{=}' in result
@ -506,8 +506,8 @@ def test_babel_with_language_ja(app, status, warning):
assert '\\usepackage{times}' in result
assert '\\usepackage[Sonny]{fncychap}' not in result
assert '\\renewcommand{\\contentsname}{Table of content}\n' in result
assert '\\renewcommand{\\figurename}{Fig.}\n' in result
assert '\\renewcommand{\\tablename}{Table.}\n' in result
assert '\\renewcommand{\\figurename}{Fig.\\@ }\n' in result
assert '\\renewcommand{\\tablename}{Table.\\@ }\n' in result
assert u'\\def\\pageautorefname{ページ}\n' in result
assert '\\shorthandoff' not in result
@ -527,8 +527,8 @@ def test_babel_with_unknown_language(app, status, warning):
assert '\\usepackage[Sonny]{fncychap}' in result
assert ('\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of content}}\n'
in result)
assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result
assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result
assert '\\addto\\extrasenglish{\\def\\pageautorefname{page}}\n' in result
assert '\\shorthandoff' in result
@ -551,8 +551,8 @@ def test_polyglossia_with_language_de(app, status, warning):
assert '\\usepackage[Sonny]{fncychap}' in result
assert ('\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n'
in result)
assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result
assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result
assert '\\def\\pageautorefname{Seite}\n' in result
assert '\\shorthandoff' not in result
@ -573,8 +573,8 @@ def test_polyglossia_with_language_de_1901(app, status, warning):
assert '\\usepackage[Sonny]{fncychap}' in result
assert ('\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n'
in result)
assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.}}\n' in result
assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.}}\n' in result
assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result
assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result
assert '\\def\\pageautorefname{page}\n' in result
assert '\\shorthandoff' not in result