그림이 포함된 페이지 수를 자동으로 결정

그림이 포함된 페이지 수를 자동으로 결정

내 문서에 그림이 있는 모든 페이지의 목록을 얻고 싶습니다. 특히 LaTeX 문서에서 생성된 PDF 파일의 페이지 번호입니다. 이렇게 하면 해당 페이지만 컬러로 인쇄하고 나머지 페이지는 흑백으로 유지하여 인쇄 비용을 절약할 수 있습니다. 안타깝게도 프린터 자체에서는 전체 인쇄 작업에 대해 컬러 또는 흑백만 선택할 수 있으므로 페이지 범위를 수동으로 구분해야 합니다(일부 모델은 페이지별로 결정할 수 있지만 이 제품은 그렇지 않습니다).

저는 Linux(Debian 기반)에서 TeX Live를 사용하고 있습니다.

일부 도구나 옵션을 사용하여 이를 자동으로 결정하는 방법이 있습니까?

답변1

예제는 egreg의 답변에서 복사되었지만 이번에는 \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}

답변2

아마도 너무 단순한 방법이 있습니다.

\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}

.lis생성된 파일 의 내용은 다음과 같습니다.

2
3
4

관련 정보