# 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
$$\label{eq_I} I = \frac{U}{R}$$
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'':

$$\label{eq_U} U= R I$$


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 close merge delete

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

( 2016-01-26 18:25:49 +0100 )edit

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

( 2016-01-28 14:06:27 +0100 )edit

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

( 2016-01-28 16:20:23 +0100 )edit

Sort by » oldest newest most voted

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{amssymb}')

latex.add_to_preamble('\usepackage[natbib=true]{biblatex}') # natbib=true, because the original document uses \citet and \citep

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

more

## Stats

Seen: 646 times

Last updated: Jan 28 '16