-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mathjax display of symbolic output from SymPy not rendering in @manipulate #275
Comments
Please add backticks next to Mhm, I think it's because we specifically disable MathJax inside widgets as it messes things up a bit (and we needed a different method anyway for it to work also in Blink or Juno), but we support LaTeX via KaTeX any way (but not automatically). Is SymPy returning a LaTeXString? If that's the case I could probably just add a method to render LaTeXString. |
MVE for Jupyter: using Interact, SymPy
x = Sym("x")
@manipulate for n=1:3
x^n
end |
maybe you know a fix for this @stevengj ? Could The problem: |
No, this has to be fixed in Interact. What happens is that the new Interact framework is designed to work not only in Jupyter but also in Blink, Juno plotpane and the browser. Normally Jupyter runs MathJax by default on things that you display but we had to disable it inside Interact widgets as they would for some reason recompile indefinitely. I can test if that's still necessary though. We have support for LaTeX using KaTeX but don't yet have a method to render |
I guess this is a question for using SymPy, Interact
x = Sym("x")
n=3
SymPy.diff(sin(x^2),x,n) can you get the MIME types by running this and interrogating the output? (way above my pay grade, sorry) |
Hi @piever, any chance for a cure here? I am not quite sure how to get this:
from the SymPy output |
It can't be fixed from here without type piracy. What happens is that julia> x = symbols("x");
julia> WebIO.render(x)
(div { setInnerHtml="<pre>\\begin{equation*}x\\end{equation*}</pre>" }) The correct method would be: using WebIO, Interact, SymPy
function WebIO.render(x::SymPy.SymbolicObject)
str = stringmime(MIME"text/latex"(), x)
lt = match(r"^\\begin{equation\*}(.*)\\end{equation\*}$", str)[1]
WebIO.render(latex(lt))
end There are two ways forward:
I can ask over at WebIO whether there option 3 is available (it is somewhat complicated by the fact that different packages use different delimiters, i.e. |
Ok, hacky is fine for now. I tried this, and got this: using WebIO, Interact, SymPy
function WebIO.render(x::SymPy.SymbolicObject)
str = stringmime(MIME"text/latex"(), x)
lt = match(r"^\\begin{equation\*}(.*)\\end{equation\*}$", str)[1]
WebIO.render(latex(lt))
end
@syms x
@manipulate for n = 1:100
x^n
end Widget{:manipulate,Any}(OrderedDict{Symbol,Any}(:n=>Widget{:slider,Int64}(OrderedDict{Symbol,Any}(:changes=>Observable{Int64} with 1 listeners. Value: |
My bad, using WebIO, Interact, SymPy, Base64
function WebIO.render(x::SymPy.SymbolicObject)
str = stringmime(MIME"text/latex"(), x)
lt = match(r"^\\begin{equation\*}(.*)\\end{equation\*}$", str)[1]
WebIO.render(latex(lt))
end |
No need for |
to summarise, this using WebIO, Interact, SymPy
function WebIO.render(x::SymPy.SymbolicObject)
str = repr(MIME"text/latex"(), x)
lt = match(r"^\\begin{equation\*}(.*)\\end{equation\*}$", str)[1]
WebIO.render(latex(lt))
end gets @syms x
@manipulate for n = 1:100
x^n
end will give a slider that renders output. It's not quite as it was, because now it only renders when you stop dragging the slider, whereas previously it updated in real time. Full disclosure: tested on |
Previously I could view a range of Hermite polynomials inside @manipulate.
Screenshot probably says it all here:
any way to get it to render?
The text was updated successfully, but these errors were encountered: