Debian Codegraph @

texmf-dist/doc/support/tex4ebook/README

raw
1 % [![Build Status](https://travis-ci.org/michal-h21/tex4ebook.svg?branch=master)](https://travis-ci.org/michal-h21/tex4ebook)
2
3 # Introduction
4
5 `TeX4ebook` is a tool for conversion from \LaTeX\ to
6 ebook formats, such as EPUB, MOBI and EPUB 3.
7 It is based on `TeX4ht`^[https://tug.org/tex4ht/],
8 which provides instructions for the actual \LaTeX\ to HTML conversion,
9 and on `make4ht`^[https://ctan.org/pkg/make4ht?lang=en].
10
11
12 The conversion is focused on the logical structure of the converted document
13 and metadata. Basic visual appearance is preserved as well, but you should use
14 custom configurations if you want to make the document more visually appealing.
15 You can include custom `CSS` or fonts in a configuration file.
16
17 `TeX4ebook` supports the same features as `make4ht`, in particular build files and extensions.
18 These may be used for post-processing of the generated HTML files, or to configure the image conversion.
19 See the `make4ht` documentation to see the supported features.
20
21 # Installation
22
23 `tex4ebook` is included in major \TeX\ distributions such as [\TeX\ Live](https://www.tug.org/texlive/)
24 and [MiKTeX](https://miktex.org/), so manual installation is usually not required.
25 A working \TeX\ distribution that includes [\TeX4ht](https://tug.org/tex4ht/) is required to run
26 `tex4ebook`, as it depends on \LaTeX\ and various programs and packages provided by \TeX\ distributions.
27
28 You only need to install it manually if you want to use the development
29 version. For detailed instructions, see the [`INSTALL.md`](./INSTALL.md) file.
30
31
32 # License
33
34 Permission is granted to copy, distribute and/or modify this software
35 under the terms of the LaTeX Project Public License, version 1.3.
36
37
38 # Usage
39
40
41 Run on the command line:
42
43 tex4ebook [options] filename
44
45 You don't have to modify your source files unless you want to use commands
46 defined by `tex4ebook` in the document, or when your document uses a
47 package which causes a compilation error.
48
49
50 If you want to use `tex4ebook` commands, add this line to your document
51 preamble:
52
53 \usepackage{tex4ebook}
54
55 But it is optional. You shouldn't need to modify your \TeX\ files
56
57 ## Available commands
58
59 - `\coverimage[<graphicx options>]{coverimage.name}` -- include cover image to
60 the document. You can pass the same options as to `\includegraphics` command
61 in the optional argument.
62
63 For example:
64
65 \thispagestyle{empty}
66 \begin{document}
67 \coverimage[scale=0.8]{coverimage.name} % include scaled cover image
68 ...
69 \pagestyle{headings}
70
71 - `\epubpage` -- add page break to the document.
72
73 # Command line options
74
75 `-a,--loglevel`
76
77 : Set message log level. Possible values: debug, info, status, warning, error, fatal. Default: status.
78
79 `-c,--config`
80
81 : specify custom config file for `TeX4ht`
82
83 **example config file**: File `sample.cfg`
84
85
86 \Preamble{xhtml}
87 \CutAt{section}
88 \begin{document}
89 \EndPreamble
90
91 run
92
93 tex4ebook -c sample filename.tex
94
95 This config file will create `xhtml` file for every section. Note that this
96 behaviour is default.
97
98 `-e,--build-file (default nil)`
99
100 : Specify make4ht build file^[https://github.com/michal-h21/make4ht#build-file].
101 Default build file filename is `filename.mk4`, use this option if you use
102 different filename.
103
104 `-f,--format (default epub)`
105
106 : Output format. Possible values are `epub`, `epub3`, `mobi`, `azw` and `azw3`.
107
108 `-j,--jobname`
109
110 : Specify the output file name, without file extension.
111
112 `-l,--lua`
113
114 : Use LuaLaTeX as TeX engine.
115
116 `-m,--mode (default default)`
117
118 : This set `mode` variable, accessible in the build file. Default supported
119 values are `default` and `draft`. In `draft` mode, document is compiled
120 only once, instead of three times.
121
122 `-s,--shell-escape`
123
124 : Enable shell escape in the `htlatex` run. This is necessary for the execution of the external
125 commands from your source files.
126
127 `-t,--tidy`
128
129 : clean-up output HTML files using the `HTML tidy` command^[if it is available on your system].
130
131 `-x,--xetex`
132
133 : Use xelatex for document compilation
134
135
136 `-v,--version`
137
138 : Print the version number.
139
140 # Configuration
141
142 `TeX4ebook` uses `TeX4ht`^[http://www.tug.org/tex4ht/] for conversion from LaTeX
143 to html. `TeX4ht` is highly configurable using config files. Basic config file
144 structure is
145
146 \Preamble{xhtml, comma separated list of options}
147 ...
148 \begin{document}
149 ...
150 \EndPreamble
151
152 Basic info about command configurations can be found in a
153 work-in-progres *TeX4ht tutorial*^[https://github.com/michal-h21/helpers4ht/wiki/tex4ht-tutorial],
154 *TeX4ht documentation*^[http://www.tug.org/applications/tex4ht/mn11.html],
155 and in series of blogposts on CV Radhakrishnan's blog:
156 *Configure part 1*^[https://web.archive.org/web/20180908234227/http://www.cvr.cc/?p=323],
157 *Configure part 2*^[https://web.archive.org/web/20180908201057/http://www.cvr.cc/?p=362],
158 *Low level commands*^[https://web.archive.org/web/20180909101325/http://cvr.cc/?p=482].
159 Available options for `\Preamble` command are listed in the article
160 *TeX4ht: options*^[https://web.archive.org/web/20180813043722/http://cvr.cc/?p=504]. *Comparison of tex4ebook and Pandoc output*^[https://github.com/richelbilderbeek/travis_tex_to_epub_example_1]
161
162 A great source of tips for `TeX4ht` configuration is *tex4ht tag on TeX.sx*^[http://tex.stackexchange.com/questions/tagged/tex4ht]. There is also a *tag for tex4ebook*^[http://tex.stackexchange.com/questions/tagged/tex4ebook].
163
164 Examples of interesting questions are
165 *including images and fonts in ebooks*^[http://tex.stackexchange.com/a/213165/2891]
166 or *setting image size in em units instead of pt*^[http://tex.stackexchange.com/a/195718/2891].
167
168 ## Provided configurations
169
170 `tex4ebook` provides some configurations for your usage:
171
172 \Configure{UniqueIdentifier}{identifier}
173
174
175 Every EPUB file should have unique identifier, like ISBN, DOI, URI etc.
176 Default identifier is URI, with value `http://example.com/\jobname`.
177
178 \Configure{@author}{\let\footnote\@gobble}
179
180 Local definitions of commands used in the `\author` command. As contents of
181 `\author` are used in XML files, it is necessary to strip away any information
182 which don't belongs here, such as `\footnote`.
183
184 \Configure{OpfScheme}{URI}
185
186 Type of unique identifier, default type is URI. It is
187 used only in the EPUB format, it is deprecated for EPUB 3.
188
189 \Configure{resettoclevels}{list of section types in descending order}
190
191 Configure section types which should be included in the `NCX` file. Default
192 value is the whole document hierarchy, from `\part` to `\paragraph`.
193
194 \Configure{DocumentLanguage}{language code}
195
196 Each EPUB file must declare the document language. It is inferred from `babel` main
197 language by default, but you can configure it when it doesn't work correctly.
198 The `language code` should be in [ISO
199 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) form.
200
201 \Configure{CoverImage}{before cover image}{after cover image}
202
203 By default, cover image is inserted in `<div class="cover-image">` element,
204 you may use this configuration option to insert different markup,
205 or even to place the cover image to standalone page.
206
207
208 \Configure{CoverMimeType}{mime type of cover image}
209
210 Default value is `image/png`, change this value if you use other image
211 type than `png`.
212
213 If you don't want to include the cover image in the document, use command
214
215 \CoverMetadata{filename}
216
217 in the config file.
218
219 \Configure{OpfMetadata}{item element}
220
221 Add item to `<metadata>` section in the `OPF` file.
222
223 \Configure{OpfManifest}{maifest element}
224
225 Add item to `<manifest>` section in the `OPF` file.
226
227 \Configure{xmlns}{prefix}{uri}
228
229 Add `XML` name space to the generated `XHTML` files. Useful in `EPUB 3`.
230
231
232 ### Example config file
233
234 \Preamble{xhtml}
235 \begin{document}
236 \Configure{DocumentLanguage}{de}
237 % Use following lines if your document has ISBN:
238 % \Configure{OpfScheme}{ISBN}
239 % \Configure{UniqueIdentifier}{3-0000-1111-X}
240 % Another possibility is URI that points for example to the ebook homepage:
241 \Configure{OpfScheme}{URI}
242 \Configure{UniqueIdentifier}
243 {https://de.wikipedia.org/wiki/Der_achte_Sch&ouml;pfungstag}
244 \Configure{CoverMimeType}{image/jpeg}
245 % If you don't use \coverimage in the document text,
246 % add cover image using this command:
247 \CoverMetadata{coverimage.jpg}
248 % You can also add more authors to your ebook metadata:
249 \Configure{OpfMetadata}
250 {\HCode{<dc:publisher>Deutscher Bücherbund</dc:publisher>}}
251 \Configure{OpfMetadata}
252 {\HCode{<dc:contributor>Image Artist</dc:contributor>}}
253 \Configure{OpfMetadata}
254 {\HCode{<dc:contributor>Trans Lator</dc:contributor>}}
255 \Configure{OpfMetadata}
256 {\HCode{<dc:date opf:event='original-publication'>1888</dc:date>}}
257 \EndPreamble
258
259 Remarks:
260
261 - Leading percent signs in the `.cfg` file introduce comments
262 - If the unique identifier is a URI which contains diacritical characters, the
263 equivalent HTML code needs to be inserted. `UTF8` is not recognized at that place.
264 - `UTF8` characters may be used in the `OpfMetadata` sections.
265
266 ## \TeX4ht options
267
268 \TeX4ht supports lot of options, that change produced HTML code without need to
269 use configurations. Their list is available in the [\TeX4ht
270 documentation](https://www.kodymirus.cz/tex4ht-doc/texfourhtOptions.html).
271 You can pass options to `tex4ebook` in the argument that follows filename:
272
273 tex4ebook filename.tex "option1,option2"
274
275 Alternatively, they can be put in the `\Preamble` command in the config file:
276
277 \Preamble{xhtml,option1,option2}
278
279 ### Options provided by `tex4ebook`
280
281 `no-cut`
282
283 : By default `tex4ebook` splits document to separate HTML pages on `\chapter` command when it is available.
284 Othervise, it splits on `\section`. This can be changed using the `\CutAt` command or numeric options, but
285 you need to use the `no-cut` option to prevent fatal error.
286
287 ## Commands available in the config file
288
289 `\OpfRegisterFile[filename]`
290
291 : register file in the `OPF` file. Current output file is added by default.
292
293 `\OpfAddProperty{property type}`
294
295 : add `EPUB3` property for the current file. See *EPUB3 spec*^[http://www.idpf.org/epub/301/spec/epub-publications.html#sec-item-property-values]
296
297 `\OpfGuide[filename]{title}{type}`
298
299 : Add file to the `<guide>` section in the `OPF` file. See
300 *Where do you start an ePUB and what is the `<guide>` section of the `.OPF` file?*^[http://epubsecrets.com/where-do-you-start-an-epub-and-what-is-the-guide-section-of-the-opf-file.php]
301 for some details. Note that `<guide>` is deprecated in `EPUB 3`.
302
303
304 ## Build files
305
306 `tex4ebook` uses `make4ht`^[https://github.com/michal-h21/make4ht] as a build
307 system. It provides support for build files written in Lua. These build files
308 can be used to call additional commands, like Bib\TeX\ or Makeindex, post-process
309 generated HTML files, change the way how images are created, or to modify
310 parameters of the conversion.
311
312 Sample build file can look like this:
313
314 if mode=="draft" then
315 Make:htlatex {}
316 else
317 Make:htlatex {}
318 Make:htlatex {}
319 Make:htlatex {}
320 end
321
322 Make:image("png$",
323 "dvipng -bg Transparent -T tight -o ${output} -D 170 -pp ${page} ${source}")
324
325 The `mode` variable holds value of the `--mode` argument to `tex4ebook`. The `draft`
326 mode is used for faster compilation, it calls LaTeX only once.
327
328 The `Make:image` function can configure handling of images created by extraction from the
329 DVI file. It can be complex math, TikZ or PSTricks pictures, and so on. The `${<name>}`
330 placeholders are filled by `tex4ebook` with parameters like current page number of
331 the image DVI file, or output image name.
332
333 You can compile your document with a build file using the `-e` option:
334
335 tex4ebook -m draft -e build.lua filename.tex
336
337 See `make4ht` documentation for more details on configuration files.
338
339 ## `.tex4ebook` configuration file
340
341 `tex4ebook` supports a default build file, which is loaded automatically
342 without need to use the `-e` option.
343
344 ### Location
345
346 The configuration file can be saved either in
347 `$HOME/.config/tex4ebook/config.lua` or in `.tex4ebook` in the current directory or
348 it's parents (up to `$HOME`).
349
350 See the `make4ht` documentation for an example and more information.
351
352 # Troubleshooting
353
354 ## Kindle formats
355
356 `tex4ebook` uses `kindlegen` command for the conversion to Kindle formats (`mobi`,
357 `azw` and `azw3`). Unfortunatelly, Amazon discontinued this command, so we use
358 also `ebook-convert` provided by Calibre if `kindlegen` fails.
359
360
361 ## Fixed layout EPUB
362
363 The basic support for the Fixed layout EPUB 3 can be enabled using the following configurations:
364
365 \Configure{OpfMetadata}
366 {\HCode{<meta property="rendition:layout">pre-paginated</meta>}}
367 \Configure{OpfMetadata}
368 {\HCode{<meta property="rendition:orientation">landscape</meta>}}
369 \Configure{OpfMetadata}
370 {\HCode{<meta property="rendition:spread">none</meta>}}
371 \Configure{@HEAD}
372 {\HCode{<meta name="viewport" content="width=1920, height=1080"/>\Hnewline}}
373
374 Modify the dimensions in the `<meta name="viewport>` element according to your needs.
375
376 ## Math issues
377
378 Note that while `mobi` is supported by Amazon Kindle, most widespread ebook
379 reader, it doesn't support `MathML`. This means that math must be represented
380 as images. The same issue is true for the EPUB format as well.
381 This is problematic especially for the inline math, as you may experience wrong
382 vertical alignment of the math content and surrounding text. If your ebook contains
383 math, a better solution is to produce the `epub3` format, as it supports `MathML`.
384 The issue with EPUB 3 is that majority of `e-ink` ebook readers don't
385 support it. Reader applications exists mainly for Android and Apple
386 devices. For books which contains mainly prose, all formats should be suitable,
387 but EPUB 3 supports most features from web standards, such as `CSS`.
388
389 ## Compilation errors
390
391 When compilation of the document breaks with error during `LaTeX` run, it may
392 be caused by some problem in `TeX4ht` configuration. Comment out line
393 `\usepackage{tex4ebook}` in your source file and run command:
394
395 htlatex filename
396
397 if same error as in `tex4ebook` run arises, the problem is in some `TeX4ht`
398 configuration. Try to identify the source of problem and if you cannot find the
399 solution, make minimal example showing the error and ask for help either on
400 *TeX4ht mailing list*^[http://tug.org/mailman/listinfo/tex4ht] or on
401 *TeX.sx*^[http://tex.stackexchange.com/].
402
403 ## Validation
404
405 In case of successful compilation, use command line tool `epubcheck`^[you need
406 to install it separately, see https://github.com/IDPF/epubcheck] to check
407 whether your document doesn't contain any errors.
408
409
410 Type
411
412 epubcheck filename.epub
413
414 ### Common validation issues:
415
416 - WARNING: filename.epub: item (OEBPS/foo.boo) exists in the zip file, but is
417 not declared in the OPF file
418
419 Delete the `filename-(epub|epub3|mobi|azw|azw3)` folder and `filename.epub`. Then
420 run `tex4ebook` again.
421
422 - WARNING(ACC-009): hsmmt10t.epub/OEBPS/hsmmt10tch17.xhtml(235,15):
423 MathML should either have an alt text attribute or annotation-xml child element.
424
425 This is accessibility message. Unless you use some macro with annotations for
426 each math instance, you will get lot of these messages. Try to use
427 `epubcheck -e` to print only serious errors.