Hi,
I wrote a template and conversion scripts for importing Inkscape SVG
graphics as PDFTEX or PSTEX as external material in LyX. It works analog
to the FIG template and its scripts.
You will need Inkscape 0.48. It can save the SVG image as a PDF or EPS
file and place the text in a LaTeX file for typesetting by pdflatex or
latex itself. For more information see
http://tug.ctan.org/tex-archive/info/svg-inkscape/ .
Installation:
1. Copy external_templates from the LyX system directory to your Lyx
user directory. And insert the SVG template there.
2. Copy the .py scripts to your scripts directory in your LyX user
directory.
3. Start LyX and go to settings > file handling. Check if you have the
format SVG.
If not, creat it:
activate vector format
short title: svg
file extenstion: svg
edit with: inkscape
view with: inkview
4. Create the converters:
SVG -> PDFTEX:
converter: python -tt $$s/scripts/svg2pdftex.py $$i $$o
SVG -> PSTEX
python -tt $$s/scripts/svg2pstex.py $$i $$o
It was tested for LyX 1.6.9. I don't know the exact englisch menu names,
because I use the German version.
Greetings,
Daniel
Template SVG
GuiName "SVG: $$AbsOrRelPathParent$$Basename"
HelpText
An SVG figure.
HelpTextEnd
InputFormat svg
FileFilter "*.{svg,svgz}"
AutomaticProduction true
Transform Rotate
Transform Resize
Preview InstantPreview
Format LaTeX
TransformCommand Rotate RotationLatexCommand
TransformCommand Resize ResizeLatexCommand
Product
"$$RotateFront$$ResizeFront\\input{$$AbsOrRelPathMaster$$Basename.pstex_t}$$ResizeBack$$RotateBack"
UpdateFormat pstex
UpdateResult "$$AbsPath$$Basename.pstex_t"
Requirement "color"
Requirement "graphicx"
# Preamble WarnNotFound
# Preamble InputOrWarn
ReferencedFile latex "$$AbsOrRelPathMaster$$Basename.pstex_t"
ReferencedFile latex "$$AbsPath$$Basename.eps"
ReferencedFile dvi "$$AbsPath$$Basename.eps"
FormatEnd
Format PDFLaTeX
TransformCommand Rotate RotationLatexCommand
TransformCommand Resize ResizeLatexCommand
Product
"$$RotateFront$$ResizeFront\\input{$$AbsOrRelPathMaster$$Basename.pdftex_t}$$ResizeBack$$RotateBack"
UpdateFormat pdftex
UpdateResult "$$AbsPath$$Basename.pdftex_t"
Requirement "color"
Requirement "graphicx"
# Preamble WarnNotFound
# Preamble InputOrWarn
ReferencedFile pdflatex
"$$AbsOrRelPathMaster$$Basename.pdftex_t"
ReferencedFile pdflatex "$$AbsPath$$Basename.pdf"
FormatEnd
Format Ascii
Product "[SVG: $$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
TemplateEnd
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# file svg2pdftex.py
#
# This script converts an SVG image to something that pdflatex can process
# into high quality PDF.
# Usage:
# python svg2pdftex.py ${base}.fig ${base}.pdft
# This command generates
# ${base}.pdf the converted pdf file
# ${base}.pdft a tex file that can be included in your latex document
# using '\input{${base}.pdft}'
#
# Note:
# Do not use this command as
# python fig2pdftex.py file.fig file.pdf
# the real pdf file will be overwritten by a tex file named file.pdf.
#
import os, sys, re
def runCommand(cmd):
''' Utility function:
run a command, quit if fails
'''
if os.system(cmd) != 0:
print "Command '%s' fails." % cmd
sys.exit(1)
# We expect two args, the names of the input and output files.
if len(sys.argv) != 3:
sys.exit(1)
input, output = sys.argv[1:]
# Fail silently if the file doesn't exist
if not os.path.isfile(input):
sys.exit(0)
# Strip the extension from ${output}
outbase = os.path.splitext(output)[0]
# Inkscape 0.48 can output the image as a PDF file ${base}.pdf and place the text
# in a LaTeX file ${base}.pdf_tex, which is renamed to ${output}, for typesetting
# by pdflatex itself.
runCommand('inkscape --file=%s --export-pdf=%s.pdf --export-latex' % (input, outbase))
os.rename('%s.pdf_tex' % outbase, output)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# file svg2pstex.py
#
# This script converts an SVG image to something that latex can process
# into high quality PostScript.
# Usage:
# python svg2pstex.py ${base}.fig ${base}.pstex
# This command generates
# ${base}.eps the converted eps file
# ${base}.pstex a tex file that can be included in your latex document
# using '\input{${output}}'.
#
# Note:
# Do not use this command as
# python svg2pstex.py file.fig file.eps
# the real eps file will be overwritten by a tex file named file.eps.
#
import os, sys
def runCommand(cmd):
''' Utility function:
run a command, quit if fails
'''
if os.system(cmd) != 0:
print "Command '%s' fails." % cmd
sys.exit(1)
# We expect two args, the names of the input and output files.
if len(sys.argv) != 3:
sys.exit(1)
input, output = sys.argv[1:]
# Fail silently if the file doesn't exist
if not os.path.isfile(input):
sys.exit(0)
# Strip the extension from ${output}
outbase = os.path.splitext(output)[0]
# Inkscape 0.48 can output the image as a EPS file ${base}.pdf and place the text
# in a LaTeX file ${base}.eps_tex, which is renamed to ${output}, for typesetting
# by latex itself.
runCommand('inkscape --file=%s --export-eps=%s.eps --export-latex' % (input, outbase))
os.rename('%s.eps_tex' % outbase, output)