2

I have found how do avoid already converted equation in this link: Avoid already converted equation in htlatex. How to do the same method in Figures Conversion? My MWE is:

\documentclass{book}
\usepackage{graphics}
\begin{document}

Sample Text here.

\begin{figure*}
\includegraphics{Figure1.pdf}
\caption{Figure Caption here.}
\end{figure*}

\begin{figure*}
\includegraphics{Fig2.pdf}
\caption{Figure Caption here.}
\end{figure*}
\end{document}
3
  • could you post a mwe? I think -p option mentioned in the linked answer should suppress all image conversions
    – michal.h21
    Sep 3, 2014 at 6:24
  • @michal.h21: I have updated my questions and when using -p also again Figure Image is converting to PNG format.
    – Balaji
    Sep 3, 2014 at 7:13
  • I see. Do you use some custom configuration for pdf to png conversion? This configuration would need to check whether the png file exists and is newer than the pdf. Maybe GNU Make could be used for this. Or some lua script.
    – michal.h21
    Sep 3, 2014 at 9:05

1 Answer 1

3

I assume that you use some configuration for converting pdf to png in your cfg file, like this one:

\Preamble{html}
\begin{document}
\makeatletter
% Various helper functions
% default font size
\newcommand\emwidth{16}
\let\emwidth\f@size
% convert pt to rem
\newcommand\CalcRem[1]{\strip@pt\dimexpr(#1)/\emwidth}

\Configure{graphics*}
  {pdf}
   {% you need to coonvert eps to png first
   \Needs{"convert \csname Gin@base\endcsname.pdf  
                           \csname Gin@base\endcsname.png"}% 
    \special{t4ht+@File: \csname Gin@base\endcsname.png}
    \Picture[pict]{\csname Gin@base\endcsname .png
     \space style="width:\CalcRem{\Gin@req@width}em;"
   }%
  }
    \makeatother
\EndPreamble

this configuration converts pdf to png using imagemagick's convert command and include css declaration for calculating image width in em units. The problem is that \Needs command is executed at every compilation. We can use simple lua script to check modification times of both input and output images and execute convert only when input is newer than output.

File imgconvert.lua:

-- usage: texlua imgconvert input_image output_image
-- this is needed to enable lfs library
kpse.set_program_name("luatex")

-- read file attributes of images to find modification times
local input = arg[1]
local attr_input = lfs.attributes(input)
if not attr_input then 
    print("Cannot read attributes for file: ".. input)
    os.exit(1)
end
local output = arg[2]
local attr_output = lfs.attributes(output) or {}

if attr_input.change > (attr_output.change or 0) then
  -- call convert command
  local command = string.format('convert %s %s', input, output)
  print(command)
  os.execute(command)
else
    print("Converted image ".. output .." is up-to-date")
end

As this is basically a wrapper for convert command, you can use this script for all image types supported by imagemagick.

Now we need to modify the cfg file:

\Preamble{html}
\begin{document}
\makeatletter
% Various helper functions
% default font size
\newcommand\emwidth{16}
\let\emwidth\f@size
% convert pt to rem
\newcommand\CalcRem[1]{\strip@pt\dimexpr(#1)/\emwidth}

\Configure{graphics*}
  {pdf}
   {% you need to coonvert eps to png first
   \Needs{"texlua imgconvert.lua \csname Gin@base\endcsname.pdf  
                           \csname Gin@base\endcsname.png"}% 
    \special{t4ht+@File: \csname Gin@base\endcsname.png}
    \Picture[pict]{\csname Gin@base\endcsname .png
     \space style="width:\CalcRem{\Gin@req@width}em;"
   }%
  }
    \makeatother
\EndPreamble

and if you observe the compilation log, you will see:

System call: texlua imgconvert.lua Fifure1.pdf Fifure1.png
convert Fifure1.pdf Fifure1.png
System return: 0
System call: texlua imgconvert.lua Fig2.pdf Fig2.png
convert Fig2.pdf Fig2.png
System return: 0

and in later runs:

System call: texlua imgconvert.lua Fifure1.pdf Fifure1.png
Converted image Fifure1.png is up-to-date
System return: 0
System call: texlua imgconvert.lua Fig2.pdf Fig2.png
Converted image Fig2.png is up-to-date
System return: 0
4
  • I have received imgconvert.lua:7: bad argument #1 to 'attributes' (string expected, got nil). How do solve this problem?
    – Balaji
    Sep 4, 2014 at 4:10
  • @Balaji could you take a look to the terminal output before this error message? at lines like: System call: texlua imgconvert.lua Fifure1.pdf Fifure1.png
    – michal.h21
    Sep 4, 2014 at 7:13
  • I have used call texlua imgcnv.lua page91-02.pdf page91-01.png and received error are imgcnv.lua:10: attempt to index local 'attr_output' (a nil value).
    – Balaji
    Sep 4, 2014 at 7:27
  • @Balaji see updated script
    – michal.h21
    Sep 4, 2014 at 8:00

You must log in to answer this question.

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