0

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}
    \begin{figure}[h]
        \includegraphics[width=\linewidth]{images/coffee1.jpeg}
    \caption{Coffee.}
      \end{figure}
      \begin{figure}[h]
        \includegraphics[width=\linewidth]{images/coffee2.jpeg}
    \caption{Coffee.}
      \end{figure}
      \begin{figure}[h]
        \includegraphics[width=\linewidth]{images/coffee3.jpeg}
    \caption{Coffee.}
      \end{figure}


\newpage}

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)

Åke
  • 167
kombo
  • 1
  • 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 08:11
  • \begin{figure}[h!] \includegraphics[width=\linewidth]{images/image1.png} \end{figure} Doing it as many photos as I have, and what i want to know is if there is any way to take all the photos at once, like twenty photos in the same folder. – kombo Jun 28 '19 at 08:14
  • 1
  • 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 08: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 https://tex.stackexchange.com/questions/53458/inserting-figures-using-loops or https://tex.stackexchange.com/questions/7653/how-to-iterate-through-the-name-of-files-in-a-folder or the already mentioned https://tex.stackexchange.com/questions/98748/including-many-figures-from-a-directory (look at all the answers to find the ones that are suitable for your operating system and (lack of) naming convention). – Marijn Jul 02 '19 at 11:30

2 Answers2

2

mwe

\documentclass[a4paper]{image-gallery}
\gallerySetup{left=20mm,right=20mm,top=20mm,bottom=20mm,
 width=5cm,height=3.75cm,rows=6,columns=3,autorotate=true}
\begin{document}
\makeGallery{mypics.txt}
\end{document}

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.

Fran
  • 80,769
  • 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 02 '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 06 '19 at 19:14
1

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

Mylist.cmd

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