[XeTeX] \XeTeXinterchartoks and \hbox
Stephen Moye
stephenmoye at mac.com
Tue May 8 14:22:07 CEST 2012
On May 6, 2012, at 4:20 AM, Vafa Khalighi wrote:
> What is the problem with the following minimal example:
>
> \documentclass{article}
> \usepackage{color}
> \makeatletter
> \newcount\n
> \n=`\a \loop \XeTeXcharclass \n=4 \ifnum\n<`\z \advance\n by 1 \repeat
> \XeTeXinterchartoks 0 4 {\startcolor}
> \XeTeXinterchartoks 255 4 {\startcolor}
> \XeTeXinterchartoks 255 0 {\finishcolor}
> \XeTeXinterchartoks 4 0 {\finishcolor}
> \newif\ifcolor
> \newcommand{\startcolor}{\ifcolor\else\bgroup\color{red}\colortrue\fi}
> \newcommand{\finishcolor}{\ifcolor\egroup\fi}
> \makeatother
> \XeTeXinterchartokenstate=1
> \begin{document}
> this is a test
>
> \end{document}
>
> It produces the following error:
>
> ! Missing } inserted.
> <inserted text>
> }
> l.19 \end{document}
> ?
>
> However if "this is a test" is replaced with "this is a test.", then I get no error. How should I fix this?
Susan's solution:
\newcommand{\finishcolor}{\ifcolor\else\egroup\fi}
does get rid of the problem with the missing }, but *everything* turns red. Things seem to work the way they should by accounting for the transition from XeTeXcharclass 4 to 255:
%%%
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = XeLaTeX
\documentclass[12pt]{article}
\usepackage{color}
\usepackage{xltxtra}
\setmainfont{Centaur MT Pro}
\makeatletter
\newcount\n
\n=`\a \loop \XeTeXcharclass \n=4 \ifnum\n<`\z \advance\n by 1 \repeat
\XeTeXinterchartoks 0 4 {\startcolor}
\XeTeXinterchartoks 255 4 {\startcolor}
\XeTeXinterchartoks 255 0 {\finishcolor}
\XeTeXinterchartoks 4 0 {\finishcolor}
\XeTeXinterchartoks 4 255 {\egroup}
\newif\ifcolor
\newcommand{\startcolor}{\ifcolor\else\bgroup\color{red}\colortrue\fi}
\newcommand{\finishcolor}{\ifcolor\egroup\fi}% VK
\makeatother
\XeTeXinterchartokenstate=1
\begin{document}
this is a te*st and séåome more* text 1234 objects
\end{document}
%%%
Thanks for the interesting puzzle.
Stephen Moye
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/xetex/attachments/20120508/74fdd7a3/attachment.html>
More information about the XeTeX
mailing list