-
-
Save jinwei233/9b58b6814808c3861caa93008135be0d to your computer and use it in GitHub Desktop.
bash script to convert a latex equation into a png image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
alias latex='/usr/bin/latex' | |
alias dvipng='/usr/bin/dvipng' | |
alias convert='/usr/bin/convert' | |
#choose a number from 75-300 | |
density=300 | |
if [ $# != 2 ] | |
then | |
echo "Usage: $0 output_file latex_code" | |
exit | |
fi | |
outfile=$1 | |
code=$2 | |
tempfile=latex2png_temp.tex | |
# write latex file | |
echo "\documentclass[fleqn]{article}" > ${tempfile} | |
echo "\usepackage{amssymb,amsmath,bm}" >> ${tempfile} | |
echo "\usepackage[latin1]{inputenc}" >> ${tempfile} | |
echo "\begin{document}" >> ${tempfile} | |
echo "\thispagestyle{empty}" >> ${tempfile} | |
echo -n "\$\$ \displaystyle \mathindent0cm \parindent0cm " >> ${tempfile} | |
echo ${code} " \$\$" >> ${tempfile} | |
echo "\end{document}" >> ${tempfile} | |
latex -interaction=nonstopmode ${tempfile} | |
dvipng -o ${outfile} -q -T tight -bg transparent -D 300 ${tempfile%.tex}.dvi | |
rm -f ${tempfile%.tex}.aux ${tempfile%.tex}.dvi ${tempfile%.tex}.log ${tempfile} | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment