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.

  • 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 9:31
  • @Marijn Please see michal.h21 answer for I wanted. – user41974 Jan 18 '17 at 3: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 3: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 9:07
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
  • That is exactly what I wanted. Thanks very much again. – user41974 Jan 18 '17 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.