Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#13632 closed defect (fixed)

Fix latex display of arguments of symbolic functions

Reported by: gouezel Owned by: burcin
Priority: minor Milestone: sage-5.4.1
Component: symbolics Keywords:
Cc: Merged in: sage-5.4.1.rc0
Authors: Sebastien Gouezel Reviewers: Burcin Erocal
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:


In sage 5.3, if the arguments of a symbolic function have no _latex_ attribute, an exception is raised if one tries to latex it:

sage: P=function('P',x)
sage: latex(P(x=int(0)))
Traceback (click to the left of this block for traceback)
AttributeError: 'int' object has no attribute '_latex_'

This is fixed in the attached patch.

Attachments (1)

trac_13632_symbolic_function_arguments.patch (1.1 KB) - added by gouezel 8 years ago.

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by gouezel

comment:1 Changed 8 years ago by gouezel

  • Status changed from new to needs_review

comment:2 Changed 8 years ago by kcrisman

Wow, that's a pretty simple fix, but it looks right. I am a little concerned about the following:

sage: type(latex(x))
<class 'sage.misc.latex.LatexExpr'>
sage: type(x._latex_())
<type 'str'>

Will that cause any problem/slow things down, or is this actually an improvement?

sage: L = [4,x,3.4]
sage: timeit("' '.join([z._latex_() for z in L])")
625 loops, best of 3: 10.1 µs per loop
sage: timeit("' '.join([latex(z) for z in L])")
625 loops, best of 3: 17 µs per loop

Naturally fixing the bug is good, just wondering if there is any slick way to avoid turning things into LatexExpr and back to strings - or maybe a try/except thing catching the attribute error?

Otherwise this looks like a good idea and nice fix.

comment:3 Changed 8 years ago by gouezel

It is certainly possible to avoid the conversion from string to LatexExpr? and then back to string. However, simply trying x._latex_() and catching an exception will not suffice, since _latex_() is broken in some cases where it exists (see has_latex_attr in So, one would need to duplicate part of the code of latex() (more precisely, the first few lines of

Since latex output should never be speed-critical (it is supposed to be read by humans, right?), I would rather stay with the current version of the patch to avoid code duplication and keep it as simple as possible.

comment:4 Changed 8 years ago by burcin

  • Status changed from needs_review to positive_review

I agree that the overhead of typesetting an equation is not really important for the usual user. If you're doing this a lot when typesetting a book it might be an issue, but I'm willing to risk it. I'm switching to positive review.

Thanks a lot for the quick patch!

comment:5 Changed 8 years ago by jdemeyer

  • Authors set to Sebastien Gouezel
  • Reviewers set to Burcin Erocal

comment:6 Changed 8 years ago by jdemeyer

  • Merged in set to sage-5.5.beta0
  • Resolution set to fixed
  • Status changed from positive_review to closed

comment:7 Changed 8 years ago by jdemeyer

  • Merged in changed from sage-5.5.beta0 to sage-5.4.1.rc0
  • Milestone changed from sage-5.5 to sage-5.4.1
Note: See TracTickets for help on using tickets.