TeX4ebook makes an "epub" folder which it automatically zips to make a .epub file. Occasionally (doing my best to be nice here) tex4ht produces code which needs to be hand-corrected. There must be an easy way at the command line to re-zip the folder to make the epub file after hand-editing, and I would love to know what it is rather than try to figure it out! Thanks!

  • With all due respect, you should have made clear in your question that you were not asking about command line tools to create zip archives but, rather, specifically about how to use whatever command line tool you prefer to create a zip archive with whatever features. But, if you already know how to make a zip archive and you know that epubs are zips, I can't for the life of me understand why you don't just try it and see if it works. How many seconds does it take to create a zip compared with asking a question here? I naturally assumed that you unable to perform such an experiment.
    – cfr
    Nov 20, 2014 at 1:09
  • Actually, either way this question is off-topic for this site since it apparently has nothing to do with TeX.
    – cfr
    Nov 20, 2014 at 1:11
  • Tidying up a bit...
    – cfr
    Nov 20, 2014 at 1:12
  • @cfr: I tagged it "tex4ebook" which is the system I am using. As I mentioned, when you are using tex4ebook it happens fairly frequently that the output files need hand-editing, and then manual repackaging. That is why I believe it is on-topic.
    – Nat Kuhn
    Nov 20, 2014 at 1:16
  • But your question has nothing to do with TeX. It is about the epub format i.e. it is essentially 'Is an .epub just a .zip archive? If not, what other conditions must be satisfied?' The fact that TeX is involved at an earlier point is no more relevant, as far as I can tell, than the fact that I use TeX to produce a set of slides is relevant to the question of how to project them on the screen. Your question isn't about the TeX part of the workflow. As such, it is off-topic as far as I can tell. If not, please clarify your question to explain.
    – cfr
    Nov 20, 2014 at 1:20

1 Answer 1


To make this question on topic, I will answer two questions, one which was asked, other question is whether exists a better solution for modifying the output.

To answer first question, generated and post-processed files are saved in directory filename-outputformat/OEBPS/, so if you want to edit files by hand, do it in this directory.

Say you have file named sample.tex and output format is mobi for Kindle. Open the terminal and go to directory:

cd dir with the TeX file/sample-mobi

edit files in OEBPS directory and run commands:

zip -qXr9D sample.epub OEBPS
kindlegen sample.epub

Better way than manually editing output files is to make make4ht build file and create filters for fixing problems automatically. Build files have same base name as main TeX file and extension .mk4. So it would be sample.mk4 in out case:

local filter = require "make4ht-filter"
local cssfix = function(s)
  return s:gsub("%,%s*%{","{")
local process = filter{"cleanspan", "fixligatures", "hruletohr"}
local cssprocess = filter{cssfix}

it is Lua script. Make:htlatex run Latex with tex4ht included one time, we call it two times (default used by htlatex is three passes).

Make:match will run a function on all output files which match regular expression. we use functions process for .html files and cssprocess for .css files. These functions are created by filter function, which in turn takes table with processing functions, or names of filters (see make4ht documentation for details).

To fix issue with trailing comma in the css file, I created function cssfix, which takes the css file as string and replaces all strings directly before left brace. The modified string is then saved.

  • Thank you very much, Michal. You have anticipated my next question, but I had thought it best to separate them. As you can see, I'm still new to the site and learning how to do things. Oddly, kindlegen does not seem to take mobi input, so I am using epub. Just want to confirm it is the same -qXr9D switches to package an epub... Thanks again.
    – Nat Kuhn
    Nov 20, 2014 at 11:51
  • @NatKuhn with tex4ebook -f mobi epub version is created first and then it is converted with kindlegen. -qXr9D is just switch for zip command to use full compression, as epub is basically just zip file with different extension
    – michal.h21
    Nov 20, 2014 at 12:03
  • I don't know if OS X still does this but, if it does, I assume it would be best to delete files such as .DS_Store prior to repackaging if files are edited by hand?
    – cfr
    Nov 20, 2014 at 15:22
  • 1
    FWIW I just ran the output file through epubcheck and while it flagged various figures as existing in the zip file but not being declared in the OPF file it did not flag .DS_Store. My guess is that the zip utility that ships with OSX is (now) smart enough not to do this.
    – Nat Kuhn
    Nov 20, 2014 at 18:51
  • 1
    @cfr it seems that dot files are added by zip command as well. but validation error would be produced by epubcheck if some spurious file was included in the epub file, so maybe this file isn't created when directory is created programmatically. (or no tex4ebook used uses OS X)
    – michal.h21
    Nov 20, 2014 at 19:01

This site is temporarily in read-only mode and not accepting new answers.

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