5

I would like to use a predefined list of numbers in the csvsimple-l3 range option.

The MWE will explain better:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc} 

\usepackage{csvsimple-l3}


\begin{document}

\def\auswahl{1,3}

\begin{filecontents*}[overwrite]{\jobname.csv}
Line 1
Line 2
Line 3
\end{filecontents*}

\csvreader[range=\auswahl,after line=\\]{\jobname.csv}{}{\csvcoli }

\end{document}

The result is

,3Line 2

So it reads line 2 but not the third line. I tried different define commands but up to now nothing worked.

Could anyone please help? Thanks

1 Answer 1

4

No macro is expanded when absorbing the value for range.

You can define yourself a new key that performs expansion (although this uses private functions, so it's a bit of a stretch).

\begin{filecontents*}[overwrite]{\jobname.csv}
Line 1
Line 2
Line 3
\end{filecontents*}

\documentclass[11pt]{article}
%\usepackage[utf8]{inputenc} 

\usepackage{csvsimple-l3}

\ExplSyntaxOn
\keys_define:nn { csvsim }
  {
    range-exp .code:n =
      {
        \__csvsim_set_range:e { #1 }
      },
  }
\cs_generate_variant:Nn \__csvsim_set_range:n { e }
\ExplSyntaxOff

\setlength{\parindent}{0pt} % just for the example

\def\auswahl{1,3}

\begin{document}

\subsection*{All}

\csvreader[head=false,after line=\par]{\jobname.csv}{}{\csvcoli}

\subsection*{Range}

\csvreader[head=false,range={1,3},after line=\par]{\jobname.csv}{}{\csvcoli}

\subsection*{Implicit range}

\csvreader[head=false,range-exp=\auswahl,after line=\par]{\jobname.csv}{}{\csvcoli}

\end{document}

enter image description here

I believe you should ask the author for a new feature. Actually, I see reasons for always doing expansion of the value for range.

1
  • Currently, I see no reason why not to use this as default. Is there a reason why you took e instead of x for the expansion? Commented Sep 21, 2022 at 9:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .