[Tex/LaTex] Suppress pdflatex warning about missing eps file

epsepstopdfpdftexwarnings

I use .eps graphics in my latex documents converted at compile using the epstopdf package and it works great.

When I build the file, epstopdf creates the <filename>-eps-converted-to.pdf file and includes it in the resulting .pdf.

I would now like to now delete the .eps file and just use the converted<filename>-eps-converted-to.pdf file. This actually works, sort of – epstopdf doesn't complain (rightly or wrongly), it just returns

Package epstopdf Info: Output file is already uptodate.

and the resulting .pdf contains the image as desired.

However, I get an annoying LaTeX warning

LaTeX Warning: File `test.eps' not found on input line 8.

MWE:

\documentclass{article}

\usepackage{graphicx}
\usepackage{epstopdf} 
\usepackage{epsfig}

\begin{document}
\includegraphics{test.eps}
\end{document}

Build this with any .eps file and it builds fine. Now delete or rename the .eps file and it still builds fine, but gives the annoying warning above.

My question: is there any way to just disable the warning for missing .eps files?

The reason for this is that I often auto-generate .eps files outside of the latex source directory and would like to just commit the latex source to git with the converted .pdf files (output locally by using the [outdir=./] option with epstopdf) but without the source .eps files – this way I or anyone else can build it stand-alone.

Updated MWE with .eps file outside the source path:

\documentclass{article}
\usepackage{graphicx}
\usepackage[outdir=./]{epstopdf}
\epstopdfsetup{suffix=}
\begin{document}
  \includegraphics{../test}   
\end{document}

Best Answer

It doesn't seem that there is a way to prevent the warning showing up directly.

One work-around would be to use the silence package to filter out the warnings from the output.

However, silence doesn't detect these warnings as they're generated using

\@warning{File `#1' not found}%`

(line 166 of graphics.sty) and silence only picks up warnings generated using \PackageWarning, \ClassWarning, \@latex@warning and \@font@warning (lines 381-431 in v1.5b of silence.sty).

I have contacted the maintainer of silence about this but received no response, so the simplest solution is to place the following code in the preamble:

\usepackage{silence}

\WarningFilter[latex_file_not_found]{latex}{File}

\makeatletter
\let\sl@warning\@warning
\def\@warning#1{%
  \def\sl@PackageName{latex}%
  \ifsl@NoLine
    \sl@NoLinefalse
  \else
    \sl@StoreMessage{#1}%
  \fi
  \sl@warning{#1}}

\def\@warning@no@line#1{%
  \sl@StoreMessage{#1}%
  \sl@NoLinetrue
  \@warning{#1\@gobble}}
\makeatother

\ActivateWarningFilters[latex_file_not_found]

This will ignore all \@warnings that start with File.

It is also possible to wrap all \includegraphics with \ActivateWarningFilters[latex_file_not_found] and \DeactivateWarningFilters[latex_file_not_found] to only apply this to graphics imports (I'm not sure where File warnings would otherwise show up).

Alternatively, this can also be automatically included in all \includegraphics calls with the following re-definition (credit to David Carlisle and this answer):

\makeatletter
  \let\oldGin@ii\Gin@ii
  \def\Gin@ii[#1]#2{%
  \ActivateWarningFilters[latex_file_not_found]%
  \oldGin@ii[{#1}]{#2}%
  \DeactivateWarningFilters[latex_file_not_found]}
\makeatother