From 9e0b2d9b1cebb626bf67a18914cd18ad70e9835a Mon Sep 17 00:00:00 2001 From: fennecj Date: Mon, 2 Aug 2021 01:39:02 +0800 Subject: [PATCH] Generate HTML via make4ht This patch add some scripts which are meant to generate html files successfully using `make4ht`. The target is to build a directory html/ for github page deployment usuage. Problems : When you try using `make4ht -suf html5 -d html lkmpg.tex` to parse the file, you'll find out that make4ht has several defectors: 1. The layout is unsatisfying 2. When it parsing lkmpg.tex and meet \tableofcontents will throw error 3. It generated a lot unneeded files when parsing lkmpg.tex 4. The output filenames are based on input filename and you can't assign them, which is inconvinient cause github page will only recognize the file named `index.html`. Solutions : For problem 1, we can write a config file `html.cfg` to specify the layout style of lkmpg.html with css selectors. For problem 2, we can turn off the \tableofcontents section when using make4ht. However, this cause the output html files without table of contents part. And we can fix this by adding `\Configure{tableofcontents*}{chapter,section,subsection}` into html.cfg so the output html files will contain table of contents again. For problem 3, we can add some delete commands into Makefile. For problem 4, we can add a symbolic link `index.html` lined to `lkmpg.html` Overview of file changes : In html.cfg : Specify the layout of lkmpg.html. Add tables of contents. In Makefile : Add a new target `html` for generating html files and put them in html/ directory. Add a symbolic link `index.html` linked to `lkmpg.html`. Add several `rm` command to get rid of unneeded files. In lkmpg.tex : Turn off the \tableofcontens section when using `make4ht` to prevent from error. --- .gitignore | 12 ++++++++++++ Makefile | 8 ++++++++ html.cfg | 36 ++++++++++++++++++++++++++++++++++++ lkmpg.tex | 4 ++++ 4 files changed, 60 insertions(+) create mode 100644 html.cfg diff --git a/.gitignore b/.gitignore index 555e937a..c2a2be60 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,15 @@ _minted-lkmpg *.out lkmpg.pdf *.toc + +# make4ht +*.html +*.svg +*.tmp +*.css +*.4ct +*.4tc +*.dvi +*.lg +*.idv +*.xref diff --git a/Makefile b/Makefile index d7d60a55..fd97442e 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,14 @@ all: lkmpg.tex bibtex main >/dev/null || echo pdflatex -shell-escape $< 2>/dev/null >/dev/null +html: lkmpg.tex html.cfg + make4ht --shell-escape --utf8 --format html5 --config html.cfg --output-dir html lkmpg.tex + ln -sf lkmpg.html html/index.html + rm -f lkmpg.xref lkmpg.tmp lkmpg.html lkmpg.css lkmpg.4ct lkmpg.4tc lkmpg.dvi lkmpg.lg lkmpg.idv lkmpg*.svg lkmpg.log lkmpg.aux + clean: rm -f *.dvi *.aux *.log *.ps *.pdf *.out lkmpg.bbl lkmpg.blg lkmpg.lof lkmpg.toc rm -rf _minted-lkmpg + rm -rf html + +.PHONY: html diff --git a/html.cfg b/html.cfg new file mode 100644 index 00000000..8657127f --- /dev/null +++ b/html.cfg @@ -0,0 +1,36 @@ +\Preamble{xhtml} + +\Configure{tableofcontents*}{chapter,section,subsection} + +\Css{* :not(img) { + max-width: 100\%; + width: 50vw; + height: auto; + margin: 0 auto; +}} + +\Css{* { + font-size: 1vw; +}} + +\Css{.ecrm-0500 { + font-size: 70\%; + font-style: italic; + color: gray; + -webkit-user-select: none; + -moz-user-select: none; + -o-user-select: none; + user-select: none; +}} + +\Css{.ecrm-0500:after { + content:" "; + white-space: pre; + -webkit-user-select: none; + -moz-user-select: none; + -o-user-select: none; + user-select: none; +}} + +\begin{document} +\EndPreamble \ No newline at end of file diff --git a/lkmpg.tex b/lkmpg.tex index 6b309b1a..2a7919ce 100644 --- a/lkmpg.tex +++ b/lkmpg.tex @@ -39,7 +39,11 @@ \begin{document} \maketitle +\ifdefined\HCode +% turn off TOC +\else \tableofcontents +\fi \section{Introduction} \label{sec:introduction}