It is easy to type text into a cell and define the cell as a Title, Chapter, Sub-chapter, etc.

But I would like to make the text of the Title, Chapter, etc dynamic; the text in the Title, Chapter, etc is defined by the output of another cell.

Example: x = 234;

Title = "My Favorite Number Is 234"

This seems like it would be easy, but I have not found a solution. Anyone care to nudge me in the right direction?

  • $\begingroup$ You can always generate the dynamic content outside of the "Title" cell and copy it in. Or you can edit the cell at the box-language (RawData) level. $\endgroup$ – b3m2a1 Dec 4 '17 at 0:47
  • $\begingroup$ By copy it in, do you mean manually? I need to generate the text of the Title, Chapter, etc dynamically. Example: a SQL query result would be used to populate the text. $\endgroup$ – cjpembo Dec 4 '17 at 5:18
  • 1
    $\begingroup$ I think I am a little unclear on what you want. If you want to programatically generate this, then you can do so using Cell constructs and NotebookWrite/CellPrint. In that case you can do very sophisticated things. If you want to manually create a notebook with Dynamic content, then yes, copy by hand. $\endgroup$ – b3m2a1 Dec 4 '17 at 5:20
  • $\begingroup$ What do you mean by dynamically? You want Dynamic content or did you mean programmatically? p.s. something like: NotebookWrite[EvaluationNotebook[], Cell[StringTemplate["My favorite number is ``"]@123, "Section"]]? $\endgroup$ – Kuba Dec 4 '17 at 6:47

Just type your text into the cell, and then where you want your content to depend on another cell, type Dynamic[x] in an inline cell, i.e., a cell you create by using Ctrl + 9. Then, select Dynamic[x] and use the menu item: Evaluation | Evaluate In Place (or use the corresponding shortcut, which on a mac is Cmd + Return).

Perhaps an animation would help:

enter image description here

  • $\begingroup$ That is what I was looking for. Thanks $\endgroup$ – cjpembo Dec 4 '17 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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