I’m writing a Latex manuscript and it has gone through several revisions. The figures folder is now full of many figures, and I want to remove all of the unused figures. Is there some convenient way to figure out which of the figures are being used and which aren’t?
Yes, you can use the -recorder
option flag of pdflatex
, which produces a .fls
file that lists all of the files used as input. You run it like this:
# In the directory that contains your latex file
$ pdflatex -recorder paper.tex
...
Output written on paper.pdf (14 pages, 2028761 bytes).
Transcript written on paper.log
$ less paper.fls
You’ll see that this will contain many extraneous files and duplicates…like this:
INPUT /opt/homebrew/Cellar/texlive/20230313_2/share/texmf-var/web2c/pdftex/pdflatex.fmt
INPUT paper.tex
OUTPUT paper.log
INPUT ./acmart.cls
INPUT ./acmart.cls
INPUT acmart.cls
INPUT ./acmart.cls
INPUT ./acmart.cls
...
To get just the input figures, you can filter down to see just the INPUTs that are in your figures directory. So if your figures are in ./figures
…
$ grep 'INPUT ./figures/' paper.fls | sort | uniq
INPUT ./figures/rsvpte_box_plot.pdf
INPUT ./figures/blip.png
INPUT ./figures/computation_box_plot.pdf
INPUT ./figures/convergence-behavior-comparison.pdf
INPUT ./figures/core_restriction_varying.pdf
...
You can use this to know which files you can or can’t delete.