diff --git a/doc/source/user_guide/options.rst b/doc/source/user_guide/options.rst index c415616affcd5..00da304ec9516 100644 --- a/doc/source/user_guide/options.rst +++ b/doc/source/user_guide/options.rst @@ -499,6 +499,9 @@ styler.format.thousands None String representation for t integers, and floating point and complex numbers. styler.format.escape None Whether to escape "html" or "latex" special characters in the display representation. +styler.html.mathjax True If set to False will render specific CSS classes to + table attributes that will prevent Mathjax from rendering + in Jupyter Notebook. ======================================= ============ ================================== diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index aef6128c63829..bb594b896d55e 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -75,7 +75,9 @@ Styler - :meth:`.Styler.to_latex` introduces keyword argument ``environment``, which also allows a specific "longtable" entry through a separate jinja2 template (:issue:`41866`). - :meth:`.Styler.to_html` introduces keyword arguments ``sparse_index`` and ``sparse_columns`` (:issue:`41946`) - 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`) - - Global options have been extended to configure default ``Styler`` properties including formatting and encoding options (:issue:`41395`) + - Global options have been extended to configure default ``Styler`` properties including formatting and encoding and mathjax options (:issue:`41395`) + +Formerly Styler relied on ``display.html.use_mathjax``, which has now been replaced by ``styler.html.mathjax``. There are also bug fixes and deprecations listed below. diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index a6aa285f538d3..cbe75e914981b 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -798,11 +798,17 @@ def register_converter_cb(key): The encoding used for output HTML and LaTeX files. """ +styler_mathjax = """ +: bool + If False will render special CSS classes to table attributes that indicate Mathjax + will not be used in Jupyter Notebook. +""" + with cf.config_prefix("styler"): - cf.register_option("sparse.index", True, styler_sparse_index_doc, validator=bool) + cf.register_option("sparse.index", True, styler_sparse_index_doc, validator=is_bool) cf.register_option( - "sparse.columns", True, styler_sparse_columns_doc, validator=bool + "sparse.columns", True, styler_sparse_columns_doc, validator=is_bool ) cf.register_option( @@ -847,3 +853,5 @@ def register_converter_cb(key): styler_formatter, validator=is_instance_factory([type(None), dict, callable, str]), ) + + cf.register_option("html.mathjax", True, styler_mathjax, validator=is_bool) diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index f51a1f5d9809d..370abe715185b 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -250,8 +250,7 @@ def _translate(self, sparse_index: bool, sparse_cols: bool, blank: str = "  d.update({k: map}) table_attr = self.table_attributes - use_mathjax = get_option("display.html.use_mathjax") - if not use_mathjax: + 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 ') diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index dc8be68532f0e..011730cca8136 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -402,10 +402,10 @@ def test_repr_html_ok(self): self.styler._repr_html_() def test_repr_html_mathjax(self): - # gh-19824 + # gh-19824 / 41395 assert "tex2jax_ignore" not in self.styler._repr_html_() - with pd.option_context("display.html.use_mathjax", False): + with pd.option_context("styler.html.mathjax", False): assert "tex2jax_ignore" in self.styler._repr_html_() def test_update_ctx(self):