Skip to content

Commit 0070f74

Browse files
authored
ENH: styler.html.mathjax option (#43283)
1 parent 9981172 commit 0070f74

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

doc/source/user_guide/options.rst

+3
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ styler.format.thousands None String representation for t
499499
integers, and floating point and complex numbers.
500500
styler.format.escape None Whether to escape "html" or "latex" special
501501
characters in the display representation.
502+
styler.html.mathjax True If set to False will render specific CSS classes to
503+
table attributes that will prevent Mathjax from rendering
504+
in Jupyter Notebook.
502505
======================================= ============ ==================================
503506

504507

doc/source/whatsnew/v1.4.0.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ Styler
7575
- :meth:`.Styler.to_latex` introduces keyword argument ``environment``, which also allows a specific "longtable" entry through a separate jinja2 template (:issue:`41866`).
7676
- :meth:`.Styler.to_html` introduces keyword arguments ``sparse_index`` and ``sparse_columns`` (:issue:`41946`)
7777
- Keyword argument ``level`` is added to :meth:`.Styler.hide_index` and :meth:`.Styler.hide_columns` for optionally controlling hidden levels in a MultiIndex (:issue:`25475`)
78-
- Global options have been extended to configure default ``Styler`` properties including formatting and encoding options (:issue:`41395`)
78+
- Global options have been extended to configure default ``Styler`` properties including formatting and encoding and mathjax options (:issue:`41395`)
79+
80+
Formerly Styler relied on ``display.html.use_mathjax``, which has now been replaced by ``styler.html.mathjax``.
7981

8082
There are also bug fixes and deprecations listed below.
8183

pandas/core/config_init.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,17 @@ def register_converter_cb(key):
798798
The encoding used for output HTML and LaTeX files.
799799
"""
800800

801+
styler_mathjax = """
802+
: bool
803+
If False will render special CSS classes to table attributes that indicate Mathjax
804+
will not be used in Jupyter Notebook.
805+
"""
806+
801807
with cf.config_prefix("styler"):
802-
cf.register_option("sparse.index", True, styler_sparse_index_doc, validator=bool)
808+
cf.register_option("sparse.index", True, styler_sparse_index_doc, validator=is_bool)
803809

804810
cf.register_option(
805-
"sparse.columns", True, styler_sparse_columns_doc, validator=bool
811+
"sparse.columns", True, styler_sparse_columns_doc, validator=is_bool
806812
)
807813

808814
cf.register_option(
@@ -847,3 +853,5 @@ def register_converter_cb(key):
847853
styler_formatter,
848854
validator=is_instance_factory([type(None), dict, callable, str]),
849855
)
856+
857+
cf.register_option("html.mathjax", True, styler_mathjax, validator=is_bool)

pandas/io/formats/style_render.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ def _translate(self, sparse_index: bool, sparse_cols: bool, blank: str = " 
250250
d.update({k: map})
251251

252252
table_attr = self.table_attributes
253-
use_mathjax = get_option("display.html.use_mathjax")
254-
if not use_mathjax:
253+
if not get_option("styler.html.mathjax"):
255254
table_attr = table_attr or ""
256255
if 'class="' in table_attr:
257256
table_attr = table_attr.replace('class="', 'class="tex2jax_ignore ')

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ def test_repr_html_ok(self):
402402
self.styler._repr_html_()
403403

404404
def test_repr_html_mathjax(self):
405-
# gh-19824
405+
# gh-19824 / 41395
406406
assert "tex2jax_ignore" not in self.styler._repr_html_()
407407

408-
with pd.option_context("display.html.use_mathjax", False):
408+
with pd.option_context("styler.html.mathjax", False):
409409
assert "tex2jax_ignore" in self.styler._repr_html_()
410410

411411
def test_update_ctx(self):

0 commit comments

Comments
 (0)