Skip to content

Instantly share code, notes, and snippets.

@kazad
Created September 11, 2015 21:35
Show Gist options
  • Save kazad/93fce8d759bf0915473a to your computer and use it in GitHub Desktop.
Save kazad/93fce8d759bf0915473a to your computer and use it in GitHub Desktop.
Softcover build script
shopt -s expand_aliases
alias softcover-docker='docker run -v $(pwd):/opt/book -w /opt/book --rm=true --entrypoint /usr/local/bin/softcover kazad/softcover'
# Move and convert in place
rm chapters/*.md
cp src/* chapters/
# sync images
pushd images
rsync -rv --include '*/' --include '*.png' --include '*.jpg' --include '*.jpeg' --exclude '*' --prune-empty-dirs /Users/kazad/Dropbox/servers/betterexplained.com/wp-content/uploads/calculus .
popd
pushd chapters
# change images from blog to local image folder
sed -i '' 's#http://betterexplained.com/wp-content/uploads#images#g' *.md
# convert $$$ to \( \) for inline math. Important to add spaces around \1
sed -i '' 's#[$][$][$]\([^$]*\)[$][$][$]#\\\( \1 \\\)#g' *.md
# convert $$$ to $$ for inline math
# sed -i '' 's#[$][$][$]\([^$]*\)[$][$][$]#$$\1$$#g' *.md
# convert $$$ to {$$}{/$$} for inline math
#sed -i '' 's#[$][$][$]\([^$]*\)[$][$][$]#{\$\$}\1{\/\$\$}#g' *.md
#then, convert $$ to \[ \] for inline math. Make sure there's no closing } from above. Important to add spaces around \1.
sed -i '' 's#[$][$]\([^${}][^$]*\)[$][$]#\\\[ \1 \\\]#g' *.md
popd
# Build HTML and polytex
# softcover build:epub
# softcover-docker build:epub
softcover-docker build:html
# Process generated latex
pushd generated_polytex/
rm prod/*
cp *.tex prod/
pushd prod
# inline latex commands
sed -i '' 's/^.*%[ ]*<!--latex:[ ]*\(.*\)-->/\1/g' *.tex
# replace \image command
sed -i '' 's/\\image/\\includegraphicscenter{1.0}/g' *.tex
# include imagesuffix
sed -i '' 's#\(\\include[^ ]*\).jpg}#\1\\ImageSuffix.jpg}#g' *.tex
sed -i '' 's#\(\\include[^ ]*\).png}#\1\\ImageSuffix.png}#g' *.tex
# fix \kode command from softcover
sed -i '' 's#\\kode#\\texttt#g' *.tex
# convert href that has a link title a URL
sed -i '' 's#\\href{\([^}]*\)}{http[^}]*}#\\url{\1}#g' *.tex
popd
popd
# Build PDF
pdflatex calculus.tex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment