I use tex4ebook with \coverimage[someOptions]{AbsolutePath/someimage.jpg} in the document, directly after \begin{document}. But the AbsolutePath is not respected and does not find someimage.jpg, respectively is not shown in the epub.

As AbsolutePath I use something like C:/Somepath/folder/anotherfolder/someimage.jpg. But in the epub no image is shown.

When I use someimage.jpg located in the current folder, where the .tex file is, it works and the someimage.jpg is shown in the epub.

Only the absolute path is not showing the image in the epub. But of cource the someimage.jpg is located in the AbsolutePath folder.

Is there anything to know that I miss?

It seems as if the


does not work with tex4ebook. Though it was said, that all options with \includegraphics[]{} will work with \coverimage[]{}.

Is there a fix to it?

1 Answer 1


tex4ebook doesn't copy images, you need to do it using a build file. I've handled a similar case some time ago in this answer, but it doesn't work correctly with tex4ebook. Here is a fixed version, which also contains other DOM filter that you want to use:

local mkutils = require "mkutils"
local domfilter = require "make4ht-domfilter"

local allowed_chars = {
  ["-"] = true,
  ["."] = true
local function fix_colons(id)
  -- match every non alphanum character
  return id:gsub("[%W]", function(s)
    -- some characters are allowed, we don't need to replace them
    if allowed_chars[s] then return s end
    -- in other cases, replace with underscore
    return "_"

local function id_colons(obj)
  -- replace : characters in links and ids with unserscores
    local name = string.lower(obj:get_element_name(el))
    if name == "a" then
      local href = el:get_attribute("href")
      -- don't replace colons in external links
      if href and not href:match("[a-z]%://") then
        local base, id = href:match("(.*)%#(.*)")
        if base and id then
          id = fix_colons(id)
          el:set_attribute("href", base .. "#" .. id)
    local id  = el:get_attribute("id")
    if id then
      el:set_attribute("id", fix_colons(id))
  return obj

local function fix_img_names(dom)
    for _, img in ipairs(dom:query_selector("img")) do
        local src = img:get_attribute("src")
        if src then
            -- remove path specification
            src = src:match("([^/]+)$")
            img:set_attribute("src", src)
    return dom

local process = domfilter {id_colons,fix_img_names}

local function image_copy(path, parameters)
  -- get image basename
  local basename = path:match("([^/]+)$")
  -- if outdir is empty, keep it empty, otherwise add / separator
  local outdir = parameters.outdir == "" and "" or parameters.outdir .. "/"
  -- handle trailing //
  outdir = outdir:gsub("//$","/")
  local output_file = outdir .. basename
  for pos, name in pairs(Make.lgfile.files) do 
    if name == path then
      Make.lgfile.files[pos] = output_file
  mkutils.cp(path, output_file)

Make:match("png$", function(path, parameters)
  image_copy(path, parameters)
  -- prevent further processing of the image
  return false

Make:match("jpg$", function(path, parameters)
  image_copy(path, parameters)
  -- prevent further processing of the image
  return false

if mode=="draft" then
  Make:htlatex {}
  Make:htlatex {}
  Make:xindy {modules={"duden-utf8"}}
  Make:biber {}
  Make:htlatex {}
  Make:htlatex {}

Make:match("html$", process)

Details on how it works are in the link above.

  • Thank you Michal, you are a wonder. But I can not understand the code. You said yesterday, we could combine several build files together in one file. Right? So I think, I have at least 3 of them (in the meanwhile of the last 10 days). Should I just copy them in one file, one after the other? I do not quite understand this adding together.
    – Thomkrates
    Commented Apr 11, 2023 at 17:21
  • @Thomkrates I've already added everything here, hopefully.
    – michal.h21
    Commented Apr 12, 2023 at 14:05
  • Yes, I was partially successful with it. When using \graphicspath{} of the graphicx package, I discovered that image file name with - in it, will not be found or as not exists. For example an image file with name image-name.jpg or this-is-a-longer-image-name.jpg will be found as not exists. Whereas imagename.jpg will get no error message and the generated epub will show the image file. Can you see this too? Or is there anything else with my system?
    – Thomkrates
    Commented Apr 12, 2023 at 19:38
  • I set the absolute path of the imagename.jpg within \coverimage[]{AbsolutPath/imagename.jpg}. Then it generated an epub with no error runnig epubcheck. (In two of my projects). But with the same issues while using an imagename like This-is-a-longer-image-name.jpg (in another project) it does generate an epub without error code, but lacks the image in the epub and is not shown there. Additionally an error with epubcheck "Absolutepath/This-is-a-longer-image-name.jpg" must be located in EPUB container. Is this reproduceable by your system?
    – Thomkrates
    Commented Apr 12, 2023 at 20:55
  • @Thomkrates no, filenames with - works for me, but I am on Linux. Do you use forward slashes in your file paths, or backslashes?
    – michal.h21
    Commented Apr 13, 2023 at 10:44

You must log in to answer this question.

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