First time here? Check out the FAQ!

Ask Your Question
1

paste latex code into notebook text cell

asked 9 years ago

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 "???" 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.

Preview: (hide)

Comments

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

kcrisman gravatar imagekcrisman ( 9 years ago )

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 ( 9 years ago )

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

kcrisman gravatar imagekcrisman ( 9 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 9 years ago

stan gravatar image

updated 9 years ago

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

Preview: (hide)
link

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: 9 years ago

Seen: 851 times

Last updated: Jan 28 '16