8

I'm using Lyx 2.2 on windows 10 and ghostscript 9.19. When I have pdfs images embedded in my document they don't display in the Lyx window (they appear in the final PDF however).

Where the images should preview it just says, "Error converting to loadable format".

I've tried looking at the latex log, but I can't seem to gain any insight as to how to resolve this issue. I've also tried searching many forums online but they all seem to point to updating ghostscript, which doesn't apply to me since I'm running the latest version.

5
  • 2
    Seem that pdf to png conversion for the preview fail for some reason. This has nothing to do with LaTeX, that do not need at all this conversion. Check the instalation and configuration of the converter (See Preferences > File Handling > Converters > "LyX Preview -> PNG". For Linux the default is python -tt $$s/scripts/lyxpreview2bitmap.py --png
    – Fran
    Aug 23, 2016 at 23:45
  • @Fran, I'm using windows. this was the command there: python -tt $$s/scripts/lyxpreview2bitmap.py --png.
    – Veridian
    Aug 24, 2016 at 16:32
  • Sorry, I noticed that is not the right converter. Probably is another convert or a bug of Ghostsript. I posted a general answer that should allow you to find the solution.
    – Fran
    Aug 25, 2016 at 8:27
  • Looks like the next version of Lyx will use sips on OSX instead of ImageMagick.
    – Timmmm
    Jun 27, 2017 at 9:11
  • On the recent linux desktops (May 2019), the issue is due to imagemagick policy update. It's a pity that Dmitry Zotikov comment (solution) is at the bottom of the page May 28, 2019 at 4:52

15 Answers 15

6

Short answer: https://wiki.lyx.org/LyX/FiguresInLyX

Long answer:

To view a image on the LyX screen, it is required a compatible format with that XForms or Qt GUI libraries, namely bmp, gif, jpeg, pbm, pgm, ppm, tif, xbm or mng, png and xpm, respectively.

A message "Error converting to loadable format" mean that is not possible convert the image to PNG or any of these formats.

then you'll need to augment the list of known converters.

The link shows a detailed example of adding a converter. Pay attention that the converters are in the right path.

However,

If you see the "Error converting to loadable format" message only with PDF files and you've verified that you have the converter tools mentioned above, check which version of GhostScript you are using.

Version 8.7 of GhostScript has a known bug that prevents LyX from loading PDFs. Use the newest version. (The link above also explain a manual fix).

2
  • 1
    Thanks for the answer. I've seen this answer posted online. As I said in my question, I'm using GhostScript 9.19, so that isn't the issue, and yes this is only happening with PDFs.
    – Veridian
    Aug 25, 2016 at 16:39
  • @Veridian Then focus first on the converters and Lyx configuration. I would start by checking that ImageMagick is there and you can use the convert tool in a Windows console (the C\:> DOS prompt) to make manually some PDF to PNG conversion, for instance. Good luck!
    – Fran
    Aug 26, 2016 at 2:17
5

There is a non-obvious detail that can cause this error despite having setup a suitable converter.

So for example, following Fran's answer and the LyX wiki instructions:

https://wiki.lyx.org/LyX/FiguresInLyX

you decide to add a pdf to png converter. Since png is well supported and is among the GUI displayable formats, that is a reasonable choice.

Under linux you might decide to use:

pdftoppm -png -singlefile $$i $$o

which generates slightly smaller files than pdftocairo -png .... The difficulty is, the output file will be named outfile.png.png and LyX will be unable to find it, causing the error:

Error converting to loadable format

which leaves no real clue about what the problem is.

An easy way to fix this is to use the command:

pdftoppm -png -singlefile $$i > $$o

which generates outfile.png and LyX proceeds normally.

Another issue is the display resolution. Under the LyX options tab you may wish to set the display size to 75% or so - this does not affect the ultimate pdf size, but it makes it easier to see what you have inserted in the GUI, since you can see the whole image.

4

I'm using Lyx 2.2 under macOS Sierra. In my case, the problem was the ImageMagick version (7), and its incompatibility issues with LyX conversion scripts, as mentioned here: https://www.mail-archive.com/[email protected]/msg194142.html.

I'm using brew, so I fixed this problem by removing imagemagic and installing the latest 6.x version: imagemagick@6 and then creating a symbolic link (in /usr/local/bin) pointing to /usr/local/Cellar/imagemagick\@6/6.9.7-5/bin/convert .

brew uninstall imagemagick
brew install imagemagick@6
ln -s /usr/local/Cellar/imagemagick\@6/6.9.7-9/bin/convert /usr/local/bin/convert

Hope it helps

1
  • Hmm this no longer seems to work.
    – Timmmm
    Jun 26, 2017 at 16:13
3

Ok rather than fiddling around with ImageMagick and Ghostscript, we can rely on sips which is built in to OSX. It's what the official fix does.

  1. Go to Lyx->Preferences->File Handling->Converters.
  2. Change the From format: to PDF (graphics), the To format: to PNG and paste this in the Converter: box: sips --resampleWidth 800 --setProperty format png $$i --out $$o.
  3. Click Add. Yes this dialog is weird - you don't add an entry then configure it, you change the options and then click Add. Confusing.
  4. Click Save. DO NOT CLICK APPLY! For some reason it shows an empty window and crashes Lyx.

The resulting PDFs can be a bit low res. You can increase the 800 if you like.

This fix should already be in Lyx 2.2.4 or later I think.

3

In /etc/ImageMagick-6/policy.xml, comment out the lines like

<policy domain="coder" rights="none" pattern="(...)" />

This introduces a slight security risk, which may be (it seems!) ignored on a desktop system.

2

I'm using LyX 2.2.2 on Windows 7, and I have the same problem. After installing GhostScript 9.20, open LyX and click "Tools" -> "Reconfigure", finally restart LyX, and the problem is solved. I can see all PDF figures displayed in LyX. (However, the quality of the display is a little rough)

2

I had a similar problem, and none of the existing solutions worked for me (updating Ghostscript, uninstalling/reinstalling things, making sure imagemagick was there, etc.). I finally managed to solve the problem, so I'm posting what worked for me here in case others run into the same problem. For the record, I'm running Windows 10 Home.

Essentially, the problem boiled down to the fact that imagemagick was looking for a 32-bit version of Ghostscript, when I had a 64-bit version installed. The simple solution was to download the most recent 32-bit version of Ghostscript, and install it to \Program Files (x86)\GPLGS\. Problem solved.

I was able to diagnose this problem by navigating to the imagemagick directory (\Program Files (x86)\LyX x.x\imagemagick\), and running a test pdf-to-png conversion from the command line. So:

  • Put a PDF file of some kind (one containing just a simple image) in the imagemagick directory. Call this test.pdf or something.
  • Open a command prompt (you might have to run as administrator), and navigate to the imagemagick directory.
  • Run the command: magick convert test.pdf test.png

When I did this, I got an error message, the first bit of which suggested that it had tried and failed to run the Ghostscript executable in the target folder \Program Files (x86)\GPLGS\. This folder didn't exist, because I had only a 64-bit version of Ghostscript installed (which was located in \Program Files\gs\). Getting the 32-bit version fixed the problem instantly.

0
1

For me on OSX the problem was that I didn't have ImageMagick installed at all. I'm not sure when it was expected to be installed, but anyway. Just follow Hector's instructions:

brew install imagemagick@6
ln -s /usr/local/Cellar/imagemagick\@6/6.9.7-9/bin/convert /usr/local/bin/convert
1

I had exactly the same problem for LyX 2.2, whereas previously LyX 2.1 worked fine. So what I did was moving the ghostscript folder and the imagemagick folder from LyX 2.1 to LyX 2.2, and it turned out that it is imagemagick that has something wrong.

1

Windows usernames containing certain non-alphanumeric characters like umlauts can cause the described symptoms.

On my system (Windows 8.1, LyX 2.2.2, ghostscript 9.15) Windows accounts with umlauts in their usernames suffer the problem described by Veridian: Embedded PDF images are not displayed in LyX, stating "Error converting to loadable format", even though they are displayed in the final PDF. On the contrary, Windows accounts with alphanumeric usernames do not suffer this problem on my system. This also holds for newly created accounts.

For me the following workaround helped:

  • In LyX go to Tools > Preferences > Paths
  • Set Temporary Directory to C:\Users\Public\AppData\Local\Temp
  • Make sure the path exists
  • Restart LyX
2
  • Welcome to TeX.SX! Are you sure this is related to the problem?
    – TeXnician
    Apr 6, 2017 at 15:20
  • @TeXnician Thanks! I edited my contribution and hope I made more clear, how it is related to the problem.
    – Dörrobst
    Apr 7, 2017 at 15:38
1

For me, on Windos 10 the following solved the problem:

1

In case you are using Inkscape 1.0 or later (as of 05/04/2020) AND your source files are in SVG format (or another vector format handled by Inkscape on your system), you might actually suffer from another issue:

Inkscape changed some command line options frequently used by LyX. For example --without-gui must not longer be used, --export-png now is --export-filename etc.

Check out this Inkscape wiki page for a full list:
https://wiki.inkscape.org/wiki/index.php/Using_the_Command_Line#Deprecations_and_Replacements

Solutions:
a) reconfigure your Lyx (via menu Tools->Reconfigure) or
b) change all the inkscape commands manually (via menu Tools->Preferences, section File Handling->Converters) or
c) switch to another SVG conversion tool, e.g. librsvg

0

I had the same problem, and what worked for me is a variant of Dmitry Zotikov's solution : just commenting out some lines didn't do it for me (I've no clue why!). Instead, I just renamed this file : /etc/ImageMagick-6/policy.xml --> /etc/ImageMagick-6/old-policy.xml and now LyX handles pdf files nicely again.

Now, have I just created some horrible security liability for my home computer?

0

It seems that Catalina breaks ImageMagick+Lyx again... Although "convert" of ImageMagick works alone in the terminal, but it does not work on Lyx.

The solution is to find an alternative converter. After a few tries, I found two.

  1. Inkscape command-line version (need to install with Macports), then put inkscape $$i -e $$o in the converter for "EPS->PNG" in the LyX Preferences/File Handling
  2. GhostScript, using gs -dSAFER -dBATCH -dNOPAUSE -dEPSCrop -r100 -sDEVICE=pngalpha -sOutputFile=$$o $$i (r100 means DPI=100, you can change it)

gs is working better than Inkscape, as the latter is not handling well with some vector fonts.

0

For what it's worth, in Ubuntu 20.04, the conversion went PDF -> EPS -> PNG.

Thus, the problem was the EPS -> PNG converter.

Per this answer, https://askubuntu.com/a/1210683/13169 , I changed the EPS -> PNG converter to:

gs -dSAFER -dEPSCrop -r600 -sDEVICE=pngalpha -o $$o $$i

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .