Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

UseInkscapeSVGImages

<< | Page list | >>

As of version 1.6.6 LyX directly supports SVG files - only librsvg or Inkscape needs to be installed on your computer. To enable the default support on Windows, edit preferences and add the path to Inkscape to the paths section (it appears that the path entry may be case sensitive, so use the correct letter casing on the path, even on Windows). Then use Tools | Reconfigure. If you open up the Converters preference again, you should see new entries there for SVG to PNG, SVG to EPS, and SVG to PDF. Once you have them, everything should work fine. You do NOT have to add the converters yourself; they will be automatically added when LyX detects Inkscape on the path during a reconfigure operation. If they're not there, check the path you entered and ensure that you have matched the case perfectly, and that the target directory exists, and that inkscape.exe is there.

Note that as of version 2.0.0 LyX is capable of displaying SVGs without configuring Inkscape as converter (i.e. without doing the procedure above) but in some cases (e.g. SVG containing text, LyX running on Windows), the rendering will be buggy (see http://www.lyx.org/trac/ticket/7657). Using Inkscape as converter with the procedure described below solves the issues.

Include SVG Images in LyX

The are three possibilities based on Inkscape, Apache Batik and librsvg(approve sites). 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.) Inkscape has to be in the PATH in order to have LyX automatically configure the right converters.

MacOS X

  • In the Preferences under Paths you should append :/Applications/Inkscape.app/Contents/Resources/bin at the end if you have Inkscape installed at the default location. (Make sure a colon separates it from the other entries.)
  • Then Save and choose Lyx->Reconfigure. After a restart, in the Preferences there should now be listed three converters for SVG.

Then the correct entries should be automatically added:

 SVG -> EPS
 inkscape --file=$$p/$$i --export-area-drawing --without-gui --export-eps=$$p/$$o
 SVG -> PDF (ps2pdf)
 inkscape --file=$$p/$$i --export-area-drawing --without-gui --export-pdf=$$p/$$o
 SVN -> PNG
 inkscape --without-gui --file=$$i --export-png=$$o
  • In Preferences under File Handling under File Formats, select SVG from the dropdown and enter:
Editor: Custom: open -a Inkscape

(Note the capital I is important. OS X will open the App with the -a option)

Then you can right-click on an svg and choose "Edit externally...."

If you encounter errors using the MacOS X integration, see the Correction of 13/05/16 near the bottom of this page.

Inkscape Mac OSX SVG Converter

Windows

You can add support for SVG manually:

  1. Install Inkscape
  2. 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 $$i --export-area-drawing --export-filename=$$o
      • Important: Press add
      • Fill in the fields with the following values
        From: SVG
        To: EPS
        Converter: inkscape $$i --export-area-drawing --export-filename=$$o
      • Important: Press add
      • Fill in the fields with the following values
        From: SVG
        To: PNG
        Converter: inkscape $$i --export-area-drawing --export-filename=$$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.

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:

  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.)
  4. Click the "fit page to selection" button.
  5. Move both scrollbars to their centers and verify that the picture is still visible.
  6. If the picture is not visible, exit without saving and try again.
  7. 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.

Correction 13/05/16: On MacOS El Capitan (10.11), you may need to add the path to the inkscape binary (/Applications/Inkscape.app/Contents/Resources/bin) to your shell PATH environment variable. Also, confirm that the EPS, PDF and PNG conversion entries include both the path and file variables, for instance: --file=$$p/$$i. In at least some cases, this in missing the $pp/ as set up after the Reconfigure step described above.

Categories

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2024-11-29 19:51 UTC