File: run-latex2html.sh

package info (click to toggle)
form 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 8,312 kB
  • sloc: ansic: 110,546; cpp: 20,395; sh: 5,874; makefile: 545
file content (52 lines) | stat: -rwxr-xr-x 1,106 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
#
# @file run-latex2html.sh
#
# Usage:
#   run-latex2html.sh main.tex
#
set -euo pipefail

if [ $# -ne 1 ]; then
  echo "Usage: $(basename "$0") main.tex" >&2
  exit 1
fi

MAIN_PATH=$1
MAIN_TEX=$(basename "$MAIN_PATH")
MAIN_DIR=$(dirname "$MAIN_PATH")

case $MAIN_TEX in
  *.tex)
    MAIN=$(basename "$MAIN_TEX" .tex)
    ;;
  *)
    MAIN_PATH=$MAIN_PATH.tex
    MAIN=$MAIN_TEX
    MAIN_TEX=$MAIN.tex
    ;;
esac

MAIN_DIR=$MAIN_DIR/$MAIN

if [ -z "${LATEX2HTML+x}" ] || [ -z "$LATEX2HTML" ]; then
  LATEX2HTML=latex2html
fi

# https://stackoverflow.com/a/43919044
a="/$0"; a="${a%/*}"; a="${a:-.}"; a="${a##/}/"; BINDIR=$(cd "$a"; pwd)

LATEX2HTML_INIT=$BINDIR/.latex2html-init

"$LATEX2HTML" -init_file "$LATEX2HTML_INIT" "$MAIN_PATH"

fix_html() {
  # (1) HREF="main.html#SECTION..." -> HREF="#SECTION..."
  # (2) workaround for latex2html < v2025
  #     See: https://github.com/latex2html/latex2html/commit/b77ee98
  sed "s/$2.html#/#/g" "$1" | sed 's/&&#x308;#305;/\&iuml;/g' >"$1.tmp"
  mv "$1.tmp" "$1"
}

fix_html "$MAIN_DIR/index.html" "$MAIN"
fix_html "$MAIN_DIR/$MAIN.html" "$MAIN"