Skip to content

Instantly share code, notes, and snippets.

@jannisteunissen
Created April 25, 2017 12:27
Show Gist options
  • Save jannisteunissen/46e55e603a4839a57a28dc8fcb4e818c to your computer and use it in GitHub Desktop.
Save jannisteunissen/46e55e603a4839a57a28dc8fcb4e818c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [ $# -lt 2 ]; then
echo "Number of arguments should at least be 2."
echo "$0 \"gnuplot commands\" \"pdf_file\" [\"xsize\"] [\"ysize\"]"
exit 1
fi
tmpdir=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`
filename=$tmpdir/$2
tex_file=${filename%.pdf}".tex"
tex_fig=${filename%.pdf}"fig_.tex"
XSIZE="8.0cm"
if [ $# -gt 2 ]; then
XSIZE=$3
fi
YSIZE="5.6cm"
if [ $# -gt 3 ]; then
YSIZE=$4
fi
gnuplot << EOF
set terminal epslatex size $XSIZE, $YSIZE linewidth 2 color;
set output "$tex_fig";
# set ylabel offset 2, 0;
# set xlabel offset 0, 0.5;
set key samplen 2;
$1;
exit;
EOF
epsfile=${tex_fig%.tex}".eps"
epstopdf $epsfile
echo "\documentclass[a4paper]{standalone}
\usepackage{graphicx}
\usepackage[active,tightpage]{preview}
\begin{document}
\begin{preview}
\input{$tex_fig}
\end{preview}
\end{document}" > $filename
pdflatex -output-directory $tmpdir $filename
cp $filename $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment