4

Consider the following:

FirstOutput=Style["Test", FontSize -> 20]

SetOptions[Style, FontSize -> 20];
SecondOutput=Style["Test"]

I would like the string "Test" to appear in SecondOutput as in FirstOutput. Why does SetOptions[Style, FontSize -> 20] not apply to SecondOutput?

Does anyone have an idea?

John
  • 4,361
  • 1
  • 26
  • 41

2 Answers2

4

There are some functions that don't work with SetOptions. This Q&A provides a WRI tech support solution to finding functions that don't work with SetOptions but it appears that that method doesn't pick up Style (or StyleBox).

Mike Honeychurch
  • 37,541
  • 3
  • 85
  • 158
2

I think Mike Honeychurch has the gist of it. I don't know why Style doesn't use it's option values, but if you test it out, get display problems if you call

Style["test", Sequence @@ Options[Style]]

send the message:

The specified setting for the option OpenerBoxOptions, BaselinePosition cannot be used.

If you want something similar I suggest you simply define your own style call, which for the most case also nicely documents that you don't just want to call an empty Style[] on a piece of text, but want it to follow some personally defined styling.

Options[myStyle]={FontSize->20};
myStyle[a__,OptionsPattern[]]:=Style[a,Sequence@@Options[myStyle]]

I would personally expect Style["text"] to be the default style, which means that the call is redundant, since "text" in and of itself would have the default style.

jVincent
  • 14,766
  • 1
  • 42
  • 74