2

I want to use a l3regex replacement together with a csv list.

\documentclass[utf8,fleqn]{scrartcl}
\usepackage{l3regex}
\usepackage{csvsimple}


\begin{filecontents*}{\jobname.csv}
a*9-2*b-13.1*a
\end{filecontents*}


\begin{document}

 \ExplSyntaxOn
 \newcommand{\ersetz}[1]{
 \tl_set:Nn \l_my_tl {#1}
\regex_replace_all:nnN { ([a-z])\*(\d+) } { \1 \c{cdot} \2 } \l_my_tl
\regex_replace_all:nnN { (\d+)\*([a-z]) } { \1  \2 } \l_my_tl
\regex_replace_all:nnN { \. } {\,} \l_my_tl
$\l_my_tl$
 }
\ExplSyntaxOff

 \csvreader[no head, late after line=\\]{\jobname.csv}{}{
\ersetz{\csvcoli}%\bkey{$\sage{latex(\csvcoli)}$}
 }


\ersetz{  a*9-2*b-13.1*a}



\end{document}

The lower command works, but it does not in the csv-environment.

old question

0

1 Answer 1

1

You have to expand \csvcoli: use \tl_set:Nx.

\begin{filecontents*}{\jobname.csv}
a*9-2*b-13.1*a
\end{filecontents*}

\documentclass{article}
\usepackage{xparse,csvsimple}

\ExplSyntaxOn

\NewDocumentCommand{\ersetz}{m}
 {
  \tl_set:Nx \l_tmpa_tl {#1}
  \regex_replace_all:nnN { ([a-z])\*(\d+) } { \1 \c{cdot} \2 } \l_tmpa_tl
  \regex_replace_all:nnN { (\d+)\*([a-z]) } { \1  \2 } \l_tmpa_tl
  \regex_replace_all:nnN { \. } {\cB\{\,\cE\}} \l_tmpa_tl
  $\l_tmpa_tl$
 }
\ExplSyntaxOff

\begin{document}

\csvreader[no head, late after line=\\]{\jobname.csv}{}{%
  \ersetz{\csvcoli}%
}

\ersetz{ a*9-2*b-13.1*a}

\end{document}

I added braces around the comma, so the spacing will be right.

enter image description here

1
  • \c{mathord}\, would also work.
    – egreg
    Commented Feb 7, 2020 at 11:47

You must log in to answer this question.

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