# CSV file and QR codes

I have a .csv file with some URLs.

• First I want to store each URL in a variable.
• Second I want to print the variables in QR codes.

What's the easiest way to do this?

MWE

\documentclass{article}

\usepackage{qrcode}

\usepackage{blindtext}

\begin{filecontents*}{url.csv}
url1
url2
url3
url4
url5
\end{filecontents*}

\begin{document}

\section{One}
\blindtext[1]

\qrcode[height=1in]{url1} % there should be a variable

\section{Two}
\blindtext[1]

\qrcode[height=1in]{url2} % there should be a variable

\section{Three}
\blindtext[1]

\qrcode[height=1in]{url3} % there should be a variable

\section{Four}
\blindtext[1]

\qrcode[height=1in]{url4} % there should be a variable

\section{Five}
\blindtext[1]

\qrcode[height=1in]{url5} % there should be a variable

\end{document}

It's not clear what “variable” means. Here I define a command \urlvar with an argument that points to the URL in the corresponding line.

\begin{filecontents*}{\jobname.dat}
https://tex.stackexchange.com
https://tex.stackexchange.com/questions/420647/
https://tex.stackexchange.com/questions/420647/csv-file-and-qr-codes
https://tex.stackexchange.com/users/101831/sr-schneider
\end{filecontents*}

\documentclass{article}
\usepackage{xparse}
\usepackage{qrcode}
\usepackage{url}

\ExplSyntaxOn
\ior_new:N \g_schneider_urlfile_ior
\seq_new:N \l_schneider_urlfile_seq

{% #1 is the name of the file
\seq_clear:N \l_schneider_urlfile_seq
\ior_open:Nn \g_schneider_urlfile_ior { #1 }
\ior_str_map_inline:Nn \g_schneider_urlfile_ior
{
\seq_put_right:Nn \l_schneider_urlfile_seq { ##1 }
}
\ior_close:N \g_schneider_urlfile_ior
}
\NewExpandableDocumentCommand{\urlvar}{m}
{
\seq_item:Nn \l_schneider_urlfile_seq { #1 }
}
\ExplSyntaxOff

\begin{document}

\section{One}
\texttt{\urlvar{1}}

\qrcode[height=1in]{\urlvar{1}} % there should be a variable

\section{Two}
\texttt{\urlvar{2}}

\qrcode[height=1in]{\urlvar{2}} % there should be a variable

\section{Three}
\texttt{\urlvar{3}}

\qrcode[height=1in]{\urlvar{3}} % there should be a variable

\section{Four}
\texttt{\urlvar{4}}

\qrcode[height=1in]{\urlvar{4}} % there should be a variable

\end{document}

You need not to use special macro for csv reading when you have one URL per line in your working file. You can simply use \read TeX primitive:

If \urlvar is empty then you are at the end of the file. It means that you can process all lines in the loop:

\loop
\if^\urlvar^\else
... do something with \urlvar
\repeat

Full working example (which reads the file url.csv) follows: