# Bug in translation to LaTeX: double supperscript error

7 views

### ma...@mendelu.cz

Nov 6, 2009, 5:24:53 AM11/6/09
to sage-devel
Hello, this topis has been started on september on sage-support (no
answer yet). I think that sage-devel is more suitable for this
problem. I repost it here with some comments (workaround and minimal
example for the bug)

On 4 zář, 12:11, "ma...@mendelu.cz" <ma...@mendelu.cz> wrote:
> Hello, this code give "doubleexponent error".
>
> var('a x b gamma p')
> f(x)=a*x^((gamma-p))+b*x^((-p))
> (f((b*p/((gamma-p)*a))^(1/gamma))).show()
>

Since another user reported similar behavior to me, I am sending more

workaround is to simplify like this

minimal example for the problem is
sage: latex((x^pi)^e)
{(x)}^{\pi}^{e} --- this is not valid TeX expression and jsmath
does not render it.

I tried to fix it ad it seems that this has to be fixed in
/libs/ginac/decl.pxi
somewhere close to
object GEx_to_str_latex "_to_PyString_latex<ex>"(GEx *s) except +
but i do not uderstand the format and the purpouse of this file.

Perhaps somebody else has better idea and more experiences with this.

Robert

- Hide quoted text -

> Is it error in sage to TeX converter?
> Tested today on sagenb.org
>
> Thanks
> Robert Marik

### Burcin Erocal

Nov 6, 2009, 5:56:03 AM11/6/09
Hi Robert,

On Fri, 6 Nov 2009 02:24:53 -0800 (PST)
"ma...@mendelu.cz" <ma...@mendelu.cz> wrote:

>
> Hello, this topis has been started on september on sage-support (no
> answer yet). I think that sage-devel is more suitable for this
> problem. I repost it here with some comments (workaround and minimal
> example for the bug)
>
> On 4 zář, 12:11, "ma...@mendelu.cz" <ma...@mendelu.cz> wrote:
> > Hello, this code give "doubleexponent error".
> >
> > var('a x b gamma p')
> > f(x)=a*x^((gamma-p))+b*x^((-p))
> > (f((b*p/((gamma-p)*a))^(1/gamma))).show()
> >
>
> Since another user reported similar behavior to me, I am sending more
>
> workaround is to simplify like this
>
> minimal example for the problem is
> sage: latex((x^pi)^e)
> {(x)}^{\pi}^{e} --- this is not valid TeX expression and jsmath
> does not render it.
>
>
> I tried to fix it ad it seems that this has to be fixed in
> /libs/ginac/decl.pxi
> somewhere close to
> object GEx_to_str_latex "_to_PyString_latex<ex>"(GEx *s) except +
> but i do not uderstand the format and the purpouse of this file.
>
> Perhaps somebody else has better idea and more experiences with this.

Thanks for taking the time to isolate the issue. The code for printing
symbolic expressions is in pynac (C++). The fix can be as simple as
printing an extra set of braces around power objects.

If anybody wants to try fixing this, the relevant function is
power::do_print_latex() in power.cpp. To get to the file (using the
instructions I wrote in another message just now), go to your SAGE_ROOT
and do:

./sage -f -s spkg/standard/pynac-0.1.9.p0.spkg

cd spkg/build/pynac-0.1.9/src/ginac

Edit power.cpp. To compile and make your changes effective, go to your
SAGE_ROOT again, and do

./sage -sh
cd spkg/build/pynac-0.1.9/src
make install

Of course, another option is to open a ticket for this if there isn't
one already and I'll take a look at it when I find some time.

Thanks.

Burcin

### ma...@mendelu.cz

Nov 6, 2009, 7:00:45 AM11/6/09
to sage-devel
Hello Burcin, thanks for detailed explanation where to fix this issue.

> "ma...@mendelu.cz" <ma...@mendelu.cz> wrote:
>
> Thanks for taking the time to isolate the issue. The code for printing
> symbolic expressions is in pynac (C++). The fix can be as simple as
> printing an extra set of braces around power objects.
>

I think that this is not sifficient: we have to clearly distinguish
between (a^b)^c and a^(b^c). Hence we need not only braces, but also
parentheses in some cases. Compare the following three LaTeX strings

${a^b}^c$

$a^{b^c}$

$\left({a^b}\right)^c$

You can use either http://www.tlhiv.org/ltxpreview/ to see that there
is only minor difference btween the first and the second output.

I guess that we need to fix also power::print_power but do not have
experisnces in C.

I will at leas check if there exists a trac abvout this and if not, I
open this issue on trac server.

Many thanks
Robert

### ma...@mendelu.cz

Nov 6, 2009, 3:40:35 PM11/6/09
to sage-devel
Do no know how to test if the base of power is another power and if it
is sufficient to ad braces, or if also parentheses should be added.
Hence I only opened the ticket at http://trac.sagemath.org/sage_trac/ticket/7406

Thank you for the hints.

Robert

On 6 lis, 13:00, "ma...@mendelu.cz" <ma...@mendelu.cz> wrote:
> I think that this is not sufficient: we have to clearly distinguish