(1)这可能是一个 bug,见:https://github.com/CTeX-org/ctex-kit/issues/530,目前未解决。
(2)容易解决,但同样无法用于 amsmath
的某些环境,而且颜色的高度固定为普通文字那么高。
\documentclass[fontset=windows]{ctexart}
\usepackage{ulem}
\usepackage{xeCJKfntef}
\usepackage{xcolor}
\makeatletter
\newcommand{\hltext}[1]{\CJKunderanyline*{0.5ex}{\color{yellow}\rule{0.1pt}{2.5ex}}{#1}}
\newcommand\hlmath[1]{\mathpalette{\hlmath@aux}{#1}}
\def\hlmath@aux#1#2{\hbox{\hltext{\m@th$#1#2$}}}
\newcommand*\hl{\ifmmode\expandafter\hlmath\else\expandafter\hltext\fi}
\makeatother
\begin{document}
一般地,设$A$,$B$是两个非空数集,\hl{如果按某种对应关系{ }$f$,对于集合~$A$中的任意一
个数~$x$,在集合~$B$中都有唯一的数~$\displaystyle\int f(x)$和它对应},那么就称$f$为集合$A$到集
合$B$的一个函数,记作
\[ \hl{y=\int f(x),x\in A.}\quad f_{\hl{x}} \]
\end{document}
问 再提一个关于段落文本高亮显示的问题(利用xeCJKfntef宏包实现效果)