Go to page:

Search help:

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

UseInkscapeSVGImages

Categories: Tips, Software
<< Using LyX with Tgif | Page list | WordCount >>

Include SVG Images in LyX

Inkscape from http://www.inkscape.org/ can be used to configure LyX to directly include .svg images and automaticaly generate .PNG preview images in lyx and .EPS for latex. 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

I have tested the scripts from SVG Files and Inkscape and the configuration below in Windows XP with LyX 1.4.2 and Inkscape 0.44. You need both, the Windows command script inkscape.cmd as well as the linux shell script inkscape. LyX for Windows uses a built in shell for generating the preview images and the windows command interpreter for converting svg to eps. That's why you need both scripts.

You can configure LyX in a few steps:

  • Install Inkscape
  • Copy the script(s) from SVG Files and Inkscape into your LyX scripts directory and change the INKSCAPE_DIR Variable in the script(s) to fit your configuration. You can also change the PNG_BACKGROUND_COLOR Variable to change the background color of the PNG files.
  • Adopt your LyX Preferences as follows:
    • In the Section Paths add to Path-Prefix the directory where the above scripts are located.
    • In the Section File Formats
      • Fill in the text fields with the following values
        Format: svg
        GUI-Name: SVG
        Extention: svg
        Viewer: inkscape SHOW $$i
        Editor: inkscape EDIT $$i
      • Important: Press Add
    • In the Section Converters
      • Fill in the fields with the following values
        From: SVG
        To: EPS
        Converter: inkscape EPS $$i $$o
      • Important: Press add
      • Fill in the fields with the following values
        From: SVG
        To: PNG
        Converter: inkscape PNG $$i $$o
      • Important: Press add
    • Press Save

You need to restart and maybe reconfigure LyX.

Linux

You can configure LyX in a few steps:

  • Install Inkscape
  • Adopt 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
        Extention: svg
        Viewer: inkview
        Editor: inkscape
      • Important: Press add
    • 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

[Note: Make sure you do not use the --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.]

You need to restart and maybe reconfigure LyX.

Some have found using convert (ImageMagick) works better on Linux. Simply leave out the SVG -> PNG definition and LyX will generate an EPS from the SVG and a PNG preview from this.

You can also use convert with Windows. Replace "inkscape EPS" and "inkscape PNG" with "convert" in the converter section.

If you add a .svg image in LyX now the Preview should work and LyX converts the image into an EPS-image if that is needed by a LaTeX run.

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

in the conversion from SVG to EPS, that is the same command used in the instructions above with the -T options added.

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!).

Mac OS X

Under Mac OSX, 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.

LyX-Friendly Inkscape Settings

On 3/17/2008 Steve Litt observed in LyX version 1.5.3 that Inkscape-produced .svg files could be directly placed in the LyX file, even without defining converters for SVG. Your mileage may vary. (This seems to use some fallback conversion and produce a bitmap graphic)

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:

  1. File->Document_Properties.
  2. Uncheck all checkboxes in the Borders section.
  3. Select everything in the drawing.

(either with Strg-A or dragging a rectangle around all elements with the mouse.)

  1. Click the "fit page to selection" button.
  2. Move both scrollbars to their centers and verify that the picture is still visible.
  3. If the picture is not visible, exit without saving and try again.
  4. If the picture is still visible, File->Save.

Categories

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2008-05-05 02:07 CEST