I am rewriting a package I wrote for XeLaTeX to handle unicode blocks. This means dealing with setting up character classes for all characters from block "BlockName" starting at codepoint 1234 and ending at codepoint 5678.
Right now I have a macro that takes three inputs, and transforms them as:
\newcounter{glyphcounter}
\newcommand{\@defineUnicodeClass}[3]{
\newXeTeXintercharclass#1
\forloop{glyphcounter}{#2}{\value{glyphcounter}<#3}\XeTeXcharclass\value{glyphcounter}=#1}
\XeTeXcharclass#3=#1}
This then gets called many, many times:
\@defineUnicodeClass{\AegeanNumbersClass}{65792}{65855}
\@defineUnicodeClass{\AlphabeticPresentationFormsClass}{64256}{64335}
\@defineUnicodeClass{\AncientGreekMusicalNotationClass}{119296}{119375}
...
I'd like to compact this in such a way that I can simply define the list of blocks, a la {{AegeanNumbers,65792,65855},{AlphabeticPresentationForms,64256,64335},{AncientGreekMusicalNotation,119296,119375},...}
and then run through this list to generate everything for each block.
I was thinking about writing the data definition as {AegeanNumbers,65792,65855,AlphabeticPresentationForms,64256,64335,AncientGreekMusicalNotation,119296,119375,...}
, so just a concatenated string in which every first%3 term is a new block definition, then having a macro that checks whether the input is empty, and if not takes the first three terms in that list, deals with them, then recurses with the list "tail", but I'm having a hard time implementing this in TeX.
If this is the best way to go about it, how do I do so? If not, what's a better way to run through this kind of data?
I had a look at http://maraist.org/comma-separated-lists-in-latex_08-2009 to figure out how to get the head/tail splitting to happen, but I am not having much luck getting this to work in XeLaTeX. I tried
\def\myTestCommand#1,#2{#1}
just to see whether it would do something, but calling it with "\myTestCommand{a,b,c,d}" just leads to a "runaway argument?" error.
I also had a look at the \forcsvlist
command from the etoolbox package, but from what I can tell this only understands a comma separated list in which every element is the same kind of thing, and has no concept of tuples. I could write a switching macro with two state variable macros to effect an "if states empty, fill first var, if one filled, fill second var, if both filled, call the following macro and empty both vars" but if someone has a cleaner approach, that would be much preferred.
\foreach
from pgffor would be able to manage this. Look at the package documentation...pgf
(includingpgffor
), so someone else might be able to help you set something up.