# Adding/subtracting to the /thecsvrow number in csvsimple

Assume a simple example centered on the csvsimple package.

\documentclass{standalone}

\usepackage{csvsimple}
\usepackage{fp}
\usepackage[table]{xcolor}

\begin{filecontents*}{input.csv}
Foo,Bar,Baz,Qux
A,1616,0.394,0.309
B,6999,0.336,0.999
C,261,0.378,0.284
D,171,0.332,0.386
E,402,0.428,0.241
\end{filecontents*}

\begin{document}

% COUNT THE ROWS
\edef\totalrows{\thecsvrow}%
%
% VISUALIZE TABLE
table head=\hline \rowcolor{gray} \# & foo & bar & baz\\\hline\hline,
late after line=\\\hline,
filter expr={
test{\ifnumgreater{\thecsvinputline}{1}}
and test{\ifnumless{\thecsvinputline}{5}}
}
]{input.csv}{
Foo=\foo,
Bar=\bar,
Baz=\baz,
Qux=\qux
}
%{\FPeval{\result}{\thecsvrow+50} & \textit{\foo} & \bar & \baz}  % NOT WORKING: simply swallows the line numbers
{\thecsvrow & \textit{\foo} & \bar & \baz}

\end{document}


I wish the line number (defined by \thecsvrow) to start at 51, not at one. Thus, the rows should display the numbers 51, 52 and 53 in the first column.

I understand that the proposed (but commented out) code line cannot possibly work, because the desired number would need to be called by invoking \result again. Nonetheless, I cannot think of a solution to this problem and hope someone in this forum can.

Use TeX native integer arithmetic to make the change: \the\numexpr50+\thecsvrow\relax.

\documentclass{standalone}

\usepackage{csvsimple}
\usepackage{fp}
\usepackage[table]{xcolor}

\begin{filecontents*}{input.csv}
Foo,Bar,Baz,Qux
A,1616,0.394,0.309
B,6999,0.336,0.999
C,261,0.378,0.284
D,171,0.332,0.386
E,402,0.428,0.241
\end{filecontents*}

\begin{document}

% COUNT THE ROWS
\edef\totalrows{\thecsvrow}%
%
% VISUALIZE TABLE
table head=\hline \rowcolor{gray} \# & foo & bar & baz\\\hline\hline,
late after line=\\\hline,
filter expr={
test{\ifnumgreater{\thecsvinputline}{1}}
and test{\ifnumless{\thecsvinputline}{5}}
}
]{input.csv}{
Foo=\foo,
Bar=\bar,
Baz=\baz,
Qux=\qux
}
%{\FPeval{\result}{\thecsvrow+50} & \textit{\foo} & \bar & \baz}  % NOT WORKING: simply swallows the line numbers
{\the\numexpr50+\thecsvrow\relax & \textit{\foo} & \bar & \baz}

\end{document}


If you wanted the fp approach as originally attempted, you only need to add \result to the end of the cell. That is because \FPeval{\result}{\thecsvrow+50} does the calculation and stores it in \result, but does not output anything. However, in that state, the output is floating point, with entries like 51.0000000000000. So you also need to \FPtruncate to get the same output as above:

\documentclass{standalone}

\usepackage{csvsimple}
\usepackage{fp}
\usepackage[table]{xcolor}

\begin{filecontents*}{input.csv}
Foo,Bar,Baz,Qux
A,1616,0.394,0.309
B,6999,0.336,0.999
C,261,0.378,0.284
D,171,0.332,0.386
E,402,0.428,0.241
\end{filecontents*}

\begin{document}

% COUNT THE ROWS
\edef\totalrows{\thecsvrow}%
%
% VISUALIZE TABLE
table head=\hline \rowcolor{gray} \# & foo & bar & baz\\\hline\hline,
late after line=\\\hline,
filter expr={
test{\ifnumgreater{\thecsvinputline}{1}}
and test{\ifnumless{\thecsvinputline}{5}}
}
]{input.csv}{
Foo=\foo,
Bar=\bar,
Baz=\baz,
Qux=\qux
}
{\FPeval{\result}{\thecsvrow+50}\FPtrunc\result{\result}{0}\result & \textit{\foo} & \bar & \baz}  % NOT WORKING: simply swallows the line numbers
%{\the\numexpr50+\thecsvrow\relax & \textit{\foo} & \bar & \baz}

\end{document}

• Wow! You are an amazing source of information. Thanks for the rapid replies. – Michael Gruenstaeudl Feb 15 at 19:54
• @MichaelGruenstaeudl Glad to help. – Steven B. Segletes Feb 15 at 19:58