2 # -*- coding: utf-8 -*-
4 # file gnuplot2pstex.py
6 # author Tobias Hilbricht
8 # This script converts a gnuplot file to two files that can be processed
9 # with latex into high quality PDF. It requires gnuplot.
10 # The extension of the gnuplot file has to be .gp as in gnuplotfile.gp
11 # Data have to be provided in gnuplotfile.gp in "heredocs". See e. g.
12 # Philipp Janert, "Gnuplot in Action Second Edition" page 72
15 # python gnuplot2pstex.py gnuplotfile.gp
16 # This command generates
17 # 1. gnuplotfile.eps -- the converted EPS file (text stripped)
18 # 2. gnuplotfile.eps_tex -- a TeX file that can be included in your
19 # LaTeX document using '\input{gnuplotfile.eps_tex}'
23 # We expect one arg: the name of the gnuplotfile
25 if len(sys.argv) != 2:
26 print("Usage: python gnuplot2pstex.py gnuplotfile.gp")
28 gnuplot_file = sys.argv[1]
29 # Strip the extension from ${gnuplotfile}
30 base_name = os.path.splitext(os.path.basename(gnuplot_file))[0]
31 # Three letter file extension of TeX file necessary for gnuplot
32 gnuplot_name = base_name + ".etx"
33 # TeX file extension known to LyX
34 lyx_name = base_name + ".eps_tex"
37 os.system(f"gnuplot -e \"set term cairolatex eps ; set output '{gnuplot_name}'\" {gnuplot_file}")
38 # Change TeX file extension
39 os.rename(gnuplot_name, lyx_name)