11

I know that Framed is used to show a frame around a symbol, how can I show a circle around a symbol?

Andrew
  • 1,050
  • 1
  • 13
  • 21

5 Answers5

8

If you don't mind having to micromanage the alignment parameters, you can overlay the empty circle character over a symbol:

TraditionalForm @ Style[
  Overlay[{x, Style[\[EmptyCircle], 24]}, Alignment -> {0.075, 0.16}]
, "DisplayFormula"
]

circled "x"

The exhibited font size and alignment parameters work for the font on my machine, but you may have to tweak them for good results on your screen. And tweak them again for a decent print-out. The following Manipulate can aid in that process:

Manipulate[
  TraditionalForm @ Style[
    Overlay[
      {Style[x, xSize], Style[\[EmptyCircle], circleSize]}
    , Alignment -> {xAlign, yAlign}
    ]
  , "DisplayFormula"
  ]
, {{xSize, 12}, 8, 40, 1, Appearance -> "Labeled"}
, {{circleSize, 24}, 8, 40, 1, Appearance -> "Labeled"}
, {{xAlign, 0.075}, -1, 1, Appearance -> "Labeled"}
, {{yAlign, 0.016}, -1, 1, Appearance -> "Labeled"}
]

image adjustment manipulator

WReach
  • 17,553
  • 3
  • 47
  • 88
8

Here is an attempt to create a function that circles arbitrary expressions. It's rather clumsy, but I cannot think of a better way at the moment.

circled =
    With[{m = Max@Rasterize[#,"RasterSize"]},
       Framed[
         Pane[#, {m, m}, Alignment -> Center],
         RoundingRadius -> 1*^6]
    ] &;


circled[1/x + y + z]

enter image description here

Mr.Wizard
  • 23,689
  • 5
  • 41
  • 116
  • 1
    What's the benefit of writing `1*^6` instead of `10^6`? – abcd Oct 30 '11 at 02:32
  • 1
    @yoda, nothing, just habit. `1*^6` is my default "large value" and when I see it I often know it is just that: an arbitrary "large" number. There is one related thing: at the extreme end of things, there is one less operation with `1*^x` than with `10^x`. For example: `Timing[a = 1*^60000000;]` and `Timing[b = 10^60000000;]`. – Mr.Wizard Oct 30 '11 at 03:14
  • @yoda Or, perhaps more relevantly: `Timing@Do[1*^6, {50000000}]` versus `Timing@Do[10^6, {50000000}]`. – Mr.Wizard Oct 30 '11 at 03:23
  • @Mr. I am not the only one being noticed of the convoluted code you are writing lately .... – Dr. belisarius Oct 30 '11 at 03:33
  • @bel Can you do better? Put up or shut up. ;-)) (I know, this is pretty ugly, but I honestly cannot think of a better way.) – Mr.Wizard Oct 30 '11 at 03:40
  • 1
    @Mr.Wizard Thanks, I wasn't aware of that performance difference. In this case however, I think it obfuscates more than it educates, but I understand, habits die hard. – abcd Oct 30 '11 at 03:48
  • 1
    @Mr. If you want to frame whole expressions (and not just simple symbols) the Pane[] size should take the largest diagonal into account. See `circled["3((1/x+y+z)/h)\n2\nm\np"]` – Dr. belisarius Oct 30 '11 at 04:27
  • @bel what should I be seeing in that example? – Mr.Wizard Oct 30 '11 at 04:33
  • @belisarius that's not what I see! I guess it is system (or setting?) dependent. http://i.stack.imgur.com/tARbx.gif – Mr.Wizard Oct 30 '11 at 14:50
  • @Mr. Ha! So I posted an answer to solve a semi-existent problem :) – Dr. belisarius Oct 30 '11 at 15:01
  • @belisarius @Mr I get what belisarius gets, but in `TraditionalForm` it's more like what Mr. Wizard gets. – Andrew Oct 30 '11 at 18:21
6

Framed can take an option RoundingRadius.

Framed[expr, RoundingRadius -> radius]

At smaller values of radius the corners of the frame are simply slightly rounded, but at larger values, the frame becomes an oval or circle.

Mr.Wizard
  • 23,689
  • 5
  • 41
  • 116
John Flatness
  • 29,079
  • 5
  • 71
  • 76
  • 3
    A combination of nondefault values of `RoundingRadius` and `FrameMargins` seems to do it, but it takes a different combination for each expression I want to put in a circle – Andrew Oct 29 '11 at 22:36
  • I was hoping you'd be fine with ovals... I'm not aware of a better solution. – John Flatness Oct 29 '11 at 22:45
  • Maybe there's a way to programmaticly calculate the right values of the options. – Andrew Oct 29 '11 at 22:59
  • Anybody able to whip up a palette button to do this? I've got a palette with a single button to overstrike a selection (from this: http://mathematica.stackexchange.com/a/112407/23076), and I'd love to add a button to automatically circle it. I'm not so hot with palettes yet… – ibeatty Dec 04 '16 at 19:53
3

The same idea of WReach, but trying to autocalculate:

cirBeli[x_] := 
 TraditionalForm@
    Style[Overlay[{#, 
       Style[\[EmptyCircle], 
        N@2 Norm[ImageDimensions[Rasterize[#]][[1 ;; 2]]]]}, 
      Alignment -> Center], "DisplayFormula"] &@x

cirBeli[x]

enter image description here

Dr. belisarius
  • 59,172
  • 13
  • 109
  • 187
  • In `cirBeli[Sin[z^2]/Exp[z] + Integrate[Sin[x] Cos[x] Sqrt[x], x]]`, the expression is not in the middle of the circle. – Andrew Oct 30 '11 at 18:26
  • @Andrew The problem is that "\[EmptyCircle]" is not vertically centered. Let's see if I can fix it. – Dr. belisarius Oct 30 '11 at 18:55
2

Using Framed[ ] with RoundingRadius

f = Rasterize[#, "RasterSize"] &;
circledBeli[x_] := Framed[ x,
                    FrameMargins -> (Norm@f@x - Array[1 &, {2, 2}] f@x)/2,
                    RoundingRadius -> Norm@f@x];

circledBeli[Sin[z^2]/Exp[z] + Integrate[Sin[x] Cos[x] Sqrt[x], x]]

enter image description here

circledBeli["3((1/x+y+z)/h)\n2\nm\np"]

enter image description here

Edit

The following seems to work better with TraditionalForm:

f = ImageDimensions[Rasterize[#]][[1 ;; 2]] &;
g = Reverse[ImageDimensions[Rasterize[Rotate[#, Pi/2]]][[1 ;; 2]]] &;
h = Max /@ Transpose@{f@#, g@#} &;
circledBeli[x_] := 
  Framed[x, FrameMargins -> (Norm@h@x - Array[1 &, {2, 2}] h@x)/2, 
   RoundingRadius -> Norm@h@x];
t = TraditionalForm[Sin[z^2]/Exp[z] + Integrate[Sin[x] Cos[x] Sqrt[x], x]]
circledBeli[t]

enter image description here

Dr. belisarius
  • 59,172
  • 13
  • 109
  • 187