Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix : Added mathjax_ignore to HTMLFormatter._write_table and changed tests to assert mathjax_ignore #60043

Closed
wants to merge 13 commits into from
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ I/O
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
- Bug in :meth:`read_stata` where extreme value integers were incorrectly interpreted as missing for format versions 111 and prior (:issue:`58130`)
- Bug in :meth:`read_stata` where the missing code for double was not recognised for format versions 105 and prior (:issue:`58149`)
- Bug in :meth:`set_option` where disabling pandas option display.html.use_mathjax has no effect (:issue:`59884`)
Maru5er marked this conversation as resolved.
Show resolved Hide resolved

Period
^^^^^^
Expand Down
1 change: 1 addition & 0 deletions pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def _write_table(self, indent: int = 0) -> None:
use_mathjax = get_option("display.html.use_mathjax")
if not use_mathjax:
_classes.append("tex2jax_ignore")
_classes.append("mathjax_ignore")
if self.classes is not None:
if isinstance(self.classes, str):
self.classes = self.classes.split()
Expand Down
6 changes: 4 additions & 2 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,11 @@ def _translate(
if not get_option("styler.html.mathjax"):
table_attr = table_attr or ""
if 'class="' in table_attr:
table_attr = table_attr.replace('class="', 'class="tex2jax_ignore ')
table_attr = table_attr.replace(
'class="', 'class="tex2jax_ignore mathjax_ignore"'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

'class="', 'class="tex2jax_ignore mathjax_ignore '

as we are prepending to an already existing class.

)
else:
table_attr += ' class="tex2jax_ignore"'
table_attr += ' class="tex2jax_ignore mathjax_ignore"'
d.update({"table_attributes": table_attr})

if self.tooltips:
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,11 @@ def test_repr_html_ok(self, styler):
def test_repr_html_mathjax(self, styler):
# gh-19824 / 41395
assert "tex2jax_ignore" not in styler._repr_html_()
assert "mathjax_ignore" not in styler._repr_html_()

with option_context("styler.html.mathjax", False):
assert "tex2jax_ignore" in styler._repr_html_()
assert "mathjax_ignore" in styler._repr_html_()

def test_update_ctx(self, styler):
styler._update_ctx(DataFrame({"A": ["color: red", "color: blue"]}))
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,9 +934,11 @@ def test_repr_html(self, float_frame):
def test_repr_html_mathjax(self):
df = DataFrame([[1, 2], [3, 4]])
assert "tex2jax_ignore" not in df._repr_html_()
assert "mathjax_ignore" not in df._repr_html_()

with option_context("display.html.use_mathjax", False):
assert "tex2jax_ignore" in df._repr_html_()
assert "mathjax_ignore" in df._repr_html_()

def test_repr_html_wide(self):
max_cols = 20
Expand Down