8000 ENH: Add option to disable MathJax (#19824). by davidchall · Pull Request #19856 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add option to disable MathJax (#19824). #19856

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

Merged
merged 11 commits into from
Mar 1, 2018
Prev Previous commit
Next Next commit
Inject tex2jax_ignore into table class attribute in Styler.
  • Loading branch information
David Hall committed Mar 1, 2018
commit 15961e1cd8c3431003bc1fd9b64758ab030ed02e
12 changes: 11 additions & 1 deletion pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,19 @@ def format_attr(pair):
.format(row=r, col=c)})
body.append(row_es)

table_attr = self.table_attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, I'm not sure about the option affecting Styler. Does anyone else (@jorisvandenbossche, @chris-b1) have thoughts?

Adding classes to the Styler is pretty easy, and you're always able to add them since you're generating the Styler. With DataFrame._repr_html, you don't have that option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's true this issue is solved by df.style.set_table_attributes('class="tex2jax_ignore"'). One could argue that this PR is unnecessary because the solution is already possible in pandas.

But this solution requires knowledge of how MathJax works – something that I've learnt whilst making this PR. The new option display.html.use_mathjax is there to make it easier for users to find the solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear, the changes to frames repr html are great.

I just worry about injecting “noise” into Styler’s generated HTML from a config option, when it’s relatively easy to do that yourself.

That said, an extra class isn’t the worst thing in the world, and it’s simple to toggle on and off. Your current PR is probably fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I could see the argument for not doing it in Styler but I agree the PR is fine, especially where it is off by default, and is sort of an obscure thing to look up.

use_mathjax = get_option("display.html.use_mathjax")
if not use_mathjax:
table_attr = table_attr or ''
if 'class="' in table_attr:
table_attr = table_attr.replace('class="',
'class="tex2jax_ignore ')
else:
table_attr += ' class="tex2jax_ignore"'

return dict(head=head, cellstyle=cellstyle, body=body, uuid=uuid,
precision=precision, table_styles=table_styles,
caption=caption, table_attributes=self.table_attributes)
caption=caption, table_attributes=table_attr)

def format(self, formatter, subset=None):
"""
Expand Down
0