automationlatex

Automating figure entry in Latex for an appendix


I would like to set up a fairly simple automation for generating a Latex document. Essentially I need to do an image dump for an appendix, with a ton of images, which have a standardised filename convention. As a minimal example, one page looks like this (ignoring the headers/footers/margin adjustment etc.).

\documentclass[a4paper]{article}
\usepackage{graphicx}
\graphicspath{{../maps/}}
\begin{document}

\Large
Complete survey area
\begin{center}
\includegraphics{AOcomplete_MR_000t005}
\vfill
\includegraphics{AOcomplete_MR_005t010}
\end{center}
\pagebreak

%repeat the above until all maps are included

\end{document}

So the filenames have the format AOcomplete_MR_AAAtBBB where AAA and BBB will be some variable. Ideally I would like to provide an array of AAA and BBB, and just have all the pages populated by looping over the array. I have multiple sets of these to include as well, so after all the AOcomplete are included, I'll have similar sets with different filename prefixes, so same AAA BBB arrays, but now Choro_MR_AAAtBBB for example. Thank you.


Solution

  • You could for example use the pgffor package to create a loop:

    \documentclass{article}
    \usepackage{graphicx}
    \usepackage{pgffor}
    
    \begin{document}
    
    \Large
    Complete survey area
    \centering
    \foreach \macro in {"a","b","c"}{
      \includegraphics{example-image-\macro}
      \vfill
    }
    
    \end{document}