In general: I need to retrieve values from an array to submit those values as indices to a function.
More specific: I want to create figures, which contain subfigures. These subfigures are loaded from mysubfigures.pdf. The order of the subfigures is saved in a seperate list ggg
. I made a minimal example below.
This is the part that doesn't work and where I need your help: page=\ggg(\subfigure)
I want it to be like page=64
when \subfigure
is1
, page=61
when \subfigure
is2
, and so on.
(I have looked at some similar questions on stackexchange but I don't understand the answers.)
\documentclass[class=minimal,border=0pt,tikz]{standalone}
\usepackage{tikz}
\usepackage{arrayjob}
\begin{document}
\newarray\ggg
\readarray{ggg}{64&61&41}
\ggg(1)
\foreach \subfig in {1,2,3}
{
%This is Figure \subfig
\includegraphics[page=\ggg(\subfig)]{./mysubfigures.pdf};
}
\end{document}
Best Answer
The problem here is that
arrayjob
does some nasty stuff to get the value out of the array and this is not compatible with how\includegraphics
handles its arguments.There are two solutions:
1. expand and then use
Here
\checkARRAYNAME(INDEX)
will save the value in the macro\cachedata
so we can use it in the arguments normally since that will not need special treatment to rewrite to the value.2. use pgfmath's arrays
Since you are using
tikz
the packagepgfmath
is already loaded and it is able to understand arrays. Simply do:A third way
Unless you really need arrays somewhere else in your document, you do not need them here as you can just exploit the excellent
\foreach
syntax: