I want to color specific character (or word) in my document with red, I know that XeTeX
can achieve this using \newXeTeXintercharclass
, \XeTeXinterchartoks
.
I find this answer Coloring all occurrences of some specific characters which look like what I need, but errors arise when compiling the code
! Too many }'s. \egroup l.20 I have been wondering for ages how to do something that is absolutely c... You've closed more groups than you opened. Such booboos are generally harmless, so keep going.
Not working example
\documentclass{article}
\usepackage{xcolor}
\XeTeXinterchartokenstate = 1
\newXeTeXintercharclass \mycharclassRed
\XeTeXcharclass `\u \mycharclassRed
\XeTeXcharclass `\W \mycharclassRed
% adding the more frequent lowercase w:
\XeTeXcharclass `\w \mycharclassRed
\XeTeXinterchartoks 0 \mycharclassRed = {\bgroup\color{red}}
\XeTeXinterchartoks 255 \mycharclassRed = {\bgroup\color{red}}
\XeTeXinterchartoks \mycharclassRed 0 = {\egroup}
\XeTeXinterchartoks \mycharclassRed 255 = {\egroup}
\begin{document}
I have been wondering for ages how to do something that is absolutely crucial
to the document I am writing. (I usually use Xe\LaTeX, but I don’t mind
changing if required.)
I would like to have a list of characters (presumably Japanese characters, but
maybe other ones as well) that would be typeset in a specific way. For
instance, put all the `u' and `W' of the document in red.
In my case, the goal is to highlight all the characters (of a text) that are
among a set of characters children should learn.
Now, I know I could define a macro or a new command for every character and
then replace all its occurrences with that macro, but that would be a titanic
job because I expect the number of different characters to be around 200.
Does anyone have an idea ? Thank you very much.
\end{document}