# Automatically determine numbers of pages with figures

I'd like to get a list of all the pages in my document that have figures on them. Specifically, the page numbers in the PDF file that is created from my LaTeX document. This would allow me to print only those pages in color while keeping the remainder in B/W, thus saving printing cost. Unfortunately, the printer itself only allows selecting color or B/W for a whole print job, so I need to separate the page ranges manually (some models are able to decide on a page-by-page basis, but not this one).

I'm using TeX Live on Linux (Debian-based).

Is there a way to automatically determine this using some tool or options?

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Martin Schröder Sep 23 '14 at 8:41
• You could use \listoffigures to generate a list of figures page and then select the pages that you want to print from there (or the .lof file), either manually or using a script. – Andrew Sep 23 '14 at 9:47

Examples copy from egreg's answer but this time with \makeindex.

\documentclass{article}
\usepackage{graphicx}
\usepackage{makeidx}
\makeindex

\let\oldincludegraphics\includegraphics
\renewcommand\includegraphics{\index{~@Pages containing figures}\oldincludegraphics}
\newwrite\listofgraphics

\begin{document}
A page without graphics
\clearpage
A page with graphics\\
\includegraphics{example-image}
\clearpage
A float
\begin{figure}[htp]
\includegraphics{example-image}
\end{figure}
and a delayed float
\begin{figure}[p]
\includegraphics{example-image}
\end{figure}
\clearpage
A page without graphics
\clearpage
Again page with graphics\\
\includegraphics{example-image}
\clearpage

\printindex

\end{document}


Here's a perhaps too simplistic way

\documentclass{article}
\usepackage{graphicx}

\let\ORIincludegraphics\includegraphics
\renewcommand{\includegraphics}{%
\write\listofgraphics{\thepage}%
\ORIincludegraphics
}
\newwrite\listofgraphics
\AtBeginDocument{\immediate\openout\listofgraphics=\jobname.lis }
\AtEndDocument{\closeout\listofgraphics}

\begin{document}

A page without graphics
\clearpage

A page with graphics

\includegraphics{example-image}

\clearpage

A float

\begin{figure}[htp]
\includegraphics{example-image}
\end{figure}

and a delayed float

\begin{figure}[p]
\includegraphics{example-image}
\end{figure}

\clearpage

A page without graphics
\clearpage

\end{document}


The contents of the .lis file that's created is

2
3
4