I would like to create some name badges using a loop. I have a spreadsheet with names and affiliations that I save in names.csv file as follows
"Name1","Surname1","Affiliation1",
"Name2","Surname2","Affiliation2",
"Name3","Surname3","Affiliation3"
I can copy the content of names.csv in a string array and use a loop to recover the entries. The following is an example of working code producing the output Surname2:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{array}
\def\names{{"Name1","Surname1","Affiliation1",
"Name2","Surname2","Affiliation2",
"Name3","Surname3","Affiliation3"}}
\begin{document}
\pgfmathparse{\names[4]}\pgfmathresult
\end{document}
I can use this idea to create hundreds of name badges in a loop. But instead of writing the whole list in the .tex file I would like to call directly my names.csv file. I used the modified code
\documentclass{article}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{array}
\def\names{{\input{names.csv}}}
\begin{document}
\pgfmathparse{\names[4]}\pgfmathresult
\end{document}
which apparently enters in an endless loop. I understood that \input{}
works just as copy-pastying, but it doesn't seem the case. Of course I can work in the spreadsheet and then copy paste the names.csv file content, but I would like to understand what happens. Any clues?
PS edit: The suggested solution is enough for my case. But still I would like to be able to define macros with \input'. It seems that
\input{}' inside a macro is not expanded immediately. I mean if I have some code in file.tex', that I want to plugin in a new macro,
\def\mymacro{\input{file}}' will save \mymacro' as '\input{file}' and will only look what's inside the file when I call the macro in the document. That's why in the previous example
\names' is not understood as an array. In the same way
\begin{filecontent*}{newfile.tex}
\input{file}
\end{filecontent*}
will save the code \input{file}' in
newfile.tex', but not the content in `file.tex'. Anyone has any idea how to force input to expand?