Finding and displaying UTF-8 characters with xesearch
This works:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Kai}
\usepackage{xesearch}
\SearchList{list1}{书}{book}
\begin{document}
The book costs \$1.
\end{document}
The current font must contain the glyph. If it doesn't, then ask XeLaTeX to use one that does:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\newfontfamily{\kanjifont}{Kai}
\usepackage{xesearch}
\SearchList{list1}{{\kanjifont 书}}{book}
\begin{document}
The book costs \$1.
\end{document}
(I've used a main font that shows more clearly the difference.)
For longer strings you have to reset the locale. At least with this code the result in the two lines is identical:
\documentclass[a5paper]{ctexbook}
\pdfpagewidth=148mm
\pdfpageheight=210mm
\usepackage{fontspec}
\setmainfont{Kai}
\setCJKmainfont{Kai}
\usepackage{xesearch}
\def\1{\XeTeXlinebreaklocale "zh" \XeTeXlinebreakskip = 0pt plus 20pt\relax}
\SearchList{list1}{{\1床前明月光,疑是地上霜。举头望明月,低头思故乡。}}{poem}
\begin{document}
\Huge
\noindent 床前明月光,疑是地上霜。举头望明月,低头思故乡。 \\
\noindent poem \\
\end{document}
But some expert in xeCJK might help better.
However, xesearch
is not the right tool for this: a macro \poem
expanding to
床前明月光,疑是地上霜。举头望明月,低头思故乡。
would be more useful.
Add \makexeCJKactive
at the beginning of the second argument of \SearchList
. This works:
\documentclass[a5paper]{ctexbook}
\pdfpagewidth=148mm
\pdfpageheight=210mm
\usepackage{fontspec}
\setmainfont{Adobe Song Std}
\setCJKmainfont{Adobe Song Std}
\usepackage{xesearch}
\SearchList{list1}{\makexeCJKactive 床前明月光,疑是地上霜。举头望明月,低头思故乡。}{poem}
\begin{document}
\Huge
\noindent 床前明月光,疑是地上霜。举头望明月,低头思故乡。 \\
\noindent poem \\
\end{document}
Warning: I haven't looked into xesearch
package to do enough tests. Any two different packages that use \XeTeXinterchartoks
heavilly may not work together well. I'm not sure about xesearch
.