Ask Your Question
1

Getting LaTeX code from Sage when running %display latex

asked 2020-02-28 11:40:02 -0500

thethinker gravatar image

updated 2020-02-28 12:01:12 -0500

I typically use

%display latex

at the beginning of all of my worksheets, so that the equations are rendered in LaTeX (when using .display(), for example). However, now I want to copy some of these equations into a LaTeX document, and I can't figure out how to "revert" them back to code. All my view(eq), print(eq), latex(eq.display()) all seem to spit out the rendered tex, or sometimes information about the object, like "rank 2 tensor g".

Is there a way I can do this without removing the display command at the beginning and re-running the sheet?

EDIT: Maybe more info is needed. I'm running Jupyter notebooks, Sage 8.7 on a linux machine. I'm pretty sure I used the Ubuntu binaries in this case to install.

edit retag flag offensive close merge delete

Comments

2

Right click on any equation to open the MathJax contextual menu. Choose Show Math As and then TeX Commands. This opens a small window with the LaTeX source used to render the equation. You can copy the contents of this window.

By the way, to revert the effect of %display latex, you can use %display default or %display plain. However, you then need to reevaluate the cells.

Juanjo gravatar imageJuanjo ( 2020-02-28 15:44:35 -0500 )edit

I marked below as answer, but this totally works as well.

thethinker gravatar imagethethinker ( 2020-03-02 17:08:29 -0500 )edit

2 answers

Sort by » oldest newest most voted
2

answered 2020-02-29 09:27:35 -0500

eric_g gravatar image

You should do

print(latex(eq.display()))
edit flag offensive delete link more

Comments

Checked on 9.1.beta5 (Python 3-based).

A much better (and lazier !) solution is to type your Sage code directly in your \LaTeX source and use SageTeX to weave your computation results in your text. This guarantees that the results you get in your output are the result of the execution by Sage of your exact input, with no possible transcription error.

For more on this not unimportant subject, Google reproducible research. SageTeX is but one solution to this problem. I use more and more org-mode's babel mode which nicely complements emacs's possibilities.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-02-29 13:13:11 -0500 )edit

I see the reproducibility argument, and have never seen not one single paper in my field that comes even remotely close to that. Maybe I will be the first!

thethinker gravatar imagethethinker ( 2020-03-02 17:07:24 -0500 )edit
0

answered 2020-02-29 08:19:10 -0500

Sébastien gravatar image

updated 2020-03-10 02:43:52 -0500

Did you try

sage: latex(eq)

? Because this is usually what works in the terminal.

edit flag offensive delete link more

Comments

Nope, this just spits back the exact same thing as "eq" by itself (pretty rendered latex)

thethinker gravatar imagethethinker ( 2020-03-02 17:04:40 -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

2 followers

Stats

Asked: 2020-02-28 11:40:02 -0500

Seen: 165 times

Last updated: Mar 10