├── .gitignore
├── .travis.yml
├── tex4ebook-doc.tex
├── tex4ebook-exec_azw.lua
├── tex4ebook-exec_azw3.lua
├── INSTALL.md
├── backup
├── make4ht.lua
└── ebookutils.lua
├── tex4ebook-exec_mobi.lua
├── tex4ebook-tidyconf.conf
├── Makefile
├── tex4ebook.sty
├── tex4ebook
├── tex4ebook-epub3.4ht
├── tex4ebook-exec_epub3.lua
├── CHANGELOG.md
├── README.md
├── tex4ebook.4ht
└── tex4ebook-exec_epub.lua
/.gitignore:
--------------------------------------------------------------------------------
1 | *.aux
2 | *.log
3 | *.lg
4 | *.xref
5 | *.tmp
6 | *.toc
7 | *.css
8 | *.out
9 | *.4ct
10 | *.4tc
11 | *.swp
12 | *.dvi
13 | *.idv
14 | *.epub
15 | *.html
16 | *.opf
17 | *.ncx
18 | *.fls
19 | *.pdf
20 | *.fdb_latexmk
21 | readme.tex
22 | changelog.tex
23 | tags
24 | tex4ebook-doc-epub3/
25 | tex4ebook-doc-epub/
26 | make4ht-eb.lua
27 | build/
28 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | dist: bionic
2 |
3 | install:
4 | - sudo apt-get install -qq luatex texlive-base texlive-luatex pandoc latexmk texlive texlive-xetex tex4ht texlive-latex-extra texlive-fonts-extra texlive-fonts-recommended fonts-lmodern tex-gyre fonts-texgyre
5 | # make4ht
6 | - git clone https://github.com/michal-h21/make4ht
7 | - cd make4ht
8 | - sudo make justinstall
9 | - cd ..
10 |
11 |
12 | script:
13 | # From https://github.com/michal-h21/tex4ebook/issues/37#issuecomment-354447097
14 | - git fetch --tags
15 | # Install globally
16 | - make
17 | - sudo make install
18 | # Run
19 | - tex4ebook tex4ebook-doc.tex
20 |
--------------------------------------------------------------------------------
/tex4ebook-doc.tex:
--------------------------------------------------------------------------------
1 | \documentclass{article}
2 |
3 |
4 | \usepackage[english]{babel}
5 | \usepackage{hyperref}
6 | \ifdefined\HCode
7 | \usepackage[T1]{fontenc}
8 | \usepackage[utf8]{inputenc}
9 | \author{\href{mailto:michal.h21@gmail.com}{Michal Hoftich}}
10 | \else
11 | \usepackage{luatexbase}
12 | \usepackage{fontspec}
13 | \setmainfont{TeX Gyre Schola}
14 | \author{Michal Hoftich\footnote{\url{michal.h21@gmail.com}}}
15 | \fi
16 | \usepackage{microtype}
17 | \providecommand\tightlist{\relax}
18 | \ifdefined\gitdate\else\def\gitdate{Date undefined}\fi
19 | \ifdefined\version\else\def\version{Version undefined}\fi
20 |
21 | \title{The \texttt{tex4ebook} package}
22 | % \author{Michal Hoftich\thanks{\url{michal.h21@gmail.com}}}
23 | \date{Version \version\\\gitdate}
24 | \begin{document}
25 | \maketitle
26 | \tableofcontents
27 | \input{readme}
28 |
29 | \input{changelog}
30 | \end{document}
31 |
--------------------------------------------------------------------------------
/tex4ebook-exec_azw.lua:
--------------------------------------------------------------------------------
1 | module(...,package.seeall)
2 | local eb = require("tex4ebook-exec_epub")
3 | local mobi = require("tex4ebook-exec_mobi")
4 | local ebookutils = require("mkutils")
5 | local log = logging.new "exec_azw"
6 |
7 | function prepare(params)
8 | return eb.prepare(params)
9 | end
10 |
11 | function run(out,params)
12 | return eb.run(out, params)
13 | end
14 |
15 | function writeContainer()
16 | local ret = eb.writeContainer()
17 | -- convert the epub file to azw
18 | local epubpath = eb.basedir .. "/" .. eb.outputfile
19 |
20 | -- find the azw filename
21 | local azwfile = eb.outputfile:gsub("epub$", "azw")
22 | local azwdist = eb.destdir .. azwfile
23 | local status = mobi.kindlegen(epubpath, azwfile)
24 | if status then
25 | -- copy the azw file to the destination directory
26 | -- the destination directory will be created by the epub writer, so it is possible to use
27 | -- the cp function which doesn't try to create directory
28 | if azwfile ~= azwdist then
29 | ebookutils.cp(azwfile, azwdist)
30 | end
31 | end
32 |
33 | return ret
34 | end
35 |
36 | function clean()
37 | return eb.clean()
38 | end
39 |
--------------------------------------------------------------------------------
/tex4ebook-exec_azw3.lua:
--------------------------------------------------------------------------------
1 | module(...,package.seeall)
2 | local eb = require("tex4ebook-exec_epub")
3 | local mobi = require("tex4ebook-exec_mobi")
4 | local ebookutils = require("mkutils")
5 | local log = logging.new "exec_azw"
6 |
7 | function prepare(params)
8 | return eb.prepare(params)
9 | end
10 |
11 | function run(out,params)
12 | return eb.run(out, params)
13 | end
14 |
15 | function writeContainer()
16 | local ret = eb.writeContainer()
17 | -- convert the epub file to azw
18 | local epubpath = eb.basedir .. "/" .. eb.outputfile
19 |
20 | -- find the azw filename
21 | local azwfile = eb.outputfile:gsub("epub$", "azw3")
22 | local azwdist = eb.destdir .. azwfile
23 | -- local command = "kindlegen " .. epubpath .. " -o " .. azwfile
24 | -- log:info("Pack azw ".. command)
25 | -- local status, output = ebookutils.execute(command)
26 | local status = mobi.kindlegen(epubpath, azwfile)
27 | if status then
28 | -- copy the azw file to the destination directory
29 | -- the destination directory will be created by the epub writer, so it is possible to use
30 | -- the cp function which doesn't try to create directory
31 | if azwfile ~= azwdist then
32 | ebookutils.cp(azwfile, azwdist)
33 | end
34 | end
35 |
36 | return ret
37 | end
38 |
39 | function clean()
40 | return eb.clean()
41 | end
42 |
--------------------------------------------------------------------------------
/INSTALL.md:
--------------------------------------------------------------------------------
1 | Installation
2 | ------------
3 |
4 | The stable version of `tex4ebook` is distributed by TeX distributions, it is included in both TeX Live and Miktex.
5 | A working \TeX\ distribution that includes [\TeX4ht](https://tug.org/tex4ht/) is required to run
6 | `tex4ebook`, as it depends on \LaTeX\ and various programs and packages provided by \TeX\ distributions.
7 | The development version may be installed using the following instructions.
8 |
9 | > This package depends on
10 | > [`make4ht`](https://github.com/michal-h21/make4ht#instalation) now, please
11 | > install it first.
12 | >
13 | > It also depends on `tidy` and `zip` commands, both are available for Unix
14 | > and Windows platforms, `zip` is distributed with TeX Live on Windows.
15 | > You need [Pandoc](http://pandoc.org/) in order to make documentation.
16 |
17 | On Unix systems, clone this repository to your disc and run command
18 |
19 | make
20 | make install
21 |
22 | `tex4ebook` is installed to `/usr/local/bin` directory by default. The
23 | directory can be changed by passing it's location to the `BIN_DIR` variable:
24 |
25 | make install BIN_DIR=~/.local/bin/
26 |
27 | For Windows settings, see a
28 | [guide](https://d800fotos.wordpress.com/2015/01/19/create-e-books-from-latex-tex-files-ebook-aus-latex-tex-dateien-erstellen/) by Volker Gottwald.
29 |
30 | If you want to produce ebooks for Amazon Kindle (MOBI, AZW and AZW3), you need
31 | to install Kindlegen or Calibre.
32 |
33 |
34 |
--------------------------------------------------------------------------------
/backup/make4ht.lua:
--------------------------------------------------------------------------------
1 | -- Simple make system for tex4ht
2 | --kpse.set_program_name("luatex")
3 | module("make4ht",package.seeall)
4 |
5 | Make = {}
6 | --Make.params = {}
7 | Make.build_seq = {}
8 | Make.add = function(self,name,fn,par)
9 | local par = par or {}
10 | self.params = self.params or {}
11 | Make[name] = function(self,p,typ)
12 | local params = {}
13 | for k,v in pairs(self.params) do params[k] = v end
14 | for k,v in pairs(par) do params[k] = v; print("setting param "..k) end
15 | local typ = typ or "make"
16 | local p = p or {}
17 | local fn = fn
18 | for k,v in pairs(p) do
19 | params[k]=v
20 | end
21 | -- print( fn % params)
22 | local command = {
23 | name=name,
24 | type=typ,
25 | command = fn,
26 | params = params
27 | }
28 | table.insert(self.build_seq,command)
29 | end
30 | end
31 |
32 | Make.length = function(self)
33 | return #self.build_seq
34 | end
35 | Make.run = function(self)
36 | local return_codes = {}
37 | for _,v in ipairs(self.build_seq) do
38 | --print("sekvence: "..v.name)
39 | local params = self.params or {}
40 | for p,n in pairs(v.params) do params[p] = n end
41 | --for c,_ in pairs(params) do print("build param: "..c) end
42 | local command = v.command % params
43 | print("Make4ht: " .. command)
44 | local status = os.execute(command)
45 | table.insert(return_codes,{name=v.name,status=status})
46 | end
47 | return return_codes
48 | end
49 |
50 | --[[Make:add("hello", "hello ${world}", {world = "world"})
51 | Make:add("ajaj", "ajaj")
52 | Make:hello()
53 | Make:hello{world="světe"}
54 | Make:hello()
55 | Make:run()
56 | --]]
57 |
--------------------------------------------------------------------------------
/tex4ebook-exec_mobi.lua:
--------------------------------------------------------------------------------
1 | module(...,package.seeall)
2 | local eb = require("tex4ebook-exec_epub")
3 | local ebookutils = require("mkutils")
4 | local log = logging.new "exec_mobi"
5 |
6 | function prepare(params)
7 | return eb.prepare(params)
8 | end
9 |
10 | function run(out,params)
11 | return eb.run(out, params)
12 | end
13 |
14 | function kindlegen(source, outputfile)
15 | -- try to run kindlegen first
16 | local command = "kindlegen " .. source .. " -o " .. outputfile
17 | local status, output = ebookutils.execute(command)
18 | log:debug("running kindlegen: " .. command, status)
19 | -- if we cannot find kindlegen, try ebook-convert
20 | if not output:match("Amazon") then
21 | log:debug("kindlegen failed, trying epub-convert")
22 | local ebookcmd = "ebook-convert " .. source .. " " .. outputfile
23 | status, output = ebookutils.execute(ebookcmd)
24 | if status > 0 then
25 | log:error("Conversion to the output format failed")
26 | log:error("Do you have either kindlegen or ebook-convert installed?")
27 | return false
28 | end
29 | end
30 | return true
31 | end
32 |
33 | function writeContainer()
34 | local ret = eb.writeContainer()
35 | -- convert the epub file to mobi
36 | local epubpath = eb.basedir .. "/" .. eb.outputfile
37 | -- find the mobi filename
38 | local mobifile = eb.outputfile:gsub("epub$", "mobi")
39 | local mobidist = eb.destdir .. eb.outputfile:gsub("epub$", "mobi")
40 | log:info("Convert Epub to mobi")
41 | local status = kindlegen(epubpath, mobifile)
42 | if status then
43 | -- copy the mobi file to the destination directory
44 | -- the destination directory will be created by the epub writer, so it is possible to use
45 | -- the cp function which doesn't try to create directory
46 | if mobifile ~= mobidist then
47 | ebookutils.cp(mobifile, mobidist)
48 | end
49 | end
50 | return ret
51 | end
52 |
53 | function clean()
54 | return eb.clean()
55 | end
56 |
57 |
--------------------------------------------------------------------------------
/tex4ebook-tidyconf.conf:
--------------------------------------------------------------------------------
1 | show-warnings: no
2 | numeric-entities:yes
3 | new-inline-tags:span,a,math,mi, mo, mn ,abs ,and ,annotation ,annotation-xml ,apply ,approx ,arccos ,arccosh ,arccot ,arccoth ,arccsc ,arccsch ,arcsec ,arcsech ,arcsin ,arcsinh ,arctan ,arctanh ,arg ,bind ,bvar ,card ,cartesianproduct ,cbytes ,ceiling ,cerror ,ci ,cn ,codomain ,complexes ,compose ,condition ,conjugate ,cos ,cosh ,cot ,coth ,cs ,csc ,csch ,csymbol ,curl ,declare ,degree ,determinant ,diff ,divergence ,divide ,domain ,domainofapplication ,el ,emptyset ,eq ,equivalent ,eulergamma ,exists ,exp ,exponentiale ,factorial ,factorof ,false ,floor ,fn ,forall ,gcd ,geq ,grad ,gt ,ident ,image ,imaginary ,imaginaryi ,implies ,in ,infinity ,int ,integers ,intersect ,interval ,inverse ,lambda ,laplacian ,lcm ,leq ,limit ,list ,ln ,log ,logbase ,lowlimit ,lt ,maction ,malign ,maligngroup ,malignmark ,malignscope ,math ,matrix ,matrixrow ,max ,mean ,median ,menclose ,merror ,mfenced ,mfrac ,mfraction ,mglyph ,mi ,min ,minus ,mlabeledtr ,mlongdiv ,mmultiscripts ,mn ,mo ,mode ,moment ,momentabout ,mover ,mpadded ,mphantom ,mprescripts ,mroot ,mrow ,ms ,mscarries ,mscarry ,msgroup ,msline ,mspace ,msqrt ,msrow ,mstack ,mstyle ,msub ,msubsup ,msup ,mtable ,mtd ,mtext ,mtr ,munder ,munderover ,naturalnumbers ,neq ,none ,not ,notanumber ,note ,notin ,notprsubset ,notsubset ,or ,otherwise ,outerproduct ,partialdiff ,pi ,piece ,piecewise ,plus ,power ,primes ,product ,prsubset ,quotient ,rationals ,real ,reals ,reln ,rem ,root ,scalarproduct ,sdev ,sec ,sech ,selector ,semantics ,sep ,set ,setdiff ,share ,sin ,sinh ,subset ,sum ,tan ,tanh ,tendsto ,times ,transpose ,true ,union ,uplimit ,variance ,vector ,vectorproduct ,xor ,bdi ,command ,details ,dialog ,summary ,figure ,figcaption ,footer ,header ,mark ,meter ,progress ,ruby ,rt ,rp ,time ,wbr ,altGlyph ,altGlyphDef ,altGlyphItem ,animate ,animateColor ,animateMotion ,animateTransform ,circle ,clipPath ,color-profile ,cursor ,defs ,desc ,ellipse ,feBlend ,feColorMatrix ,feComponentTransfer ,feComposite ,feConvolveMatrix ,feDiffuseLighting ,feDisplacementMap ,feDistantLight ,feFlood ,feFuncA ,feFuncB ,feFuncG ,feFuncR ,feGaussianBlur ,feImage ,feMerge ,feMergeNode ,feMorphology ,feOffset ,fePointLight ,feSpecularLighting ,feSpotLight ,feTile ,feTurbulence ,filter ,font ,font-face ,font-face-format ,font-face-name ,font-face-src ,font-face-uri ,foreignObject ,g ,glyph ,glyphRef ,hkern ,image ,line ,linearGradient ,marker ,mask ,metadata ,missing-glyph ,mpath ,path ,pattern ,polygon ,polyline ,radialGradient ,rect ,script ,set ,stop ,style ,svg ,switch ,symbol ,text ,textPath ,title ,tref ,tspan ,use
4 | new-blocklevel-tags: aside,section,article,nav
5 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | tex_content = tex4ebook $(wildcard *.sty) $(wildcard *.4ht) $(wildcard *.tex) tex4ebook-tidyconf.conf
2 | lua_content = $(wildcard *.lua)
3 | doc_file = tex4ebook-doc.pdf
4 | TEXMFHOME = $(shell kpsewhich -var-value=TEXMFHOME)
5 | INSTALL_DIR = $(TEXMFHOME)/tex/latex/tex4ebook
6 | LUA_DIR = $(TEXMFHOME)/scripts/lua/tex4ebook
7 | MANUAL_DIR = $(TEXMFHOME)/doc/latex/tex4ebook
8 | BIN_DIR = /usr/local/bin
9 | # expand the bin directory
10 | SYSTEM_DIR = $(realpath $(BIN_DIR))
11 | EXECUTABLE = $(SYSTEM_DIR)/tex4ebook
12 | BUILD_DIR = build
13 | BUILD_TEX4EBOOK = $(BUILD_DIR)/tex4ebook/
14 | VERSION:= undefined
15 | DATE:= undefined
16 | ifeq ($(strip $(shell git rev-parse --is-inside-work-tree 2>/dev/null)),true)
17 | VERSION:= $(shell git --no-pager describe --abbrev=0 --tags --always )
18 | DATE:= $(firstword $(shell git --no-pager show --date=short --format="%ad" --name-only))
19 | endif
20 |
21 | # use sudo for install to a destination directory outside of $HOME
22 | ifeq ($(findstring home,$(SYSTEM_DIR)),home)
23 | SUDO:=
24 | else
25 | SUDO:=sudo
26 | endif
27 |
28 | ifeq ("$(wildcard $(EXECUTABLE))","")
29 | INSTALL_COMMAND:=$(SUDO) ln -s $(INSTALL_DIR)/tex4ebook $(EXECUTABLE)
30 | else
31 | INSTALL_COMMAND:=
32 | endif
33 |
34 |
35 | all: doc
36 |
37 | .PHONY: tags
38 |
39 | tags:
40 | ifeq ($(strip $(shell git rev-parse --is-inside-work-tree 2>/dev/null)),true)
41 | git fetch --tags
42 | endif
43 |
44 | doc: $(doc_file) readme.tex
45 |
46 |
47 | tex4ebook-doc.pdf: tex4ebook-doc.tex readme.tex changelog.tex tags
48 | latexmk -pdf -pdflatex='lualatex "\def\version{${VERSION}}\def\gitdate{${DATE}}\input{%S}"' tex4ebook-doc.tex
49 |
50 | readme.tex: README.md
51 | pandoc -f markdown+definition_lists+inline_notes+autolink_bare_uris -t LaTeX README.md > readme.tex
52 |
53 | changelog.tex: CHANGELOG.md
54 | pandoc -f markdown+definition_lists -t LaTeX CHANGELOG.md > changelog.tex
55 |
56 | build: doc $(tex_content) $(lua_content)
57 | @rm -rf build
58 | @mkdir -p $(BUILD_TEX4EBOOK)
59 | @cp $(tex_content) $(lua_content) tex4ebook-doc.pdf $(BUILD_TEX4EBOOK)
60 | @cat tex4ebook | sed -e "s/{{version}}/${VERSION}/" > $(BUILD_TEX4EBOOK)tex4ebook
61 | @cat tex4ebook.sty | sed -e "s/{{version}}/${VERSION}/" | sed -e "s/{{date}}/${DATE}/" > $(BUILD_TEX4EBOOK)tex4ebook.sty
62 | @cp README.md $(BUILD_TEX4EBOOK)README
63 | cd $(BUILD_DIR) && zip -r tex4ebook.zip tex4ebook
64 |
65 | install: doc $(tex_content) $(lua_content)
66 | mkdir -p $(INSTALL_DIR)
67 | mkdir -p $(MANUAL_DIR)
68 | mkdir -p $(LUA_DIR)
69 | cp $(tex_content) $(INSTALL_DIR)
70 | cp $(lua_content) $(LUA_DIR)
71 | cp $(doc_file) $(MANUAL_DIR)
72 | chmod +x $(INSTALL_DIR)/tex4ebook
73 | $(INSTALL_COMMAND)
74 |
75 |
--------------------------------------------------------------------------------
/tex4ebook.sty:
--------------------------------------------------------------------------------
1 | % Package tex4ebook. Author Michal Hoftich }}
136 | {\EndP\printfn\HCode{ }}
137 | {\HCode{\Hnewline}}{\ }{\Tg
\Tg