Sage: Ticket #13632: Fix latex display of arguments of symbolic functions
https://trac.sagemath.org/ticket/13632
<p>
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:
</p>
<pre class="wiki">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_'
</pre><p>
This is fixed in the attached patch.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/13632
Trac 1.2Sebastien GouezelSat, 20 Oct 2012 14:38:34 GMTattachment set
https://trac.sagemath.org/ticket/13632
https://trac.sagemath.org/ticket/13632
<ul>
<li><strong>attachment</strong>
set to <em>trac_13632_symbolic_function_arguments.patch</em>
</li>
</ul>
TicketSebastien GouezelSat, 20 Oct 2012 15:11:15 GMTstatus changed
https://trac.sagemath.org/ticket/13632#comment:1
https://trac.sagemath.org/ticket/13632#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
TicketKarl-Dieter CrismanSun, 21 Oct 2012 01:37:03 GMT
https://trac.sagemath.org/ticket/13632#comment:2
https://trac.sagemath.org/ticket/13632#comment:2
<p>
Wow, that's a pretty simple fix, but it looks right. I am a little concerned about the following:
</p>
<pre class="wiki">sage: type(latex(x))
<class 'sage.misc.latex.LatexExpr'>
sage: type(x._latex_())
<type 'str'>
</pre><p>
Will that cause any problem/slow things down, or is this actually an improvement?
</p>
<pre class="wiki">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
</pre><p>
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?
</p>
<p>
Otherwise this looks like a good idea and nice fix.
</p>
TicketSebastien GouezelSun, 21 Oct 2012 12:26:37 GMT
https://trac.sagemath.org/ticket/13632#comment:3
https://trac.sagemath.org/ticket/13632#comment:3
<p>
It is certainly possible to avoid the conversion from string to <a class="missing wiki">LatexExpr?</a> 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 latex.py). So, one would need to duplicate part of the code of latex() (more precisely, the first few lines of Latex.<span class="underline">call</span>).
</p>
<p>
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.
</p>
TicketBurcin ErocalMon, 22 Oct 2012 00:11:44 GMTstatus changed
https://trac.sagemath.org/ticket/13632#comment:4
https://trac.sagemath.org/ticket/13632#comment:4
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
<p>
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.
</p>
<p>
Thanks a lot for the quick patch!
</p>
TicketJeroen DemeyerTue, 23 Oct 2012 09:52:54 GMTreviewer, author set
https://trac.sagemath.org/ticket/13632#comment:5
https://trac.sagemath.org/ticket/13632#comment:5
<ul>
<li><strong>reviewer</strong>
set to <em>Burcin Erocal</em>
</li>
<li><strong>author</strong>
set to <em>Sebastien Gouezel</em>
</li>
</ul>
TicketJeroen DemeyerTue, 30 Oct 2012 16:16:15 GMTstatus changed; resolution, merged set
https://trac.sagemath.org/ticket/13632#comment:6
https://trac.sagemath.org/ticket/13632#comment:6
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>merged</strong>
set to <em>sage-5.5.beta0</em>
</li>
</ul>
TicketJeroen DemeyerMon, 05 Nov 2012 14:49:51 GMTmerged, milestone changed
https://trac.sagemath.org/ticket/13632#comment:7
https://trac.sagemath.org/ticket/13632#comment:7
<ul>
<li><strong>merged</strong>
changed from <em>sage-5.5.beta0</em> to <em>sage-5.4.1.rc0</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-5.5</em> to <em>sage-5.4.1</em>
</li>
</ul>
Ticket