\documentclass{article}
\usepackage{xeCJK}
\usepackage{xcolor}
\colorlet{color1}{blue!50!black}
\colorlet{color2}{green!50!black}
\usepackage{etoolbox}
\newtoggle{col}
\providecommand{\tog}%
{%
\iftoggle{col}%
{\color{color1}\togglefalse{col}}%
{\color{color2}\toggletrue{col}}%
}%
\usepackage{paracol}
\maxdeadcycles=10000
\begin{document}
\begin{paracol}{1}
\tog a\tog b\tog c\tog d\tog e\tog f\tog g\tog h\tog i\tog j\tog k\tog l\tog m\tog n\tog o\tog p\tog q\tog r\tog s\tog t\tog u\tog v\tog w\tog x\tog y\tog z
\tog a\tog b\tog c\tog d\tog e\tog f\tog g\tog h\tog i\tog j\tog k\tog l\tog m\tog n\tog o\tog p\tog q\tog r\tog s\tog t\tog u\tog v\tog w\tog x\tog y\tog z
\tog a\tog b\tog c\tog d\tog e\tog f\tog g\tog h\tog i\tog j\tog k\tog l\tog m\tog n\tog o\tog p\tog q\tog r\tog s\tog t\tog u\tog v\tog w\tog x\tog y\tog z
\tog a\tog b\tog c\tog d\tog e\tog f\tog g\tog h\tog i\tog j\tog k\tog l\tog m\tog n\tog o\tog p\tog q\tog r\tog s\tog t\tog u\tog v\tog w\tog x\tog y\tog z
\tog a\tog b\tog c\tog d\tog e\tog f\tog g\tog h\tog i\tog j\tog k\tog l\tog m\tog n\tog o\tog p\tog q\tog r\tog s\tog t\tog u\tog v\tog w\tog x\tog y\tog z
\tog a\tog b\tog c\tog d\tog e\tog f\tog g\tog h\tog i\tog j\tog k\tog l\tog m\tog n\tog o\tog p\tog q\tog r\tog s\tog t\tog u\tog v\tog w\tog x\tog y\tog z
\end{paracol}
\end{document}
I'm writing a document in Chinese, and I'm using XeTeX to compile and get Chinese fonts. I'm also using paracol to add marginal notes. I've written a function \tog to toggle the font color, for the purpose of highlighting Chinese word boundaries. To facilitate editing, I want to use a command that toggles between two colors, and not explicitly state the colors (otherwise if I delete a word, then I need to change the colors in the whole document).
I had to first overcome this problem by adding in \maxdeadcycles=10000, but even then it basically just gives up after a while:
There must be a better way. I just want to toggle the font color whenever there is a \tog (which I'll need to call thousands of times); it shouldn't be so hard.
Question: Is there a (better) way to repeatedly toggle between two font colors within a paracol environment, and compiling with XeTeX?



\maxdeadcycles=10000line. Unrelated 2: to save typing, you could define a 1-character toggler, like\newcommand{\北}% {% \iftoggle{col}%.... – Cicada Jun 26 '22 at 10:40\maxdeadcycleswithpdflatexandlualatexwith the default font, so the problem is that xeCJK needxelatexbut xelatex fail for some reason. I do not have idea of Chinese, but if you can write it without xeCJK and xelatex, this could be a solution. – Fran Jun 26 '22 at 11:12