2

Is there any way to get the storebox package to work with tex4ebook?

A MWE based on the storebox document is:

\documentclass{article}

\usepackage{storebox}

\newstorebox{\mybox}

\begin{document}

\storebox{\mybox}{Contents of box}

\usestorebox{\mybox}

\usestorebox{\mybox}

\end{document}

According to the documentation, this only stores one copy of the box in the pdf file to reduce the size of the file. It also says that the package only works with pdflatex or lualatex.

I want to use this with tex4ebook with repeated images like the modified chessboard command discussed here. I want to define a box with

\storebox{\mybox}{%
  \begin{center}
  \mychessboard
  \end{center}}
}

and use \usestorebox{\mybox} as needed in the file.

If the same chessboard is used later on, the idea is to use the previously generated image instead of creating a new one.

Thank you.

Update:

I have just discovered that using the solution from @Michal.h21 doesn't work for a mobi output.

The output from the command

tex4ebook -r 133 -f mobi mwename.tex

is

 Amazon kindlegen(Windows) V2.9 build 1029-0897292
 A command line e-book compiler
 Copyright Amazon.com and its Affiliates 2014
*************************************************************

Error(xmlmake):E27012: Item or process id already used: mwename0x_png
Pack mobi 2

Is there any way to avoid this error?

If I generate an epub, Calibre will convert the file to mobi without any errors. However, I have noticed that the Calibre conversion is not always correct with other files and so I want to avoid this if possible.

Thanks for any help.

Update 2:

@Michal.h21

Using the new tex4book files still causes an error. If I generate the epub, it runs ok but hangs when I try to view it with Calibre:

Calibre error

If I generate the mobi, I get an error:

Error(core):E1005: Could not access file.
     in file:    C:\Users\User\AppData\Local\Temp\mbp_7E1_1_1D_E_C_1F_3E7_3574_2508_1\OEBPS\mwename.html

Do you get these errors?

Thank you.

Correction:

I have noticed that the epub run gives a tidy error at the end:

HTML Tidy for Windows released on 25 March 2009
Error: Can't open "mwename-epub/OEBPS/mwename.ncx"

Could this be the problem?

mwename.ncx exists in the working directory:

   <?xml version="1.0"?>
 <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
 <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">                                                                            <head>
 <meta name="dtb:uid" content="http://example.com/mwename"/>
 <meta name="dtb:depth" content="3"/>
 <meta name="dtb:totalPageCount" content="0"/>
 <meta name="dtb:maxPageNumber" content="0"/>
 </head>
 <docTitle>
<text>Unnamed</text>
</docTitle>
  <navMap>
   <navPoint id="mainentry" playOrder="1"> <navLabel><text>Document</text></navLabel> <content src="mwename.html" /> </navPoint></navMap>
   </ncx>

It's not in the OEBPS directory. The OEBPS directory only has a file content.opf.

user41974
  • 841
  • 1
    What is the question exactly? Do you want to know how to put together the example that you present? What did you try? Do you get an error message in LaTeX? Or in tex4ebook? Also: is it really a problem to have multiple chessboard images in the source of the pdf file? – Marijn Jan 17 '17 at 09:31
  • @Marijn Please see michal.h21 answer for I wanted. – user41974 Jan 18 '17 at 03:00
  • This issue is fixed in the development version of tex4ebook, you may install it from Github. I should update also the TeX distributions soon. – michal.h21 Jan 28 '17 at 11:29
  • @michal.h21Thanks for the update. However the file still causes problems as I explain in the updated question. – user41974 Jan 29 '17 at 03:18
  • that's strange, I can open it with Calibre with no problems (on Linux), and epubcheck doesn't detect any errors. – michal.h21 Jan 29 '17 at 09:07
  • @michal.h21 I have added a correction to my last update. Does this help you to explain the issue? Thanks. – user41974 Jan 30 '17 at 06:15
  • does file mwename.ncx exist in your working directory? – michal.h21 Jan 30 '17 at 07:41
  • @michal.h21 Yes, I've included it above. Thanks. – user41974 Jan 30 '17 at 08:04
  • try to remove mwename-epub directory. It is really strange that all files are missing from the OEBPS directory, don't you get some errors at the end of compilation, where files are copied to this directory? There should be something like Copy: cp "mwename.html" "mwename-epub/OEBPS" – michal.h21 Jan 30 '17 at 08:32
  • @michal.h21I've put the log file at https://drive.google.com/file/d/0Bw1YmTtvZUu9dk5yOURqZ2pUNWM/view?usp=sharing Thanks. – user41974 Jan 30 '17 at 08:42
  • @michal.h21I have cleared the mwename-epub directory each time before running tex4ebook. The new log file is at https://drive.google.com/open?id=0Bw1YmTtvZUu9clFuX25NaHNUd1E Thanks. – user41974 Jan 30 '17 at 23:44
  • @user41974 it seems that there is a problem with recent changes in generated file handling on Windows. It works correctly on Linux. I need to investigate it. – michal.h21 Jan 31 '17 at 12:18
  • @michal.h21 Many thanks for confirming the error I am seeing. I will wait for your advice. Thanks again. – user41974 Jan 31 '17 at 12:27
  • @user41974 I!ve updated tex4ebook sources, it works on Windows for me – michal.h21 Jan 31 '17 at 13:55
  • @michal.h21 Thanks for the update. It works for me too. I have noticed some other issues but I will ask a separate question to avoid confusion. Thanks again. – user41974 Feb 01 '17 at 03:49

1 Answers1

2

It seems that every use of \savebox make a copy of the data, but using the same output image name. We can use this fact, and create custom image conversion function in the make4ht build file, which will check the file name and convert it only once.

Save the following file as mwename.mk4:

local used_images = {}
Make:image("png$", function(par)
  local output = par.output
  if not used_images[output] then
    local command = "dvipng -bg Transparent -T tight -D ${resolution} -o ${output}  -pp ${page} ${source}" % par
    print(command)
    used_images[output] = true
    os.execute(command)
  end
  return true
end)

The build file is a Lua script, function Make:image("png$",...) configures the creation of png images. It checks if the file name has been used and it will create the image only if it hadn't.

When we modify the MWE to create pictures:

\documentclass{article}

\usepackage{storebox}

\newstorebox{\mybox}


\begin{document}

\storebox{\mybox}{\Picture+{}Contents of box\EndPicture}

\usestorebox{\mybox}

\usestorebox{\mybox}

\end{document}

This is the result:

enter image description here

You can use the -r command line option to change the resolution of the picture:

 tex4ebook -r 133 mwename.tex
michal.h21
  • 50,697