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!
1 Answers
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*%{","{")
end
local process = filter{"cleanspan", "fixligatures", "hruletohr"}
local cssprocess = filter{cssfix}
Make:htlatex()
Make:htlatex()
Make:match("html$",process)
Make:match("css$",cssprocess)
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.
- 50,697
-
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
mobiinput, so I am usingepub. Just want to confirm it is the same-qXr9Dswitches to package an epub... Thanks again. – Nat Kuhn Nov 20 '14 at 11:51 -
@NatKuhn with
tex4ebook -f mobiepub version is created first and then it is converted with kindlegen.-qXr9Dis just switch forzipcommand to use full compression, asepubis basically justzipfile with different extension – michal.h21 Nov 20 '14 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_Storeprior to repackaging if files are edited by hand? – cfr Nov 20 '14 at 15:22 -
@cfr I don't use OS X, so I don't know whether it creates such directory. does it exist for every directory? and does
zipcommand pack even hidden files and folders? – michal.h21 Nov 20 '14 at 15:30 -
It certainly used to create them all over the place. (It was a file not a directory.) I still have them all over the place after migrating to Linux because eliminating them is a pain (and I'm worried about letting a
findrip through my home directory automatically). I don't know ifzipdoes or not but it is a problem when creating archives on OS X in general. (E.g. atarwill include such files which then show up when used on other systems.) – cfr Nov 20 '14 at 17:46 -
1FWIW 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 '14 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 '14 at 19:01
-
(I started composing previous message before Nat added his comment) – michal.h21 Nov 20 '14 at 19:03
-
-
Looks like I spoke too soon. @michal.h21 I think you are right that when the directory is created by the program, there is no .DS_Store, but after you visit the directory in the "Finder" it is there, so subsequent builds will include it. There is an explanation here (http://osxdaily.com/2013/04/30/how-to-exclude-files-from-a-zip-archive/) of how to deal with the problem. When I try the "zip" as above but with the switches, I can't get the file to pass epubcheck the way your packaged file does, though. – Nat Kuhn Nov 21 '14 at 00:41
-
@NatKuhn so does
tex4ebookinclude.DS_Storeor don't? I am not sure from your previous comment. – michal.h21 Nov 21 '14 at 07:22 -
It looks as though when you first run it and it creates the project-format directory, .DS_Store is not included. It seems that OSX doesn't create
.DS_Storeuntil you look at the folder in a Finder window. If you re-runtex4ebookat that point,.DS_Storewill be included. – Nat Kuhn Nov 21 '14 at 11:27 -
The shell command
find . -name .DS_Store -deletewill delete all the.DS_Storefiles in the current directory and all subdirectories. (http://superuser.com/questions/112078/delete-matching-files-in-all-subdirectories) – Nat Kuhn Nov 22 '14 at 02:26 -
So when I package the OEBPS directory as you are suggesting, it seems to work in kindlegen, but it completely fails epubcheck, with two ERRORs:
Mimetype entry missing or not the first in archiveandRequired META-INF/container.xml resource is missing, and then it stops. Running epubcheck on the tex4ebook .epub file generates > 1000 "ERRORs", going through the whole thing. When Izipthe entire project-epubdirectory, I get all the >1000 "ERRORs" and one additional one:Mimetype entry missing or not the first in archive– Nat Kuhn Nov 22 '14 at 03:12 -
@NatKuhn I think best are two ways: add some option to
zipcommand to exclude.DS_Storefiles from packing (or all files whose filename begins with., to prevent some other possible metadata files), the second way is to call command from themk4file to delete such files. maybe you can post that as standalone question, so we can research on that problem better with some code samples? – michal.h21 Nov 23 '14 at 11:10
.epubjust a.ziparchive? 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 '14 at 01:20-qXr9Dwhich is why I was hoping for a more specific answer. – Nat Kuhn Nov 20 '14 at 11:56