I know that using the xpinyin package can solve this, but I need to use Lualatex, which is not supported.
At first I used the following code:
\documentclass{ctexart}
\usepackage{amsmath}
\newcommand\zhuyin[2]{$\overset{\textrm{#1}}{#2}$}
\begin{document}
\zhuyin{tiān}{天}
\end{document}
For general Chinese characters, it works very well.
But now I have some rare characters that need to be annotated, they are in the Unicode Extension B area, which means that the normal font does not include them (I've tried fonts like Source Han Sans): (U+2724D), (U+27246). On my system, it seems that only simsunb.ttf can display them. I'm having trouble changing the font in mathematical mode. I tried the following code and it failed:
\documentclass{ctexart}
\usepackage{amsmath}
\newcommand\zhuyin[2]{$\overset{\textrm{#1}}{#2}$}
\newfontfamily{\zyextb}{simsunb.ttf}[NFSSFamily=simsunb]
\DeclareMathAlphabet{\mathzy}{TU}{simsunb}{m}{n}
\begin{document}
%I also tried \zhuyin{jí}{\zyextb }
\zhuyin{jí}{\mathzy }
\end{document}
Can you help me?

luatexja(developed for Japanese + LuaTeX) for Chinese typesetting too.luatexja(according to the manual) has an add-onluatexja-rubypackage for typesetting pronunciation annotations. Maybe you can look into that? – Willie Wong Aug 14 '23 at 01:34