Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define custom _repr_*_ methods in IJulia notebook?

When using IPython notebook, I can define a custom method _repr_*_ on my object that allows it to be rendered in a different form (e.g. a png) to a user.

I'd like to do the same in Julia using IJulia notebook. Specifically, I have a type that I'd like to always be represented by a PNG when displayed in the notebook. How can I achieve this? (I tried grepping for repr in the IJulia repository, but this has not been helpful so far.)

like image 941
Jim Garrison Avatar asked Nov 24 '25 16:11

Jim Garrison


1 Answers

Define something for writemime, e.g.

type MyType
  foo
end

Base.writemime(io::IO, ::MIME"text/latex", x::MyType) = write(io, "\$\$ $(x.foo) \$\$")

For LaTeX output. The MIME type for png is "image/png". Here is, e.g. Winston.jl writing a png to io.

like image 141
IainDunning Avatar answered Nov 27 '25 21:11

IainDunning



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!