Ask Your Question

paste latex code into notebook text cell

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

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
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'':

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


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

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

In theory, it does, but I haven't got it to work in the sage notebook:

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

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

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

1 answer

Sort by ยป oldest newest most voted

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

stan gravatar image

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

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_preamble('') `



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

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


Asked: 2016-01-25 07:34:52 -0500

Seen: 247 times

Last updated: Jan 28 '16