Feeds:
Posts

## SAGE tip: LaTeX trick in the notebook.

As I’ve mention before, actually I’m dealing with some messy supergravity calculations. 😛 Unlike most of my colleges, I don’t use Mathematica but their open source SAGE (applauses).

# Declaring (weird) Variables

Through the calculations I should care about 10 dimensions, with a 5 dimensional restriction parametrized by  five different angles, which I call $(\theta,\phi,\bar{\psi},\bar{\theta},\bar{\phi})$… thus, naturally the question of whether a variable can be declared in a way s.t., when using the function show for printing the results, the latex equivalent to my expression is shown, appears!

The answer came a few minutes ago! Thanks to Niels Bruin via sage-devel google group. 😉

sage: var("bps", latex_name=r"\hat{\psi}") bps sage: expr = sin(bps) sage: show(expr)

returns $\sin(\hat{\psi})$. 😀

Really neat!!!

# Adding equations in the text

Recently I re-discover the “office”-like functionality of sage notebook. Have you notice the thin blue line that appears when the cursor is about to reach the calculation window by above?

If you click on the blue line, an intermediate calculation line will appear. Whilst, if you click on the line while holding the Shift key, a sort of office suite environment is opened!!!

There you can write in a LibreOffice style!!!

That’s not all. Jason Grout has pointed out to me that one can insert LaTeX equations in this environment just by using the dollar-dollar ($<your code>$) for inline equations, or doubledollar-doubledollar ($$<your code>$$) for centered-nonumbered equations.

Fabulous, Isn’t it?!

That’s all for now! 😉

Enjoy.

DOX

### 4 Responses

1. […] a previous post a weird declaration of variables has been […]

2. Cool! After declaring variables, is it possible to enter a whole equation, as written in LaTeX, into sage?

3. I mean, if I declare the variables a and b, define c=a/b and write latex(c), I have the output \frac{a}{b}. I wonder if it’s possible to implement the inverse operation, i.e, enter \frac{a}{b} and have sage interpreting it as a/b so I can perform calculations.

4. Hi, nice post.
Just to correct that sage is not Wolfram opensource version of mathematica..
It’s a voluntary project initiated by William Stein.
Cheers