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
Fix the latex representation of a 1-tuple #19348
Conversation
✅ Hi, I am the SymPy bot (v158). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.7. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
55006e3
to
75f9902
Compare
AFAIK, latex printer aims to represent the common mathematical notation, not Python's. Is it common in field of mathematics to denote monuple (1-tuple) with trailing comma? |
I have the same opinion that the original one is fine for LaTeX. However, when I see pretty printings, I see it adds comma separator even if the pretty printing doesn't need to be syntactically correct for python. |
Given sympy doesn't really know anything about tuples in the mathematical sense, doesn't it make more sense to render them in the python sense? Adding this comma makes the latex rendering consistent with the repr, str, and pretty |
I'd argue the key difference here is that for When I do So maybe I should change |
Fair point. Now it sounds reasonable for me... |
c1ceaa0
to
81574d1
Compare
def _add_parens(self, s): | ||
return r"\left({}\right)".format(s) | ||
|
||
# TODO: merge this with the above, which requires a lot of test changes | ||
def _add_parens_lspace(self, s): | ||
return r"\left( {}\right)".format(s) |
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.
This is a bit ugly, but I really don't want to sift through the 50ish occurences of \left(
in the tests for whether they go through the tuple printer, as it would add tonnes of noise to this PR.
Is the presence of this space deliberate?
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.
My understanding of LaTeX is that the space should never be needed, but I could be wrong. You might want to find a reference one way or another (perhaps ask on tex.stackexchange). If the space isn't needed there's no reason the put it there.
IMO we should aim to make the the output of latex()
both human and machine readable, but we don't really do that right now. But even then, I'm not really sure if the space here helps with that.
I like this change. To me a trailing comma is perfectly valid from a mathematical notation point of view, and it is a good idea to include it because it disambiguates it from what otherwise appears at first glance to just be redundant parentheses, especially since a Tuple might often appear nested inside of some other expression. Also, I think most places where Tuple is used and would be printed, it is more of a code like object rather than a mathematical tuple. Where are the places where Tuple is used in another expression, and the Tuple printer is used for it? The only thing I can think of is multi-dimensional sets. Apparently, |
For example: >>> print(latex(ConditionSet(x, Eq(x, (1,)))))
\left\{x \mid x = \left( 1\right) \right\} This is perhaps a bit contrived, but I think it shows that 1-tuples can appear in mathematical expressions. Seeing "x = (1)" is confusing if you don't expect a tuple, because it looks like it should just mean "x = 1", whereas "x = (1,)" is clearer. |
Without this change, a 1-item tuple looks like a set of parentheses, which is misleading. This adds the trailing comma (or as appropriate, semicolon) that is typical of 1-tuples in python.
81574d1
to
aba12c8
Compare
Travis had a network issue, that was to restart it |
It is usually better to wait for someone to restart the failing job. |
In this case it was one of the baseline jobs, so it only meant rerunning a handful of tests. |
In that case, it should be ok. |
Codecov Report
@@ Coverage Diff @@
## master #19348 +/- ##
=============================================
- Coverage 75.611% 75.593% -0.019%
=============================================
Files 651 651
Lines 169482 169515 +33
Branches 39987 39997 +10
=============================================
- Hits 128148 128142 -6
- Misses 35722 35756 +34
- Partials 5612 5617 +5 |
Without this change, a 1-item tuple looks like a set of parentheses, which is misleading.
This adds the trailing comma (or as appropriate, semicolon) that is typical of 1-tuples in python
References to other Issues or PRs
Brief description of what is fixed or changed
Other comments
Release Notes