12
$\begingroup$

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.

$\endgroup$

3 Answers 3

12
$\begingroup$

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

$\endgroup$
10
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Congrats on 5K :P $\endgroup$
    – Rojo
    Commented Apr 23, 2012 at 20:36
  • $\begingroup$ @Rojo: 5K? Where? :) $\endgroup$ Commented Apr 23, 2012 at 22:58
  • $\begingroup$ I could have swooorn $\endgroup$
    – Rojo
    Commented Apr 23, 2012 at 23:11
4
$\begingroup$

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

$\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.