6
$\begingroup$

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.

$\endgroup$
2
  • 3
    $\begingroup$ My 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. $\endgroup$ Jun 15, 2019 at 21:26
  • $\begingroup$ 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 $\endgroup$ Jul 9, 2019 at 3:22

2 Answers 2

3
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ To clarify, could you technically define a custom symbol this way? Somehow escape it out and everything like that? $\endgroup$ Mar 12, 2020 at 16:20
1
$\begingroup$

$\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.

$\endgroup$
7
  • $\begingroup$ 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. $\endgroup$ Jun 16, 2019 at 1:00
  • $\begingroup$ Misunderstood. I though LATEX was your goal. If MMa is required, can't help. $\endgroup$
    – Bill Watts
    Jun 16, 2019 at 6:32
  • $\begingroup$ well, this is the Mathematica forum, not the LaTeX forum. Honestly, I would delete the answer to avoid downvotes. $\endgroup$ Jun 16, 2019 at 7:20
  • $\begingroup$ 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. $\endgroup$
    – Bill Watts
    Jun 16, 2019 at 7:39
  • $\begingroup$ @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. $\endgroup$
    – Szabolcs
    Jun 16, 2019 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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