From 39f005a288db75fd9f39a5656cbfaf89a3511355 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 29 Aug 2021 09:43:05 +0200 Subject: [PATCH 1/6] whats new --- doc/source/whatsnew/v1.4.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 450ecc85c725b..d205d95eca5e1 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -75,6 +75,7 @@ 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 mathjax options (:issue:`41395`) There are also bug fixes and deprecations listed below. From 932f47e0cca1a93a9faefe9299f5ebbcb858ea82 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 29 Aug 2021 09:47:01 +0200 Subject: [PATCH 2/6] options config --- pandas/core/config_init.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 27b898782fbef..774250284774a 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -762,11 +762,17 @@ def register_converter_cb(key): trimming will occur over columns, rows or both if needed. """ +styler_mathjax = """ +: bool + If False will render special CSS classes to cells that indicate Mathjax should not + be used for those elements 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( @@ -775,3 +781,5 @@ def register_converter_cb(key): styler_max_elements, validator=is_nonnegative_int, ) + + cf.register_option("html.mathjax", True, styler_mathjax, validator=is_bool) From e3ac3e5ff4c90e2ad5d46b9de3400322249a5218 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 29 Aug 2021 09:49:38 +0200 Subject: [PATCH 3/6] options.rst --- doc/source/user_guide/options.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/source/user_guide/options.rst b/doc/source/user_guide/options.rst index 62a347acdaa34..c460e984ab243 100644 --- a/doc/source/user_guide/options.rst +++ b/doc/source/user_guide/options.rst @@ -489,6 +489,9 @@ styler.sparse.columns True "Sparsify" MultiIndex displ in Styler output. styler.render.max_elements 262144 Maximum number of datapoints that Styler will render trimming either rows, columns or both to fit. +styler.html.mathjax True If set to False will render specific CSS classes to + cells that will prevent Mathjax from rendering + in Jupyter Notebook. ======================================= ============ ================================== From ac3804d011fe7c3c948ceba8b0e39a4e1a05ed47 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 29 Aug 2021 09:54:22 +0200 Subject: [PATCH 4/6] style_render update --- doc/source/user_guide/options.rst | 2 +- pandas/core/config_init.py | 4 ++-- pandas/io/formats/style_render.py | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/doc/source/user_guide/options.rst b/doc/source/user_guide/options.rst index c460e984ab243..5cc51ba0b74fe 100644 --- a/doc/source/user_guide/options.rst +++ b/doc/source/user_guide/options.rst @@ -490,7 +490,7 @@ styler.sparse.columns True "Sparsify" MultiIndex displ styler.render.max_elements 262144 Maximum number of datapoints that Styler will render trimming either rows, columns or both to fit. styler.html.mathjax True If set to False will render specific CSS classes to - cells that will prevent Mathjax from rendering + table attributes that will prevent Mathjax from rendering in Jupyter Notebook. ======================================= ============ ================================== diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 774250284774a..58612dcf98a33 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -764,8 +764,8 @@ def register_converter_cb(key): styler_mathjax = """ : bool - If False will render special CSS classes to cells that indicate Mathjax should not - be used for those elements in Jupyter Notebook. + 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"): diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 4f1e98225aafe..405bb99b7e7d0 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -249,8 +249,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 ') From e824834bbf6e5e44e268eeae6eeed333e4254eed Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sun, 29 Aug 2021 09:55:56 +0200 Subject: [PATCH 5/6] amend tests --- pandas/tests/io/formats/style/test_style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index 5022a1eaa2c6e..651dbadde7896 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -384,10 +384,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): From 6a8bffa2c31ce7bf09d37f058a834270f5662216 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Wed, 1 Sep 2021 07:36:43 +0200 Subject: [PATCH 6/6] whats new --- doc/source/whatsnew/v1.4.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index c87fee53dea37..e46db6aa54502 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -77,6 +77,8 @@ Styler - 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 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. .. _whatsnew_140.enhancements.pyarrow_csv_engine: