Opened 9 years ago
Closed 9 years ago
#12178 closed defect (fixed)
Error in typeset of polynomials
Reported by: | ppurka | Owned by: | jason |
---|---|---|---|
Priority: | major | Milestone: | sage-4.8 |
Component: | misc | Keywords: | latex typeset |
Cc: | jzhper@… | Merged in: | sage-4.8.alpha6 |
Authors: | Punarbasu Purkayastha | Reviewers: | Andrey Novoseltsev, Jeroen Demeyer |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
The following code leads to the typeset error:
Can't find closing delimiter for \verb
x = AA['x'].0 view(factor(x^4 + x^3 + 2 * x^2 + x + 2))
The latex output is (from notebook interface)
\newcommand{\Bold}[1]{\mathbf{#1}}(x^{2} + \verb-0.5524369848264019? x + \verb1.225088535662787?) \cdot (x^{2} + \verb1.552436984826402? x + \verb1.632535071367702?)
Apply trac_12178-fix_printing_questionmark.patch to devel/sage
.
Attachments (2)
Change History (13)
comment:1 follow-up: ↓ 2 Changed 9 years ago by
comment:2 in reply to: ↑ 1 Changed 9 years ago by
comment:3 Changed 9 years ago by
- Description modified (diff)
- Status changed from new to needs_review
Doctested. Needs review.
comment:4 Changed 9 years ago by
comment:5 follow-up: ↓ 6 Changed 9 years ago by
- Is this indeed the desired behaviour?
- If yes, the comment before that changed line should be expanded to reflect it.
- I still don't quite understand how the above output could appear, even if these numbers were wrapped into verb, it should have been done correctly. Is there another bug?..
comment:6 in reply to: ↑ 5 Changed 9 years ago by
Replying to novoselt:
- Is this indeed the desired behaviour?
I believe it should be the desired behavior. Numbers by themselves are not sandwiched between a \verb| |
construct. So, I don't understand why numbers ending with ? should be displayed as verbatim. With this patch, the only case where ? might be displayed non-verbatim is when one of the following occurs by themselves: ?
, -?
or +?
. All three of these are grammatically incorrect and I can't imagine a situation where they can arise by themselves.
- If yes, the comment before that changed line should be expanded to reflect it.
I will do that. Sorry for not noticing it.
- I still don't quite understand how the above output could appear, even if these numbers were wrapped into verb, it should have been done correctly. Is there another bug?..
It took a while, but I have finally tracked it down to a line in sage/rings/polynomial/polynomial_element.pyx
, inside the _latex_()
function of the class Polynomial
:
s = s.replace("|","")
I don't know why this replacement has to be performed, but this is the reason why the |
from \verb
is being stripped off. Example print statements are in the following output (I will attach the patch containing the print statements shortly, so that you can reproduce this):
sage: sage.misc.latex.EMBEDDED_MODE=True sage: x = AA['x'].0; y = factor(x^2 + x + 1); view(y) DEBUG: Factorization._latex_, after for: self.__x[i][0] = x^2 + x + 1.000000000000000? DEBUG: str_function, before return: x = \verb|1.000000000000000?| <type 'str'> DEBUG: Polynomial._latex_, before s.replace(|): s = x^{2} + x + \verb|1.000000000000000?| DEBUG: Factorization._latex_, before if not atomic: t = x^{2} + x + \verb1.000000000000000? DEBUG: Factorization._latex_, after for: self.__x[i][0] = x^2 + x + 1.000000000000000? DEBUG: str_function, before return: x = \verb|1.000000000000000?| <type 'str'> DEBUG: Polynomial._latex_, before s.replace(|): s = x^{2} + x + \verb|1.000000000000000?| DEBUG: Factorization._latex_, before if not atomic: t = x^{2} + x + \verb1.000000000000000? <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}(x^{2} + x + \verb1.000000000000000?)</span></html>
PS: There is a separate issue that can be seen in the above DEBUG output, and that is that the functions are all being called twice.
comment:7 follow-up: ↓ 8 Changed 9 years ago by
- Reviewers set to Andrey Novoseltsev
- Status changed from needs_review to positive_review
Thank you for such a thorough analysis! I wonder why vertical bars are thrown out of latex code, but I guess it should not be an issue anymore. All tests pass, positive review!
P.S. Is it intentional that commit message only has your initial for the first name?
comment:8 in reply to: ↑ 7 Changed 9 years ago by
Replying to novoselt:
P.S. Is it intentional that commit message only has your initial for the first name?
Probably not intentional. I set up my .hgrc half a year ago when I was a noob to Sage and hg (still am a noob!) by copying from someone else (probably rkirov). I think I never looked at the .hgrc again. :)
comment:9 follow-up: ↓ 10 Changed 9 years ago by
- Status changed from positive_review to needs_work
Could you add a doctest for the problem in the description of this ticket?
comment:10 in reply to: ↑ 9 Changed 9 years ago by
- Status changed from needs_work to needs_review
Replying to jdemeyer:
Could you add a doctest for the problem in the description of this ticket?
Added a doctest under _latex_
in factorization.py. I am unable to introduce a ? by itself in polynomials (Sage gives error if I end a number with a hand-typed ?). So, I can't add a doctest in polynomial_element.pyx.
comment:11 Changed 9 years ago by
- Merged in set to sage-4.8.alpha6
- Resolution set to fixed
- Reviewers changed from Andrey Novoseltsev to Andrey Novoseltsev, Jeroen Demeyer
- Status changed from needs_review to closed
Be sure to check this against #12156.