Skip to content

Instantly share code, notes, and snippets.

@dipietrantonio
Created January 15, 2017 11:01
Show Gist options
  • Save dipietrantonio/932a3efe6cce579dd5a367d946e4d5e7 to your computer and use it in GitHub Desktop.
Save dipietrantonio/932a3efe6cce579dd5a367d946e4d5e7 to your computer and use it in GitHub Desktop.
Convert a tex file to an ebook for Kindle
#!/bin/bash
# This script converts a tex source to azw3 format using htlatex and ebook-convert (from calibre)
# to set the resolution of math images edit this file
# sudo gedit /usr/share/texmf/tex4ht/tex4ht.env
# in the section <dvipng> modify the DPI parameter (-D) of the two commands (I use 100)
# do the operation in a temporary directory. htlatex produces a lot of files (and we can't set an output dir)
currdir=`pwd`
format="azw3"
cp . "../temp_htlatex" -r
cd "../temp_htlatex"
#now we can convert latex to html
htlatex $1
#html to ebook
ebook-convert "${1%.tex}.html" "${1%.tex}.$format" --language en
#copy the ebook file in the original directory
cp "${1%.tex}.$format" "$currdir/${1%.tex}.$format"
#finally, delete all temp files
cd "$currdir"
rm -rf "../temp_htlatex"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment