MMa version of $\LaTeX$'s overtilde doesn't look as expected

Here is one rather hacky solution:

(* create a tilde graphics expression: *)
tilde = Graphics[
   First@First@ImportString[ExportString["~", "PDF"], "PDF"]];
tilde = Show[
   tilde,
   PlotRange -> Charting`get2DPlotRange@tilde,
   AspectRatio -> Full,
   BaseStyle :> CurrentValue@FontColor
   ];

MakeBoxes[WideOverTilde[expr_], frm_] ^:= With[
  {boxes = MakeBoxes[expr, frm]},
  With[
   {
    tildeBoxes = ToBoxes@Deploy@Dynamic@Show[
         tilde,
         ImageSize -> {
           FrontEndExecute[(* get the actual size of expr *)
             GetBoundingBoxSizePacket@Cell[
               BoxData@boxes,
               "Output",
               FontSize -> 1.4 CurrentValue@FontSize,
               PageWidth -> Infinity,
               CellMargins -> {{0, 0}, {0, 0}}
               ]][[1, 1]],
           5
           }
         ]
    },
   InterpretationBox[
    OverscriptBox[boxes, tildeBoxes],
    WideOverTilde[expr]
    ]
   ]
  ]

WideOverTilde["aaaaaaaaaaaaaa"]

enter image description here

Style[WideOverTilde[Sqrt[a + b]], Red, 30]

enter image description here

The basic idea is to stretch a tilde graphics expression to the correct width, and use that together with an OverScriptBox. The tild also inherits basic style properties from its surroundings, such as font color and size. Currently, the tilde graphics is just the standard tilde in the standard font, but you can probably create a graphics that's better suited.

Tags:

Latex