9

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:

path1/fig/foo.pdf
path2/fig/bar.pdf

path1/fig-gray/foo.pdf
path2/fig-gray/bar.pdf

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.)

Caramdir
  • 89,023
  • 26
  • 255
  • 291
Frank
  • 7,175

1 Answers1

8

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

\graphicspath{{path1/fig/}{path2/fig/}}

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

\graphicspath{{path1/fig-gray/}{path2/fig-gray/}}

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
\graphicspath{{path1/fig\gray/}{path2/fig\gray/}}

This also works directly with \includegraphics:

\includegraphics[width=5in]{path1/fig\gray/foo.pdf}
Martin Scharrer
  • 262,582
  • 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 00:02
  • 3
    @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 00:07