Skip to content

Instantly share code, notes, and snippets.

@tk3369
Created December 26, 2018 18:54
Show Gist options
  • Save tk3369/0a36659bab1e0c3bb5a4d105d56af1b4 to your computer and use it in GitHub Desktop.
Save tk3369/0a36659bab1e0c3bb5a4d105d56af1b4 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Generate PDF file from ipynb notebook.
# Several tricks are done to post-process the latex files.
if [ $# -ne 1 ]; then
echo "Usage: `basename $0` filename"
exit 1
fi
file="$1"
if [ ! -f "$file" ]; then
echo "Error: file not found $file"
exit 2
fi
texfile=`echo "$file" | sed -e 's/ipynb/tex/g'`
jupyter nbconvert --to latex --template booktemplate.tplx $file
if [ $? -eq 0 ]; then # successful conversion
# deal with copyright
mv "$texfile" "bak_$texfile"
sed -e 's/©/\\textcopyright /g' < "bak_$texfile" > "$texfile"
# deal with dollar signs with the extra slash
mv "$texfile" "bak_$texfile"
sed -e 's/\\textbackslash{}\\\$/\\$/g' < "bak_$texfile" > "$texfile"
xelatex $texfile
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment