From b1a0e8062fa059a4be6a8ba2a0ebe7372825e590 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 14 Apr 2018 22:36:24 +0900 Subject: [PATCH 1/3] Fix #4767: html: search highlighting breaks mathjax equations --- CHANGES | 1 + sphinx/ext/jsmath.py | 6 +++--- sphinx/ext/mathjax.py | 4 ++-- sphinx/themes/basic/static/doctools.js_t | 4 +++- tests/test_ext_math.py | 22 +++++++++++----------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index 93377cd20..1f78e2139 100644 --- a/CHANGES +++ b/CHANGES @@ -60,6 +60,7 @@ Bugs fixed * #1435: qthelp builder should htmlescape keywords * epub: Fix docTitle elements of toc.ncx is not escaped * #4520: apidoc: Subpackage not in toc (introduced in 1.6.6) now fixed +* #4767: html: search highlighting breaks mathjax equations Release 1.7.1 (released Feb 23, 2018) ===================================== diff --git a/sphinx/ext/jsmath.py b/sphinx/ext/jsmath.py index 05d5dc290..5d8ec876e 100644 --- a/sphinx/ext/jsmath.py +++ b/sphinx/ext/jsmath.py @@ -20,14 +20,14 @@ from sphinx.locale import _ def html_visit_math(self, node): - self.body.append(self.starttag(node, 'span', '', CLASS='math notranslate')) + self.body.append(self.starttag(node, 'span', '', CLASS='math notranslate nohighlight')) self.body.append(self.encode(node['latex']) + '') raise nodes.SkipNode def html_visit_displaymath(self, node): if node['nowrap']: - self.body.append(self.starttag(node, 'div', CLASS='math notranslate')) + self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight')) self.body.append(self.encode(node['latex'])) self.body.append('') raise nodes.SkipNode @@ -40,7 +40,7 @@ def html_visit_displaymath(self, node): self.body.append('(%s)' % number) self.add_permalink_ref(node, _('Permalink to this equation')) self.body.append('') - self.body.append(self.starttag(node, 'div', CLASS='math notranslate')) + self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight')) else: # but only once! self.body.append('
') diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py index 6c5d0a642..bb9964fa8 100644 --- a/sphinx/ext/mathjax.py +++ b/sphinx/ext/mathjax.py @@ -21,7 +21,7 @@ from sphinx.locale import _ def html_visit_math(self, node): - self.body.append(self.starttag(node, 'span', '', CLASS='math notranslate')) + self.body.append(self.starttag(node, 'span', '', CLASS='math notranslate nohighlight')) self.body.append(self.builder.config.mathjax_inline[0] + self.encode(node['latex']) + self.builder.config.mathjax_inline[1] + '') @@ -29,7 +29,7 @@ def html_visit_math(self, node): def html_visit_displaymath(self, node): - self.body.append(self.starttag(node, 'div', CLASS='math notranslate')) + self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight')) if node['nowrap']: self.body.append(self.encode(node['latex'])) self.body.append('
') diff --git a/sphinx/themes/basic/static/doctools.js_t b/sphinx/themes/basic/static/doctools.js_t index b261a44f3..1dca47404 100644 --- a/sphinx/themes/basic/static/doctools.js_t +++ b/sphinx/themes/basic/static/doctools.js_t @@ -70,7 +70,9 @@ jQuery.fn.highlightText = function(text, className) { if (node.nodeType === 3) { var val = node.nodeValue; var pos = val.toLowerCase().indexOf(text); - if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) { + if (pos >= 0 && + !jQuery(node.parentNode).hasClass(className) && + !jQuery(node.parentNode).hasClass("nohighlight")) { var span; var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); if (isInSVG) { diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py index 755a9e955..28ce094a8 100644 --- a/tests/test_ext_math.py +++ b/tests/test_ext_math.py @@ -35,19 +35,19 @@ def test_jsmath(app, status, warning): app.builder.build_all() content = (app.outdir / 'math.html').text() - assert '
\na^2 + b^2 = c^2
' in content - assert ('
\n\\begin{split}a + 1 < b\\end{split}
' - in content) + assert '
\na^2 + b^2 = c^2
' in content + assert ('
\n\\begin{split}a + 1 < ' + 'b\\end{split}
' in content) assert (u'(1)\xb6' - u'
\ne^{i\\pi} = 1
' - in content) + u'
' + '\ne^{i\\pi} = 1
' in content) assert (u'(2)\xb6' - u'
\n' + u'
\n' u'e^{ix} = \\cos x + i\\sin x
' in content) - assert '
\nn \\in \\mathbb N
' in content - assert '
\na + 1 < b
' in content + assert '
\nn \\in \\mathbb N
' in content + assert '
\na + 1 < b
' in content @pytest.mark.skipif(not has_binary('dvipng'), @@ -91,7 +91,7 @@ def test_mathjax_align(app, status, warning): app.builder.build_all() content = (app.outdir / 'index.html').text() - html = (r'
\s*' + html = (r'
\s*' r'\\\[ \\begin\{align\}\\begin\{aligned\}S \&= \\pi r\^2\\\\' r'V \&= \\frac\{4\}\{3\} \\pi r\^3\\end\{aligned\}\\end\{align\} \\\]
') assert re.search(html, content, re.S) @@ -104,7 +104,7 @@ def test_math_number_all_mathjax(app, status, warning): app.builder.build_all() content = (app.outdir / 'index.html').text() - html = (r'
\s*' + html = (r'
\s*' r'\(1\)\xb6\\\[a\^2\+b\^2=c\^2\\\]
') assert re.search(html, content, re.S) @@ -169,7 +169,7 @@ def test_mathjax_numfig_html(app, status, warning): app.builder.build_all() content = (app.outdir / 'math.html').text() - html = ('
\n' + html = ('
\n' '(1.2)') assert html in content html = ('

Referencing equation Date: Sat, 14 Apr 2018 18:47:11 +0200 Subject: [PATCH 2/3] Fix #4837: (latex with class memoir) Font command \sf is not supported --- CHANGES | 1 + sphinx/writers/latex.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 93377cd20..6962814e4 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,7 @@ Bugs fixed * #4817: wrong URLs on warning messages * #4784: latex: :confval:`latex_show_urls` assigns incorrect footnote numbers if hyperlinks exists inside substitutions +* #4837: latex: Class memoir Error Font command ``\sf`` is not supported Testing -------- diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 0fecd7b8a..aca5d91ab 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -615,7 +615,9 @@ class LaTeXTranslator(nodes.NodeVisitor): if builder.config.language \ and 'fncychap' not in builder.config.latex_elements: # use Sonny style if any language specified - self.elements['fncychap'] = '\\usepackage[Sonny]{fncychap}' + self.elements['fncychap'] = ('\\usepackage[Sonny]{fncychap}' + '\\ChNameVar{\\Large\\sffamily}' + '\\ChTitleVar{\\Large\\sffamily}') self.babel = ExtBabel(builder.config.language) if builder.config.language and not self.babel.is_supported_language(): From aa21d78e42ebbc993f4f5df66755a044a95d52c8 Mon Sep 17 00:00:00 2001 From: jfbu Date: Sat, 14 Apr 2018 19:48:24 +0200 Subject: [PATCH 3/3] Fix again #4837, using better equivalent to deprecated \sf --- CHANGES | 2 +- sphinx/writers/latex.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 6962814e4..fd1e8dcbe 100644 --- a/CHANGES +++ b/CHANGES @@ -26,7 +26,7 @@ Bugs fixed * #4817: wrong URLs on warning messages * #4784: latex: :confval:`latex_show_urls` assigns incorrect footnote numbers if hyperlinks exists inside substitutions -* #4837: latex: Class memoir Error Font command ``\sf`` is not supported +* #4837: latex with class memoir Error: Font command ``\sf`` is not supported Testing -------- diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index aca5d91ab..c742cdc1a 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -615,9 +615,10 @@ class LaTeXTranslator(nodes.NodeVisitor): if builder.config.language \ and 'fncychap' not in builder.config.latex_elements: # use Sonny style if any language specified - self.elements['fncychap'] = ('\\usepackage[Sonny]{fncychap}' - '\\ChNameVar{\\Large\\sffamily}' - '\\ChTitleVar{\\Large\\sffamily}') + self.elements['fncychap'] = ('\\usepackage[Sonny]{fncychap}\n' + '\\ChNameVar{\\Large\\normalfont' + '\\sffamily}\n\\ChTitleVar{\\Large' + '\\normalfont\\sffamily}') self.babel = ExtBabel(builder.config.language) if builder.config.language and not self.babel.is_supported_language():