! Missing \endcsname inserted.
\countuno
l.67 }
From what I've seen about this error the fact that it is a tex error makes it very difficult to pinpoint its origins. Hopefully this is not the case here but I've personally been unable to find the issue with this document. I have a similar document differing only slightly in that the tabular environment is enclosed by a subtable and the control structures take a different shape. I have a feeling that it might have something to do with the counters used to do some calculations, but I haven't seen anything off with them.
In my document I loop through a master data file and typeset it into a tabular environment by looping through the data file, calculating row placements with counter arithmetic, and bundling all the contents in a \tablecontents macro to be delivered to the tabular environment and expanded.
\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{float}
\usepackage{hhline}
\usepackage{booktabs}
\usepackage[strict]{changepage}
\usepackage[position=top]{subfig}
\renewcommand\thesection{}
\makeatletter
\renewcommand\thesubsection{\@arabic\c@subsection}
\makeatother
\begin{filecontents}{data.dat}
28.1 0.7 0.9 1.2 1.4 1.5
40.0 11.2 11.7 12.0 12.2 12.9
44.7 18.2 19.3 19.7 19.8 20.4
50.9 28.0 28.9 29.4 29.6 30.1
57.0 43.2 42.2 41.6 40.7 40.4
61.5 50.2 51.0 52.1 52.6 52.7
67.0 62.8 64.5 65.5 65.6 68.5
72.2 78.3 79.2 80.7 80.8 82.7
\end{filecontents}
\pgfplotsset{compat=1.14}
\pgfplotstableread{data.dat}\Data
\begin{document}
\newcount\countuno
\newcount\countdos
\begin{table}[H]
\begin{tabular}{lll}
\toprule
$D$ & $h$ & $h/D$\\
\midrule
\gdef\tablecontents{}%
\foreach\row in {0,...,34}
{%
\countdos = \row
\countuno = \row
\divide\countuno by 5
\divide\countdos by 5
\multiply\countuno by -5
\advance\countuno by \row
\pgfplotstablegetelem{\countdos}{0}\of\Data\pgfmathsetmacro\elemtable{\pgfplotsretval}%
\ifnum\countuno=1
\xdef\tablecontents{%
\unexpanded\expandafter{\tablecontents}%
\noexpand\pgfmathprintnumber{\elemtable}%
}%
\fi
\pgfplotstablegetelem{\countdos}{\countuno}\of\Data\pgfmathsetmacro\elemtabledos{\pgfplotsretval}%
\pgfmathsetmacro\elemtabletres{\elemtabledos / \elemtable}
\xdef\tablecontents{%
\unexpanded\expandafter{\tablecontents}%
& \noexpand\pgfmathprintnumber{\elemtabledos} & \noexpand\pgfmathprintnumber{\elemtabletres}\noexpand\\
}%
\ifnum\countuno=5 \xdef\tablecontents{%
\unexpanded\expandafter{\tablecontents}%
\noexpand\midrule\noexpand\\
}%
\fi
}
\tablecontents
\bottomrule
\end{tabular}
\end{table}
\end{document}
EDIT: I've done some messing around, and I created a similar chunk of code to take the place of the table in the above and the error is still present, so it is not coming from the tabular environment. When I comment out all references to pointers the error goes away. When scrolling through future error messages the next error---occurring on the same line---is "! Missing number, treated as zero." and the next---also on the same line---is "! Extra \endcsname."
I also tried placing the code \countuno 1 \foreach\row in {0,...,5}{\multiply\countuno\row} \the\countuno before the table and it does not trigger an error so I'm not sure it is the counter arithmetic that is causing the error.
\pgfplotstablegetelem{\countdos}{[index]\countuno}\of\Data
. See p. 61 of the manual.\pgfplotstablegetelem
accepted the0
, even though you'd think it would want[index]0
, while the second wouldn't take the index and produced no useful error.