I guess this is a part where unicode-math
might benefit from a reworking.
What happens is that the package inputs unicode-math-table.tex
which has the definition for all math symbols; for instance it has
\UnicodeMathSymbol{"0211D}{\BbbR}{\mathalpha}{/bbb r, open face r}%
which basically does
\Umathcode "0211D = "7 "0 "211D
\Umathchardef \BbbR = "7 "0 "211D
so typing \mathbb{R}
will do the expected thing, because it produces \BbbR
, but in a context where the math group might be different from 0 and indeed it is when a font with range=bb
has been specified.
In my opinion, unicode-math-table
should also record what range a character is assigned to, in order to be able to pair up the range and the corresponding math group so as to make the above definitions to have the correct default math group. Well, it does, but in a different place and does not go the whole way.
Alas! This is not possible at the moment. You can however get your \BbbX
commands to work by redefining them at the right spot:
\documentclass{article}
\usepackage{unicode-math}
\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}
\setmathfont{TeX Gyre DejaVu Math}[
Scale=MatchUppercase,
range=bb,
]
\setmathfont{STIX Two Math}[range=] % to reset the font parameters
\ExplSyntaxOn
\cs_new_protected:Nn \__noble_reset_bb:
{
\int_step_inline:nnn { `A } { `Z }
{
\cs_set_protected:cpx { Bbb \char_generate:nn { ##1 } { 11 } }
{
\exp_not:N \mathbb { \char_generate:nn { ##1 } { 11 } }
}
}
}
\AtBeginDocument{\__noble_reset_bb:}
\ExplSyntaxOff
\begin{document}
\[
X \BbbR \mathbb{R} ℝ Y
\]
\end{document}
The example however shows that direct input of the Unicode character will not work.
For that a different approach has to be taken.