MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Making parts of formulae blinking

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91201] Re: Making parts of formulae blinking
  • From: "David Park" <djmpark at comcast.net>
  • Date: Sat, 9 Aug 2008 07:45:58 -0400 (EDT)
  • References: <g7h9r7$bca$1@smc.vnet.net>

Alexei,

This is a very interesting question because in the larger sense it relates 
to how one manipulates expressions and presents concepts, in a clear and 
elegant manner, to a reader of a notebook. I think this is somewhat an open 
question and we have to learn how to do it. So my answer is not going to be 
totally responsive and I think that your first approach is not the best 
because it draws you off into computer science and away from the math and 
physics. Also, a blinking graphical display may serve a tutorial purpose but 
it is a dead-end expression that can't be further used. (Also I don't know 
right off how to get some blinking in, but I'm certain some member of 
MathGroup will do it.)

So instead of going to graphics, which in general might be quite complicated 
to get all the formatting correct, let's try to stay with regular 
expressions that can be accentuated with EventHandlers and then returned 
again to regular expressions. Here are two routines to help do that:

Accentuate[expr_] :=
 Module[{col = Black, size = Medium},
  EventHandler[
   Style[expr, FontColor -> Dynamic[col],
    FontSize ->
     Dynamic[size]], {"MouseClicked" :> (col =
       col /. {Black -> Red, Red -> Black};
      size = size /. {Large -> Medium, Medium -> Large})}]]

ClearAccentuate[expr_] :=
 expr /. HoldPattern[EventHandler[Style[subexpr_, __], __]] -> subexpr

Now we can use these on your example and then return to a normal expression. 
Or we could have just saved the initial expression. In any case, we don't 
have to go to graphics.

A B + x y
Accentuate /@ %
% // ClearAccentuate // InputForm

Another possibility is to put labeled Tooltips on subexpressions. One can 
then use the mouse to identify the subexpressions. This has an additional 
advantage that a Tooltip behaves somewhat like a HoldForm in that it holds a 
subexpression together when using general Mathematica commands such as 
Simplify. In the Presentations package I have provided routines 
CreateSubexpression and ReleaseSubexpressions. This allows individual labels 
for various subexpressions and we can individually release them (or leave 
them if we want to keep them as subexpressions.) Then your expression might 
take the following form. The second argument specifies whether to put 
parentheses around the subexpression. The first output can be copied into a 
notebook to see how the Tooltips work for this example.

Needs["Presentations`Master`"]

test = CreateSubexpression[A B, False, "part 1"] +
  CreateSubexpression[x y, False, "part 2"]
% // ReleaseSubexpressions[All]

\!\(\*
TagBox[
TooltipBox[
RowBox[{"A", " ", "B"}],
"\"part 1\"",
LabelStyle->"TextStyling"],
Annotation[#, "part 1", "Tooltip"]& ]\) + \!\(\*
TagBox[
TooltipBox[
RowBox[{"x", " ", "y"}],
"\"part 2\"",
LabelStyle->"TextStyling"],
Annotation[#, "part 2", "Tooltip"]& ]\)

A B + x y

I would think that in many cases the tooltips would be sufficient. But if 
you want both the tooltips and the ability to accentuate by mouse clicking 
you could use the following. The expression has to be copied to a notebook, 
and for some reason the copies don't get the Red color correct but you can 
see that it has both the tooltips and the ability to accentuate the 
subexpressions.


test /. t : Tooltip[expr_, label_] :> Accentuate[t]

\!\(\*
TagBox[
StyleBox[
TagBox[
TooltipBox[
RowBox[{"A", " ", "B"}],
"\"part 1\"",
LabelStyle->"TextStyling"],
Annotation[#, "part 1", "Tooltip"]& ],
StripOnInput->False,
FontSize->Dynamic[$CellContext`size$805],
FontColor->Dynamic[$CellContext`col$805]],
EventHandlerTag[{
     "MouseClicked" :> ($CellContext`col$805 = ReplaceAll[$\
CellContext`col$805, {
          Black -> Red,
           Red -> Black}]; $CellContext`size$805 = ReplaceAll[$\
CellContext`size$805, {Large -> Medium, Medium -> Large}]),
      PassEventsDown -> Automatic, PassEventsUp -> True}]]\) + \!\(\*
TagBox[
StyleBox[
TagBox[
TooltipBox[
RowBox[{"x", " ", "y"}],
"\"part 2\"",
LabelStyle->"TextStyling"],
Annotation[#, "part 2", "Tooltip"]& ],
StripOnInput->False,
FontSize->Dynamic[$CellContext`size$806],
FontColor->Dynamic[$CellContext`col$806]],
EventHandlerTag[{
     "MouseClicked" :> ($CellContext`col$806 = ReplaceAll[$\
CellContext`col$806, {

          Black -> Red,
           Red -> Black}]; $CellContext`size$806 = ReplaceAll[$\
CellContext`size$806, {Large -> Medium, Medium -> Large}]),
      PassEventsDown -> Automatic, PassEventsUp -> True}]]\)

The following is a case of keeping a subexpression together while 
manipulating an expression. FactorOut is another Presentations routine.

c1 = CreateSubexpression[1/(4 \[Pi] \[Epsilon]), False, "constant"];
c1 (a + b)/(a b);
% // Expand // FactorOut[c1]

(1/a + 1/b) \!\(\*
TagBox[
TooltipBox[
FractionBox["1",
RowBox[{"4", " ", "\[Pi]", " ", "\[Epsilon]"}]],
"\"constant\"",
LabelStyle->"TextStyling"],
Annotation[#, "constant", "Tooltip"]& ]\)

Again, if you paste the expression into a notebook you will see that the 
subexpression is kept together and has a tooltip. We could also have 
accentuated it.


-- 
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/


"Alexei Boulbitch" <Alexei.Boulbitch at iee.lu> wrote in message 
news:g7h9r7$bca$1 at smc.vnet.net...
> Dear MathGroup members,
>
> making presentations on Mathematics or Physics, sometimes I need to
> discuss independently of one another certain parts of mathematical
> expressions belonging to the same formula. This requires to separate
> them out or somehow to highlight them. Such an aim may be achieved in
> several ways. Say, below  a simple mathematical formula is defined. It
> consists of two parts. By a mouse click one of the parts is blended
> while the other changes its color to a more striking:
>
> part1 = Graphics[
>   Text[Style["AB+", "Times New Roman", Italic, 22,
>     FontColor -> Dynamic[col1]]], ImageSize -> {80, 70}];
> part2 = Graphics[
>   Text[Style["xy", "Times New Roman", Italic, 22,
>     FontColor -> Dynamic[col2]]], ImageSize -> {80, 70}];
> collst1 = {Black, Black};
> collst2 = {Blue, Gray};
> collst3 = {Gray, Blue};
> DynamicModule[{col1 = Black, col2 = Black},
>  EventHandler[
>   GraphicsRow[{part1, part2},
>    Spacings -> -35], {"MouseClicked" :> ({col1,
>        col2} = {col1, col2} /.{collst3 -> collst1,
>         collst1 -> collst2, collst2 -> collst3})}]]
>
>
> Now comes my question:
>
> It would still better catch the eye, if (before the part in question
> will definitely change its color to Blue) it blinks few times. Say, it
> may change few times its color between blue and gray, or it may
> increase and decrease its size few times or so.
>
> Have you an idea of how to reach such a result?
>
> My system is Windows XP/Mathematica 6.0.1
>
> Thank you,
> Alexei
>
> -- 
> Alexei Boulbitch, Dr., Habil.
> Senior Scientist
>
> IEE S.A.
> ZAE Weiergewan
> 11, rue Edmond Reuter
> L-5326 Contern
> Luxembourg
>
> Phone: +352 2454 2566
> Fax:   +352 2454 3566
>
> Website: www.iee.lu
>
> This e-mail may contain trade secrets or privileged, undisclosed or 
> otherwise confidential information. If you are not the intended recipient 
> and have received this e-mail in error, you are hereby notified that any 
> review, copying or distribution of it is strictly prohibited. Please 
> inform us immediately and destroy the original transmittal from your 
> system. Thank you for your co-operation.
>
>
> 



  • Prev by Date: Re: More Inquiries
  • Next by Date: Re: Making parts of formulae blinking
  • Previous by thread: Re: Making parts of formulae blinking
  • Next by thread: Re: Making parts of formulae blinking