Opened 7 years ago
Last modified 4 years ago
#12908 needs_work defect
unnecessary blank in latex expression of multivariate polynomial
Reported by: | dkrenn | Owned by: | was |
---|---|---|---|
Priority: | trivial | Milestone: | sage-6.4 |
Component: | user interface | Keywords: | beginner, latex, blank, multivariate polynomial |
Cc: | Merged in: | ||
Authors: | André Apitzsch | Reviewers: | Debbie Matthews |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
In the LaTeX representation of a multivariate polynomial is an unnecessary blank when variable is concatenated with a -
, see
sage: R.<X,Y> = ZZ[] sage: latex(X-Y) X - Y sage: latex(X^2-X) X^{2} - X
It does not happen with +
sage: latex(X+Y) X + Y
or with a constant
sage: latex(X-1) X - 1
In the univarate case the problem does not appear.
Note that this "wrong" output is no problem (i.e. a correct input for LaTeX)
Attachments (2)
Change History (16)
comment:1 Changed 7 years ago by
Changed 6 years ago by
comment:2 Changed 6 years ago by
- Status changed from new to needs_review
The attached patch removes the unnecessary blank.
But now we also have
sage: latex(-X^2-X) -X^{2} - X
instead of
sage: latex(-X^2-X) - X^{2} - X
Is this reasonable or should we find a solution to keep the blank between the leading variable and its sign ("-
")?
comment:3 Changed 6 years ago by
- Status changed from needs_review to needs_work
No, it is not reasonable. As it was pointed out, the current output is correct and the only reason to "fix" is aesthetics. From this point of view, getting rid of a double space and swallowing a single one is not good - better to have more spaces then less.
comment:4 follow-up: ↓ 5 Changed 6 years ago by
Currently we have
sage: latex(-x^2-x) -x^{2} - x sage: R.<y> = ZZ[] sage: latex(-y^2-y) -y^{2} - y
Notice, there is no blank in the leading term, if it's no multivariate polynomial. So why do we need one if it's a multivariate polynomial?
IMO it should be consistent.
comment:5 in reply to: ↑ 4 Changed 6 years ago by
Replying to aapitzsch:
IMO it should be consistent.
Yes, and this means that there is always exactly one space, if it is missing, it is the same "bug" as with double spaces or even worse since it makes reading more difficult and interferes with word wrapping.
A more useful LaTeX alteration than decreasing spaces would be getting rid of {}
around singletons, i.e. instead of x_{1}^{2}
it would be better to have x_1^2
, again for reasons of readability and subsequent "manual manipulations". Macaulay2 is making such a change, as can be seen in one of the failing tests here:
http://trac.sagemath.org/sage_trac/ticket/11710#comment:23
Changed 6 years ago by
comment:6 Changed 6 years ago by
- Status changed from needs_work to needs_review
Apply only trac_12908_latex_blank.patch.
This patch doesn't fix all "space bugs" in LaTeX expressions, only those which are related to the bug mentioned at the top.
comment:7 Changed 5 years ago by
I attempted to apply trac_12908_latex_blank.patch to Sage 5.10, but it appears rotted.
~/sage/devel/sage$ hg qimport trac_12908_latex_blank.patch adding trac_12908_latex_blank.patch to series file ~/sage/devel/sage$ hg qpush applying trac_12908_latex_blank.patch patching file doc/de/tutorial/latex.rst Hunk #1 succeeded at 73 with fuzz 1 (offset -5 lines). patching file doc/en/tutorial/latex.rst Hunk #1 succeeded at 70 with fuzz 1 (offset -10 lines). patching file sage/algebras/free_algebra_quotient_element.py Hunk #1 FAILED at 136 1 out of 1 hunks FAILED -- saving rejects to file sage/algebras/free_algebra_quotient_element.py.rej patching file sage/combinat/free_module.py Hunk #1 FAILED at 1032 1 out of 1 hunks FAILED -- saving rejects to file sage/combinat/free_module.py.rej patching file sage/rings/polynomial/polynomial_quotient_ring_element.py Hunk #1 FAILED at 185 1 out of 1 hunks FAILED -- saving rejects to file sage/rings/polynomial/polynomial_quotient_ring_element.py.rej patch failed, unable to continue (try -v) patch failed, rejects left in working dir errors during apply, please fix and refresh trac_12908_latex_blank.patch
On a side note, I would like to vote that the space between the sign and leading term should not be there. I am new to sage and trac, but I prefer
-X - Y
as opposed to
- X - Y
The leading negative indicates an inverse where as the subtraction between objects is an operation (adding an inverse). That is:
-X + -Y = -X - Y
Since the original patch has the same problems applying, I will change the status to needs work.
comment:8 Changed 5 years ago by
- Reviewers set to Debbie Matthews
- Status changed from needs_review to needs_work
comment:9 Changed 5 years ago by
Are there any particular style guidelines that recommend smaller space for unitary minus? I personally prefer the same space as for binary for consistency.
comment:10 Changed 5 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:11 Changed 5 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:12 Changed 5 years ago by
FWIW, Don Knuth doesn't use spaces in his TeXbook
. A better style guide you won't get.
comment:13 Changed 5 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:14 Changed 4 years ago by
- Milestone changed from sage-6.3 to sage-6.4
Does this really need a fix? The latex output can be used in two ways:
In both the cases, the output will be fine.