Skip to content

Instantly share code, notes, and snippets.

@isovector
Created November 22, 2018 02:30
Show Gist options
  • Select an option

  • Save isovector/5ee53cd1c75f81416c492e607f8e56ac to your computer and use it in GitHub Desktop.

Select an option

Save isovector/5ee53cd1c75f81416c492e607f8e56ac to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
set -ex
rm -r /tmp/ebook || echo ""
mkdir /tmp/ebook
cp *.shiatsu /tmp/ebook
cp *.tex /tmp/ebook
cp *.html /tmp/ebook
cp -r .latex-live-snippets/ /tmp/ebook
cd /tmp/ebook
# for FILE in .latex-live-snippets/*.tex
# do
# NAME=$(basename -s .tex $FILE)
# shiatsu mixins.shiatsu $FILE ".latex-live-snippets/$NAME.txt"
# done
sed -i 's/\\input{\([^}]\+\)}/include([[[[[\1]]]]])/' *.tex
sed -i 's/\\subfile{\([^}]\+\)}/include([[[[[\1.tex]]]]])/' *.tex
sed -i 's/``/\“/g' *.tex
sed -i "s/''/\”/g" *.tex
sed -i 's/\\Gls{\([^}]\+\)}/\u\1/g' *.tex
sed -i 's/\\Gls{\([^}]\+\)}/\u\1/g' *.tex
sed -i 's/^%.*//' *.tex
m4 print.tex > book.txt || echo ""
shiatsu includes.shiatsu book.txt book2.txt
sed -i 's/\\input{\([^}]\+\)}/include(`\1'"'"')/' book2.txt
m4 book2.txt > book3.txt || echo ""
sed -i 's_<_\&lt;_g' book3.txt
sed -i 's_>_\&gt;_g' book3.txt
# TODO(sandy): this doesn't work for repls
awk 'OFS= /^\\begin/ {env=1} /^\\end/ {env=0} /^[A-Za-z]|^\\(ty|defn|hs|emph|ext|kind)/ { if (env == 0 && inblock == 0) { inblock = 1; print "<p>"; }} /^$/ {if (env == 0 && inblock == 1) { inblock = 0; print "</p>" } } {print}' book3.txt > book4.txt
mkdir fracked
math-frack injection.shiatsu "fracked/taken" "fracked/given" book4.txt > boook.txt
# for FILE in fracked/taken*.Dollar.tex; do
# FILE2=$(basename $FILE)
# DEST=fracked/given${FILE2#taken}
# mjpage --dollars --extensions 'TeX/AMSmath' --fragment --noGlobalSVG < $FILE > $DEST
# done
# for FILE in fracked/taken*.DoubleDollar.tex; do
# FILE2=$(basename $FILE)
# DEST=fracked/given${FILE2#taken}
# mjpage --extensions 'TeX/AMSmath' --fragment --noGlobalSVG < $FILE > $DEST
# done
shiatsu mixins.shiatsu includes.shiatsu boook.txt book5.txt
awk 'OFS='' /!BEGIN_NEW_CHAPTER_NUMBER/ {chapter++;count=0} /\\begin{dorepl}/ {print sprintf("%s{%s}{%s}", $0,chapter,count); count++; matching=1} {if (!matching) print} /\\end{dorepl}/ {matching=0}' book5.txt | sed 's/\\begin{dorepl}/\\snipRepl/' > book9.txt
shiatsu mixins.shiatsu includes.shiatsu book9.txt book6.txt
sed -i 's/\\input{\([^}]\+\)}/include(`\1'"'"')/' book6.txt
m4 book6.txt > book7.txt || echo ""
shiatsu mixins.shiatsu includes.shiatsu book7.txt book8.html
sed -i 's/\\begin{code}/<pre><code>/' book8.html
sed -i 's_\\end{code}_</code></pre>_' book8.html
sed -i 's/\\begin{lstlisting}/<pre><code>/' book8.html
sed -i 's_\\end{lstlisting}_</code></pre>_' book8.html
sed -i 's_!\\tyeq!_~_g' book8.html
sed -i 's_\\#_#_g' book8.html
sed -i 's_\\\$_$_g' book8.html
sed -i 's_---_\&mdash;_g' book8.html
sed -i 's_--_\&ndash;_g' book8.html
sed -i 's_•_\&copy;_g' book8.html
sed -i 's_•_\&bull;_g' book8.html
sed -i 's_‘_\&lsquo;_g' book8.html
sed -i 's_’_\&rsquo;_g' book8.html
sed -i 's/\\_/_/g' book8.html
sed -i 's_!\\annotate{\([0-9]\+\)}!_<span class="annotate"><span class="ann">\1</span></span>_g' book8.html
cat mixin.html book8.html > book9.html
# # csplit -f chapter -b '%02d.txt' -z book7.txt '/^BEGIN_NEW_CHAPTER$/' "{*}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment