This is a continued thought from here.

If I have a figure folder hierarchy such as:



Is there any method to string search all paths,
such that in scenarios in which:


has duplicates, the user could use a partial path string
to still get the image, such as:


All of these should find a unique answer in the search path.

I understand that the full path could get me there,
but in cases where that path is long and could easily change,
it would be nice to only need to extend the string
until it becomes unique.

  • @DavidCarlisle : Even when not writing the whole word, like with ana and a? I just assumed it wouldn't work without some additional tool..
    – kando
    Jul 6, 2017 at 20:46
  • oh sorry I misread no you need the directory name, I'll delete first comment. Jul 6, 2017 at 21:00
  • Figures/Banana/a.pdf Banana/a.pdf and a.pdf should all work if TEXINPUTS includes .// or ./Figures// Jul 6, 2017 at 21:02
  • My first idea would be to use \graphicspath. If that is too repetitive, e.g. because you have too many documents, I would suggest to create shortcuts in the form of symlinks; you can then update in one place only in case your folder locations to actually change. Jul 6, 2017 at 21:25

1 Answer 1


You could indeed use a very large \graphicspath like:


With this a will be found as Figures/Banana/a.pdf very soon, but /Apples/b.pdf will try Figures/Banana//Apples/b.pdf, Figures/Banana/Apples/b.pdf, Figures/Banana/Apples/b.pdf, Figures/Banan/Apples/b.pdf, Figures/Bana/Apples/b.pdf, Figures/Ban/Apples/b.pdf, Figures/Ba/Apples/b.pdf, Figures/B/Apples/b.pdf, Figures/Apples//Apples/b.pdf, Figures/Apples//Apples/b.pdf, Figures/Apples/Apples/b.pdf, Figures/Apple/Apples/b.pdf, Figures/Appl/Apples/b.pdf, Figures/App/Apples/b.pdf, Figures/Ap/Apples/b.pdf, Figures/A/Apples/b.pdf before it will find Figures//Apples/b.pdf or Figures/Apples/b.pdf.

And if there would be additional sub-folders like Figures/RedApples it could be hard for the user to always have the correct a.pdf. So at the end the suggestion could result in more mess than comfort. I would not do it. Instead I would only use \graphicspath{{Figures/}} and always use \includegraphics{Bananas/a} to have the banana picture and \includegraphics{Apples/a} to get the apple picture.

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.