Opened 13 years ago

Closed 13 years ago

#7406 closed defect (fixed)

bug in conversion powers in to LaTeX

Reported by: robert.marik Owned by: burcin
Priority: major Milestone: sage-4.3
Component: symbolics Keywords: latex, power, jsmath, pynac
Cc: Merged in: sage-4.3.rc0
Authors: Burcin Erocal Reviewers: Karl-Dieter Crisman
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by robert.marik)

The LaTeX representation of (xpi)e is not valid TeX string and is not rendered by jsmath

sage: latex((x^pi)^e)

Burcin suggested how to fix this and get output like

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 

However a better fix would be to get


if the base is an atom (or not power) and


if the base is a power. This allows to distinguish easily between




A workaround is to remove powers of powers by simplification. For example radcan function from Maxima perfoms such simplifications

sage: latex(maxima((x^pi)^e).radcan().sage())
x^{\pi e}

Attachments (1)

trac_7406-power_latex.patch (3.7 KB) - added by burcin 13 years ago.
add doctests

Download all attachments as: .zip

Change History (7)

comment:1 Changed 13 years ago by robert.marik

  • Description modified (diff)

comment:2 Changed 13 years ago by robert.marik

  • Keywords pynac added

comment:3 Changed 13 years ago by robert.marik

Perhaps close problem is

sage: latex(x*(1/(x^2)+sqrt(x^7)))
{(\sqrt{x^{7}} + \frac{1}{x^{2}})} x

Note missing \left and \right at outside parentheses which makes the rendering of the expression far from perfect. Should look like

sage: latex(x*(1/(x^2)+sqrt(x^7)))
{\left(\sqrt{x^{7}} + \frac{1}{x^{2}}\right)} x

Changed 13 years ago by burcin

add doctests

comment:4 Changed 13 years ago by burcin

  • Authors set to Burcin Erocal
  • Report Upstream set to N/A
  • Status changed from new to needs_review

The new pynac package here

contains fixes for both the problem in the description and the one in comment:3.

attachment:trac_7406-power_latex.patch contains doctests for the fix.

Note that the new pynac version also contains fixes for #7508 and #7264. Tests should be run with the patches from those tickets also applied in this order:

This ticket now depends on #7490, #7508 and #7264.

comment:5 Changed 13 years ago by kcrisman

  • Status changed from needs_review to positive_review

Positive review - they look great in show()! Obviously pending #7264 or a rebase.

comment:6 Changed 13 years ago by mhansen

  • Merged in set to sage-4.3.rc0
  • Resolution set to fixed
  • Reviewers set to Karl-Dieter Crisman
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.