Hi,

the patch below [1] allows me to:
-) insert gnuplot scripts within a LyX document, just as I can add a .dia, .fig 
or .odg diagrams
-) auto-converts the generated output for on-screen rendering, or for .ps or 
.pdf output, as needed
-) allows me to right-click on the on-screen picture and select "Edit 
externally..." and opens up
   a text editor

It works with a gnuplot2pdf.py conversion script that just adds a simple
  set terminal pdf
  set output ...
in front of the .gnuplot script before running it.

Comments welcome, thanks!

    T.


[1] (from my own user repo tommaso/master)

commit 40e88a08
Author: Tommaso Cucinotta <tomm...@lyx.org>
Date:   Mon Oct 17 08:44:16 2016 +0200

    Enable graphics generation from external gnuplot scripts.

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 75934379..a19d4f2c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -2321,6 +2321,7 @@ dist_scripts_DATA += \
        scripts/svg2pdftex.py \
        scripts/svg2pstex.py \
        scripts/fig_copy.py \
+       scripts/gnuplot2pdf.py \
        scripts/html2latexwrapper.py \
        scripts/include_bib.py \
        scripts/layout2layout.py \
diff --git a/lib/configure.py b/lib/configure.py
index a11050fb..09d053e9 100644
--- a/lib/configure.py
+++ b/lib/configure.py
@@ -1017,7 +1017,10 @@ def checkConverterEntries():
         rc_entry = [ r'''\converter svg        png "%%"    "",
 \converter svgz       png        "%%"    ""'''],
         path = ['', inkscape_path])
-
+    #
+    checkProg('Gnuplot', ['gnuplot'],
+        rc_entry = [ r'''\Format gnuplot     "gp, gnuplot"    "Gnuplot"     "" "" ""  
"vector" "text/plain"
+\converter gnuplot      pdf6      "python -tt $$s/scripts/gnuplot2pdf.py $$i $$o"    
""''' ])
     #
     # gnumeric/xls/ods to tex
     checkProg('a spreadsheet -> latex converter', ['ssconvert'],
diff --git a/lib/scripts/gnuplot2pdf.py b/lib/scripts/gnuplot2pdf.py
new file mode 100755
index 00000000..fb036b2d
--- /dev/null
+++ b/lib/scripts/gnuplot2pdf.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+
+from subprocess import Popen, PIPE
+from sys import argv, stderr, exit
+import os
+import shutil
+
+if (len(argv) != 3):
+    stderr.write("Usage: %s <src_file> <dst_file>\n" % argv[0])
+    exit(1)
+
+with open(argv[1], 'rb') as fsrc:
+    subproc = Popen("gnuplot", shell=True, stdin=PIPE)
+    subproc.stdin.write("set terminal pdf\nset output '%s'\n" % argv[2])
+    shutil.copyfileobj(fsrc, subproc.stdin)
+    subproc.stdin.write("exit\n")
+    subproc.wait()


Reply via email to