4

The LaTeX compiler is able to determine the file without adding the filetype e.g.,

\includegraphics[width=0.8\textwidth]{images/frontend/verbose}

which is similar to

\includegraphics[width=0.8\textwidth]{images/frontend/verbose.pdf}

Now the question is:

  • is it considered good practice to add the filetype so it's verbose?
  • Should I omit it, since the compiler is able to detect it automatically, which will make it kind of redundant? This will also have the advantage if the type changes from e.g., pdf to png no changes in the include will be needed.
  • Is it a question of personal preference as to what is preferred?

Thank for the answers in advance :)

I know this may not be such a relevant topic, but I've been thinking about it for the last few days and couldn't find an answer somewhere.

1
  • I believe there is no strict technical guideline; rather, one should prioritize a context-dependent balance between flexibility and accuracy. Commented May 24, 2025 at 9:38

2 Answers 2

9

It is a choice for you to make.

If you omit it then you can easily switch between (say) .eps for latex/dvips and .pdf for pdftex. (This was the main motivation for allowing the extension to be omitted in the first place).

If however the extension is omitted then it tries a list of extensions in turn, which requires a search of the file system in each case to see if the file is there. This has a time cost on every run (which may or may not be negligible depending on the size of your file tree, and whether you hit any directories that are really mounted in the cloud not on your local machine). This cost is of course negligible if you arrange the order of extensions tried so that in practice the first extension tried is always the one found.

3

I would omit the file extension in most cases I can think of. If there are several versions in different formats, then the directory is searched in some default order, e.g. .pdf,.png,.jpg, etc, and the first one found is used. You can use \DeclareGraphicsExtensions to specify the order in which they should be searched, for example \DeclareGraphicsExtensions{.png,.jpg,.pdf}.

I would even omit the paths of the graphics files. If you specify a \graphicspath, then LaTeX knows where to look for. Usually some scheme like \graphicspath{{../plots/}} or \graphicspath{{images/frontend/}} in your example would keep your work organized and the documents portable, while you type less and avoid chances of making errors.

Of course you can always use the full filename or full path in includegraphics to override the declarations.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.