# Xelatex math weirdness - misaligned \not

I generally use xelatex for my documents, and the following snippet generally works fine for my math:

\usepackage{fontspec}
\usepackage{unicode-math}
\setmathfont{Asana Math}


But I recently discovered a weird problem with xelatex, with or without the math. I was trying to typeset the expression

$A \not\subset B$


And the \not sign misaligned (instead of striking through the \subset symbol. I thought the problem was in Asana Math,and removed it, but it got even worse - the \subset symbol disappeared altogether. This is the result of compiling the following MWE:

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
\begin{document}
$A \subset B$
\setmathfont{Asana Math}
$A \not\subset B$
\end{document}


What might be going on here ?

-
Unicode has its own glyph for that, which is called in unicode-math \nsubset. –  morbusg Mar 8 '12 at 8:24
The problem is not with XeLaTeX per se. Omit \usepackage{unicode-math}, and it works. –  Andrey Vihrov Mar 8 '12 at 8:37
Great. both of these worked. I have a mild preference for the first option. –  Suresh Mar 8 '12 at 8:45
With Unicode math fonts, \not should be treated as a combining mark, but neither LuaTeX nor XeTeX support it yet (TeX went away specially designing the glyph for \not, something that can not be guaranteed in Unicode world). I had a patch for LuaTeX, and I'll look into adding it to XeTeX too. –  Khaled Hosny Mar 8 '12 at 9:40
BTW I had the same problem with \not\in, I replaced it with \notin ; thanks for the tips –  user67648 Apr 17 '13 at 8:39

As morbusg points out in his comment, one ought to use \nsubset for this glyph. Not only does this make the character look right, it also means that the spacing is correct.

There are some packages and classes that define the \not command to look to see if there is a command \n<whatever> or \not<whatever> and use those before trying to overlay the not-slash on top - this makes them a bit more font-independent. The ones that I know of are pxfonts and the lms journal class. Adapting these is fairly straightforward. Here's some code that does that (I don't seem to have Asana Math so I've tested with STIX instead).

\documentclass{article}
%\url{http://tex.stackexchange.com/q/47224/86}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmathfont{xits-math.otf}

\makeatletter

\@namedef{not=}{\ne}
\@namedef{not>}{\ngtr}
\@namedef{not<}{\nless}

\let\oldnot=\not

\DeclareRobustCommand*{\not}[1]{%
\begingroup \escapechar\m@ne\xdef\@gtempa{not\string#1}\endgroup
\@ifundefined{\@gtempa}%
{\not@n@{#1}}%
{\@nameuse{\@gtempa}}}
\def\not@n@#1{%
\begingroup \escapechar\m@ne\xdef\@gtempa{n\string#1}\endgroup
\@ifundefined{\@gtempa}%
{\neg #1}%
{\@nameuse{\@gtempa}}}

\makeatother

\begin{document}
$$A \subset B$$
$$A \not\subset B$$
$$A \not B$$
$$A \not= B$$

$$A \subset B$$
$$A \oldnot\subset B$$
$$A \oldnot B$$
$$A \oldnot= B$$
\end{document}


The \oldnot is for comparison. Here's the result, note the spacing in particular:

-

A possible LaTeX3 implementation that might be included in unicode-math:

\ExplSyntaxOn
\tl_new:N \l_not_token_name_tl
\cs_new:Npn \not_newnot:N #1
{
\tl_set:Nx \l_not_token_name_tl { \token_to_str:N #1 }
\tl_if_empty:xF { \tl_tail:V \l_not_token_name_tl }
{ \tl_set:Nx \l_not_token_name_tl { \tl_tail:V \l_not_token_name_tl } }
\cs_if_exist:cTF { n \l_not_token_name_tl }
{ \use:c { n \l_not_token_name_tl } }
{
\cs_if_exist:cTF { not \l_not_token_name_tl }
{ \use:c { not \l_not_token_name_tl } }
{ \neg \l_not_token_name_tl } % or error?
}
}
\cs_set_eq:NN \not \not_newnot:N
% Common negated symbols
\cs_new:cpn { not= } { \neq } % not \let, as the meaning is changed later
\cs_new:cpn { not< } { \nless }
\cs_new:cpn { not> } { \ngtr }
\ExplSyntaxOff


It works essentially as Andrew's. However it doesn't work if one says, for instance,

$$A \not⊂ B$$


One might add some other definitions on the line of the last three, but a complete table of equivalences would be really huge.

-
I think manually listing the equivalents would be the only reliable way. It can be wrapped in a simple macro, say \DeclareMathNegatedSymbol{<symbol>}{<negated>}, and put in a separate file like the existing unicode-math-table.tex file. It would be even better to check if the negated symbol is supported by the font and fallback to using negation slash otherwise (but this can be tricky, e.g. when multiple fonts are used). –  Khaled Hosny Mar 8 '12 at 21:53
I used a modified version of that code in my (temporary) unicode-math fork, hopefully Will will eventually merge it. It works for the common case, but if on is going to type \not⊂, I guess he can type ⊄ directly. –  Khaled Hosny Apr 23 '12 at 16:07
@KhaledHosny Thanks for telling (and doing). I surely won't be the one that uses \not⊂, as I'll continue to say \not\subset. :) –  egreg Apr 23 '12 at 16:33