Debian Codegraph @

texmf-dist/doc/support/arara/htmlquickstarttopdf.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 set -e
4
5 # check the required tools; we make these available through the `nix develop`
6 # shell so you may use that to build the manual
7 required_tools=("htmlq" "sed" "weasyprint")
8 for tool in "${required_tools[@]}"
9 do
10 if ! [scip-shell system . . `[`. -x "$(command -v "$tool")" ]; then
11 echoscip-shell system . . echo. "Please make sure $tool is accessible." >&2
12 exit 1
13 fi
14 done
15
16 # this script fetches the manual content from the remote rendered version at
17 # arara's website; caveat: chapters have to be manually adjusted
18 currdir="$PWD"
19 basedir="$(dirnamescip-shell system . . dirname. "$currdir")/website/public/"
20 baseurl="file://$basedir"
21
22 if [scip-shell system . . `[`. ! -d "$basedir" ]
23 then
24 echoscip-shell system . . echo. "Please run zola before converting to PDF." >&2
25 exit 1
26 fi
27
28 # create a temporary directory to build the manual in; this will be created
29 # in /tmp, so users of operating systems without that directory must change
30 # it here
31 tempdir="/tmp/arara-quickstartscip-shell filesystem . . `/tmp/arara-quickstart`."
32 if [scip-shell system . . `[`. -d "$tempdir" ]
33 then
34 rmscip-shell system . . rm. -r "$tempdir"
35 fi
36 mkdirscip-shell system . . mkdir. -p "$tempdir"
37 cpscip-shell system . . cp. ./resources/* "$tempdir/"
38 cd "$tempdir"
39
40 # these files are created in the temporary directory; no need to change
41 # anything at this point except that the name of the PDF file will be used
42 # when copying back to the source directory
43 htmlfile="quickstart.html"
44 pdffile="arara-quickstart.pdf"
45
46 catscip-shell system . . cat. <<EOF > $htmlfile
47 <!DOCTYPE html>
48 <html lang="en-US">
49 <head>
50 <meta charset="UTF-8">
51 <title>arara</title>
52
53 <meta name="keywords" content="tex, latex, context, build tool, automation">
54 <meta name="name" content="The cool TeX automation tool">
55 <meta name="description" content="arara is a TeX automation tool based on directives and rules.">
56
57 <link href="file://$tempdir/manual.css" rel="stylesheet">
58 </head>
59 <body>
60 <article>
61 <h1>A quickstart guide to arara</h1>
62 EOF
63
64 # assemble the manual content by fetching chapters from the webpage;
65 # while doing so assemble the toc for that chapter as well
66 catscip-shell system . . cat. <<EOF >> $htmlfile
67 $(catscip-shell system . . cat. "$(echoscip-shell system . . echo. "$baseurl" | cutscip-shell system . . cut. -c8-)quickstart/index.html" | htmlq 'div.content.text' --remove-nodes 'div.heading-text' \
68 | tailscip-shell system . . tail. -n +3 | headscip-shell system . . head. -n -1 \
69 | sedscip-shell system . . sed. -r 's/<(\/?)h5/<\1h6/g' | sedscip-shell system . . sed. -r 's/<(\/?)h4/<\1h5/g' \
70 | sedscip-shell system . . sed. -r 's/<(\/?)h3/<\1h4/g' | sedscip-shell system . . sed. -r 's/<(\/?)h2/<\1h3/g' \
71 | sedscip-shell system . . sed. -r 's/<(\/?)h1/<\1h2/g')
72 EOF
73
74 catscip-shell system . . cat. <<EOF >> $htmlfile
75 </body>
76 </html>
77 EOF
78
79 # convert the created HTML manual to PDF
80 weasyprint -u "$baseurl" "$htmlfile" "$pdffile"
81
82 # change back to the docs directory and copy output PDF there
83 cd "$currdir"
84 cpscip-shell system . . cp. "$tempdir/$pdffile" ./