I use LaTeX for scientific reporting in brain imaging (fMRI). I have a tabular
array in LaTeX, that contains quite a lot of rows and columns, which both are brain regions and in the each intersecting cell there is some data about their connections.
The content of this tabular
array is defined separately in another .tex file that is loaded using \input
command. In this another .tex file the content of each cell of the tabular
array is defined separately using hundreds of \newcommand
commands. In tabular
array there is no other content except these \newcommand
commands. tabular
array is inside \begin{spreadtab}
to permit some basic calculations of cells values (although this is not a requirement). Everything works fine so far.
So, the \newcommand
definitions look like this:
\newcommand{\origREGIONONEdestREGIONONE}{ NA } % NA for cells on the diagonal.
\newcommand{\origREGIONONEdestREGIONTWO}{ - } % this is the default case.
...
\newcommand{\origREGINOTWOdestREGIONTWO}{ NA }
\newcommand{\origREGIONTWOdestREGIONONE}{ \ref{Spielberg1981} }
\newcommand{\origREGIONTWOdestREGIONTHREE}{ bilateral \ref{Cameron1989} }
...
There is a specific \newcommand
definition for all column x row intersections.
The tabular
array code looks like this (a 3x3 example but in reality it is bigger than 20x20):
\tiny
\begin{table}
\scalebox{0.6}{
\begin{spreadtab}{{tabular}{*{3}{c}}}
\hline
\to/from :={} & REGIONONE :={} & REGIONTWO :={} & REGIONTHREE :={} \\
\hline
to REGIONONE :={} & \origREGIONONEdestREGIONONE :={} & \origREGIONTWOdestREGIONONE :={} &\origREGIONTHREEdestREGIONONE :={} \\
to REGIONTWO :={} & \origREGIONONEdestREGIONTWO :={} & \origREGIONTWOdestREGIONTWO :={} &\origREGIONTHREEdestREGIONTWO :={} \\
to REGIONTHREE :={} & \origREGIONONEdestREGIONTHREE :={} & \origREGIONTWOdestREGIONTHREE :={} &\origREGIONTHREEdestREGIONTHREE :={} \\
\hline
\end{spreadtab}
} % end scalebox
\caption{A table of connections between brain regions 1, 2 & 3}
\begin{enumerate}
\item \cite{Spielberg1981}\label{Spielberg1981}
\item \cite{Cameron1989}\label{Cameron1989}
\end{enumerate}
\end{table}
\normalsize
Now what I want is to be able to generate a similar tabular
definition dynamically according to a list or an array of strings (or using any possible datatype):
in MATLAB syntax it would be: ListOfBrainRegions = { 'BRAINREGIONABC', 'BRAINREGIONDEF', 'BRAINREGIONXYZ' }
In Python syntax: ListOfBrainRegions = [ 'BRAINREGIONABC', 'BRAINREGIONDEF', 'BRAINREGIONXYZ' ]
The list or array would be translated into a code like this inside spreadtab
(or without spreadtab
if it causes some problems):
\hline
\to/from :={} & REGIONABC :={} & REGIONDEF :={} & REGIONXYZ :={} \\
\hline
to REGIONABC :={} & \origREGIONABCdestREGIONABC :={} & \origREGIONDEFdestREGIONABC :={} &\origREGIONXYZdestREGIONABC :={} \\
to REGIONDEF :={} & \origREGIONABCdestREGIONDEF :={} & \origREGIONDEFdestREGIONDEF :={} &\origREGIONXYZdestREGIONDEF :={} \\
to REGIONXYZ :={} & \origREGIONABCdestREGIONXYZ :={} & \origREGIONDEFdestREGIONXYZ :={} &\origREGIONXYZdestREGIONXYZ :={} \\
\hline
So, how should I define ListOfBrainRegions
in LaTeX? And then how can I generate LaTeX code during compiling of a .tex file? If I was to program this in some other programming language, for example in MATLAB, Common Lisp or awk the task (generating program code) would not be difficult at all. It seems that LaTeX does not have built-in arrays, if
... elseif
... else
commands nor for
or while
loops, although some packages provide some added functionality. So, how this could be implemented? Or, which LaTeX commands, packages and/or extra tools should I use for this task?
Thank you for any help :)