12
$\begingroup$

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.

$\endgroup$
13
  • $\begingroup$ Do you have any experience setting up a custom stylesheet? It might be needed to control the various styling elements in an Around object $\endgroup$
    – Jason B.
    Commented May 18, 2022 at 14:30
  • 1
    $\begingroup$ what do you get from CurrentValue[{StyleDefinitions, "Around"}] and from CurrentValue[{StyleDefinitions, "AroundAsym"}]? $\endgroup$
    – kglr
    Commented May 18, 2022 at 14:56
  • 1
    $\begingroup$ @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. $\endgroup$
    – Jason B.
    Commented May 18, 2022 at 16:05
  • 2
    $\begingroup$ @Syed something like that? Style[Around[10, {Style[1, Red], Style[0.5, Green]}], 20, Red]? Or did I misunderstand? $\endgroup$
    – bmf
    Commented May 18, 2022 at 17:31
  • 1
    $\begingroup$ @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. $\endgroup$
    – Syed
    Commented May 18, 2022 at 17:42

2 Answers 2

9
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ This is fantastic!!! $\endgroup$
    – bmf
    Commented Jun 10, 2022 at 5:47
10
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – Syed
    Commented May 19, 2022 at 17:15
  • $\begingroup$ @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. $\endgroup$
    – bmf
    Commented May 19, 2022 at 17:47

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.