<< Using LyX with Tgif | Page list | WordCount >>
As of version 1.6.6 LyX directly supports SVG files - only librsvg or Inkscape needs to be installed on your computer.
Include SVG Images in LyX
The are three possibilities based on Inkscape, Apache Batik and librsvg. Please read details below about first of these two techniques.
Inkscape
Inkscape from http://www.inkscape.org/ can be used to configure LyX to directly include .svg images and automatically generate PNG preview images in LyX, PDF for pdflatex, and EPS for latex.
Just add an SVG file type and conversion rules as described below (this is #3349 enhancement request in LyX's Trac.)
I use those settings for several months now and I am very happy with that solution, because inkscape is a great tool to draw vector graphics with and I don't have to keep the eps files up to date manually to match the svg files - LyX does that for me! Another great thing is, that Inkscape exports text to eps as a whole and not single characters (you may not resize text blocks with the mouse to be sure about that). This is useful for psfrag.
Windows
When installing LyX using the alternative installer, Inkscape is automatically used to convert and display SVG images.
Alternatively you can add support for SVG manually:
- Install Inkscape
- Adopt your LyX Preferences as follows:
- In the Section Paths add to Path-Prefix the directory where the inkscape.exe is located.
- In the Section File Formats
- Fill in the text fields with the following values
Format: svg
GUI-Name: SVG
Extension: svg
Viewer: inkscape $$i
Editor: inkscape $$i
- Make sure the Vector graphics format checkbox is checked.
- Important: Press Add
- In the Section Converters
- Fill in the fields with the following values
From: SVG
To: PDF
Converter: inkscape --file=$$p/$$i --export-area-drawing --without-gui --export-pdf=$$p/$$o
- Important: Press add
- Fill in the fields with the following values
From: SVG
To: EPS
Converter: inkscape --file=$$p/$$i --export-area-drawing --without-gui --export-eps=$$p/$$o
- Important: Press add
- Fill in the fields with the following values
From: SVG
To: PNG
Converter: inkscape --without-gui --file=$$i --export-png=$$o
- Important: Press add
- Press Save
Finally you need to reconfigure LyX.
Linux
You can configure LyX in a few steps:
- Install Inkscape
- Update 2009-02-23: With LyX-1.6.1 on Ubuntu 8.10, the LyX insert->graphics menu will allow the insertion of SVG files without any customization of the LyX Preferences. Output documents can be viewed without any configuration changes. However, LyX will not be able to launch the SVG editor (The right-click on the graphic to edit the SVG file will not work). The first set of steps outlined next is needed to let LyX know that the editor program is the executable "inkscape". The end result of that first set of instructions will be new lines in the $/.lyx/preferences file's FORMATS section:
\format "svg" "svg" "SVG" "" "inkview" "inkscape" "vector"
In my experience, this is the only configuration change that is truly necessary to make LyX-1.6.1 work together with SVG and Inkscape. The Converter options described below are not strictly necessary, but they may improve the quality of output obtained in pdf and postscript. These settings may make a difference because Inkscape might generate more suitable pdf or eps output.
- Adapt your LyX Preferences as follows (The dialog entries are bold.)
- In the Section File Formats
- Fill in the text fields with the following values
Format: svg
GUI-Name: SVG
Extension: svg
Viewer: inkview
Editor: inkscape
- Important: Press add
- Make sure the Vector graphics format checkbox is checked.
The following steps add these lines in the CONVERTERS section of $/.lyx/preferences
\converter "svg" "eps" "inkscape $$i --export-eps=$$o" ""
\converter "svg" "png" "inkscape $$i --export-png=$$o" ""
\converter "svg" "pdf" "inkscape --export-area-drawing $$i --export-pdf=$$o" ""
- In the Section Converters
- Fill in the fields with the following values
From: SVG
To: EPS
Converter: inkscape $$i --export-eps=$$o
- Important: Press add
- Fill in the fields with the following values
From: SVG
To: PDF (ps2pdf)
Converter: inkscape --export-area-drawing $$i --export-pdf=$$o
- Important: Press add
- (Optionally) Fill in the fields with the following values
From: SVG
To: PNG
Converter: inkscape $$i --export-png=$$o
- Important: Press add
- Press Save
You need to restart and maybe reconfigure LyX.
MacOS X
Under MacOS X, it should work just as described in the Linux section. You need to provide the full path to the Inkscape executable, on my system, this is: /Applications/Multimedia/Inkscape.app/Contents/Resources/bin/inkscape because I have Inkscape.app installed in /Applications/Multimedia.
Hints
- it might work out of the box
- On 3/17/2008 Steve Litt observed in LyX version 1.5.3 that SVG files could be directly placed in the LyX file, even without defining converters for SVG. Your mileage may vary. (Others reported that this produces a bitmap graphic with bad quality)
- preview
- Some have found using
convert (ImageMagick) works better for the preview: Leave out the SVG -> PNG definition and LyX will generate the preview the default way.
You can also use convert with Windows. Replace "inkscape PNG" with "convert" in the converter section.
- text export bug
- There is a bug in Inkscape 0.44: It does not export text correctly to EPS if the font name has spaces in it. In order to succeed in exporting text, it can be converted to "paths", by using the command
inkscape --export-bbox-page -T --without-gui --file=$$i --export-eps=$$o (The text cannot be processed by psfrag after that (see psfrag below).) in the conversion from SVG to EPS, that is the same command used in the instructions above with the -T (--export-text-to-path) option added.
- psfrag
- You can use psfrag (in ERTs) to replace text in the images with LaTeX Text and formulas (It would be great if LyX would support that without ERTs!).
Make sure you do not use the -T (--export-text-to-path) option when converting from SVG to EPS with Inkscape. Likewise, when exporting figures by hand via the Inkscape GUI, the checkbox labeled "Convert text to path" should be unchecked. See the Inkscape manual page for details.
Get the right size
If the SVG is converted to EPS, the size of the resulting graphic is automatically set to the size of the content.
For both, bitmap and PDF output, by default the size is set to the "paper-size" of the canvas (letter or A4).
In order to get a graphic that can be input in a LyX document,
the Inkscape drawing must be sized right. Either add --export-area-drawing to the SVG->PDF converter definition (see above) or, after your drawing is complete, do the following:
- File->Document_Properties.
- Uncheck all checkboxes in the Borders section.
- Select everything in the drawing. (either with Strg-A or dragging a rectangle around all elements with the mouse.)
- Click the "fit page to selection" button.
- Move both scrollbars to their centers and verify that the picture is still visible.
- If the picture is not visible, exit without saving and try again.
- If the picture is still visible, File->Save.
Correction 18/05/08: setting the figure size in Inkscape's File->Document_Properties seems to be mandatory, while the --export-area-drawing doesn't seem to do anything.
Correction 11/25/09: --export-area-drawing is working for export to pdf and png since Inkscape 0.47.
Categories