User:Mattrix/Graph-O-Matic

Here is a script I botched together for converting GNUPlot files into PNGs. To see its output go to User:Mattrix/Scripts. If you'd like any help using it then please ask on the talk page. Here's some hints:

  • It requires gnuplot, LaTeX (including dvips and a few packages) and ImageMagick.
  • You might like to fiddle with the number after -density on the convert line.
#!/bin/sh
#
# This shell script is Copyright (c) 2005 "Mattrix"
# < http://en.wikibooks.org/wiki/User:Mattrix/Graph-O-Matic >
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this shell script (the "Software"), to deal in the Software 
# without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is 
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#GNUPlot the graph in epslatex format
cat > ${1}_temp_commands <<EOF
set terminal pslatex color
set output "${1}_temp_input"
replot
EOF
gnuplot ${1} ${1}_temp_commands || { echo "gnuplot run failed."; exit;}

#Make LaTeX document and include GNUPlot output
cat > ${1}_temp_doc.tex <<EOF
\documentclass{article}
\usepackage[dvips]{graphicx}
\usepackage[dvips]{color}
\pagestyle{empty}
\begin{document}
\input{${1}_temp_input}
\end{document}
EOF

#LaTeX->dvi2ps->ImageMagick
latex -interaction=batchmode ${1}_temp_doc.tex > /dev/null || { echo "LaTeX run failed."; exit; }
dvips -E ${1}_temp_doc.dvi 2> /dev/null || { echo "dvips run failed."; exit; }
convert -density 150 ${1}_temp_doc.ps ${1}.png || { echo "convert run failed."; exit; }

#Cleanup
rm ${1}_temp_*

#Say some stuff
echo "${1}.png produced."
echo "If uploading to wikibooks, please copy and paste the ${1} source file and link to [[User:Mattrix/Graph-O-Matic]] on the image description page. I also suggest you waive any potential copyrights with the {{PD}} tag."

#If you want to automatically open the image, uncomment the following line
#and change the viewer if desired
#gqview ${1}.png