2

I'd like to put some formula over the tilde in math mode and adjust the tilde length to the length of that formula. It seems that \widetilde{} is almost what I need, however it puts the formula below the tilde. Is there a way to actually put the formula above?

An example of the formula to put above is:

\widetilde{(p_1',p_2') \in C}

Edit: I wasn't exactly clear with the expected effect. I'd like to have tilde in the middle of line (like \sim does), however with the formula above.

tomash
  • 227

2 Answers2

1

I took my answer at Big tilde in math mode and made two changes: 1) I changed it from an overstack to an understack; and 2) I increased the vertical stacking gap to \LMpt, which is 1pt scaled to the local mathstyle.

\documentclass{article}
\usepackage{scalerel}[2014/03/10]
\usepackage{stackengine}

\newcommand\reallywidetilde[1]{\ThisStyle{%
  \setbox0=\hbox{$\SavedStyle#1$}%
  \stackengine{\LMpt}{$\SavedStyle#1$}{%
    \stretchto{\scaleto{\SavedStyle\mkern.2mu\sim}{.5467\wd0}}{.7\ht0}%
%    .2mu is the kern imbalance when clipping white space
%    .5467++++ is \ht/[kerned \wd] aspect ratio for \sim glyph
  }{U}{c}{F}{T}{S}%
}}

\def\test#1{$%
  \reallywidetilde{#1}\,
  \scriptstyle\reallywidetilde{#1}\,
  \scriptscriptstyle\reallywidetilde{#1}
$\par}

\parskip 1ex
\begin{document}
$x = \reallywidetilde{(p_1',p_2') \in C}$

$\scriptstyle x = \reallywidetilde{(p_1',p_2') \in C}$

$\scriptscriptstyle x = \reallywidetilde{(p_1',p_2') \in C}$
\end{document}

enter image description here

If, by some chance, you actually wanted the text over the tilde (rather than the tilde under the text), that is also easy:

\documentclass{article}
\usepackage{scalerel}[2014/03/10]
\usepackage{stackengine}

\newcommand\reallywidetilde[1]{\ThisStyle{%
  \setbox0=\hbox{$\SavedStyle#1$}%
  \stackengine{\LMpt}{%
    \stretchto{\scaleto{\SavedStyle\mkern.2mu\sim}{.5467\wd0}}{.7\ht0}%
    }{$\SavedStyle#1$%
%    .2mu is the kern imbalance when clipping white space
%    .5467++++ is \ht/[kerned \wd] aspect ratio for \sim glyph
  }{O}{c}{F}{T}{S}%
}}

\def\test#1{$%
  \reallywidetilde{#1}\,
  \scriptstyle\reallywidetilde{#1}\,
  \scriptscriptstyle\reallywidetilde{#1}
$\par}

\parskip 1ex
\begin{document}
$xyz \reallywidetilde{(p_1',p_2') \in C} abc$

$xyz {\scriptstyle\reallywidetilde{(p_1',p_2') \in C}} abc$

$xyz {\scriptscriptstyle\reallywidetilde{(p_1',p_2') \in C}} abc$
\end{document}

enter image description here

  • I've utilized over a hundred instances of your \reallywidetilde code in my project for well over a year. While attempting to implement a pdflatex to lualatex conversion, I've located where the \scaleto command appears to error with a ! Missing number, treated as zero., likely due to a font implementation issue that I've not properly addressed (e.g. Missing character: There is no ∶ (U+2236) in font mdugmr7t!). As a neophyte to the conversion, any thoughts as to how or what I should look for to help address the Missing number issue would be appreciated. – RosesBouquet Feb 13 '24 at 00:55
  • @RosesBouquet I am not an expert in the topic of your question. The only glyph intrinsically used by \reallywidetilde is \sim. And yet, your error code refers to U+2236, which, the best I can tell, is the "ratio" colon: https://www.compart.com/en/unicode/U+2236. So I really don't have a good understanding of what is happening. – Steven B. Segletes Feb 13 '24 at 01:31
  • Thank you Steven ... let me try to work this out. Thanks again! – RosesBouquet Mar 13 '24 at 03:46
0

The package undertilde by Benjamin Bayart has it.

http://www.ctan.org/pkg/undertilde