I just want to automate a report, but i have to add photos from a folder one after the other (all with the same termination(.jpg)), is there a macro or something that adds all the photos at once? For now im doing it manually, but it would be a lot faster and easier like this. I suppose I need to write a macro and then add it in my LaTeX file, but im new in this I don't know how to do it. I'm using windows

{\section{Imatges seguiment}


That's what I'm calling manually, so the thing is taking all the photos that are in the same folder (Note: not all the photos start with coffee, this is just an example)

  • Welcome to TeX.SE! Please show us with some small complete document, how you do this now "manually". It is not clear what you mean with "add all photos at once".
    – Zarko
    Jun 28 '19 at 8:11
  • 1
    Including many figures from a directory might be related.
    – leandriis
    Jun 28 '19 at 8:18
  • 1
    @kombo, please edit your question and add information there and not in comment. For including images the extension .jpg is not needed, if all photos have the same size, you can use key Gin, and if photos are collected in one figure, you can include them in the loop (as suggested @leandriis. in his comment. Also you can define path to your folder with photos (images).
    – Zarko
    Jun 28 '19 at 8:24
  • 2
    See the 'incgraph' package and its '\incmultigraph' command
    – Ross
    Jun 28 '19 at 12:22
  • 1
    @kombo thanks for the edit, now the question is more clear. However, it is more or less a duplicate of tex.stackexchange.com/questions/53458/… or tex.stackexchange.com/questions/7653/… or the already mentioned tex.stackexchange.com/questions/98748/… (look at all the answers to find the ones that are suitable for your operating system and (lack of) naming convention).
    – Marijn
    Jul 2 '19 at 11:30



To make mypics.txt in Windows is simply dir *.jpg > mypics.txt if a remember correctly, but it is best if you remove the extensions. As commented, the image extensions is not needed (except when you have JPG, PNG and PDF files with the same name) and this way are not showed in the gallery.

  • Perdona, no entiendo mucho, la funcion de mypics.txt cual es? El gallerySetup supongo que es para definir como se van a posicionar las fotos? Y me da error error solo de poner el {image-gallery} del documentclass. Perdona la ignorancia y gracias de antemano.
    – kombo
    Jul 2 '19 at 10:46
  • Es una simple lista de los nombres de las imágenes que deben salir, una por linea, que se puede hacer con todas las imágenes como he explicado arriba o simplemente escribiéndola a mano con las que quieras. No explicas nada sobre el error, pero parece que te falta el archivo image-gallery.cls. En https://ctan.org/pkg/image-gallery tienes todo lo necesario.
    – Fran
    Jul 6 '19 at 19:14

A task such as this usually boils down to one line so save the following into a file.


for %%f in (*.jpg) do echo \begin{figure}[h!] \includegraphics[width=\linewidth]{images/%%f} \end{figure}>>includes.tex

To use for png simply change the *.jpg to *.png

For multiple types its safest to use *.jpg,*.png but then they will be grouped by types.

Place that file in the images folder alongside the jpgs and double click it you will find in include.tex a list like this for cut and paste into report.tex.

\begin{figure}[h!] \includegraphics[width=\linewidth]{images/image1.jpg} \end{figure}
\begin{figure}[h!] \includegraphics[width=\linewidth]{images/image10.jpg} \end{figure}
\begin{figure}[h!] \includegraphics[width=\linewidth]{images/image18.jpg} \end{figure}
\begin{figure}[h!] \includegraphics[width=\linewidth]{images/image19.jpg} \end{figure}
\begin{figure}[h!] \includegraphics[width=\linewidth]{images/image2.jpg} \end{figure}
\begin{figure}[h!] \includegraphics[width=\linewidth]{images/image20.jpg} \end{figure}
\begin{figure}[h!] \includegraphics[width=\linewidth]{images/image3.jpg} \end{figure}

Note it may not be what you expect since in my case the order is alphabetic natural order and I would need to at least rename those single numbered files to image01.jpg image02.jpg etc. to ensure all are listed in numeric order. If you want to test what the sequence will potentially look like once compiled you could run this self producing contact-sheet.cmd .

echo \documentclass{article}\usepackage{graphicx}\begin{document}\centering My Images\newpage>includes.tex
for %%f in (*.jpg,*.png) do echo \begin{figure}[h!] \includegraphics[width=\linewidth]{%%f} \end{figure}>>includes.tex
echo \end{document}>>includes.tex
pdflatex includes

Not the answer you're looking for? Browse other questions tagged or ask your own question.