2

I am using expl3 now, I want to read data from file, and store them in a comma list, then use the comma list one by one.

I don't have any code, I just know exp13 have these function, so need someone help me.

(I guess \seq_gset_from_clist:NN maybe used after store the following data in a comma list.)

\begin{filecontents*}{\jobname.dat}
 1.23
 -3.78
 1.23
 -3.78
\end{filecontents*}

1 Answer 1

3

Official answer

Open a read stream and map it line by line.

\begin{filecontents*}{\jobname.dat}
 1.23
 -3.78
 1.23
 -3.78
\end{filecontents*}

\documentclass{article}
\usepackage{expl3}

\ExplSyntaxOn
\ior_new:N \g_zongxian_readfile_stream
\ior_open:Nn \g_zongxian_readfile_stream { \jobname.dat }
\clist_clear:N \l_tmpa_clist
\ior_map_inline:Nn \g_zongxian_readfile_stream
 { \clist_put_right:Nn \l_tmpa_clist { #1 } }

\clist_show:N \l_tmpa_clist

\stop

Unofficial answer

Setting \endlinechar has no real interface in expl3.

\begin{filecontents*}{\jobname.dat}
 1.23
 -3.78
 1.23
 -3.78
\end{filecontents*}

\documentclass{article}
\usepackage{expl3}

\ExplSyntaxOn

\tl_set_from_file:Nnn \l_tmpa_tl { \endlinechar=`, } { \jobname.dat }
\clist_set:NV \l_tmpa_clist \l_tmpa_tl

\clist_show:N \l_tmpa_clist

\stop

Output on the console for both methods

The comma list \l_tmpa_clist contains the items (without outer braces):
>  {1.23}
>  {-3.78}
>  {1.23}
>  {-3.78}.

You must log in to answer this question.

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