latex - inputting all items of a list into an environment -
i have list of names input given surrounding, e.g. box. put in different way: i'd latex create surrounding every item in given list.
here's list: frank, fred, fran
here's surrounding:
\fbox{\name}
\name following: inputs first item list , creates \fbox each successive item in list until end of list, result outputting same (but saving typing of)
\fbox{frank} \fbox{fred} \fbox{fran}
i thinking of list of names "count" (redefining 1 frank, 2 fred...) , might wrong approach. realise command can not 2 things @ once.
if there's simple solution this: called , can find it? searching 'variables' or 'foreach' didn't help.
depending on application, can either specify list explicitly, or in file:
as explicit list (see how iterate on comma separated list?):
\documentclass{article} \usepackage{etoolbox} \newcommand{\printlist}[1]{% \begin{enumerate} \renewcommand*{\do}[1]{\item \fbox{##1}}% \docsvlist{#1}% \end{enumerate}% } \begin{document} \printlist{frank, fred, fran} \end{document}as file in (say)
names.csv:\documentclass{article} \usepackage{filecontents} \begin{filecontents*}{names.csv} frank fred fran \end{filecontents*} \usepackage{datatool} \newcommand{\printlist}[1]{% \dtlloaddb[noheader,keys=name]{namesdb}{#1}% load names database file \begin{enumerate} \dtlforeach{namesdb}{\name=name}{\item \fbox{\name}} \end{enumerate} } \begin{document} \printlist{names.csv} \end{document}
in both instances, output resembles:

Comments
Post a Comment