Thank you so much for your help. I fixed the problem of writemime calling
display and am using the latest IJulia master. I can get (some) markdown to
display correctly when the button is clicked (though line breaks don't work
as expected). However, I have two problems:
1. I can't get LaTeX to display in Markdown using writemime. The display
function works perfectly, but writemime does not. Are LaTeX equations
currently unsupported, or did I mess something up?
2. The text doesn't clear when I click the button off. I've tried
replacing output by printing and clearing output with IJulia.
clear_output(false), but no luck.
Here's what I'm doing:
import Base: writemime, show, write
function write(io::IO, x::Revealable)
write(io, x.content)
end
function writemime(io::IO, ::MIMEtext/markdown, x::Revealable)
if x.show
write(io, x)
else
#write(io,) -- I tried this too without success
IJulia.clear_output(false)
end
end
function show(io::IO, x::Revealable)
Base.print_quoted_literal(io, x.content)
end
Here's the whole thing if you want to run it:
using Reactive
using Interact
using IJulia
type Revealable
content::ASCIIString
label::ASCIIString
show::Bool
end
function revealable(x::Revealable)
@manipulate for n in togglebutton(; label=string(Show/Hide, x.label ==
? : string( , uppercase(x.label[1]),x.label[2:end])), value=x.show,
signal=Input(x.show))
x.show = n
x
end
end
import Base: writemime, show, write
function write(io::IO, x::Revealable)
write(io, x.content)
end
function writemime(io::IO, ::MIMEtext/markdown, x::Revealable)
if x.show
write(io, x)
else
#write(io,) -- I tried this too without success
IJulia.clear_output(false)
end
end
function show(io::IO, x::Revealable)
Base.print_quoted_literal(io, x.content)
end
### To run it:
r = Revealable(#This is an *awesome* equation: \$e^u \\frac{du}{dx} e^x
dx\$.,example,false)
revealable(r)
On Friday, July 17, 2015 at 7:06:37 AM UTC-7, Steven G. Johnson wrote:
function writemime(stream, ::MIMEtext/latex, x::Revealable) #was
::MIMEtext/markdown in my actual code
if x.show
display(x.content)
else
display()
end
end
This is wrong. writemime should not call display. It should just write
the LaTeX form of x to the (text) stream using print or write. (You have
it backwards: display calls writemime.)
With regards to your other equation; for mixing equations and formatted
text, the latest IJulia master [Pkg.checkout(IJulia)] can display
text/markdown directly, including equations, e.g.:
display(text/markdown, This is an *awesome* equation: \$e^u
\\frac{du}{dx} e^x dx\$.)
So, in an @manipulate loop, you just need to return an object that knows
how to display itself as text/markdown (i.e. that has a writemime method to
output text/markdown text to an I/O stream).