Katex: Double Tilde

Created on 3 Jan 2019  路  5Comments  路  Source: KaTeX/KaTeX

\tilde{\tilde d}} sometimes works and sometimes not. two tildes are not horizontally aligned.
How can I render a correct double tilde with Katex?

https://tex.stackexchange.com/questions/415659/double-tilde-over-symbol
katex

---


15. $$\begin{aligned}\tilde{\tilde d}(x,y)&=max(d_1(x_1,y_1),d_2(x_2,y_2))\\
    &=max(xy1, xy2)\\
    &=max(xz1+zy1,xz2+zy2)=\triangle
    \end{aligned}$$
bug

Most helpful comment

I suggest something like: \tilde{\tilde{\kern{-0.3ex}d}}.

In TeX and KaTeX, \tilde makes an automatic horizontal correction for the slant of an individual italic letter. That correction doesn't apply to the upper stacked tilde, so they don't align. So you need to avoid applying \tilde to an individual letter. Instead, wrap the letter in braces to make it a group: {d}. Then you can apply double tildes and they will align with each other.

Inside the group, you'll need to do the italic correction yourself and it will vary from letter to letter. To me, \kern{-0.3ex} looks about right for a "d", but your taste may differ.

All 5 comments

I suggest something like: \tilde{\tilde{\kern{-0.3ex}d}}.

In TeX and KaTeX, \tilde makes an automatic horizontal correction for the slant of an individual italic letter. That correction doesn't apply to the upper stacked tilde, so they don't align. So you need to avoid applying \tilde to an individual letter. Instead, wrap the letter in braces to make it a group: {d}. Then you can apply double tildes and they will align with each other.

Inside the group, you'll need to do the italic correction yourself and it will vary from letter to letter. To me, \kern{-0.3ex} looks about right for a "d", but your taste may differ.

Also, If you write \max instead of max, it will read like a function name, not three variables.

In the linked StackExchange, one of the answers points to \accentset defined in the accents.sty package, which would enables\accentset{\approx}{d}. I wonder if it would be feasible to add support for that in KaTeX?

I wonder if there's some way we can propagate the italic correction from d to the \tilde{d}. 馃

Ah, I hadn't realized before that this is a bug. (I thought LaTeX and KaTeX agreed on behavior.) But it is: here's how

\tilde{\tilde d}} \tilde{\tilde A}}

renders in LaTeX (via quicklatex):

image

Was this page helpful?
0 / 5 - 0 ratings