Hi us,

I use LyX 1.6 SVN.
I use sometimes Inkscape to make vectorial pictures, with the "external 
material" feature.
To use Inkscape with LyX, a method is given here:

http://wiki.lyx.org/Tips/UseInkscapeSVGImages

At the end, you see "Correction 18/05/08: setting the figure size in 
Inkscape's File->Document_Properties seems to be mendatory, while 
the --export-area-drawing doesn't seem to do anything.".

So, some people seems to have the same problem than me, if I understand well. 
My problem is that I obtain a preview with A4 size, whereas I would like to 
obtain a preview cropped to the "bounding box" size.

I have tried several configurations:

1/ SVG format not defined, no converter.
I see a A4 preview. After careful examination, it seems that this is a preview 
generated by ImageMagick "convert" tool, called in the Python script:

/lib/scripts/convertDefault.py

2/ Definition of the format svg, as hinted at 
http://wiki.lyx.org/Tips/UseInkscapeSVGImages , but no definition of 
converters.

The preview is still A4, but it has changed: another tool has been used to 
transform the SVG picture. I know it because there are arrows in my picture, 
and they are badly converted by ImageMagick (configuration 1), and here 
(configuration 2) they do not appear at all.
It seems that this is not inkview (the viewer defined in the file format svg) 
that is used, because inkview shows correctly the arrows in command line.

3/ Compared to configuration 2, additional definition of the svg=>png 
converter, as asked in the LyX Wiki. Same result than in 2.

4/ Compared to configuration 3, additional definition of the svg=>EPS and 
svg=>PDF(pstopdf), as said in the LyX Wiki. Same result.

5/ Try to add -D option to Inkscape in the svg=>EPS and svg=>PNG already 
defined filters. No result.

Note that the PS view (CTRL+T) works correctly in configuration 5. It is only 
a problem of preview.
Note also that the converters work correctly in command line.

I have found a workaround, I have modified the already quoted Python file 

/lib/scripts/convertDefault.py

I have replaced the following lines:

======
if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[1], sys.argv[2])) != 0:
    print >> sys.stderr, sys.argv[0], 'ERROR'
    print >> sys.stderr, 'Execution of "convert" failed.'
    sys.exit(1)
======

by:

======
if sys.argv[1][-3:] == 'svg' and sys.argv[2][0:3] == 'ppm':
   if 
os.system(r'inkscape -D "%s" --export-background=white --export-png="%s";\
         convert -verbose "%s" "%s"'\
         % (sys.argv[1], sys.argv[2][4:-4] + ".png", sys.argv[2][4:-4] 
+ ".png", sys.argv[2][4:]) ) != 0:

      os.system(r'echo "%s => %s => %s: conversion has failed!"' % 
(sys.argv[1], sys.argv[2][4:-4] + ".png", sys.argv[2][4:] ) );
   else:

      os.system(r'echo "%s => %s => %s : conversion has suceeded"' % 
(sys.argv[1], sys.argv[2][4:-4] + ".png", sys.argv[2][4:] ) );

elif sys.argv[1][-3:] == 'svg' and sys.argv[2][0:3] == 'eps':

   if os.system(r'inkscape -D "%s" --export-eps="%s"'\
         % (sys.argv[1][4:], sys.argv[2][4:]) ) != 0:

      os.system(r'echo "%s => %s: conversion has failed!"' % (sys.argv[1][4:], 
sys.argv[2][4:] ) );
   else:

      os.system(r'echo "%s => %s : conversion has suceeded"' % (sys.argv[1]
[4:], sys.argv[2][4:] ) );

else:

   if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[1], sys.argv[2])) != 
0:
      print >> sys.stderr, sys.argv[0], 'ERROR'
      print >> sys.stderr, 'Execution of "convert" failed.'
   sys.exit(1)

======

And it works perfectly well.
So, contrary to what is said in the LyX Wiki, it seems that the important 
converter for the preview is svg=>PPM. I have tried to keep the orginal 
convertDefault.py, and defined a filter svg=>PPM with the following command:

inkscape $$i --export-png=$$o.png;convert $$o.png $$o

(the redirection does not seem to work in command line, I have not found 
another solution than the semicolon in command line).

But it does not work.
To go further in the examination of the problem, I have to examine C++ code. 
It is too difficult for me.
So could you help me, please?
If no solution with standard definition of format and filters in LyX 
preferences does work, I will keep my modified Python file!

Thanks

Julien

Reply via email to