12

I would like to use Mathematica as a kind of report generator.

I'm working in a Mathematica notebook and I want to handle Mathematica like this:

1) I want to define one cell as a text cell. In this cell I want to integrate an expression (maybe as an inline cell) lets say a*b (a and b have been defined in an input cell before).

2) After evaluating this cell a*b should be replaced by (assume a=10 and b=5) 50, so that the resulting cell would look like this.

some text ....... 50.. some other text......

More general: I want to have the possibility to call a function or an expression (which has been defined before) in a text cell. The displayed result of the call should be updated, whenever I change the input values.

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
john
  • 121
  • 2

3 Answers3

12

In addition to @Rojo's here's a more detailed explanation:

total = Dynamic[x + y]

Define the variable total that dynamically sums x and y

x = 10;
y = 5;

Now create a text cell by right clicking on the cell bracket at the right and choose style Text. I Type:

When I count the value x plus y I get: total

Now double click on total and right click and choose Create Inline Cell. A background color will appear on the word total. Now double click again again on the word total , right click, and choose Evaluate in Place.

The TEXT cell now changed to:

When I count the value x plus y I get: 15

Every time x or y changes your text cell adjust the correct value

Lou
  • 3,822
  • 23
  • 26
10

How about using TextCell?

computation = 1 + 2;
TextCell[StringJoin@{"And the result is ", ToString@computation, 
   " according to the computation."}, "Section"]

Mathematica graphics

Of course other styles can be also used instead of "Section". You can even make it dynamic, and then you don't have to evaluate the TextCell again:

Dynamic@TextCell[
  StringJoin@{"And the result is ", ToString@computation, 
    " according to the computation."}, "Section"]

Any subsequent calls updating computation updates the TextCell as well.

István Zachar
  • 47,032
  • 20
  • 143
  • 291
4

If I understood correctly you want to run a Dynamic[a*b] in an inline cell and evaluate it in place

Rojo
  • 42,601
  • 7
  • 96
  • 188