Skip to content

Instantly share code, notes, and snippets.

@FliiFe
Created March 21, 2019 21:11
Show Gist options
  • Save FliiFe/96fae12058fc9187a108252ae3e90133 to your computer and use it in GitHub Desktop.
Save FliiFe/96fae12058fc9187a108252ae3e90133 to your computer and use it in GitHub Desktop.
A quick and dirty script to transform ctan documentation pdf to devhelp booklet
#!/usr/bin/env fish
#
# Smelly code ahead
set file $argv[1]
set bn (basename $file | rev | cut -d. --complement -f1 | rev)
set pdf2htmlEX docker run -ti --rm -v (pwd):/pdf bwits/pdf2htmlex pdf2htmlEX
$pdf2htmlEX --printing 0 --embed-outline 0 --zoom 1.2 $file
bat -p -- $bn.outline | \
sed -E "s/ ?data-dest-detail='[^>]*'//g" | \
sed -E 's/ ?class=.[^"]*"//g' | \
sed "s/href=\"/link=\"$bn.html/g" | \
sed -E "s/>([^<]+)/ name='\1'>/g" | \
sed 's/\ba\b/sub/g' | \
sed -E 's/<ul>|<\/sub>|<li>//g' | \
sed -E 's/<\/ul>|<\/li>/<\/sub>/g' | \
tidy -quiet -indent -xml - 2>/dev/null >$bn.outline2
read -p "echo Package name: ' '" pn
read -p "echo Package title: ' '" pt
read -p "echo Package version: ' '" pv
echo "<book language=\"LaTeX\" link=\"$bn.html\" name=\"$pn\" title=\"$pt\" version=\"$pv\">" >$bn.devhelp2
echo "<chapters><sub link=\"$bn.html\" name=\"Index\">" >>$bn.devhelp2
cat $bn.outline2 >> $bn.devhelp2
echo '</sub> </chapters> </book>' >> $bn.devhelp2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment