mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4987 from tk0miya/4979_latex_index_escaping
Fix #4979: latex: Incorrect escaping of curly braces in index entries
This commit is contained in:
commit
713aa82140
1
CHANGES
1
CHANGES
@ -33,6 +33,7 @@ Bugs fixed
|
|||||||
* #4978: latex: shorthandoff is not set up for Brazil locale
|
* #4978: latex: shorthandoff is not set up for Brazil locale
|
||||||
* #4928: i18n: Ignore dot-directories like .git/ in LC_MESSAGES/
|
* #4928: i18n: Ignore dot-directories like .git/ in LC_MESSAGES/
|
||||||
* #4946: py domain: type field could not handle "None" as a type
|
* #4946: py domain: type field could not handle "None" as a type
|
||||||
|
* #4979: latex: Incorrect escaping of curly braces in index entries
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -1608,6 +1608,10 @@
|
|||||||
% figure legend comes after caption and may contain arbitrary body elements
|
% figure legend comes after caption and may contain arbitrary body elements
|
||||||
\newenvironment{sphinxlegend}{\par\small}{\par}
|
\newenvironment{sphinxlegend}{\par\small}{\par}
|
||||||
|
|
||||||
|
% For curly braces inside \index macro
|
||||||
|
\def\sphinxleftcurlybrace{\{}
|
||||||
|
\def\sphinxrightcurlybrace{\}}
|
||||||
|
|
||||||
% Declare Unicode characters used by linux tree command to pdflatex utf8/utf8x
|
% Declare Unicode characters used by linux tree command to pdflatex utf8/utf8x
|
||||||
\def\spx@bd#1#2{%
|
\def\spx@bd#1#2{%
|
||||||
\leavevmode
|
\leavevmode
|
||||||
|
@ -1949,6 +1949,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
|
|
||||||
def visit_index(self, node, scre=re.compile(r';\s*')):
|
def visit_index(self, node, scre=re.compile(r';\s*')):
|
||||||
# type: (nodes.Node, Pattern) -> None
|
# type: (nodes.Node, Pattern) -> None
|
||||||
|
def escape(value):
|
||||||
|
value = self.encode(value)
|
||||||
|
value = value.replace(r'\{', r'\sphinxleftcurlybrace')
|
||||||
|
value = value.replace(r'\}', r'\sphinxrightcurlybrace')
|
||||||
|
return value
|
||||||
|
|
||||||
if not node.get('inline', True):
|
if not node.get('inline', True):
|
||||||
self.body.append('\n')
|
self.body.append('\n')
|
||||||
entries = node['entries']
|
entries = node['entries']
|
||||||
@ -1958,24 +1964,23 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
m = '|textbf'
|
m = '|textbf'
|
||||||
try:
|
try:
|
||||||
if type == 'single':
|
if type == 'single':
|
||||||
p = scre.sub('!', self.encode(string))
|
p = scre.sub('!', escape(string))
|
||||||
self.body.append(r'\index{%s%s}' % (p, m))
|
self.body.append(r'\index{%s%s}' % (p, m))
|
||||||
elif type == 'pair':
|
elif type == 'pair':
|
||||||
p1, p2 = [self.encode(x) for x in split_into(2, 'pair', string)]
|
p1, p2 = [escape(x) for x in split_into(2, 'pair', string)]
|
||||||
self.body.append(r'\index{%s!%s%s}\index{%s!%s%s}' %
|
self.body.append(r'\index{%s!%s%s}\index{%s!%s%s}' %
|
||||||
(p1, p2, m, p2, p1, m))
|
(p1, p2, m, p2, p1, m))
|
||||||
elif type == 'triple':
|
elif type == 'triple':
|
||||||
p1, p2, p3 = [self.encode(x)
|
p1, p2, p3 = [escape(x) for x in split_into(3, 'triple', string)]
|
||||||
for x in split_into(3, 'triple', string)]
|
|
||||||
self.body.append(
|
self.body.append(
|
||||||
r'\index{%s!%s %s%s}\index{%s!%s, %s%s}'
|
r'\index{%s!%s %s%s}\index{%s!%s, %s%s}'
|
||||||
r'\index{%s!%s %s%s}' %
|
r'\index{%s!%s %s%s}' %
|
||||||
(p1, p2, p3, m, p2, p3, p1, m, p3, p1, p2, m))
|
(p1, p2, p3, m, p2, p3, p1, m, p3, p1, p2, m))
|
||||||
elif type == 'see':
|
elif type == 'see':
|
||||||
p1, p2 = [self.encode(x) for x in split_into(2, 'see', string)]
|
p1, p2 = [escape(x) for x in split_into(2, 'see', string)]
|
||||||
self.body.append(r'\index{%s|see{%s}}' % (p1, p2))
|
self.body.append(r'\index{%s|see{%s}}' % (p1, p2))
|
||||||
elif type == 'seealso':
|
elif type == 'seealso':
|
||||||
p1, p2 = [self.encode(x) for x in split_into(2, 'seealso', string)]
|
p1, p2 = [escape(x) for x in split_into(2, 'seealso', string)]
|
||||||
self.body.append(r'\index{%s|see{%s}}' % (p1, p2))
|
self.body.append(r'\index{%s|see{%s}}' % (p1, p2))
|
||||||
else:
|
else:
|
||||||
logger.warning('unknown index entry type %s found', type)
|
logger.warning('unknown index entry type %s found', type)
|
||||||
|
@ -10,3 +10,7 @@ A :index:`famous` :index:`equation`:
|
|||||||
.. index:: Einstein, relativity
|
.. index:: Einstein, relativity
|
||||||
|
|
||||||
and some text.
|
and some text.
|
||||||
|
|
||||||
|
.. index:: main {
|
||||||
|
|
||||||
|
An index entry containing non paired curly brace
|
||||||
|
@ -1209,6 +1209,7 @@ def test_latex_index(app, status, warning):
|
|||||||
result = (app.outdir / 'Python.tex').text(encoding='utf8')
|
result = (app.outdir / 'Python.tex').text(encoding='utf8')
|
||||||
assert 'A \\index{famous}famous \\index{equation}equation:\n' in result
|
assert 'A \\index{famous}famous \\index{equation}equation:\n' in result
|
||||||
assert '\n\\index{Einstein}\\index{relativity}\\ignorespaces \nand' in result
|
assert '\n\\index{Einstein}\\index{relativity}\\ignorespaces \nand' in result
|
||||||
|
assert '\n\\index{main \\sphinxleftcurlybrace}\\ignorespaces ' in result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('latex', testroot='latex-equations')
|
@pytest.mark.sphinx('latex', testroot='latex-equations')
|
||||||
|
Loading…
Reference in New Issue
Block a user