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

6

1

I am (mis)using Mathematica as a WYSIWYG LaTex editor. I want to put a (long) tilde over an expression.

DisplayForm[OverscriptBox[a + b, "_"]]
DisplayForm[OverscriptBox[a + b, "~"]]

This Is how it looks:

overtilde

(Of course I'm using cntrl-7 to type in the above)

I want that the tilde stretched out over the whole expression, not just a small tilde in the middle. Just the same as with the underscore.

The corresponding LaTex expressions are

\overline{a+b}
\widetilde{a+b}

And the same issue with "^" and \widehat

I know I can mark the tilde (or hat) and use Command-"+" to increase the font size, but that doesn't look right.

Ideally, it would be something that exports easily to the mentioned Latex commands.

By the way,

FullForm[ToExpression["\\widetilde{a+b}", TeXForm]]

results in

OverTilde[Plus[a, b]]

which looks just like the above (tilde only above "+", not whole).

version: Mathematica 11.0

Edit/Clarification

I am well aware that this is not an issue with LaTeX itself, and that other, better working LaTeX editors exist. I want to continue writing Mathematica notebooks having parts which look like theorems or proofs look in math text books, referring to that look loosely as "LaTeX" (parts of which might later be exported for publication), and this question is about how to make those parts look right. So don't suggest any alternative LaTeX editors, that's not what the question is about.

mathheadinclouds

Posted 2019-06-15T13:09:49.287

Reputation: 835

3My guess would be that there is currently no good way to do it, that OverTilde[something] is supposed to (=planned to by later Mathematica version) look like LaTeX's widetilde, and that this will be accomplished in a later version by there being a new special "widetilde" character, which will be a "strechable" tilde. I think that, because with \[OverBrace] (esc-o{-esc), it works just as it does with "_", and as one would wish for with "~", and [OverBrace] is just another special character. – mathheadinclouds – 2019-06-15T21:26:39.683

yes, a new extensible character is what you want, but I don't know of any way to make new characters (extensible or not). Code for a palette of Mathematica's extensible brackets etc. can be found in the answers to this question

– Andrew Norton – 2019-07-09T03:22:43.770

Answers

3

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.

Lukas Lang

Posted 2019-06-15T13:09:49.287

Reputation: 17 767

To clarify, could you technically define a custom symbol this way? Somehow escape it out and everything like that? – CA Trevillian – 2020-03-12T16:20:24.460

1

$\widetilde{a+b}$

Maybe MMa's TeXForm doesn't do it properly, but it seems to work in MathJax. Or am I not understanding the question.

Bill Watts

Posted 2019-06-15T13:09:49.287

Reputation: 6 261

I want to use the Mathematica front end as a WYSIWYG editor, and there is no MathJax in the Mathematica front end, so that doesn't help in any way. Or am I not understanding the answer. – mathheadinclouds – 2019-06-16T01:00:06.067

Misunderstood. I though LATEX was your goal. If MMa is required, can't help. – Bill Watts – 2019-06-16T06:32:27.443

well, this is the Mathematica forum, not the LaTeX forum. Honestly, I would delete the answer to avoid downvotes. – mathheadinclouds – 2019-06-16T07:20:49.850

I am way too old to worry about downvotes. The ultimate result was to be in LaTeX, and I worked it that way. Anyone who thinks my answer is worthless can downvote it all they want. – Bill Watts – 2019-06-16T07:39:52.440

@mathheadinclouds The title of the question makes it appear that you're looking either for a LaTeX command or a way to generate a LaTeX command from Mathematica. It's easy to misunderstand what you want. – Szabolcs – 2019-06-16T08:47:31.990

@Szabolcs: you're absolutely right, bad misleading title, so I changed it. – mathheadinclouds – 2019-06-16T09:03:57.417

@BillWatts "Anyone who thinks my answer is worthless can downvote it all they want." Now that's simply not true. (Just sayin') – Daniel Lichtblau – 2019-06-16T14:58:01.253