There is no Unicode “LATIN SMALL LETTER X WITH TILDE” so you get “x̃” by typing x
followed by U+0303 “COMBINING TILDE”.
This can't work in math mode, which strictly works from left to right and a following character doesn't influence what's before it.
You can make existent Unicode points such as “LATIN SMALL LETTER O WITH TILDE” to behave like \tilde{o}
in math mode with a trick such as
\AtBeginDocument{\mathcode`õ="8000 }
\begingroup\lccode`~=`õ
\lowercase{\endgroup\def~}{\tilde{o}}
One can think to do something like this for x
(doing a lookahead to see if a combining character follows) but it would be slow and not particularly robust. It's really better to make your intentions clearer by typing
\tilde{x}
Just as a proof of concept, here's how you could manage x̃
(I also left the precomposed õ
). The \@ifnextchar
test should be extended to the other needed composite characters.
\documentclass{scrartcl}
\usepackage{unicode-math}
\AtBeginDocument{\mathcode`õ="8000 }
\begingroup\lccode`~=`õ
\lowercase{\endgroup\def~}{\tilde{o}}
\AtBeginDocument{\edef\mathcodex{\Umathcharnum\the\Umathcodenum`x }}
\AtBeginDocument{\mathcode`x="8000 }
\begingroup\lccode`~=`x
\lowercase{\endgroup\def~}{\addaccentx}
\makeatletter
\newcommand\addaccentx{%
\@ifnextchar ^^^^0303{\tilde{\mathcodex}\@gobble}{\mathcodex}%
}
\makeatother
\begin{document}
x̃ŷz̄ $õx̃$
\end{document}
\~
from math accents\tilde
with good reason, the tilde in math is presumably denoting some mathematical operator and might potentially be applied to an arbitrary subterm rather than just a base letter. Therefore you don't want to use the combining character or pre-composed glyph in math even if the font has it, so that the same tilde construct is used as for built up expressions, it is also clearer in the input to mark this up as an operation on x rather than as a different character than just happens to look like an x with a tilde.x̃
is a symbol just likex
, not an operator. Admittedly, in some situations\tilde{some_expression}
is an operator, this tilde and the tilde over myx̃
is however different: in my case, it is part of the symbolx̃
and should be typed as such. That is my humble opinion.