2

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

\graphicpath{{PathA/}{PathB/}{C:/folder/anotherfolder/}}

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

Is there a fix to it?

Sebastiano
  • 54,118

1 Answers1

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 "_" end) end

local function id_colons(obj) -- replace : characters in links and ids with unserscores obj:traverse_elements(function(el) 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) end end end local id = el:get_attribute("id") if id then el:set_attribute("id", fix_colons(id)) end end) return obj end

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) end end return dom end

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 end end mkutils.cp(path, output_file) end

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

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

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

Make:match("html$", process)

Details on how it works are in the link above.

michal.h21
  • 50,697
  • 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 Apr 11 '23 at 17:21
  • @Thomkrates I've already added everything here, hopefully. – michal.h21 Apr 12 '23 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 Apr 12 '23 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 Apr 12 '23 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 Apr 13 '23 at 10:44
  • It was a mistake by me, the - seem not to be the problem. But I do not understand why I get discrepancies, since 2 of my sourcenameX.tex result in a epub with 0 error epubcheck. But with a third sourcenameY.tex it gives the error that the im-age-na-me.jpg not exists. And: No the slashes are correct in all paths the same. I really looked closely to the similarities between the 2 working sourcenameX.tex and hoped to get again a third epub with 0 error in epubcheck. But I can not find a hint where the difference is that is resulting in the error in epubcheck. - Any other ideas? – Thomkrates Apr 13 '23 at 18:05
  • I have also issued a problem in https://tex.stackexchange.com/questions/681968/epubcheck-with-error-while-using-tex4ebook-and-nocite-bibtexing for 20 errors in epubcheck concering \pageref{somelabel}. This is strange, since pageref appears in ordinary text body and nothing else with it. In the epub the pageref-number is a non-functional hyperlink, and therefore the error message with epubcheck Fragmentbezeichner is missing. What could here be missing? – Thomkrates Apr 13 '23 at 20:25
  • @Thomkrates I will need MWEs for both of these issues, – michal.h21 Apr 14 '23 at 08:40
  • Meanwhile I found out, that the error with epubcheck and the 20 pageref commands, has obviously nothing to do with the -c myconfig.cfg and the -e build.lua since a MWE with minimal \pageref{} and minimal \index{} and minimal bibliography did not reproduce the error in epubcheck. All minimal pagerefs worked in the epub (while in my sourcename.tex - with myconficg.cfg and build.lua the pageref in the epub do not work and do get 20 errors in epubcheck). So I will need to look at my packages in sourcename.tex and strategically look for the problem. – Thomkrates Apr 14 '23 at 18:39
  • @Thomkrates yes, there needs to be something strange, because \pageref should work correctly. They probably point to some \label that is missing in the HTML file. – michal.h21 Apr 14 '23 at 18:53
  • It is strange indeed. Since I used for the MWE the same preamble after \documentclass as in the sourcename.tex and the error in epubcheck could not be reproduced. I also looked in the html files for the \label{somelabelx} and checked the somelabelx within the sourcename.tex. But I could not find a lack of labels; all labels are present as pageref, for all pagerefs there is a label. I used the package refcheck and no warning can be found in the log file. But the 20 errors in epubcheck remain saying Fragmentbezeichner ist nicht angegeben (Some fragmented label is not specified). – Thomkrates Apr 14 '23 at 20:34
  • Dear Michal, if you do not find a solution to this pageref-Situation-Problem (tex4ht?), I might be able to handle it with the program sigil. Do you know about it? It is said, that this is an epub-editor, which might be able to resolve the pageref-errors which result here via epubcheck. Do you think that could be possible? – Thomkrates Apr 17 '23 at 09:54
  • @Thomkrates I cannot reproduce the issue, so it is hard for me to fix it :( I think it would be better to fix it in tex4ebook, because when you use manual edits, you would need to do them again when you recompile your book. Is it really not possible to make a MWE for this? – michal.h21 Apr 17 '23 at 10:09
  • Yes, it would be better to fix it in tex4ebook. I do not know if it is not possible. But up to now it was not possible for me to reproduce the error (with epubcheck) in a MWE. Ok. I will try again to find a MWE, but I can not promise to be successful. – Thomkrates Apr 17 '23 at 12:36
  • Dear Michal, see the new question: https://tex.stackexchange.com/questions/683283/errors-with-epubcheck-after-tex4ebook-concerning-pagerefsomelabel for a MWE. – Thomkrates Apr 18 '23 at 20:54