Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am writing a Latex file that needs to include figures from a directory graphs.

graphs has several sub-directories say, one , two and three. These individually contain several graphics that should be included in the file.

One way is to include every graphic in the file manually. But, that is too cumbersome. Is there a better way to do this?

share|improve this question
So you want to include all graphic files from certain directories automatically? In this case see How to iterate through the name of files in a folder, which looks like a duplicate. The adjustments to multiple directories should be easily done. –  Martin Scharrer Dec 20 '11 at 10:00
@MartinScharrer: Ah. You beat me to the punch. –  night owl Dec 20 '11 at 10:08
You question is not well-defined at the moment. Do you only want to reduce the amount of work, e.g. not have to write the full directory names all the time, or do you want to include all graphic files from a certain directory structure automatically? I personally think it is the later, but looking at the two answers so far other people think more about the former. In that case Automatically Locate Included Images looks like a duplicate. –  Martin Scharrer Dec 20 '11 at 10:35
@Martin: Yea, I guess the question could be a tad bit more specific at what is the optimal goal here. Whether to reduce the typing or have it auto included. –  night owl Dec 20 '11 at 10:49
@MartinScharrer. My main motive here is to reduce the amount of work as I have about 100 plots to include and including each of them one by one is a pain in the bottom –  Ankit Dec 21 '11 at 3:29
show 2 more comments

2 Answers

try in your preamble:


makes sense if you do not have too many subdirectories.

share|improve this answer
Hi, But how do I include the files then as each one, two etc have the same file name like a.pdf and b.pdf –  Ankit Dec 21 '11 at 3:26
@Ankit: you can use \graphicspath several times in your document to define other search rules. –  Herbert Dec 21 '11 at 8:08
add comment

Here is a solution. Comments will be added later.

            \@latex@error{Unknown processor \unexpanded{##1}}\@ehc
      % \openin will not take spaces in path or filename:
          \@latex@error{Inputpath '##1' not ended with slash (/)}\@ehc
  cmd/\needvalue{viewport}/0 0 100 100;
% Why didn't I want to say \let\fim@phantomenv\relax?
  \usename{ltxkeys@\fim@setorlaunch keys}[KV]{importfiles}{#1}%
  % Some paths might have been suggested via \input@path
  % and/or \graphicspath. So we heed them here.
      % Hmm, why don't I want to use \IfFileExists?
        \typeout{File '\fileonpath' found}%
    \@latex@error{Command \noexpand\fiminclude cannot be nested}\@ehc
    % I don't know why LaTeX chose to do a loop here. We don't need it here:

\section{Test section}

  processor   =includegraphics,
  viewport    =20 21 590 400,
  scale       =.25,
  inputpaths  ={D:/MyTempDoc/Path1/,D:/MyTempDoc/Path2/},
  stuffbefore =\bigskip\centering Importing \currfile\space from path \currpath\endgraf,
  stuffafter  =\endgraf\centering File import succeeded (\currfile).\endgraf

  processor   =include,
  inputpaths  ={D:/MyTempDoc/Path1/,D:/MyTempDoc/Path2/}

  processor   =\input,
  inputpaths  ={D:/MyTempDoc/Path1/,D:/MyTempDoc/Path2/}

This is only a partial listing of the code. The full version can handle stand-alone documents in the manner of docmute and standalone packages. I will release it as a package.

enter image description here enter image description here

share|improve this answer
Remember to also update Who are the package maintainers here once you've packaged this up, as well as marking this original question as having led to the creation of a new package (as suggested by Mark questions that led to creating a new package). Some examples, if you're interested... –  Werner Dec 22 '11 at 4:29
Please try to avoid code-only answers here. It would be great if you would add some basic explanation. Thank you. –  Martin Scharrer Dec 22 '11 at 19:55
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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