LaTeX forum ⇒ Generalreadarray fails with underline in path

LaTeX specific issues not fitting into one of the other forums of this category.
gallioleo
Posts: 13
Joined: Thu Nov 18, 2021 6:35 pm

readarray fails with underline in path

Postby gallioleo » Mon Aug 15, 2022 7:51 pm

Hello Latex Gurus,

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]



\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}



Do you have any suggestions how i can enable underlines in filename? An addition works the first call of \csvval as expected the second produces garbage. The thing is i like to extract from an csv file with one call an value.

Thanks for your help!

BR,
Andreas

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook

Return to “General”

Who is online

Users browsing this forum: No registered users and 9 guests