Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Can you extract the Style attributes from a variable. For example:

var = Style["aString", Bold, 24]

You can get back "aString" by using ToString[var] but I am not able to get the attributes {Bold, 24}.


1 Answer 1

up vote 3 down vote accepted

Examine its FullForm:

var = Style["aString", Bold, 24];
var // InputForm

(* Out: Style["aString", Bold, 24] *)

Exactly as you typed in. You can manipulate it just as you would any Mathematica expression. For example:

List @@ Rest[var]

(* Out: {Bold, 24} *)
Did not think of replacing the Head on var. Perfect, thank you so much. Peter –  pjc42 Dec 27 '13 at 1:10
There ought to be a way to compare Style["aString", Bold, 24] and Style["aString", FontWeight -> Bold, FontSize -> 24]... –  rm -rf Dec 27 '13 at 1:25
@rm-rf Isn't there? var2 = Style["aString", Bold, 24]; var1 = Style["aString", FontWeight -> Bold, FontSize -> 24]; OrderedQ[{var2, var1}] returns a reasonable result. Do you want var1 and var2 to be the same? –  Mark McClure Dec 27 '13 at 1:33
@MarkMcClure Yes, the same. I understand why Mathematica sees them differently and why SameQ is False... I was just surprised that both forms didn't have the same underlying representation (I thought Style["aString", FontWeight -> Bold, FontSize -> 24] would auto-evaluate to Style["aString", Bold, 24] or something like that). –  rm -rf Dec 27 '13 at 1:36
@rm-rf So you'd like Equal[var2,var1] to evaluate to True in the same way that Equal[1,1.0] evaluates. I can see that. But, are there other situations where Equal[a,b] evaluates to True where a and b are non-identical, non-numeric expressions? I'm not sure off the top of my head, but I haven't been thinking about code so much lately. It's a little far afield of the OP's intention, perhaps. :) –  Mark McClure Dec 27 '13 at 1:53

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .