9

I have a long LaTeX document with lots of figures that were included using commands of the form

\includegraphics[page=10]{foo.pdf}

Everything compiles fine with pdfLaTeX. I planned to convert the document into HTML using TeX4ht, but it seems that TeX4ht does not understand the page= attributes in \includegraphics.

Are there any easy solutions? Ideally, I would prefer to keep my main Latex source unmodified and just tweak the preamble.

2 Answers 2

13

Sorry for being late. Following code is likely to help the Jukka:

\makeatletter

\@ifundefined{Configure}
 {\def\Includegraphics[#1]#2{\includegraphics[page={#1}]{#2}}}
 {\def\Includegraphics[#1]#2{\def\GPT@page{#1}\includegraphics{#2}}
  \Configure{graphics*}
   {pdf}
   {\Needs{"
    pdftops -eps -f \GPT@page\space -l \GPT@page\space \[email protected] \Gin@base-\[email protected]"
    ;
    convert \Gin@base-\[email protected] \Gin@base-\[email protected]
    "}%
    \Picture[pict]{\Gin@base-\[email protected]}%
   }%
  }%
\makeatother

\Includegraphics[10]{foo.pdf} should work now both with pdfLaTeX and TeX4ht.

1
  • 1
    We are glad to have you here in TeX.SX. A warm welcome to you.
    – user11232
    Sep 15, 2012 at 6:44
8

TeX4ht does not use pdfTeX in PDF mode, but dvips instead. However dvips can neither read PDF files nor multipage files. Page 10 can be extracted and converted to eps with epstopdf of xpdf:

epstopdf -eps -f 10 -l 10 foo.pdf foo-10.eps

Or ghostscript can be used, e.g.:

gs -dFirstPage=10 -dLastPage=10 -sDEVICE=epswrite -dBATCH -dNOPAUSE -sOutputFile=foo-10.eps foo.pdf

Then in the source:

\ifpdf
  \includegraphics[page=10]{foo.pdf}
\else
  \includegraphics{foo-10.eps}
\fi

And package ifpdf is needed in the preamble:

\usepackage{ifpdf}
2
  • Something along these lines certainly works, but it requires changes in the body of the Latex document. I wonder if I could easily redefine \includegraphics; moreover, perhaps I could have Latex run gs automatically to when needed? Aug 28, 2012 at 18:02
  • It could be done, looking at package epstopdf that support external conversion programs for pdfTeX in PDF mode, I would expect several hundred lines of code. Aug 28, 2012 at 20:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .