I am writing an interactive document and have an idea to make in-line buttons that on demand would create and bring up separate notebooks containing some explanations or a remindings. One example of the code of such a button is as follows:
Button["Show it",
CreateDocument[
Column[{
Spacer[30],
TextCell["some explanatory text:" , "Text", FontSize -> 20],
Spacer[10],
TextCell[
Row[{Spacer[50], Style["Φ=", 24, Italic],
Style[HoldForm[(ϕ*τ^2*ν^3*ω*θ[
1 - ν*ω])/(τ^2*ν^2 +
2*δ*ν*τ + ω^2)^2], Italic, 30]}],
TextAlignment -> Center] // TraditionalForm
}, Alignment -> Left],
WindowTitle -> "An expression", WindowSize -> {400, 300}],
ImageSize -> {70, 18}, Background -> Brown,
BaseStyle -> {"GenericButton", Bold}]
Upon its evaluation a button is created. This button one can copy-pasted into a necessary part of the text, say, into an in-line cell. It works, in principle. It works irreproachably, if there is only a text or a text and any graphics inside. With the formula it is more complex. If the button contains a formula such as the one in the code above, and if I press the button for the first (second and so on ) time I get the document open with the formula that looks as follows:
If you see here no picture, try yourself, what I explained in words.
And that is what I intended to. Now comes my "however". However, if I save/close the main document (the one containing the button code and the button itself, then open it once more and press the button, I get this:
If you see here no picture, try yourself, what I explained in words.
As you see there is a lot of unwanted patantheses appeared. The question is how can I get rid of these parasitic parantheses?
Small addition: I have forgotten to write that there is an evident work around. The expression in question may be saved as an image and in that form passed into the button statement. Then the code is like this
Button["Show it",
CreateDocument[
Column[{
Spacer[30],
TextCell["some explanatory text:" , "Text", FontSize -> 20],
Spacer[10],
ExpressionCell[
Row[{Spacer[50],
Show["Paste here the image of a formula", ImageSize -> 250]}]]
}, Alignment -> Left],
WindowTitle -> "An expression", WindowSize -> {400, 300}],
ImageSize -> {70, 18}, Background -> Brown,
BaseStyle -> {"GenericButton", Bold}]
This is the way, of course, but I am not fond of it. The reason is that my document contains dozens of such buttons. If each of them will contain an image or two, the document size will rise too much.
To summarize: after the very helpful answers made by bil s and bobknight I see two ways of coping with the problem. I first outline the problem below and then discuss the solutions.
The problem consists in making a button to show a window with a formula as described. The difficulty is that the variables met in the formula may take part in calculations in the document and may have already been assigned to something. Even more, this assignment may be needed in some place of the document after the place where the button is used.
I initially tried to cope with it by applying HoldForm. This is not the right way, however, since it is the HoldForm statement that is responsible for extra parentheses that show up when one closes the document, then opens it and then presses the button. I also tried to use the scoping constructs like Module, but with no success, as I explained in discussion with bil s (see comments).
In the present form neither of the answers deal with this problem. However, on the basis of these answers I think I understand now how to deal with it. I see two ways.
First, it is possible to clear the variables met in the formula. Then one should take care that the necessary variables should be defined before each calculations, or each calculation should use a scoping construct. Like this the bil s solutions works as follows:
Button["Show it",
Clear[Φ, τ, ϕ, ν, ω, θ, \
δ];
CreateDocument[
Column[{Spacer[30],
TextCell["some explanatory text:", "Text", FontSize -> 20],
Spacer[10],
TextCell[
Row[{Spacer[50], Style["Φ=", Italic, 30],
Style[(ϕ τ^2 ν^3 ω θ (1 - ν \
ω))/(τ^2 ν^2 +
2 δ ν τ + ω^2)^2, Italic, 30]}],
TextAlignment -> Center] // TraditionalForm},
Alignment -> Left], WindowTitle -> "An expression",
WindowSize -> {400, 300}], ImageSize -> {70, 18},
Background -> Brown, BaseStyle -> {"GenericButton", Bold}]
Second, one may use the bobknight's solution, but write the formula as a string:
Button["Show it", CreateDocument[
Notebook[{
Cell["some explanatory text:", "Text", FontSize -> 20], Cell[""],
Cell[BoxData[
ToBoxes[Row[{TraditionalForm[
Style["Φ", 30, Italic]],
TraditionalForm[Style[" = ", 30, Italic]],
TraditionalForm[
Style["\!\(\*FractionBox[\(ϕ\\\ \*SuperscriptBox[\(\
τ\), \(2\)]\\\ \*SuperscriptBox[\(ν\), \(3\)]\\\ ω\\\ \
θ \((1 - ν\\\ ω)\)\), \
SuperscriptBox[\((\*SuperscriptBox[\(τ\), \(2\)]\\\ \
\*SuperscriptBox[\(ν\), \(2\)] + 2\\\ δ\\\ ν\\\ τ \
+ \*SuperscriptBox[\(ω\), \(2\)])\), \(2\)]]\)", Italic,
30]]}]]], TextAlignment -> Center,
ShowStringCharacters -> False]
},
WindowTitle -> "An expression", WindowSize -> {500, 300},
ShowCellBracket -> False
]
],
ImageSize -> Automatic, Background -> Brown,
BaseStyle -> {"GenericButton", Bold}]
I like this solution better, since it does not interact with the definitions of the parameters.