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.
- 158,329
- 1,596
5 Answers
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%
}
\newcommand\shadowfy[1]{\expandafter\shadowfypars#1\par\relax\relax}
\long\def\shadowfypars#1\par#2\relax{%
\ifx#1\relax\else
\shadowfywords#1 \relax\relax%
\fi%
\ifx\relax#2\else\par\shadowfypars#2\relax\fi%
}
\def\shadowfywords#1 #2\relax{%
\outline{#1}%
\ifx\relax#2\else\ \shadowfywords#2\relax\fi%
}
\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}
- 237,551
-
Oh wow! This looks perfect! I'll get back to you today. (I am only using pdflatex, so this might just do the trick!) – Patrick Da Silva Jan 08 '18 at 08: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. – Patrick Da Silva Jan 08 '18 at 13:59
-
@PatrickDaSilva That was my worry that, at small scale, the hollowed tilde would be indistinguishable. – Steven B. Segletes Jan 08 '18 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}
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}
- 60,462
-
I'll give it a try tomorrow and give you my feedback! Thanks a lot! – Patrick Da Silva Jan 07 '18 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.
- 42,558
-
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. – Jan 09 '18 at 04: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!
- 1,596




\mathbb-tilde which is stretched to that width above the argument. – Skillmon Jan 07 '18 at 21:33\setbox0\hbox{<something>}after that\wd0,\ht0, and\dp0contain 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\wd0there. That's what I'd do (but I'm too lazy to do thetikzpart of it, atm) :) – Skillmon Jan 07 '18 at 21:52