Memo-migrated‎ > ‎

Use .eps.gz in LaTeX

posted Jun 28, 2012, 6:40 PM by Teng-Yok Lee   [ updated Jan 2, 2021, 7:40 PM ]
To Embed figures in LaTeX files, .eps format is often used but the file sizes are too big. Using other formats such .PNG might be incompatible with TeX/LaTeX. Therefore, .EPS is still the better choice. To reduce the file size, .eps.gz is another good choice. The following steps could be applied.
  1. Prerequisite: Install gzip, grep, and ImageMagick. For Windows, please add the path to their executable to the environment variable PATH.
  2. Add the following rule at the beginning of the LaTeX file after the library graphix:
    • \DeclareGraphicsExtensions{.eps,.eps.gz}
    • \DeclareGraphicsRule{.eps.gz}{eps}{.bb}{}
  3. Convert the image, for instance, img.png to .eps
    • convert img.png img.eps
  4. Extract the BoundingBox
    • grep "%%BoundingBox" img.eps >
  5. Compress the .eps file
    • gzip -9 img.eps
The attached archive contain a Windows .bat file to convert an image file to .eps.gz with .bb. The most updated one now can be cloned from GIT: Based on this script with the looping scheme in the shell, the images in a folder can be computed in a single command.

Teng-Yok Lee,
Dec 9, 2012, 8:35 AM