ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 03 Mar 2020 00:08:29 +0100Getting LaTeX code from Sage when running %display latexhttps://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/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.Fri, 28 Feb 2020 18:40:02 +0100https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/Comment by thethinker for <p>I typically use</p>
<pre><code>%display latex
</code></pre>
<p>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".</p>
<p>Is there a way I can do this without removing the display command at the beginning and re-running the sheet?</p>
<p>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.</p>
https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50144#post-id-50144I marked below as answer, but this totally works as well.Tue, 03 Mar 2020 00:08:29 +0100https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50144#post-id-50144Comment by Juanjo for <p>I typically use</p>
<pre><code>%display latex
</code></pre>
<p>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".</p>
<p>Is there a way I can do this without removing the display command at the beginning and re-running the sheet?</p>
<p>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.</p>
https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50109#post-id-50109Right 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.Fri, 28 Feb 2020 22:44:35 +0100https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50109#post-id-50109Answer by eric_g for <p>I typically use</p>
<pre><code>%display latex
</code></pre>
<p>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".</p>
<p>Is there a way I can do this without removing the display command at the beginning and re-running the sheet?</p>
<p>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.</p>
https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?answer=50122#post-id-50122You should do
print(latex(eq.display()))
Sat, 29 Feb 2020 16:27:35 +0100https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?answer=50122#post-id-50122Comment by Emmanuel Charpentier for <p>You should do</p>
<pre><code>print(latex(eq.display()))
</code></pre>
https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50124#post-id-50124Checked 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](http://doc.sagemath.org/html/en/tutorial/sagetex.html) 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](https://en.wikipedia.org/wiki/Reproducibility#Reproducible_research). SageTeX is but one solution to this problem. I use more and more [org-mode's babel mode](https://orgmode.org/worg/org-contrib/babel/) which nicely complements [emacs](https://www.gnu.org/software/emacs/)'s possibilities.Sat, 29 Feb 2020 20:13:11 +0100https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50124#post-id-50124Comment by thethinker for <p>You should do</p>
<pre><code>print(latex(eq.display()))
</code></pre>
https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50143#post-id-50143I 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!Tue, 03 Mar 2020 00:07:24 +0100https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50143#post-id-50143Answer by Sébastien for <p>I typically use</p>
<pre><code>%display latex
</code></pre>
<p>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".</p>
<p>Is there a way I can do this without removing the display command at the beginning and re-running the sheet?</p>
<p>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.</p>
https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?answer=50118#post-id-50118Did you try
sage: latex(eq)
? Because this is usually what works in the terminal.Sat, 29 Feb 2020 15:19:10 +0100https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?answer=50118#post-id-50118Comment by thethinker for <p>Did you try</p>
<pre><code>sage: latex(eq)
</code></pre>
<p>? Because this is usually what works in the terminal.</p>
https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50142#post-id-50142Nope, this just spits back the exact same thing as "eq" by itself (pretty rendered latex)Tue, 03 Mar 2020 00:04:40 +0100https://ask.sagemath.org/question/50107/getting-latex-code-from-sage-when-running-display-latex/?comment=50142#post-id-50142