EPS (Encapsulated PostScript) files store vector graphics as PostScript. The classic latex command with dvips includes them directly. pdfLaTeX can’t read EPS, so you convert the file to PDF first. The “no BoundingBox” error means LaTeX can’t find the size of the EPS file, which is stored in a %%BoundingBox line near the top of the file.
What an EPS file is
An EPS file is a PostScript program with a header. The header includes a line such as:
%%BoundingBox: 0 0 216 144
The four numbers are the lower-left and upper-right corners of the drawing, in PostScript points (72 points make one inch). LaTeX uses these numbers to decide how big the image is. If the line is missing or wrong, LaTeX can’t size the image.
Include an EPS file with latex and dvips
The classic route uses the latex command, then dvips, then ps2pdf:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.6\linewidth]{figure}
\caption{A vector drawing saved as EPS.}
\label{fig:eps}
\end{figure}
\end{document}
Compile in three steps:
latex main.tex
dvips main.dvi
ps2pdf main.ps
The .eps extension can be left out in the \includegraphics command.
Include an EPS file with pdfLaTeX
pdfLaTeX can’t read EPS, and it looks for a PDF version of the file first. There are two ways to handle this.
Convert by hand. Run epstopdf on the file:
epstopdf figure.eps
This creates figure.pdf. Then \includegraphics{figure} picks up the PDF.
Convert automatically. The epstopdf package runs the conversion for you when LaTeX finds an EPS file:
\usepackage{epstopdf}
Compile with shell escape turned on, because the package needs to run the conversion tool:
pdflatex --shell-escape main.tex
If shell escape is off, the conversion can’t run. Use the manual step instead. On Overleaf, the compile settings decide whether the automatic conversion runs. If an EPS figure fails there, convert it on your computer and upload the PDF.
Understand the “no BoundingBox” error
The error looks like this:
LaTeX Error: Cannot determine size of graphic in figure.eps (no BoundingBox).
It usually has one of three causes:
- The EPS file has no
%%BoundingBoxline. Some programs leave it out. - The line is present but its numbers are wrong, for example a box that is too small.
- The file is not really EPS. A JPG or PNG renamed to
.epscauses the same error.
To check the header, open the file in a plain text editor. Most EPS files begin with a %!PS-Adobe line, and the bounding box line appears near the top. If the file starts with something else, it may not be EPS at all.
Fix the bounding box
You have three options.
Use epstool. The epstool utility can compute a bounding box from the drawing and write it into a new file:
epstool --copy --bbox figure.eps figure-fixed.eps
Include figure-fixed.eps instead of the original.
Use Ghostscript. Ghostscript can report the bounding box of an EPS file:
gs -q -dNOPAUSE -dBATCH -sDEVICE=bbox figure.eps
The command prints %%BoundingBox values. Copy them into the %%BoundingBox line of the file. This edits the header by hand, so check the numbers before you recompile.
Re-export from the source program. Many drawing and plotting programs have an EPS export option that writes a correct bounding box. Exporting again is often the cleanest fix.
After any of these, recompile the document.
Clip and size EPS graphics
If the bounding box is correct but the drawing extends past its edges, clip the image to the box:
\includegraphics[width=\columnwidth,clip=true]{figure}
clip=true hides anything outside the bounding box. It depends on the box being right. If the numbers are too small, clipping cuts off real content. Fix the box first, then add clip=true.
width scales the drawing, including its line weights. Choose a width close to the size you want in the final document, so that the lines and text keep their intended look.
Common mistakes
- Including an EPS file in pdfLaTeX without conversion. This gives
Unknown graphics extension: .eps. Convert the file or use the classic route. - Renaming a file to
.eps. Changing only the extension doesn’t change the format. Export a real EPS file. - Mixing
latexandpdflatexcommands. Choose one compile route for the whole document, and check the build settings if your LaTeX editor runs a different one. - Spaces in file names. Rename the file to remove spaces. The guide to inserting images in LaTeX covers folder setup and naming.
- Forgetting shell escape. The automatic
epstopdfconversion needs--shell-escape.
Summary
EPS works best with the classic latex and dvips route. With pdfLaTeX, convert the file to PDF first, either by hand or with the epstopdf package. For the no-bounding-box error, add a correct %%BoundingBox line with epstool, Ghostscript or a fresh export, and then recompile.