Skip to content

Instantly share code, notes, and snippets.

@mistivia
Created September 1, 2024 08:32
Show Gist options
  • Select an option

  • Save mistivia/f29a4f2be6c58af19bfd5fa65daba0a2 to your computer and use it in GitHub Desktop.

Select an option

Save mistivia/f29a4f2be6c58af19bfd5fa65daba0a2 to your computer and use it in GitHub Desktop.
convert latex formula to jpeg image
#!/bin/bash
# usage: echo '$$E=mc^2$$' | tex2jpg out.jpg
PPWD=$(pwd)
DIR=/tmp/$(head -c10 /dev/urandom | base32)
mkdir -p $DIR
cd $DIR && \
echo '\documentclass{minimal}' > input.tex && \
echo '\begin{document}' >> input.tex && \
echo '' >> input.tex && \
cat >> input.tex && \
echo '' >> input.tex && \
echo '\end{document}' >> input.tex && \
cat input.tex && \
latex input.tex && \
magick convert -density 300 input.dvi -trim -bordercolor white -border 20 out.jpg && \
cd $PPWD && \
cp $DIR/out.jpg $1
rm -rf $DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment