Hi all,

I'm working on a module that will use a toggle button to show and hide 
content in an IJulia notebook. Everything works as intended if the content 
is HTML, but I also need to be able to display equations. I have two 
questions:

   1. Is it possible to display equations within blocks of HTML? If so, 
   how? It would be nice to take advantage of the MathJax already running in 
   the notebooks. I'd love it if someone could point me in the right direction.
   2. How can I get Markdown to hide/show when the button is 
   clicked? Currently, clicking the button correctly changes the field that 
   determines whether to display the object, but you have to run the code cell 
   again for the display to change (see Section 2).

Below are the relevant bits of code.

I'd appreciate any pointers you can give. Thank you!

-----------------------------

*1) *This code for HTML blocks works correctly:

using Reactive
using Interact
import Base.writemime

type Revealable
    html::ASCIIString
    divclass::ASCIIString
    show::Bool
end

function revealable(x::Revealable)
    @manipulate for n in togglebutton(; label=string("Show/Hide", x.divclass 
== "" ? "" : string(" ", uppercase(x.divclass[1]),x.divclass[2:end])), value
=x.show, signal=Input(x.show))
        x.show = n
        x
    end
end

function Base.writemime(stream, ::MIME"text/html", x::Revealable)
    if x.show
        println(stream, string("""<div class='""", x.divclass, """'>""", x.
html, """</div>"""))
    else
        println(stream, """        
            """
            )
    end
end

To run it:

h = Revealable("<b>Any HTML can go here!</b>", "hint", false)
revealable(h)



*2)* This code requires the user to re-run the cell after clicking the 
button:

using Markdown
using Reactive
using Interact
import Base.writemime

type Revealable
    content::Markdown.MD
    divclass::ASCIIString
    show::Bool
end

function revealable(x::Revealable)
    @manipulate for n in togglebutton(; label=string("Show/Hide", x.divclass 
== "" ? "" : string(" ", uppercase(x.divclass[1]),x.divclass[2:end])), value
=x.show, signal=Input(x.show))
        x.show = n
        x
    end
end

function writemime(stream, ::MIME"text/latex", x::Revealable)
   if x.show
        display(x.content)
    else
        display("")
    end
end

To run it:

m = Revealable(md"""
    #Heading!

    Here is some LaTeX: ${3+a}\over{2-b^4}$
    """, "hint", false)

revealable(m)

Reply via email to