Skip to content

Commit 3c25c8c

Browse files
authored
BUG: Disabling pandas option display.html.use_mathjax has no effect; add mathjax_ignore to fix (#60311)
* add bugfix to whatsnew * append "mathjax_ignore" in "tex2jax_ignore" related funcs * add "mathjax_ignore" on existing tests * remove old table_attr
1 parent c4a2026 commit 3c25c8c

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ I/O
702702
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
703703
- Bug in :meth:`read_stata` where extreme value integers were incorrectly interpreted as missing for format versions 111 and prior (:issue:`58130`)
704704
- Bug in :meth:`read_stata` where the missing code for double was not recognised for format versions 105 and prior (:issue:`58149`)
705+
- Bug in :meth:`set_option` where setting the pandas option ``display.html.use_mathjax`` to ``False`` has no effect (:issue:`59884`)
705706
- Bug in :meth:`to_excel` where :class:`MultiIndex` columns would be merged to a single row when ``merge_cells=False`` is passed (:issue:`60274`)
706707

707708
Period

pandas/io/formats/html.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def _write_table(self, indent: int = 0) -> None:
241241
use_mathjax = get_option("display.html.use_mathjax")
242242
if not use_mathjax:
243243
_classes.append("tex2jax_ignore")
244+
_classes.append("mathjax_ignore")
244245
if self.classes is not None:
245246
if isinstance(self.classes, str):
246247
self.classes = self.classes.split()

pandas/io/formats/style_render.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,11 @@ def _translate(
366366
if not get_option("styler.html.mathjax"):
367367
table_attr = table_attr or ""
368368
if 'class="' in table_attr:
369-
table_attr = table_attr.replace('class="', 'class="tex2jax_ignore ')
369+
table_attr = table_attr.replace(
370+
'class="', 'class="tex2jax_ignore mathjax_ignore '
371+
)
370372
else:
371-
table_attr += ' class="tex2jax_ignore"'
373+
table_attr += ' class="tex2jax_ignore mathjax_ignore"'
372374
d.update({"table_attributes": table_attr})
373375

374376
if self.tooltips:

pandas/tests/io/formats/style/test_style.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,11 @@ def test_repr_html_ok(self, styler):
488488
def test_repr_html_mathjax(self, styler):
489489
# gh-19824 / 41395
490490
assert "tex2jax_ignore" not in styler._repr_html_()
491+
assert "mathjax_ignore" not in styler._repr_html_()
491492

492493
with option_context("styler.html.mathjax", False):
493494
assert "tex2jax_ignore" in styler._repr_html_()
495+
assert "mathjax_ignore" in styler._repr_html_()
494496

495497
def test_update_ctx(self, styler):
496498
styler._update_ctx(DataFrame({"A": ["color: red", "color: blue"]}))

pandas/tests/io/formats/test_to_html.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,11 @@ def test_repr_html(self, float_frame):
934934
def test_repr_html_mathjax(self):
935935
df = DataFrame([[1, 2], [3, 4]])
936936
assert "tex2jax_ignore" not in df._repr_html_()
937+
assert "mathjax_ignore" not in df._repr_html_()
937938

938939
with option_context("display.html.use_mathjax", False):
939940
assert "tex2jax_ignore" in df._repr_html_()
941+
assert "mathjax_ignore" in df._repr_html_()
940942

941943
def test_repr_html_wide(self):
942944
max_cols = 20

0 commit comments

Comments
 (0)