3
$\begingroup$

I am attempting to create popup definitions for important words in my lecture notebooks. I plan to create a glossary containing a list of words and their definitions and then search through my lecture notebooks replacing each instance of those words with a button (that has no appearance) which when moused over will display the definition of the word.

I figured out the latter part. The code below creates an AttachCell[] with a definition that appears and disappears when hovering over the word "domain". You can try it out if you like.

Button[Style["domain", "Text"], 
 obj = AttachCell[EvaluationBox[], 
   Panel[
    Style[
     TextCell[
      "The domain of a function is the set of all possible inputs for \
the function."], Background -> LightGreen], Background -> LightGreen, 
    ImageSize -> {150, Automatic}], Top, 8, Bottom, 
   RemovalConditions -> "MouseExit"], AutoAction -> True, 
 Appearance -> None]

I know that I can search through a lecture notebook for the word "domain" in a text cell, so that's not the issue.

This issue I am having is that once I find an instance of the word "domain", I can't seem to figure out how to replace the word with the button above. It seems simple. I must be missing something very easy. I tried Paste[] but the button isn't active once pasted. Any ideas?

enter image description here

$\endgroup$

1 Answer 1

3
$\begingroup$

Use NotebookWrite after NotebookFind to automatically create an inline cell within a text cell:

NotebookFind[EvaluationNotebook[], "domain"];
NotebookWrite[EvaluationNotebook[], ToBoxes@mybutton]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.