[Tex/LaTex] How to switch from using color graphics to grayscale graphics

graphics

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

Best Answer

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}
Related Question