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.

I like to use Mathematica text cells for creating draft technical documents. When entering equations in a text cell, the ^ (hat accent) does not dynamically adjust its size to fit. It looks good if you enter x^, but if you wanted abc^, the ^ covers only the b. Anyone know how to make the ^ (and other accents) adjust to the size of the text?

share|improve this question
    
Don't know how to do it automatically. You can change the font size of the hat when you use the upper script (ctrl-7). Still much work when you have to type the hat alot. –  Lou Mar 10 '12 at 20:21
3  
Good question: how to create a custom extensible character –  Rojo Mar 10 '12 at 20:40
1  
Okay, someone had to do it. –  Mr.Wizard Mar 11 '12 at 14:29
add comment

1 Answer

This answer is just a quick hack. I think that to make true extensible character might not be something that an end-user can do...

Anyway, redefine the formatting for OverHat using

OverHat /: MakeBoxes[OverHat[a_], form_] := 
 With[{s = First[Rasterize[a, "RasterSize"]], 
   ab = MakeBoxes[a]}, With[{sl = N[2 Log[2 s]]},
   InterpretationBox[OverscriptBox[ab, 
     TagBox[GraphicsBox[LineBox[{{-s, 0}, {0, sl}, {s, 0}}], 
       ImageSize -> {s, Automatic}], "LongOverHat", 
      Selectable -> False]], OverHat[a]]]]

Then, just type in the expression as per normal, e.g., abc 1, and then select the OverHat expression and reformat the boxes using the menu command Cell > Convert To > Standard From (which can also be done using the shortcut CtrlShiftN) to get abc 2. The FullForm of this expression is OverHat[abc].

Here's an example showing how the modified OverHat scales for longer expressions

Powers of ten

The MakeBoxes command also works with TraditionalForm (CtrlShiftT), but you might want to modify it to include an AdjustmentBox[..., BoxBaselineShift -> b] in order to get the vertical spacing looking right.

share|improve this answer
2  
Rasterize[..., "BoundingBox"] and Rasterize[..., "RasterSize"] may be of interest. –  Szabolcs Mar 11 '12 at 9:55
    
Nice work Simon. +1 –  Mr.Wizard Mar 11 '12 at 10:00
    
Thanks @Szabolcs - it is of interest! And thanks Mr.Wizard. –  Simon Mar 11 '12 at 14:24
    
this is great - thank you for the quick response –  gamma Mar 13 '12 at 7:05
    
Not a problem @gamma. If you're happy with the answer, press the checkmark button at the top left of the answer. Also, maybe submit a request to Wolfram Research for a proper extensible circumflex glyph... –  Simon Mar 13 '12 at 11:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.