]> git.lyx.org Git - wiki-uploads.git/blob - Examples/gnuplot.xtemplate/gnuplot2pstex.py
Add gnuplot.xtemplate from Tobias Hilbricht
[wiki-uploads.git] / Examples / gnuplot.xtemplate / gnuplot2pstex.py
1 #!/usr/bin/python3
2 # -*- coding: utf-8 -*-
3
4 # file gnuplot2pstex.py
5
6 # author Tobias Hilbricht
7
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
13
14 # Usage:
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}'
20
21 import os, sys
22
23 # We expect one arg: the name of the gnuplotfile
24
25 if len(sys.argv) != 2:
26     print("Usage: python gnuplot2pstex.py gnuplotfile.gp")
27
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"
35
36 # Call gnuplot    
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)