3
$\begingroup$

I want to put together an equation graphic with a live calculation in it. If I use HoldForm, it retains the formatting I want, but I don't know how to ReleaseHold (or whatever is required) to insert a live calculation.

Here is an example:

miles = 3 Sqrt[Pi/4/.02 35 .001];
Show[Graphics[
  Text[Style[
    HoldForm[
     Subscript[G, 3 \[Sigma]] = 
      3 Sqrt[Pi/4/\[Zeta] Subscript[f, n] Subscript[A, in]] = 
       3 Sqrt[Pi/4/.02 35 .011] = 3.517 g' s], Large, 
    FormatType -> TraditionalForm]], ImageSize -> Large]]

This does exactly what I want to do except that I have to hard code the value into the final typeset whereas I would prefer to insert the value from the variable "miles."

Thanks for your help!

$\endgroup$
  • $\begingroup$ try Text[Style[ HoldForm[Subscript[G, 3 \[Sigma]] = 3 Sqrt[Pi/4/\[Zeta] Subscript[f, n] Subscript[A, in]] = 3 Sqrt[Pi/4/.02 35 .001] = # g' s] &@(3 Sqrt[ Pi/4/.02 35 .001]), Large, FormatType -> TraditionalForm]]? $\endgroup$ – kglr Oct 15 at 19:30
  • $\begingroup$ ... or Text[Style[ HoldForm[Subscript[G, 3 \[Sigma]] = 3 Sqrt[Pi/4/\[Zeta] Subscript[f, n] Subscript[A, in]] = 3 Sqrt[Pi/4/.02 35 .001] = x g' s] /. x -> miles, Large, FormatType -> TraditionalForm]]? Also Text[Style[ With[{x = miles}, HoldForm[ Subscript[G, 3 \[Sigma]] = 3 Sqrt[Pi/4/\[Zeta] Subscript[f, n] Subscript[A, in]] = 3 Sqrt[Pi/4/.02 35 .001] = x g' s]], Large, FormatType -> TraditionalForm]] $\endgroup$ – kglr Oct 15 at 19:32
  • $\begingroup$ Thanks kglr! The simple replacement rule works well for me! $\endgroup$ – mh2000 Oct 15 at 19:38
2
$\begingroup$

You can inject miles using

text = Text[Style[HoldForm[Subscript[G, 3 σ] = 3 Sqrt[Pi/4/ζ Subscript[f, n] 
    Subscript[A, in]] = 3 Sqrt[Pi/4/.02 35 .001] = x g' s] /. x -> miles, 
    Large, FormatType -> TraditionalForm]]

or

text = Text[Style[ HoldForm[Subscript[G, 3 σ] = 3 Sqrt[Pi/4/ζ 
   Subscript[f, n] Subscript[A, in]] = 3 Sqrt[Pi/4/.02 35 .001] = # g' s] & @ miles, 
   Large, FormatType -> TraditionalForm]]

or

text = Text[Style[ With[{x = miles}, HoldForm[ Subscript[G, 3 σ] = 3 Sqrt[Pi/4/ζ 
  Subscript[f, n] Subscript[A, in]] = 3 Sqrt[Pi/4/.02 35 .001] = x g' s]], 
  Large, FormatType -> TraditionalForm]]

With any of the above

Show[Graphics[text, ImageSize -> Large]]

gives

enter image description here

$\endgroup$

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.