[Wiki-uploads/master] Add gnuplot.xtemplate from Tobias Hilbricht

Pavel Sanda sanda at lyx.org
Wed Apr 24 18:57:30 UTC 2024


commit 4fa520e50b8a16ac7eccfe0d8517399ffcaa467a
Author: Pavel Sanda <sanda at lyx.org>
Date:   Wed Apr 24 20:56:21 2024 +0200

    Add gnuplot.xtemplate from Tobias Hilbricht
---
 Examples/gnuplot.xtemplate/gnuplot.xtemplate | 96 ++++++++++++++++++++++++++++
 Examples/gnuplot.xtemplate/gnuplot2pdftex.py | 39 +++++++++++
 Examples/gnuplot.xtemplate/gnuplot2pstex.py  | 39 +++++++++++
 3 files changed, 174 insertions(+)

diff --git a/Examples/gnuplot.xtemplate/gnuplot.xtemplate b/Examples/gnuplot.xtemplate/gnuplot.xtemplate
new file mode 100644
index 0000000..be34d30
--- /dev/null
+++ b/Examples/gnuplot.xtemplate/gnuplot.xtemplate
@@ -0,0 +1,96 @@
+#
+# Gnuplot External Template
+#
+# This file is part of LyX, the document processor.
+# Licence details can be found in the file COPYING.
+#
+# author Tobias Hilbricht
+#
+# based on external templates by:
+#
+# author Asger Alstrup Nielsen
+# author Angus Leeming
+# author Johnathan Burchill
+#
+# Full author contact details are available in file CREDITS.
+
+
+PreambleDef WarnNotFound
+	%% Print a warning encased in an fbox.
+	\def\lyxstripprefix#1>{}
+	\newcommand{\warnNotFound}[1]{%
+	        \def\lyxtempfilename{#1}%
+	        \fbox{Could not find
+	                \ttfamily\expandafter\lyxstripprefix\meaning\lyxtempfilename!}%
+	        \typeout{Could not find \lyxtempfilename!}%
+	}
+PreambleDefEnd
+
+
+PreambleDef InputOrWarn
+	%% Input the file if it exists, using \input, else print a warning
+	\newcommand{\inputOrWarn}[1]{%
+	        \IfFileExists{#1}{\input{#1}}{\warnNotFound{#1}}}
+PreambleDefEnd
+
+
+Template Gnuplot
+	GuiName "Gnuplot"
+	HelpText
+		A Gnuplot figure.
+		Note that using this template automatically uses the 
+		document text in the image (like with the Xfig template).
+	HelpTextEnd
+	InputFormat gnuplot
+	FileFilter "*.{gp}"
+	AutomaticProduction true
+	Transform Rotate
+	Transform Resize
+	Preview InstantPreview
+	Format PDFLaTeX
+		TransformCommand Rotate RotationLatexCommand
+		TransformCommand Resize ResizeLatexCommand
+		Product "$$RotateFront$$ResizeFront\\input{$$AbsOrRelPathMaster$$Basename.pdf_tex}$$ResizeBack$$RotateBack"
+		UpdateFormat pdftex2
+		UpdateResult "$$AbsPath$$Basename.pdf_tex"
+		Requirement "xcolor"
+		Requirement "graphicx"
+		Requirement "mathtools"
+		# Preamble WarnNotFound
+		# Preamble InputOrWarn
+		ReferencedFile pdflatex "$$AbsOrRelPathMaster$$Basename.pdf_tex"
+		ReferencedFile pdflatex "$$AbsPath$$Basename.pdf"
+	FormatEnd
+	Format LaTeX
+		TransformCommand Rotate RotationLatexCommand
+		TransformCommand Resize ResizeLatexCommand
+		Product "$$RotateFront$$ResizeFront\\input{$$AbsOrRelPathMaster$$Basename.ps_tex}$$ResizeBack$$RotateBack"
+		UpdateFormat pstex2
+		UpdateResult "$$AbsPath$$Basename.ps_tex"
+		Requirement "xcolor"
+		Requirement "graphicx"
+		Requirement "mathtools"
+		# Preamble WarnNotFound
+		# Preamble InputOrWarn
+		ReferencedFile latex "$$AbsOrRelPathMaster$$Basename.ps_tex"
+		ReferencedFile latex "$$AbsPath$$Basename.eps"
+		ReferencedFile dvi   "$$AbsPath$$Basename.eps"
+	FormatEnd
+	Format Ascii
+		Product "[InkscapeGraphics: $$FName]"
+	FormatEnd
+	Format DocBook
+		Product "<graphic fileref=\"$$AbsOrRelPathMaster$$Basename.eps\"></graphic>"
+		UpdateFormat eps
+		UpdateResult "$$AbsPath$$Basename.eps"
+		ReferencedFile docbook     "$$AbsPath$$Basename.eps"
+		ReferencedFile docbook-xml "$$AbsPath$$Basename.eps"
+	FormatEnd
+	Format XHTML
+		Product "<img src=\"$$AbsOrRelPathMaster$$Basename.svg\" />"
+		UpdateFormat svg
+		UpdateResult "$$AbsPath$$Basename.svg"
+		ReferencedFile xhtml "$$AbsPath$$Basename.svg"
+	FormatEnd
+TemplateEnd
+
diff --git a/Examples/gnuplot.xtemplate/gnuplot2pdftex.py b/Examples/gnuplot.xtemplate/gnuplot2pdftex.py
new file mode 100644
index 0000000..e454a9a
--- /dev/null
+++ b/Examples/gnuplot.xtemplate/gnuplot2pdftex.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
+# file gnuplot2pdftex.py
+
+# author Tobias Hilbricht
+
+# This script converts a gnuplot file to two files that can be processed
+# with pdflatex into high quality PDF. It requires gnuplot.
+# The extension of the gnuplot file has to be .gp as in gnuplotfile.gp
+# Data have to be provided in gnuplotfile.gp in "heredocs". See e. g.
+# Philipp Janert, "Gnuplot in Action Second Edition" page 72
+
+# Usage:
+#   python gnuplot2pdftex.py gnuplotfile.gp
+# This command generates
+#   1. gnuplotfile.pdf     -- the converted PDF file (text stripped)
+#   2. gnuplotfile.pdf_tex -- a TeX file that can be included in your
+#                             LaTeX document using '\input{gnuplotfile.pdf_tex}'
+
+import os, sys
+
+# We expect one arg: the name of the gnuplotfile
+
+if len(sys.argv) != 2:
+    print("Usage: python gnuplot2pdftex.py gnuplotfile.gp")
+
+gnuplot_file = sys.argv[1]
+# Strip the extension from ${gnuplotfile}
+base_name = os.path.splitext(os.path.basename(gnuplot_file))[0]
+# Three letter file extension of TeX file necessary for gnuplot
+gnuplot_name = base_name + ".ptx"
+# TeX file extension known to LyX
+lyx_name = base_name + ".pdf_tex"
+
+# Call gnuplot    
+os.system(f"gnuplot -e \"set term cairolatex pdf ; set output '{gnuplot_name}'\" {gnuplot_file}")
+# Change TeX file extension 
+os.rename(gnuplot_name, lyx_name)
diff --git a/Examples/gnuplot.xtemplate/gnuplot2pstex.py b/Examples/gnuplot.xtemplate/gnuplot2pstex.py
new file mode 100644
index 0000000..c68a926
--- /dev/null
+++ b/Examples/gnuplot.xtemplate/gnuplot2pstex.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
+# file gnuplot2pstex.py
+
+# author Tobias Hilbricht
+
+# This script converts a gnuplot file to two files that can be processed
+# with latex into high quality PDF. It requires gnuplot.
+# The extension of the gnuplot file has to be .gp as in gnuplotfile.gp
+# Data have to be provided in gnuplotfile.gp in "heredocs". See e. g.
+# Philipp Janert, "Gnuplot in Action Second Edition" page 72
+
+# Usage:
+#   python gnuplot2pstex.py gnuplotfile.gp
+# This command generates
+#   1. gnuplotfile.eps     -- the converted EPS file (text stripped)
+#   2. gnuplotfile.eps_tex -- a TeX file that can be included in your
+#                             LaTeX document using '\input{gnuplotfile.eps_tex}'
+
+import os, sys
+
+# We expect one arg: the name of the gnuplotfile
+
+if len(sys.argv) != 2:
+    print("Usage: python gnuplot2pstex.py gnuplotfile.gp")
+
+gnuplot_file = sys.argv[1]
+# Strip the extension from ${gnuplotfile}
+base_name = os.path.splitext(os.path.basename(gnuplot_file))[0]
+# Three letter file extension of TeX file necessary for gnuplot
+gnuplot_name = base_name + ".etx"
+# TeX file extension known to LyX
+lyx_name = base_name + ".eps_tex"
+
+# Call gnuplot    
+os.system(f"gnuplot -e \"set term cairolatex eps ; set output '{gnuplot_name}'\" {gnuplot_file}")
+# Change TeX file extension 
+os.rename(gnuplot_name, lyx_name)


More information about the lyx-cvs mailing list