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 ppurka)

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)

12178_latex_debug.patch (1.6 KB) - added by ppurka 9 years ago.
print DEBUGs
trac_12178-fix_printing_questionmark.patch (1.4 KB) - added by ppurka 9 years ago.
Added doctest under factorization

Download all attachments as: .zip

Change History (13)

comment:1 follow-up: Changed 9 years ago by jdemeyer

Be sure to check this against #12156.

comment:2 in reply to: ↑ 1 Changed 9 years ago by ppurka

Replying to jdemeyer:

Be sure to check this against #12156.

The error is still there with #12156. Attaching a potential patch. I will doctest over the next couple of hours.

comment:3 Changed 9 years ago by ppurka

  • Description modified (diff)
  • Status changed from new to needs_review

Doctested. Needs review.

comment:4 Changed 9 years ago by ppurka

  • Authors set to Punarbasu Purkayastha

comment:5 follow-up: Changed 9 years ago by novoselt

  1. Is this indeed the desired behaviour?
  2. If yes, the comment before that changed line should be expanded to reflect it.
  3. 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 ppurka

Replying to novoselt:

  1. 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.

  1. If yes, the comment before that changed line should be expanded to reflect it.

I will do that. Sorry for not noticing it.

  1. 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.

Changed 9 years ago by ppurka

print DEBUGs

comment:7 follow-up: Changed 9 years ago by novoselt

  • 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 ppurka

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: Changed 9 years ago by jdemeyer

  • Status changed from positive_review to needs_work

Could you add a doctest for the problem in the description of this ticket?

Changed 9 years ago by ppurka

Added doctest under factorization

comment:10 in reply to: ↑ 9 Changed 9 years ago by ppurka

  • 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 jdemeyer

  • 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
Note: See TracTickets for help on using tickets.