# File format preference with graphicx

I'm using `Mathematica`to produce some of my graphics (when i'm not able to just TikZ them easily). All these images are availabvle as `.eps` and `.png`having the same file name - let's use `img.eps` / `img.png` in the following.

I would like to set a preference for `graphicx` to use only one type, i.e. using

``````\includegraphics[width=.6\textwitdh]{img}
``````

I would like to specify, which `img` to use with one switch, (package) option or variable.

I tried

``````\DeclareGraphicsExtension{.eps}
``````

to restrict the allowed image extension to `.eps`, but still the `.png` file is included. It seems, `.png`is preferred over `.eps`.

Though this is of course restricted to `XeTeX` it might be interesting for others, if you use `.png` together with some lossy format like `.jpg` to have a file extension preference.

Is there a package option for that or an easy command (global document option) for that?

To provide an MWE is - I think - difficult, because it would be necessary to provide at least 3 files.

-
– Werner Jan 1 '13 at 20:28
At least if you have all images available in both formats `\RemoveGraphicsExtension` from `grfext` does the job. By removing the unwanted extension. Though, if one of all your images is available only in one format - a preference would be necessary (removing the extension disables to use that specific image). – Ronny Jan 1 '13 at 20:52
`\DeclareGraphicsExtensions{.eps}` (note `s` at end of command name) would make LaTeX only handle `.eps` explicitly, in particular it should only ever add a .eps extension. (other file types may be handled if their extension is explicit) – David Carlisle Jan 1 '13 at 21:47
"to TikZ something" sounds quite cool. :-) – Christian Feuersänger Jan 1 '13 at 21:53
@DavidCarlisle oh, that works quite nice, if you don't mind you just can turn that into an answer, i don't know, why i didn't get that idea, but i haven't found the documentation for those commands... Christian - yeah. I noticed when I typed that, it really does. – Ronny Jan 1 '13 at 21:58

## 1 Answer

`\DeclareGraphicsExtensions{.eps}` (note `s` at end of command name) would make LaTeX only handle `.eps` explicitly, in particular it should only ever add a `.eps` extension. (other file types may be handled if their extension is explicit)

The version without an `s` presumably gave an error when you tried it? (It's best not to ignore error messages:-)

Further documentation on these commands is in the document grfguide, part of the core LaTeX distribution. (`texdoc grfguide` might work depending on your TeX distribution)

-
Actually in my efforts to construct this topic i might also have misstyped it, but my i'm not sure anymore. It didn't work in the first tries I did (in the meaning that in didn't exclude `.png`) - The hint to use grfguide is great. – Ronny Jan 1 '13 at 22:10
Though, then, no png is accepted and everything has to be `.eps` - but okay, I haven't seen anything to specify a preference, and can work with eps-only, even if a preference would be nice (for lazy graphics or things that are only in one of the formats). – Ronny Jan 1 '13 at 22:58
If you want a preference use {.eps,.png} as the argument, the extensions are just tried in order – David Carlisle Jan 1 '13 at 23:03
Oh :) Maybe I'm already a little bit tired, so I was a little slow to notice that. It work's great :) – Ronny Jan 1 '13 at 23:17