Is there a way in LaTeX to include a file name in a signature?

I have a LaTeX document with a lot of drawings included from external files with \includegraphics{bla.pdf}. Drawings made in Inkscape. All of this works great. However, it is sometimes difficult to keep track of all the drawings and their source files. So I'm looking for a way to include the source name in the example bla.pdfin the header. Being not an expert of LaTeX, I did not find a way to automatically access the file name string from the header. Using Google-foo also failed. Is there a way to refer to the file name and include it in the header, for example \caption{A fancy drawing of bla (\filename}?

+3
source share
2 answers

You can fix the image file name by correcting some of the nested calls inside \includegraphics:

enter image description here

\documentclass{article}

\usepackage{graphicx,etoolbox}

\makeatletter
\patchcmd{\Gin@setfile}% <cmd>
  {\ProvidesFile}% <search>
  {\xdef\imgfilename{#3}\ProvidesFile}% <replace>
  {}{}% <success><failure>
\makeatother

\begin{document}

\begin{figure}
  \centering
  \includegraphics[width=.5\linewidth]{example-image}
  \caption{Image: \imgfilename}
\end{figure}

\end{document}

\imgfilenamewill contain the file name used in \includegraphicsonly after its use.

+1
source

Override \includegraphics. In the case of no arguments (width = 3cm, scale = 2 or something like this)

\let \saveinclude \includegraphics
\def \includegraphics#1{\def\filename{#1}\saveinclude{#1}}

Using

\includegraphics{bla.pdf}
\caption{A fancy drawing of bla (\filename)}
0
source

Source: https://habr.com/ru/post/1765302/


All Articles