Ask Your Question
0

paste latex code into notebook text cell

asked 2016-01-25 07:34:52 -0600

stan gravatar image

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.

edit retag flag offensive close merge delete

Comments

I don't think MathJax necessarily supports this kind of linking.

kcrisman gravatar imagekcrisman ( 2016-01-26 11:25:49 -0600 )edit

In theory, it does, but I haven't got it to work in the sage notebook: http://meta.math.stackexchange.com/qu...

stan gravatar imagestan ( 2016-01-28 07:06:27 -0600 )edit

Maybe there is additional MJ stuff we need, or an updated version?

kcrisman gravatar imagekcrisman ( 2016-01-28 09:20:23 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-01-28 07:14:45 -0600

stan gravatar image

updated 2016-01-28 07:21:37 -0600

Here 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 references

edit flag offensive delete link more

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-01-25 07:34:52 -0600

Seen: 307 times

Last updated: Jan 28 '16