Ask Your Question

How to get latex expression in exponential notation?

asked 2016-11-27 06:47:22 -0600

stan gravatar image

updated 2016-11-27 06:50:16 -0600

I need a latex representation of equations in exponential notation, e.g. units of J/K should be represented as:

J K^{-1}

Is there a way to force sage to return such a result? Here is an example:

var('J K ')
unit1 = J/K



I tried expand(), but it does not seem to expand fractions to their exponential representation.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2016-11-27 17:11:58 -0600

stan gravatar image

I found an ugly way to get the latex representation step by step:

var('J K ')
units1 = J/K
facs = units1.factor_list()
str1 = ''
for term1 in facs:
    str1 = str1 +' ' + str(term1[0])
    op1 = term1[1]
    if op1!=1:
        str1 = str1 + '^{' + str(op1) + '} '
latex_expr = '$'+str1+'$'
edit flag offensive delete link more


Notice that in the last line, you can do instead latex_expr = LatexExpr(str1). If you have %display typeset allowed in you notebook, it will display in latex; alternatively, you can use show(LatexExpr(str1)).

mforets gravatar imagemforets ( 2016-11-29 02:07:45 -0600 )edit

answered 2016-11-27 12:05:54 -0600

castor gravatar image

The following may help:


it gives what you need J K^{-1}.

edit flag offensive delete link more


Wow, thanks. Not sure what side effects converting my symbolic expressions to LaurentPolynomial would have, so I added below another solution.

stan gravatar imagestan ( 2016-11-27 17:07:04 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-11-27 06:47:22 -0600

Seen: 63 times

Last updated: Nov 27 '16