Ask Your Question
0

How to get latex expression in exponential notation?

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

stan gravatar image

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

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
latex(unit1)

returns:

 \frac{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
1

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

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

Comments

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 -0500 )edit
1

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

castor gravatar image

The following may help:

P.<J,K>=LaurentPolynomialRing(QQ,2)
u1=J/K
latex(u1)

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

edit flag offensive delete link more

Comments

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 -0500 )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

Stats

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

Seen: 164 times

Last updated: Nov 27 '16