I am trying to loop and include subfigures in LaTex.
The dir contains the following figures:
newcommand*{fields}{
Artificial intelligence,
Economics,
% Ethnic & cultural studies,
}
I then loop over and insert each file:
begin{figure}[H]
caption{Citation Degree Distribution}label{fig:citation_degree_dist}
foreach name in fields {
begin{subfigure}[p]{0.47textwidth}
centering
resizebox{.4textwidth}{!}{%
includegraphics[width=textwidth]{figures/citation_descriptive_stats/name}
}
caption{name}
end{subfigure}quad
}
end{figure}
It works well, but if I include any field with &
if breaks:
Missing endcsname inserted. <to be read again>
Does anyone know why this is happening and how I could fix it?