调试 - arrayjob 包中出现“缺少 \endcsname”

调试 - arrayjob 包中出现“缺少 \endcsname”

我想制作宏来从源文件创建图表。

我有以下代码:

\newcommand{\simplePlotWithFuncs}[9]{
\newarray\labels
\readarray{labels}{#2}
\newarray\datacol
\readarray{datacol}{#3}
\datacol(1)
\begin{figure}[hbtp!]
\centering
\begin{tikzpicture}[domain=0:25, scale=0.75, transform shape]
\begin{axis}[
xlabel=\labels(1),
ylabel=\labels(2),
legend pos={#4},
xmajorgrids=true,
ymajorgrids=true,
grid style=dashed,
width=\textwidth*0.8,
height=\textwidth*0.5,
cycle list name = color list,
each nth point = 1,
filter discard warning=false
]
\setcounter{counter}{0}
\foreach \datafile in {#1} {
\addplot+[only marks, mark=square*] table [x=\datacol(1), y=\datacol(2), col sep=comma] {\datafile};
\addtocounter{counter}{-1}
}
\pgfplotsset{cycle list shift=\value{counter}-1}
\foreach \func in {#9} {
\addplot+[mark=none, dashed]{\func};
}
\legend{#5}
\end{axis}
\end{tikzpicture}
\caption{#6}
\label{#7}
\smallskip
{\small #8}
\end{figure}
\medskip
}

我是这样使用它的:

\simplePlotWithFuncs
    {data/ratioThProcs-size10.csv,
     data/ratioThProcs-size20.csv,
     data/ratioThProcs-size90.csv,
     data/ratioThProcs-size100.csv}
    {Number of processes & Time [s]}
    {nprocs & time}
    {north east}
    {size 10x10x10,
     size 10x10x20,
     size 10x10x90,
     size 10x10x100}
    {Stiffness matrix assembling speed dependence on decomposition style}   
    {fig:threadsProcsDecompDifference}
    {Fixed size of problem. Changing style of the decomposition - ratio of MPI processes and threads. Number of threads per process is computed by the formula $\frac{24}{nprocs}$. Points are measured values, dashed line is a hyperbola got by inverse regression.}
    {0.0550340156 + 0.64833795/x, 
     0.095864 + 1.076260/x,
     0.156679 + 5.088291/x,
     0.154080159 + 5.86336629/x}

问题是,它在编译过程中导致以下错误pdflatex

! Missing \endcsname inserted.
<to be read again> 
                   \temp@@@count 
l.152      0.154080159 + 5.86336629/x}

这是由datacol像这样从数组读取引起的\datacol(1)。问题是,我不知道为什么,当我labels以相同的方式使用数组时,没有任何问题。

您知道问题是什么吗?


编辑

最小工作示例:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{subfig}     % makra pro "podobrazky" a "podtabulky"
\usepackage{tikz}       % makra pro kresleni
\usepackage{underscore}
\usepackage{amsmath}
\usepackage{pgffor}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{arrayjob}

\pgfplotsset{compat=newest}

\newcounter{counter}

\newcommand{\simplePlotWithFuncs}[9]{
\newarray\labels
\readarray{labels}{#2}
\newarray\datacol
\readarray{datacol}{#3}
\begin{figure}[hbtp!]
\centering
\begin{tikzpicture}[domain=0:25, scale=0.75, transform shape]
\begin{axis}[
xlabel=\labels(1),
ylabel=\labels(2),
legend pos=#4,
xmajorgrids=true,
ymajorgrids=true,
grid style=dashed,
width=\textwidth*0.8,
height=\textwidth*0.5,
cycle list name = color list,
each nth point = 1,
filter discard warning=false
]
\setcounter{counter}{0}
\foreach \datafile in {#1} {
\addplot+[only marks, mark=square*] table [x=\datacol(1), y=\datacol(2), col sep=comma] {\datafile};
\addtocounter{counter}{-1}
}
\pgfplotsset{cycle list shift=\value{counter}-1}
\foreach \func in {#9} {
\addplot+[mark=none, dashed]{\func};
}
\legend{#5}
\end{axis}
\end{tikzpicture}
\caption{#6}
\label{#7}
\smallskip
{\small #8}
\end{figure}
\medskip
}

\begin{document}

\simplePlotWithFuncs
    {ratioThProcs-size10.csv}
    {Number of processes & Time [s]}
    {nprocs & time}
    {north east}
    {size 10x10x10}
    {Stiffness matrix assembling speed dependence on decomposition style}   
    {fig:threadsProcsDecompDifference}
    {Fixed size of problem. Changing style of the decomposition - ratio of MPI processes and threads. Number of threads per process is computed by the formula $\frac{24}{nprocs}$. Points are measured values, dashed line is a hyperbola got by inverse regression.}
    {0.0550340156 + 0.64833795/x}

\end{document}

ratioThProcs-size10.csv

nprocs,nthreads,size,time
1,24,10,0.656395
2,12,10,0.256914
3,8,10,0.271941
4,6,10,0.174338
6,4,10,0.130503
8,3,10,0.123015
12,2,10,0.173938
24,1,10,0.114695

编辑2

我认为问题可能是由axis环境的本机行为引起的,据我所知,变量直到循环结束才会扩展,如所述这里例如。

所以我想我应该使用类似的东西\edef,但我不知道如何......


大幅降低 MWE

\documentclass{article}
\usepackage{pgfplots}
\usepackage{arrayjob}

\begin{filecontents}{ratioThProcs-size10.csv}
nprocs,nthreads,size,time
1,24,10,0.656395
2,12,10,0.256914
3,8,10,0.271941
4,6,10,0.174338
\end{filecontents}

\newcommand{\simplePlotWithFuncs}[2]{
\newarray\datacol
\readarray{datacol}{#2}
\begin{tikzpicture}
\begin{axis}
\foreach \datafile in {#1} {
\addplot table [x=\datacol(1),y=\datacol(2),col sep=comma] {\datafile};
}
\end{axis}
\end{tikzpicture}
}

\begin{document}
\simplePlotWithFuncs{ratioThProcs-size10.csv}{nprocs & time}
\end{document}

相关内容