12

How do I apply Style to Around objects? Are there any workarounds, resource functions or custom solutions available? Thanks for your help.

enter image description here

Code:

Style[Around[10, 1]
 , 20, Red
 ]
Style[
 Around[10, {1, 0.5}]
 , 20, Red
 ]

EDIT

I am using v12.2.0 on Win7-x64.

CurrentValue[{StyleDefinitions, "Around"}]

{Selectable -> False, ShowStringCharacters -> False,
TemplateBoxOptionsDisplayFunction -> (RowBox[{#1, StyleBox["[PlusMinus]", "AroundSmall"], StyleBox[#2, "AroundTiny"]}] &), TemplateBoxOptionsTooltip -> None}

CurrentValue[{StyleDefinitions, "AroundAsym"}]

{Selectable -> False, ShowStringCharacters -> False,
TemplateBoxOptionsDisplayFunction -> (SubsuperscriptBox[#1, StyleBox[RowBox[{"-", #2}], "AroundSmall"], StyleBox[RowBox[{"+", #3}], "AroundSmall"]] &), TemplateBoxOptionsTooltip -> None}


EDIT II Adding a toy example:

SeedRandom[1];
t = Transpose@{Range[10, 20], RandomReal[{-1, 1}, 11]};
data = Around @@@ t;
ListLinePlot[Callout[#, Style[#, Blue]] & /@ data, PlotStyle -> Red, 
 Mesh -> All, MeshStyle -> Directive[AbsolutePointSize[5], Red]]

enter image description here

With a Gray color (instead of Blue) it is still usable.

Syed
  • 52,495
  • 4
  • 30
  • 85
  • Do you have any experience setting up a custom stylesheet? It might be needed to control the various styling elements in an Around object – Jason B. May 18 '22 at 14:30
  • No I don't. I was hoping to glean some info from FullForm, but didn't make much progresss or I would have written a custom function. – Syed May 18 '22 at 14:34
  • 1
    what do you get from CurrentValue[{StyleDefinitions, "Around"}] and from CurrentValue[{StyleDefinitions, "AroundAsym"}]? – kglr May 18 '22 at 14:56
  • @kglr I have updated the post. – Syed May 18 '22 at 15:04
  • thank you Syed. – kglr May 18 '22 at 15:04
  • do you want to use the same font size for all elements (x, y, z, +, and -) in Around[x, {y,z}] ? – kglr May 18 '22 at 15:24
  • I guess it should still look and feel like an Around object with Uncertainty displayed with slightly smaller fontsize than the Value. What would WRI choose to do if they wanted to incorporate this functionality at a later date? – Syed May 18 '22 at 15:29
  • 1
    @Syed - the functionality exists right now. The style definitions for Around objects are stored at the stylesheet level, and to change them you need to modify them there. You can either create your own custom stylesheet, or modify it on a per-notebook method by adapting the code here. – Jason B. May 18 '22 at 16:05
  • 2
    @Syed something like that? Style[Around[10, {Style[1, Red], Style[0.5, Green]}], 20, Red]? Or did I misunderstand? – bmf May 18 '22 at 17:31
  • 1
    @bmf Interesting!! Compare the output of the regular: Around[10, {1, 0.5}] +Around[10, 0.2] with Around[10, {Style[1, Red] , Style[0.5, Green]}] + Around[10, Style[0.2, Blue]] as shown here. Can certainly write this as an answer although there is more going on there as we can see. – Syed May 18 '22 at 17:42
  • @Syed I saw that kglr and JasonB got engaged in the comments. I think that the best thing to do is to give them some time and see if they can come up with a more complete and satisfactory answer. I will get back to this post to check once I am done from the office :) – bmf May 18 '22 at 17:44
  • @bmf - I was just trying to point OP in the right direction :-) – Jason B. May 18 '22 at 18:35
  • @JasonB. thanks for letting me know. I thought that there was a way to manipulate the $\pm$ elements as well :) – bmf May 18 '22 at 18:42

2 Answers2

10

The following seems to work, albeit not at the level of the $\pm$ symbols.

Style[Around[10, {Style[1, Red], Style[0.5, Green]}], 20, Red]

around

Following the logic above, one is able, of course, to manipulate the Style in any given expression.

bmf
  • 15,157
  • 2
  • 26
  • 63
  • 1
    I think this has utility, if one wants to see Around components getting used in a computation as I mentioned in a previous comment. With pattern matching more can be done. Since Around objects follow many syntax variations, a consolidated solution would be the ultimate goal. I can't say that I know what it would look like. Thanks for the effort. – Syed May 19 '22 at 17:15
  • @Syed totally agree with you and this is why I was hesitant to write this as a first answer. I was kind of hoping for a more complete approach by someone. – bmf May 19 '22 at 17:47
8

It seems to be an oversight that an explicit font color is specified in the style sheet. For example:

CurrentValue[{StyleDefinitions, "AroundTiny"}]

{FontSize :> 0.8 Inherited, FontColor -> GrayLevel[0.4]}

So, one possibility is to create your own versions of "AroundTiny" and "AroundSmall":

SetOptions[
    EvaluationNotebook[], 
    StyleDefinitions -> Notebook[
        {
        Cell[StyleData[StyleDefinitions -> "Default.nb"]],
        Cell[StyleData["Around"], TemplateBoxOptions->
            {
            DisplayFunction->(RowBox[{#1, StyleBox["\[PlusMinus]", "MyAroundSmall"], StyleBox[#2,"MyAroundTiny"]}]&)
            }
        ],
        Cell[StyleData["MyAroundTiny"], FontSize :> 0.8` Inherited, FontOpacity -> 0.6`],
        Cell[StyleData["MyAroundSmall"], FontSize :> 0.9` Inherited, FontOpacity -> 0.6`]
        },
        StyleDefinitions->"PrivateStylesheetFormatting.nb"
    ]
]

Then:

Style[Around[10, 1], Red]

enter image description here

Carl Woll
  • 130,679
  • 6
  • 243
  • 355