Message Boards Message Boards


Text output from calculations and text

Posted 9 years ago
2 Replies
0 Total Likes

Quick summary of what I am doing: I like to use Mathematica to write select homework assignments because it is easy to display calculations and text side by side. That being said, when combining code(input) and text(strings) it is sometimes nice to output a final answer combining Strings of text and a value/expression calculated in StandardForm.

The Problem: When outputting the final answer I like to add a CellFrame. This can be accomplished by having the Writing Assistant Pallette open, go to Cell Properties, and add a frame. I find this a bit of a pain when writing the text and find it easier to just type it (call me lazy). When attempting to replicate the CellFrame from Writing Assistant Pallette, Mathematica outputs my Strings with extra "\" between variables.

I have attached a Notebook with a simple function displaying the issue. I am joining the string:"The answer is: " and the output from the integration of b x^2. The output should be bx^3/3, however when using CellPrint or TextCell the output is b\x^3/3. I am curious of why this is occurring and if there is a way to fix it or maybe use a different method.

Any help or insight would be appreciated :D


function = Integrate[b x^2, x];
out = StringJoin["The answer is: ", ToString[StandardForm[function]]];
TextCell[String[out], CellFrame -> True]
CellPrint[Cell[String[out], CellFrame -> True]]
2 Replies

Thanks for the response, that did seem to fix the issue. However, the goal was to no just enter the answer, but allow mathematica to compute an expression then output it in the cell with text. Not quite sure why Row[] seems to solve the issue.

Either way thanks!

Try the following simpler code:

In[95]:= function = Integrate[b x^2, x];
out = Row[{"The answer is: ", TraditionalForm[function]}];
TextCell[out, CellFrame -> True]

Out[97]= TextCell[
Row[{"The answer is: ", 
TraditionalForm[Rational[1, 3] b x^3]}], CellFrame -> True]
POSTED BY: S M Blinder
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract