Subject: Math rendering breaks with hightlighting
if you search for a keyword in a math formula, it interferes with rendering of the formula:
See e.g.
https://picongpu.readthedocs.io/en/latest/usage/workflows/laserPeakOnTarget.html?highlight=laser
vs.
https://picongpu.readthedocs.io/en/latest/usage/workflows/laserPeakOnTarget.html
cc @psychocoderHPC (initial report)
See the links above :-)
N/A
Still render the math formula correctly even with highlight.
see above.
Source code: https://github.com/ComputationalRadiationPhysics/picongpu/blob/dev/docs/source/usage/workflows/laserPeakOnTarget.rst
Math extension: sphinx.ext.mathjax
This can be fixed using
diff --git a/sphinx/themes/basic/static/doctools.js_t b/sphinx/themes/basic/static/doctools.js_t
index b261a44f3..3df8c6c31 100644
--- a/sphinx/themes/basic/static/doctools.js_t
+++ b/sphinx/themes/basic/static/doctools.js_t
@@ -70,7 +70,7 @@ 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("math")) {
var span;
var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg");
if (isInSVG) {
But better would be to highlight inside MathJax. This appears to be possible if one inserts via js this mark-up:
\color{#C00}{highlighted element}
I picked #C00 because the #fbe54e from basic.css for background color isn't very legible as text color, and I don't know if MathJax offers a possibility for background color. I fear a bit that injecting this \color will not be robust against search terms mixing letters and latex mark-up... so perhaps first measure would be to apply above patch because indeed the <span> tags added by the highlighter break MathJax.
Ah, ok I did not know bbox MathJax extension so the correct fix is to get javascript to modify document mark-up into something like
\bbox[#fbe54e]{laser}
in order to highlight search results also in math blocks.
Fixed by #4844
Thank you for reporting!
Thank you so much for the fix, this is wonderful! :sparkles: