From 5412aa6e50d136e409858b850f3319cdf9406392 Mon Sep 17 00:00:00 2001 From: Hendrik Kleinwaechter Date: Fri, 26 May 2023 13:35:04 +0200 Subject: [PATCH] Ebook improvements (#103) * Ebook improvements Removes fixed height and width from the resulting HTML and adds an additional css for the ebook formats. * Update gitignore * Strip tags --- .gitignore | 1 + book/book-ebook.css | 9 +++++++++ book/book.mk4 | 9 +++++++++ book/makefile | 5 +++-- book/tex4ebook.cfg | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 book/book-ebook.css create mode 100644 book/book.mk4 diff --git a/.gitignore b/.gitignore index bb985d4..d4b68f5 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,5 @@ book/book-mobi/ book/book-azw3/ *.bak book_sans_serif/ +release_sans_serif/ *.opf diff --git a/book/book-ebook.css b/book/book-ebook.css new file mode 100644 index 0000000..ecc3e08 --- /dev/null +++ b/book/book-ebook.css @@ -0,0 +1,9 @@ +.figure { + max-width: 100%; +} +.figure img { + max-width: 100% !important; + height: auto; + object-fit: contain; + width: auto; +} diff --git a/book/book.mk4 b/book/book.mk4 new file mode 100644 index 0000000..eb3ff75 --- /dev/null +++ b/book/book.mk4 @@ -0,0 +1,9 @@ +local filter = require "make4ht-filter" +local changePath = function(s) return s:gsub("%./images//","images/") end +local removeHeight = function(s) return s:gsub('height="%d+"', '') end +local removeWidth = function(s) return s:gsub('width="%d+"', '') end +local removeMaxWidth = function(s) return s:gsub(' max-width: %d+px;', '') end +local removeFixedSettings = function(s) return removeMaxWidth(removeWidth(removeHeight(changePath(s)))) end +local process = filter{removeFixedSettings} +Make:htlatex() +Make:match("html$",process) diff --git a/book/makefile b/book/makefile index e257e1a..41e6cc4 100644 --- a/book/makefile +++ b/book/makefile @@ -111,8 +111,9 @@ release_sans_serif: make_release_dir .PHONY: build_ebook build_ebook: make_release_dir - find . -name "*.jpg" | xargs ebb -x - find . -name "*.png" | xargs ebb -x tex4ebook -c tex4ebook.cfg -f epub book.tex tex4ebook -c tex4ebook.cfg -f mobi book.tex + # not sure why, but I hvae to generate the mobi twice for the + # release command to properly work. + tex4ebook -c tex4ebook.cfg -f mobi book.tex tex4ebook -c tex4ebook.cfg -f azw3 book.tex diff --git a/book/tex4ebook.cfg b/book/tex4ebook.cfg index b84c63a..53c9efa 100644 --- a/book/tex4ebook.cfg +++ b/book/tex4ebook.cfg @@ -3,6 +3,7 @@ \Configure{DocumentLanguage}{en} \Configure{OpfScheme}{URI} \Configure{UniqueIdentifier}{https://the-bread-code.io} +\Configure{AddCss}{book-ebook.css} \Configure{CoverMimeType}{image/jpeg} \CoverMetadata{images/cover-page.jpg} \EndPreamble