I would like to obtain something similar to this: What I want

A user, has to answer the question selecting an answer from a popupmenu and he can check it.

I wrote that:

         {"",Sequence @@ RandomSample[{"Sin(60)","Cos(60)"}]}]};
         Row[Flatten[{{Text[Subscript["V","x"]],Text["=v*"], listarisposte,Text["40*1/2=20"]}, 
         Button["Controlla", r2 = (r1 == "Cos(60)")],
         Graphics[{Dynamic[If[r2, Green, Red, Gray]], Rectangle[{0, 0}]},ImageSize -> {20, 20}],
         Dynamic[If[r2, "Giusto!", "Sbagliato, riprova!", ""]]}]]];

The output is Output

but it isn't very well styled. How can I write 1/2 in the fraction form?

How can I resize the text? I tried with Style but it doesn't work.

  • 1
    $\begingroup$ See 69655 and ref/FontSize $\endgroup$
    – Kuba
    May 30, 2017 at 16:36
  • $\begingroup$ @Kuba FontSize works well, but HoldForm not. I modified the previous lines as {Text[Style[Subscript["V","x"],FontSize->30]],Text[Style["=V* ",FontSize->30]], listarisposte, Text[Style[" 40*"<>ToString[HoldForm[1/2]]<>"=20 ",FontSize->30]]} But the result is this i66.tinypic.com/15zmazo.png $\endgroup$
    – Ale1794
    May 30, 2017 at 19:46
  • $\begingroup$ You can use ToString[1/2, TraditionalForm] or use HoldForm with Row etc, they don't convert it to strings in the linked question. $\endgroup$
    – Kuba
    May 30, 2017 at 19:52
  • $\begingroup$ Perfect, thank you $\endgroup$
    – Ale1794
    May 30, 2017 at 19:56

1 Answer 1


I've modified your code a bit for readability. The stylish functions st and st2 define the fonts. The value i is identifier of the right answer.


DynamicModule[{r1 = "", r2, i = RandomInteger[{1, 2}]},
 listarisposte = 
   Sort@{If[i == 1, 2, 1] -> st@"Sin(60)", i -> st@"Cos(60)"}];
   st@"\!\(\*SubscriptBox[\(V\), \(x\)]\)=v*", listarisposte, 
   st@"40*\!\(\*FractionBox[\(1\), \(2\)]\)=20", Spacer[20],
   Button[st@"Controlla", r2 = (r1 == i)], Spacer[20], 
   Graphics[{Dynamic[If[r2, Green, Red, Gray]], Rectangle[{0, 0}]}, 
    ImageSize -> {20, 20}], Spacer[20],
   Dynamic[If[r2, st2@"Giusto!", st2@"Sbagliato, riprova!", ""]]}]

enter image description here

These complicated constructions with a lot of slashes appear when you need to write formatted text as plain one. In MMA it looks nice.

Actually, the formatting of the fractions and subscripts\superscripts in traditional form can be done in MMA easy just using ctrl+/ instead of / or ctrl+_ (ctrl+^) switch the next symbol to subscript or superscript.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.