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.Thu, 28 Jan 2016 16:20:23 +0100paste latex code into notebook text cellhttps://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/ Sometimes, I'd like to paste code from a latex document into a sage worksheet to follow a set of derivations step by step. Surprisingly, pasting the following text into the rich-text cell of a worksheet actually displays one of the equations in typeset form but not the other, if re-evaluated, the other is typeset but not the first and if re-evaluated again, none of the equations are typeset:
Ohm's law is commonly stated as
\begin{equation}\label{eq_I}
I = \frac{U}{R}
\end{equation}
where $I$ is the current, $U$ is the voltage and $R$ is the resistance. The easiest way of remembering Eq. \ref{eq_I} is its multiplicative form, resulting in ``URI'':
\begin{equation}\label{eq_U}
U= R I
\end{equation}
In all cases the reference "\ref{eq_I}" gives a link to "???" in worksheet after evaluation. Is there a way to make the interpretation of code snippets more persistent and manipulate it somehow? Could such code be used for cross-referencing within the worksheet?
Putting the same code in a %latex cell does not display the cross-reference, either. Mon, 25 Jan 2016 14:34:52 +0100https://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/Comment by kcrisman for <p>Sometimes, I'd like to paste code from a latex document into a sage worksheet to follow a set of derivations step by step. Surprisingly, pasting the following text into the rich-text cell of a worksheet actually displays one of the equations in typeset form but not the other, if re-evaluated, the other is typeset but not the first and if re-evaluated again, none of the equations are typeset:</p>
<pre><code>Ohm's law is commonly stated as
\begin{equation}\label{eq_I}
I = \frac{U}{R}
\end{equation}
where $I$ is the current, $U$ is the voltage and $R$ is the resistance. The easiest way of remembering Eq. \ref{eq_I} is its multiplicative form, resulting in ``URI'':
\begin{equation}\label{eq_U}
U= R I
\end{equation}
</code></pre>
<p>In all cases the reference "\ref{eq_I}" gives a link to "???" in worksheet after evaluation. Is there a way to make the interpretation of code snippets more persistent and manipulate it somehow? Could such code be used for cross-referencing within the worksheet?</p>
<p>Putting the same code in a %latex cell does not display the cross-reference, either. </p>
https://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/?comment=32340#post-id-32340I don't think MathJax necessarily supports this kind of linking.Tue, 26 Jan 2016 18:25:49 +0100https://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/?comment=32340#post-id-32340Comment by stan for <p>Sometimes, I'd like to paste code from a latex document into a sage worksheet to follow a set of derivations step by step. Surprisingly, pasting the following text into the rich-text cell of a worksheet actually displays one of the equations in typeset form but not the other, if re-evaluated, the other is typeset but not the first and if re-evaluated again, none of the equations are typeset:</p>
<pre><code>Ohm's law is commonly stated as
\begin{equation}\label{eq_I}
I = \frac{U}{R}
\end{equation}
where $I$ is the current, $U$ is the voltage and $R$ is the resistance. The easiest way of remembering Eq. \ref{eq_I} is its multiplicative form, resulting in ``URI'':
\begin{equation}\label{eq_U}
U= R I
\end{equation}
</code></pre>
<p>In all cases the reference "\ref{eq_I}" gives a link to "???" in worksheet after evaluation. Is there a way to make the interpretation of code snippets more persistent and manipulate it somehow? Could such code be used for cross-referencing within the worksheet?</p>
<p>Putting the same code in a %latex cell does not display the cross-reference, either. </p>
https://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/?comment=32351#post-id-32351In theory, it does, but I haven't got it to work in the sage notebook:
http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-referenceThu, 28 Jan 2016 14:06:27 +0100https://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/?comment=32351#post-id-32351Comment by kcrisman for <p>Sometimes, I'd like to paste code from a latex document into a sage worksheet to follow a set of derivations step by step. Surprisingly, pasting the following text into the rich-text cell of a worksheet actually displays one of the equations in typeset form but not the other, if re-evaluated, the other is typeset but not the first and if re-evaluated again, none of the equations are typeset:</p>
<pre><code>Ohm's law is commonly stated as
\begin{equation}\label{eq_I}
I = \frac{U}{R}
\end{equation}
where $I$ is the current, $U$ is the voltage and $R$ is the resistance. The easiest way of remembering Eq. \ref{eq_I} is its multiplicative form, resulting in ``URI'':
\begin{equation}\label{eq_U}
U= R I
\end{equation}
</code></pre>
<p>In all cases the reference "\ref{eq_I}" gives a link to "???" in worksheet after evaluation. Is there a way to make the interpretation of code snippets more persistent and manipulate it somehow? Could such code be used for cross-referencing within the worksheet?</p>
<p>Putting the same code in a %latex cell does not display the cross-reference, either. </p>
https://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/?comment=32361#post-id-32361Maybe there is additional MJ stuff we need, or an updated version?Thu, 28 Jan 2016 16:20:23 +0100https://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/?comment=32361#post-id-32361Answer by stan for <p>Sometimes, I'd like to paste code from a latex document into a sage worksheet to follow a set of derivations step by step. Surprisingly, pasting the following text into the rich-text cell of a worksheet actually displays one of the equations in typeset form but not the other, if re-evaluated, the other is typeset but not the first and if re-evaluated again, none of the equations are typeset:</p>
<pre><code>Ohm's law is commonly stated as
\begin{equation}\label{eq_I}
I = \frac{U}{R}
\end{equation}
where $I$ is the current, $U$ is the voltage and $R$ is the resistance. The easiest way of remembering Eq. \ref{eq_I} is its multiplicative form, resulting in ``URI'':
\begin{equation}\label{eq_U}
U= R I
\end{equation}
</code></pre>
<p>In all cases the reference "\ref{eq_I}" gives a link to "???" in worksheet after evaluation. Is there a way to make the interpretation of code snippets more persistent and manipulate it somehow? Could such code be used for cross-referencing within the worksheet?</p>
<p>Putting the same code in a %latex cell does not display the cross-reference, either. </p>
https://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/?answer=32352#post-id-32352Here is a workaround, which allows me to paste latex commands into a computation cell, evaluate and display the results within the notebook.
First, in a separate input cell, load the latex packages that you need to deal with the latex code from the original document, e.g.:
> latex.extra_macros('')
> latex.extra_preamble('') `
>latex.add_to_preamble('\\usepackage{amsmath}')`
> latex.add_to_preamble('\\usepackage{amssymb}')`
> latex.add_to_preamble('\\usepackage[natbib=true]{biblatex}') # natbib=true, because the original document uses
\citet and \citep`
> latex.add_to_preamble('\\addbibresource{/path-to/MyLibrary.bib}')
> latex.add_to_preamble('\\usepackage{hyperref}')
> latex.add_to_preamble('\\usepackage[]{showlabels}') # To display equation labels on the side
Then, in every input cell, I first enter the following code, followed by the copied and pasted latex code:
> %hide
> %latex
> \renewcommand{\ref}[1] {\url{#1}} % to print names of referencesThu, 28 Jan 2016 14:14:45 +0100https://ask.sagemath.org/question/32332/paste-latex-code-into-notebook-text-cell/?answer=32352#post-id-32352