2

i did read the following thread:

How to get a list of the filenames of the figures embedded in a document

and found myself in a similar problem. The actual problem is that the filenames printed by the accepted solution in the thread mentioned do not have any linking to the actual figure numbering. Ofcourse they occur in the order the figures do in the text. But I not only pass on the PDF produced I also do pass on the images included (or not) in the document just in case they got rendered unreadable by scaling, typesetting, low quality printouts, duplication of existing print versions etc. Therefor I do usually include a table that shows the number of the figure in one column and the filename in the next one. Just to make things 'idiot-proof'. Now the solution shown in the thread mentioned is very promising so far but how do I get the numbers in there automatically as well. Pressing it all into a 'tabular' should not be too hard in my opinion…

I am using pages like the one produced by this Code (although this may be the most extreme example through out the whole document)

\section{Illustrationen}
Hier seien nun illustrativ Bildschirminhalte für die dargestellte Menüführung abgebildet.
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2913px,natheight=633px]{img/LCD-Menu/statusanzeige.jpg}
    \caption{LCD-Menü: Statusanzeige}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2785px,natheight=657px]{img/LCD-Menu/zeit.jpg}
    \caption{LCD-Menü: Status\textbackslash{}Zeitanzeige}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=1905px,natheight=395px]{img/LCD-Menu/aktTemp.jpg}
    \caption{LCD-Menü: Status\textbackslash{}Temperaturanzeige}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2401px,natheight=633px]{img/LCD-Menu/schaltzustand.jpg}
    \caption{LCD-Menü: Status\textbackslash{}Schaltzustandsanzeige}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2529px,natheight=593px]{img/LCD-Menu/schaltschwellen.jpg}
    \caption{LCD-Menü: Status\textbackslash{}Schaltschwellen}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=3065px,natheight=697px]{img/LCD-Menu/konfig.jpg}
    \caption{LCD-Menü: Konfig.}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2129px,natheight=477px]{img/LCD-Menu/anzLasten1.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Anzahl der Lasten $=1$}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2121px,natheight=497px]{img/LCD-Menu/anzLasten2.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Anzahl der Lasten $=2$}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2525px,natheight=589px]{img/LCD-Menu/0PunktAbgl-.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Offset negativ}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2785px,natheight=585px]{img/LCD-Menu/0PunktAbgl+.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Offset positiv}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2397px,natheight=581px]{img/LCD-Menu/setzeSchaltschwellen.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Schaltschwellen setzen}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2313px,natheight=493px]{img/LCD-Menu/schwellenheizer.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Schaltschwellen\textbackslash{}Heizer}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2873px,natheight=665px]{img/LCD-Menu/heizeroben.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Schaltschwellen\textbackslash{}Heizer\textbackslash{}Obere Schwelle}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2705px,natheight=537px]{img/LCD-Menu/heizerunten.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Schaltschwellen\textbackslash{}Heizer\textbackslash{}Untere Schwelle}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2705px,natheight=537px]{img/LCD-Menu/schwellenkuehler.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Schaltschwellen\textbackslash{}Kühler}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2497px,natheight=577px]{img/LCD-Menu/kuehleroben.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Schaltschwellen\textbackslash{}Kühler\textbackslash{}Obere Schwelle}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2497px,natheight=577px]{img/LCD-Menu/kuehlerunten.jpg}
    \caption{LCD-Menü: Konfig.\textbackslash{}Schaltschwellen\textbackslash{}Kühler\textbackslash{}Untere Schwelle}
\end{figure}
\begin{figure}[H]
    \includegraphics[width=\columnwidth,natwidth=2853px,natheight=645px]{img/LCD-Menu/wertuebernehmen.jpg}
    \caption{LCD-Menü: Dialog \inQuotes{Wert übernehmen}}
\end{figure}

and in the main file

many many stuff
                \bibliography{literatur} %Eine Datei 'literatur.bib' wird hierfür benötigt.

                \clearpage

                \addcontentsline{toc}{chapter}{Abbildungsverzeichnis}

                \setlength{\cftfignumwidth}{3em}
                \listoffigures

\end{document}
  • Are you inserting the images in the figure environment, and then using the normal \listoffigures? – Alan Munn Feb 3 at 19:12
  • just added one of the most extreme examples i could find – der bender Feb 3 at 19:18
  • tldr yes i do.... – der bender Feb 3 at 19:19
0

Here's a slightly different way of doing things which integrates the list into the document more seamlessly. The basic idea is to create a new \listofimages and then make a command the goes inside the figure caption to add the entry.

\documentclass{article}
\usepackage{graphicx}
\usepackage[T1]{fontenc} % not needed for LuaTeX or XeLaTeX
\usepackage{letltxmacro}
\usepackage{tocloft}
% make a new list of image filenames
\newlistof{images}{img}{List of Filenames}
\renewcommand{\cftimgtitlefont}{\normalfont\bfseries\Large}
% redefine \includegraphics to save the filename inserted
\LetLtxMacro{\OldIncludegraphics}{\includegraphics}
\renewcommand{\includegraphics}[2][]{%
    \gdef\CurrentImage{#2}%
    \OldIncludegraphics[#1]{#2}%
}
% make a command to add to the list of images
% since this will be inserted into the caption command, we check for the figure environment
%
\makeatletter
\newcommand{\Img}{\def\@tmp{figure}\ifx\@tmp\@currenvir\addcontentsline{img}{images}{Figure \thefigure. \texttt{\protect\detokenize{\CurrentImage}}}\else\relax\fi}
\makeatother
% redefine caption to add \Img command
% technique here from https://tex.stackexchange.com/a/97279/
\LetLtxMacro{\OldCaption}{\caption}
\renewcommand{\caption}[2][]{%
    \if\relax\detokenize{#1}\relax
    \OldCaption{#2}\Img
    \else
    \OldCaption[#1]{#2}\Img
    \fi}

\begin{document}
\listoffigures
\listofimages
\clearpage
\begin{figure}
\includegraphics[width=.2\linewidth]{example-image-a.pdf}
\caption{Example Image A}
\end{figure}

\begin{figure}
\includegraphics[width=.2\linewidth]{example-image-c.pdf}
\caption{Example Image C}
\end{figure}

\end{document}


\documentclass[dottedtoc]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{arsclassica}

\usepackage{lipsum}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{A chapter}
\section{A section}
\subsection{A subsection}
\subsubsection{A subsubsection}

\end{document}

output of TOC

  • gonna give this a try – der bender Feb 8 at 16:29
  • the subcaption package does not like this and therefor stops working with this solution (glad im not really using subcaptions or subfigures in my main document) anyway it is somewhat annoying – der bender Feb 8 at 16:42
  • @derbender Well given that you didn't give us a working minimal example of what you were doing, it's hard to anticipate problems. – Alan Munn Feb 8 at 16:45
  • not your fault.... – der bender Feb 8 at 16:46
  • appart from that i apprechiate Solutions that work for ALL my documents no matter which feature i happen to use in one document and not to use in another. and in past documents i did use the subfigures and subcaptions. this also makes giving a mwe quite a bit more challenging as i just tried this solution and it does work for me i should Maybe denote this as accepted solution and close the thread… thanks to you all – der bender Feb 8 at 16:49
4

Your example is the opposite of minimal. Regardless, I came across an answer on stackoverflow for retrieving each image filename (include the filename of a graphic into a caption?) which you can make use of.

To avoid having to change anything in your current files, you could redefine the \caption command in the preamble (the caption package won't like this however - see edit below for an alternative).

Code:

\documentclass{article}
\usepackage{graphicx} % \includegraphics
\usepackage{letltxmacro} % \LetLtxMacro
\usepackage{etoolbox} % \patchcmd

% Source: https://stackoverflow.com/questions/3736292/in-latex-is-there-a-way-to-include-the-filename-of-a-graphic-into-a-caption
\makeatletter
\patchcmd{\Gin@setfile}% <cmd>
  {\ProvidesFile}% <search>
  {\xdef\imgfilename{#3}\ProvidesFile}% <replace>
  {}{}% <success><failure>
\makeatother
% Redefine caption to save us having to manually add the \write to each figure
\LetLtxMacro{\OldCaption}{\caption}
\renewcommand{\caption}[1]{%
    \OldCaption{#1}%
    \immediate\write\tempfile{Figure \thefigure: \imgfilename\space (page \thepage)}%
}
% Open output stream
\newwrite\tempfile
\immediate\openout\tempfile=figurelist.txt
\begin{document}
\begin{figure}
  \centering
  \includegraphics[width=.5\linewidth]{foo.png}
  \caption{My caption}
\end{figure}
\clearpage
\begin{figure}
  \centering
  \includegraphics[width=.5\linewidth]{bar.png}
  \caption{My caption}
\end{figure}
% Close output stream
\immediate\closeout\tempfile
\end{document}

Output (figurelist.txt):

Figure 1: foo.png(page 1)
Figure 2: bar.png(page 2)

Edit:

As pointed out in a comment, this will also try to add file names if a caption is used in another type of float environment (e.g. table), which is probably not what you want (\imgfilename will hold the last actual file name and so you will see duplicates in figurelist.txt). A better solution would be a custom caption command that you use in figures with images only:

% Alternative - define a new type of caption to use in figures with grpahics
\newcommand\imgcaption[1][]{%
    \caption{}%
    \immediate\write\tempfile{Figure \thefigure: \imgfilename\space (page \thepage)}%
}
  • 1
    +1 One downside of hooking into caption is that if you have captions for tables they will also generate a line in the list of files, which is not what you want. So either you check for whether you're in a figure caption, or you just make a macro to add to each of the relevant captions. – Alan Munn Feb 3 at 23:57
  • Thanks for pointing this out - I've addressed it in an edit. – Pippip19 Feb 4 at 6:44
  • tried it works quite well – der bender Feb 4 at 15:42
  • if i could have this in the document though (and not in some external Textfile) this would be even more awesome. but if anything Fails i can still just copy and paste the Content from the text file to a tex file and call it a day – der bender Feb 4 at 15:44
  • found some solution (sort of): i rename the file to figurelist.tex and place a \input{figurelist.tex} right before the end document and after \immediate\openout\tempfile=figurelist.tex i then place a couple of \immediate\write s to start a new chapter and a tabular environment (that i have to end ofcourse before i input the file...) and then its just a matter of modifying the \img caption. question i now have is how to make the \ for the \begin{tabular} ? – der bender Feb 4 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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