Ask Your Question
1

How to get latex expression in exponential notation?

asked 2016-11-27 13:47:22 +0100

stan gravatar image

updated 2016-11-27 13:50:16 +0100

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
2

answered 2016-11-27 19:05:54 +0100

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-28 00:07:04 +0100 )edit
2

answered 2016-11-28 00:11:58 +0100

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 09:07:45 +0100 )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 13:47:22 +0100

Seen: 1,239 times

Last updated: Nov 28 '16