# A mathbb version of widetilde

Essentially, I would like to be able to use a hollow version of widetilde, a bit like $\mathbb P$ is a hollow version of a $P$ with a very fat vertical line. It would really suit my purposes. I tried to be clever and stack two widetildes to imitate the idea, but two issues happened : tilde is too short and the widetildes don't align. So I think creating a new accent would be the better solution, but I don't know where to start.

• Could you please include an image of the results you want to get? Jan 7, 2018 at 21:25
• @Skillmon : Done (it's not turned on the side on my phone... Bite me!) This represents what I would want $\fancywidetilde M$ to do. Jan 7, 2018 at 21:29
• I guess the route I'd take is something like the following: Create a macro which 1. measures the width of its argument, 2. draw a TikZ picture of your \mathbb-tilde which is stretched to that width above the argument. Jan 7, 2018 at 21:33
• @Skillmon : I know a fair bit about TikZ and LaTeX, it's the TeX part that I don't know how to do! Jan 7, 2018 at 21:36
• To measure the width of something: \setbox0\hbox{<something>} after that \wd0, \ht0, and \dp0 contain the width, height, and depth, respectively. It does only work on stuff which can be used in a \hbox (which shouldn't be a problem for the stuff you want to put under a tilde). Then to print the character without using space: \mathrlap{<something>} (requires \usepackage{mathtools}). After that you put your TikZ-tilde with the width \wd0 there. That's what I'd do (but I'm too lazy to do the tikz part of it, atm) :) Jan 7, 2018 at 21:52

A "for fun" answer that only works in pdflatex, based on my answer here: Outline text using TrueType fonts. It could be cleaned up quite a bit. It uses pdfliterals to get the glyph outline of \widetilde.

\documentclass{article}
\usepackage{xcolor,amsmath,stackengine}
\input pdf-trans
\newbox\qbox
\def\usecolor#1{\csname\string\color@#1\endcsname\space}
\newcommand\bordercolor[1]{\colsplit{1}{#1}}
\newcommand\fillcolor[1]{\colsplit{0}{#1}}
\newcommand\outline[1]{\leavevmode%
\def\maltext{#1}%
\setbox\qbox=\hbox{\maltext}%
\boxgs{Q q 2 Tr \thickness\space w \fillcol\space \bordercol\space}{}%
\copy\qbox%
}
\ifx#1\relax\else
\fi%
}
\outline{#1}%
}
\newcommand\colsplit[2]{\colorlet{tmpcolor}{#2}\edef\tmp{\usecolor{tmpcolor}}%
\def\tmpB{}\expandafter\colsplithelp\tmp\relax%
\ifnum0=#1\relax\edef\fillcol{\tmpB}\else\edef\bordercol{\tmpC}\fi}
\def\colsplithelp#1#2 #3\relax{%
\edef\tmpB{\tmpB#1#2 }%
\ifnum #1>9\relax\def\tmpC{#3}\else\colsplithelp#3\relax\fi
}

\newcommand\widespecialtilde[1]{%
\stackengine{0pt}{\shadowfy{$\widetilde{\mathcal{#1}}$}}{$\mathcal{#1}$}%
{O}{c}{F}{F}{L}%
}
\begin{document}
\bordercolor{black}
\fillcolor{white}
\def\thickness{.1}
$x = \widespecialtilde{M}$\medskip

\fillcolor{red!50}
\def\thickness{.05}
$y = \widespecialtilde{W}$

\end{document}


• Oh wow! This looks perfect! I'll get back to you today. (I am only using pdflatex, so this might just do the trick!) Jan 8, 2018 at 8:15
• I tried to use it in my code, but it won't compile. I tried several fixes, but it's hard to go through code you never understood the syntax of (i.e. TeX). However, I tried a workaround and I realized that what I want over M is something similar to \scalebox{1.2}[0.7]{$\approx$} because in your case the hollow part of the tilde is too small and when one zooms out, it almost doesn't look hollow at all. Jan 8, 2018 at 13:59
• @PatrickDaSilva That was my worry that, at small scale, the hollowed tilde would be indistinguishable. Jan 8, 2018 at 14:40

Using the tricks here, one may try

\documentclass{article}
\usepackage{amsmath}
\usepackage{wasysym,graphicx}
\usepackage{scalerel,stackengine}
\newcommand{\Pffft}{\rotatebox{90}{\leftmoon}\kern-0.05em\rotatebox{90}{\rightmoon}}

%from https://tex.stackexchange.com/a/337989/121799
\newcommand\reallywidetilde[1]{\ThisStyle{%
\setbox0=\hbox{$\SavedStyle#1$}%
\stackengine{-.1\LMpt}{$\SavedStyle#1$}{%
\stretchto{\scaleto{\SavedStyle\mkern.2mu\AC}{.5150\wd0}}{.6\ht0}%
}{O}{c}{F}{T}{S}%
}}

\newcommand{\reallywidehat}[1]{%
\savestack{\tmpbox}{\stretchto{%
\scaleto{%
\scalerel*[\widthof{\ensuremath{#1}}]
{\kern-.6pt\bigwedge\kern-.6pt}%
{\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED     BIG WEDGE
}{\textheight}%
}{0.5ex}}%
\ensurestackMath{\stackon[1pt]{#1}{\tmpbox}}%
}

\newcommand{\DoubleTilde}[1]{%
\savestack{\tmpbox}{\stretchto{%
\scaleto{%
\scalerel*[\widthof{\ensuremath{#1}}]
{\kern-.1pt\Pffft\kern-.1pt}%
{\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED     BIG WEDGE
}{\textheight}%
}{1ex}}%
\ensurestackMath{\stackon[1pt]{#1}{\tmpbox}}%
}

\begin{document}
~\DoubleTilde{A}~\DoubleTilde{AB}~\DoubleTilde{\text{koala bear}}
\end{document}


• Koalas aren’t bears, btw :-) Jan 9, 2018 at 4:33
• @WillRobertson Yes, that's why they like to hide under a fake tilde ;-)
– user121799
Jan 9, 2018 at 4:34

A basic setup (might not be the best approach though). As you suggested, I did not draw the tilde but only a bar. The problem with the \hbox approach is that the surrounding formatting switches are lost.

\documentclass[]{article}

\usepackage{tikz,mathtools}

\newcommand*\fancytilde[1]{%
\mathchoice
{\fancytildehelper{\displaystyle}{#1}{0.3ex}}
{\fancytildehelper{}{#1}{0.3ex}}
{\fancytildehelper{\scriptstyle}{#1}{0.2ex}}
{\fancytildehelper{\scriptscriptstyle}{#1}{0.15ex}}}

\newcommand*\fancytildehelper[3]{%
\setbox0\hbox{$#1#2$}%
\mathrlap{#2}%
\raisebox{\dimexpr\ht0+#3\relax}{%
\begin{tikzpicture}%
\draw (0,0) -- (\wd0,0);%
\end{tikzpicture}%
}}

\begin{document}
$\fancytilde{foo}_{\fancytilde{bar}_{\fancytilde{baz}}}$
\end{document}

• I'll give it a try tomorrow and give you my feedback! Thanks a lot! Jan 7, 2018 at 23:33

Here is a possibility created by altering an \approx symbol with two vertical lines created with \rule.

First there is a macro \bbtild that overlays the \approx symbol in its original size with two lines using \ooalign. This creates the blackboardbold-like tilde symbol. The length \aproxlen is created in the preamble to be the width of the \approx symbol.

\newcommand{\bbtild}{%
\ooalign{$\approx$\cr%
\hfil$\rule[.8pt]{.27pt}{.55ex}\hspace{.787\aproxlen}\rule[2.1pt]{.27pt}{.55ex}$\hfil\cr}%
}


Then there is the macro that expands the new \bbtild symbol to the \widthof the desired character or characters:

\newcommand{\fancytilde}[1]{%
\setlength{\fancylen}{\widthof{${#1}$}}%
\overset{\resizebox{\fancylen}{.6ex}{$\bbtild$}}{#1}%
}


Adjusting the .6ex will change the thickness of the new symbol. The complete code is here:

\documentclass{article}

\usepackage{amsmath}
\usepackage{graphicx} % needed for \resizebox
\usepackage{calc} % needed for \widthof

\newlength{\fancylen}
\newlength{\aproxlen}

\setlength{\aproxlen}{\widthof{$\approx$}}

\newcommand{\bbtild}{%
\ooalign{$\approx$\cr%
\hfil$\rule[.8pt]{.27pt}{.55ex}\hspace{.787\aproxlen}\rule[2.1pt]{.27pt}{.55ex}$\hfil\cr}%
}

\newcommand{\fancytilde}[1]{%
\setlength{\fancylen}{\widthof{${#1}$}}%
\overset{\resizebox{\fancylen}{.6ex}{$\bbtild$}}{#1}%
}

\begin{document}

$\fancytilde{N}\fancytilde{M}\fancytilde{\mathcal{M}}\fancytilde{AB}$

\end{document}


Note that the vertical lines start to get very thick if the \fancytilde has to cover many characters. Note also that if you want to use this as a subscript you will have to use the form

$T_{\fancytilde{\scriptstyle N}}$


since the style of the input is not carried into the macro. If you wish, this could be done using \mathchoice.

• Looks very good! Originally tried something very similar, but in my attempts the vertical \rules got very ugly when I stretched the tilde too much.
– user121799
Jan 9, 2018 at 4:37

Right now, I have the following temporary solution for myself which is slightly satisfactory :

\newcommand{\fancytilde}[1]{\overset{\mbox{}\scalebox{1.2}[0.7]{$\approx$}}{#1}}
\newcommand{\Fancytilde}[1]{\overset{\mbox{}\scalebox{2}[0.7]{$\approx$}}{#1}}


I get my tilde M via

$\fancytilde M$


in the document.

However, whenever there's TeX involved, I don't know how to tweak it. I didn't manage to compile the above answers. It would be nice if my command would stretch to its argument (hence my need for two commands, one for a single letter and one for potentially more symbols).

I inspired myself from the above answers, so I'd like to thank everyone!