TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the easiest way to switch from a document with color graphics to one with grayscale graphics?

I have various fig/ directories that contain my color graphics, and I already have corresponding fig-gray/ directories that contain the same graphics in grayscale.

Example directories:



I have includegraphics commands in various included .tex files, e.g. \includegraphics[width=5in]{path1/fig/foo.pdf}.

Now what is the easiest way to tell LaTeX to switch to using the fig-gray/ directories instead? (I'd like to avoid having to preprocess my .tex files with search and replace.)

share|improve this question
@user823: It would be nice if you could rename your user name to something more meaningful. Thanks. – Martin Scharrer Feb 27 '11 at 0:02
@Martin: That actually seems to be a stack exchange bug. I have never registered as "user823". – Frank Feb 27 '11 at 0:11
Yes, you have now two accounts. The user823 one is 6 month old and the Frank one only 2 days. But I think the moderators can merge the two. – Martin Scharrer Feb 27 '11 at 0:46
Strange. I have no idea how that happened. I personally don't care though. :) – Frank Feb 27 '11 at 0:59
up vote 7 down vote accepted

Use the \graphicspath macro from the graphics/x package to specify the directories with your images:


Then you can remove them from the \includegraphics macros and only need to change the one line to:


Alternative you could make the -gray part a macro, which avoid adding new paths twice:

%\newcommand*{\gray}{-gray}% Uncomment to switch to gray-scale images

This also works directly with \includegraphics:

share|improve this answer
Thanks! But unfortunately, many files in the different directories have similar names, e.g. path1/fig/illustration.pdf and path2/fig/illustration.pdf. I hope there's a way that doesn't require me to rename them to make globally unique names... – Frank Feb 27 '11 at 0:02
@Frank: I see. In this case you should use my second suggestion of using macros as part of the path, but with the actual \includegraphics commands. – Martin Scharrer Feb 27 '11 at 0:07

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.