Opened 11 years ago

Closed 11 years ago

# Error in typeset of polynomials

Reported by: Owned by: ppurka jason major sage-4.8 misc latex typeset jzhper@… sage-4.8.alpha6 Punarbasu Purkayastha Andrey Novoseltsev, Jeroen Demeyer N/A

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

### comment:1 follow-up:  2 Changed 11 years ago by jdemeyer

Be sure to check this against #12156.

### comment:2 in reply to:  1 Changed 11 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 11 years ago by ppurka

Description: modified (diff) new → needs_review

Doctested. Needs review.

### comment:4 Changed 11 years ago by ppurka

Authors: → Punarbasu Purkayastha

### comment:5 follow-up:  6 Changed 11 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 11 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 11 years ago by ppurka

Attachment: 12178_latex_debug.patch​ added

print DEBUGs

### comment:7 follow-up:  8 Changed 11 years ago by novoselt

Reviewers: → Andrey Novoseltsev needs_review → 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 11 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:  10 Changed 11 years ago by jdemeyer

Status: positive_review → needs_work

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

### Changed 11 years ago by ppurka

Attachment: trac_12178-fix_printing_questionmark.patch​ added

Added doctest under factorization

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

Status: needs_work → 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 11 years ago by jdemeyer

Merged in: → sage-4.8.alpha6 → fixed Andrey Novoseltsev → Andrey Novoseltsev, Jeroen Demeyer needs_review → closed
Note: See TracTickets for help on using tickets.