TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use the value of an array in a function. But it does not work. Any ideas?

See below my LaTeX code





share|improve this question
Are you using xcolor too for \textcolor? – percusse Jun 26 '12 at 20:53

It can't work. The command \textcolor does expand its argument looking for a color, but unfortunately the extraction of a value from \Color requires actions that are not allowed when doing "pure expansion".

As the manual explains that you have to do in an indirect way:


The operation \checkColor extracts the value and places it as the expansion of \cachedata and now the expansion by \textcolor is possible.

Note that you should be using arrayjobx instead of arrayjob, which has serious problems with LaTeX.

A different strategy with LaTeX3 macros


\NewDocumentCommand{\xarraynew}{m O{&} m}
  \xarray_define:nnn {#1} {#2} {#3}
\cs_new_protected:Npn \xarray_define:nnn #1 #2 #3
  \seq_new:c { g_xarray_ #1 _seq }
  \seq_gset_split:cnn { g_xarray_ #1 _seq } { #2 } { #3 }
\cs_generate_variant:Nn \seq_gset_split:Nnn { c }

\DeclareExpandableDocumentCommand{\xarrayget}{m m}
  \xarray_get:nn { #1 } { #2 - 1 }
\cs_new:Npn \xarray_get:nn #1 #2
  \seq_item:cn { g_xarray_ #1 _seq } { #2 }





The user level commands are \xarraynew that takes two arguments: the array name and the data. It's possible also to specify a different delimiter, so


would be equivalent.

You can extract a value with \xarrayget, which takes again as argument the array name and the position.

share|improve this answer
Ah just seconds ..... :) – percusse Jun 26 '12 at 21:03
Thanks a lot for your response. I am surprising that Latex3 is working on my configuration. I though that I had only Latex2. – latex alpha Jun 27 '12 at 20:07
@latexalpha It's really expl3, which will become LaTeX3 in some years. – egreg Jun 27 '12 at 20:08

As indicated by @egreg, you need to use expandable definitions. I would use a simple expandable lookup as follows:




\ifnum#4=#1 #2\else\xgetcolor#3\getcolor{#4}\fi}



share|improve this answer
Your proposition working fine. But I do not understand it at all – latex alpha Jun 27 '12 at 20:23
I understand your suggestion using tracingall. Thanks a lot – latex alpha Jun 27 '12 at 21:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.