Opened 12 years ago

Closed 12 years ago

#8707 closed defect (fixed)

view(x) calls x._latex_() 5 times!

Reported by: Nicolas M. Thiéry Owned by: Alex Ghitza
Priority: major Milestone: sage-4.4
Component: misc Keywords: latex
Cc: Sage Combinat CC user Merged in: sage-4.4.alpha1
Authors: Nicolas M. Thiéry Reviewers: Andrey Novoseltsev
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

latex(x) calls x._latex_() twice, and view(x) 5 times!!!

For small objects, that's fine, but when x is a graph, and latex'ing it requires calling graphviz, dot2tex, ... it is not reasonable!

sage: class blah():
....:     def _latex_(x):
....:         print "coucou"
....:         return "x"
....: 
sage: latex(blah())
coucou
coucou
x
sage: view(blah())
coucou
coucou
coucou
coucou
coucou

Analysis:

  • latex makes use of has_latex_expr which makes a call to _latex_ but discards the result
  • latex_file does not reuse its calls to latex(x)

Attachments (1)

trac_8707-5x_faster_latex-nt.patch (2.1 KB) - added by Nicolas M. Thiéry 12 years ago.

Download all attachments as: .zip

Change History (6)

Changed 12 years ago by Nicolas M. Thiéry

comment:1 Changed 12 years ago by Nicolas M. Thiéry

Authors: Nicolas M. Thiéry
Cc: Sage Combinat CC user added
Component: algebramisc
Status: newneeds_review

Now, e.g.

sage: g = sage.categories.category.category_graph()
sage: g.set_latex_options(format = "dot2tex")
sage: view(g, viewer="pdf", tightpage = True)

takes 6 seconds instead of .5 minutes, which makes it finally usable!

comment:2 Changed 12 years ago by Andrey Novoseltsev

Reviewers: Andrey Novoseltsev
Status: needs_reviewpositive_review

Looks good, passes all doctests!

comment:3 Changed 12 years ago by John Palmieri

Do we know for sure that types are the only sorts of objects which have this problem (that is, which seem to inherit a _latex_ method according to hasattr, but which actually don't when you try to call it)?

comment:4 Changed 12 years ago by Andrey Novoseltsev

I thought about it, but it seems to me that such objects should be "special" rather than "usual". Then it makes sense to check if x is in one of the special classes and hope that everything is good otherwise, i.e. return True. If it will turn out that there are other special cases, we can add tests for them and document them!

comment:5 Changed 12 years ago by John Palmieri

Merged in: sage-4.4.alpha1
Resolution: fixed
Status: positive_reviewclosed

Merged into 4.4.alpha1.

Note: See TracTickets for help on using tickets.