I am using a Manipulate
control to show different calculations for the same user-specified parameters. I would like to show the results for the calculation the user selected and also provide some formatted text to describe how I arrived at the result.
So as a test I placed the formatted text in a Cell
set as Text
and assigned that cell to a variable. I then show in a Table
the results of the calculation and the text cell. What I'm finding is that the text displays the Mathematica functions which are used to format the text instead of just displaying the formatted text.
If I use CellPrint
for this text variable I can get the cell to display properly in the notebook. CellPrint
however returns Null
so I can't pass it's value to my Dynamic
or Manipulate
controls.
Let me show an example of my code:
testText1 :=
Cell[TextData[{Cell[
BoxData[FormBox[SuperscriptBox["R", "*"], TraditionalForm]],
FormatType -> "TraditionalForm"], " = Rate of star formation = 10 "}],
"Text", CellChangeTimes -> {{3.547210260347546*^9, 3.547210296541616*^9}}]
CellPrint[testText1]
Manipulate[
Switch[testStatChoice, 1,
testText1], {{testStatChoice, 1,
"Select Calculation"}, {1 -> "1: First Calculation Example"},
ControlType -> PopupMenu}]
I have hunted around for other methods or properties that will allow me to display my paragraphs of text with equations within an Manipulate
but haven't yet found a solution.
Edit: So I am now headed in the right direction. So a trimmed down version of what I have so far is the following:
[Code sample deleted. Look at final solution below.]
My issue is with the 2nd, 3rd and 4th paragraphs. The text continues onto the next line but it gets indented.
Edit2: I solved the line indenting issue with RowBoxes that continue onto another line by wrapping the RowBox with a StyleBox and setting the LineIndent property to 0.0 for that StyleBox.
You may have also noticed that I was using spaces for my indenting of my code lines. That was ugly and I replaced that with AdjustmentBoxes that have BoxMargins set so that the line was indented to my preference.
I am going to delete my large code insert above and replace it below with my fixed end result. I still have an issue with my last paragraph but I think I should be able to solve it.
stat1TestText :=
DisplayForm[
Column[{Cell[
"This statistic is calculated by adding up from the beginning \
of the Milky Way the time it took for the first Sun-like stars to \
come into existence, the time that elapsed on Earth for life to start \
on Earth once the Sun had formed and the time it takes for new life \
to come into existence based on the given set of Drake Equation \
Parameters."],
StyleBox[
RowBox[{"The last number to calculate is the amount of time (on \
average) that it would take for life to come into existence given the \
first 4 parameters of the Drake Equation", " (",
SuperscriptBox["R", "*"], " = rate of star formation, ",
SubscriptBox["f", "p"], " = fraction of stars with planets, ",
SubscriptBox["n", "e"],
" = # of planets that could support life, and ",
SubscriptBox["f", "l"],
" = fraction that develop life). So Frank Drake\
\[CloseCurlyQuote]s original values for these parameters were:"}],
LineIndent -> 0.0],
AdjustmentBox[
RowBox[{SuperscriptBox["R", "*"], "= 10 new stars per year "}],
BoxMargins -> {{4, 0}, {0, 0}}],
AdjustmentBox[
RowBox[{SubscriptBox["f", "p"],
"= 0.50 fraction of stars with planets", " = ",
RowBox[{"50", "%"}]}], BoxMargins -> {{4, 0}, {0, 0}}],
AdjustmentBox[
RowBox[{SubscriptBox["n", "e"],
"= 2 planets that could support life for each star"}],
BoxMargins -> {{4, 0}, {0, 0}}],
AdjustmentBox[
RowBox[{SubscriptBox["f", "l"],
"= 1.00 fraction of stars that develop life = ",
RowBox[{"100", "%"}]}], BoxMargins -> {{4, 0}, {0, 0}}],
Cell["Using the above parameters,every year, the number of stars \
to have the genesis of life in the Milky Way can be calculated by \
mulitplying those 4 numbers together."],
AdjustmentBox[
RowBox[{SuperscriptBox["R", "*"], "\[Times]",
SubscriptBox["f", "p"], "\[Times]", SubscriptBox["n", "e"],
"\[Times]", SubscriptBox["f", "l"], "=",
RowBox[{"10", "\[Times]", "0.50", "\[Times]", "2.0",
"\[Times]", "1.00"}],
" = 10 stars in the Milky Way have life begin on a habitable \
planet in their solar system each year."}],
BoxMargins -> {{4, 0}, {0, 0}}],
AdjustmentBox[
StyleBox[
RowBox[{"This means that every ", FractionBox[1, 10], "th",
Cell["of a year new life will show up in the galaxy. For \
Drake Equation Parameters that are not so optimistic, such as the \
numbers I label More Reserved, you can estimate life coming into \
existence in the galaxy once every 150 years up to 28000 years. \
Really this number is small enough that it doesn't play a significant \
role in our calculation of microbial life first began in the Milky \
Way but I will use it anyway."]}], LineIndent -> 0.0],
BoxMargins -> {{0, 0}, {0, 0}}],
Cell["This means that every 1/10th of a year new life will show \
up in the galaxy. For Drake Equation Parameters that are not so \
optimistic, such as the numbers I label More Reserved, you can \
estimate life coming into existence in the galaxy once every 150 \
years up to 28000 years. Really this number is small enough that it \
doesn't play a significant role in our calculation of microbial life \
first began in the Milky Way but I will use it anyway."],}, Left,
1.5]];