i have following MWE. For the first case with test.csv works my code very fine for the second dataset test_data.csv crashes the compiler with:
[cmd]
! Missing $ inserted.
<inserted text>
$
l.52 OK: \csvval{test_
data.csv}{1,1} % fail caused by '_' in file name
?
[/cmd]
Code: Select all
\documentclass[
fontsize=12pt,% changed because of the package info in the log file
DIV=14
]{scrreprt}
\usepackage[english]{babel}
\usepackage{readarray}
\usepackage{xifthen}
% https://tex.stackexchange.com/questions/562789/how-to-look-up-a-cell-value-of-a-multi-column-csv-file
% https://latex.org/forum/viewtopic.php?f=5&t=34743
% \csvval[<separator>]{file.csv}{row,column}
\newcommand{\csvval}[3][]{%
% https://stackoverflow.com/questions/2144176/latex-newcommand-default-argument-is-empty
\ifthenelse{\isempty{#1}} {%default separator
\readarraysepchar{,}%
} {% else
\readarraysepchar{#1}%
}%
\readdef{#2}\csvvaldata%
\readarray\csvvaldata\csvvalarray[-,\ncols]%
\arraytomacro\csvvalarray[#3]\csvval%
}
\begin{document}
\begin{filecontents*}{test_data.csv}
val11; 0.1
val21; 0.5
val31; 5e-3
val41; 22
\end{filecontents*}
\begin{filecontents*}{test.csv}
val11; 0.1
val21; 0.5
val31; 5e-3
val41; 22
\end{filecontents*}
OK: \csvval[;]{test.csv}{1,1}\csvval%
FAIL: \csvval[;]{test.csv}{3,2}\csvval%
%OK: \csvval[;]{test_data.csv}{1,1} % fail caused by '_' in file name
%OK: \csvval[;]{test_data.csv}{3,2}
\end{document}
Thanks for your help!
BR,
Andreas