-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: add LaTeX math mode with parentheses #51903
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
ENH: add LaTeX math mode with parentheses #51903
Conversation
@attack68, could you please take a look at this pr? |
pandas/io/formats/style_render.py
Outdated
The substrings in LaTeX math mode, which either are surrounded | ||
by two characters ``$`` or start with the character ``\(`` and end with ``\)``, | ||
are preserved without escaping. Otherwise regular LaTeX escaping applies. | ||
See ``_escape_latex()``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_escape_latex is an internal function so shouldn't be publically stated or pointed to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
completely agree, I'll remove _escape_latex() from docs
ALso may or may not need a whatsnew release note dependin which release this gets into |
I think it would be 2.1 at this point |
50e51c7
to
2e283a7
Compare
Hi @attack68, could you please take a look at my last changes? |
Hi @attack68. I added an example to latex-math mode and a line to Could you please take a look at my last changes? |
pandas/io/formats/style_render.py
Outdated
pattern_d = re.compile(r"\$.*?\$") | ||
pattern_p = re.compile(r"\(.*?\)") | ||
pos_d = 0 | ||
pos_p = 0 | ||
ps_d = pattern_d.search(s, pos_d) | ||
ps_p = pattern_p.search(s, pos_p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pattern_d = re.compile(r"\$.*?\$") | |
pattern_p = re.compile(r"\(.*?\)") | |
pos_d = 0 | |
pos_p = 0 | |
ps_d = pattern_d.search(s, pos_d) | |
ps_p = pattern_p.search(s, pos_p) | |
ps_d = re.compile(r"\$.*?\$").search(s, 0) | |
ps_p = re.compile(r"\(.*?\)").search(s, pos_p) |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I completely agree. I applied this change in the next commit.
I did it locally and pushed the commit.
str : | ||
Escaped string | ||
""" | ||
s = s.replace(r"\$", r"rt8§=§7wz") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this code.
You are replacing the string \$
with a uuid string, first.
Then, you are searching for a pattern (r"\$.*?\$"
) that cannot exist, since it was replaced.
Then in line 2490 you are replacing the same string s
again with the same uuid, but this is unnecessary since it has already done this in line 2481.
I think your tests pass and this does the correct thing but I think some of these lines are redundant and do nothing for the overall effect??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the comment.
It’s right, the replacement in line 2490 has a mistake. The right one would be the reverse replacement: s.replace(r"rt8§=§7wz", r"\$")
I can explain what I am trying to do. When I checked the function _escape_latex_math
I noticed that for a string like r"$&%#^$" which contains only one sign "$" and only one combination "\$" I got a wrong result, because the function processed this string in math mode. By doing the replacement in line 2481 I exclude from the consideration the string “\$” to avoid confusing it with “$”. Then I get the correct result and do the reverse replacement. If we don’t have a combination of one sign "$" and one sign "\$" we don’t need to do this check, but I prefer to leave it.
I corrected my mistake a made a new commit. I also added an example for this case in the test.
Hi @attack68, could you please take a look at my last changes? |
not sure why this is failing some checks, but otherwise LGTM. |
Thank you @attack68, I updated my branch. Now, all checks pass without failures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Thanks @natmokval |
* ENH: add math mode with parentheses * ENH: add math mode with parentheses II * ENH: add math mode with parentheses III * ENH: add an example to latex-math mode and a line to whatsnew * ENH: update docs for Styler: add description latex-math mode to escape * improve code style * add an example to test and correct _escape_latex_math
This pr is related to pr #50398
A new way to enter latex-math mode was added. Now we can apply math mode by starting substrings with the character
\(
and ending with the character\)
.