chemfig, pdflatex and imagemagick

carldejager's Avatar

carldejager

10 Mar, 2013 03:38 AM

Hi

I'm trying to get Anki on OSX to work with the chemfig package. I found a thread about the issue: (http://code.google.com/p/anki/issues/detail?id=3088) that points to LATeX being the problem and suggests using pdflatex + imagemagick instead of latex + dvipng for rendering.

The thread suggests editing a latex.py file to get Anki to use pdflatex instead of latex, but I can't find this file.

Does anyone know if this is possible on OSX, whether it is advisable, or if perhaps there is an easier way around this problem?

  1. 1 Posted by Soren Bjornstad on 10 Mar, 2013 03:47 AM

    Soren Bjornstad's Avatar
  2. 2 Posted by carldejager on 10 Mar, 2013 08:00 AM

    carldejager's Avatar

    Soren, I did my best, but I don't know enough to get it working. I have installed imagemagick and tested it by converting a pdf file to png via the command line. Then I updated your plugin script as follows:

    newLatex = ["pdflatex", "-interaction=nonstopmode","tmp.tex", "tmp.pdf"]
    newDviPng = ["convert", "-density", "200x200","-trim", "+repage", "-background", "white", "-flatten", "tmp.pdf", "tmp.png"]
    import anki.latex
    anki.latex.latexCmd = newLatex
    anki.latex.latexDviPngCmd = newDviPng

    However, I get an "Error executing dvipng." message in Anki. Any ideas where I'm going wrong? (I've attached the error log)

    Many thanks for your time.

  3. 3 Posted by Soren Bjornstad on 10 Mar, 2013 03:18 PM

    Soren Bjornstad's Avatar

    Ah, I see the problem—dvipng can't use pdflatex. I forgot about that (it
    generates a pdf instead of a dvi). If you can figure out another command
    that will convert the pdf into a png file (perhaps using ImageMagick) and
    put that into the dvipng call, you may be able to make it work.

  4. Support Staff 4 Posted by Damien Elmes on 11 Mar, 2013 09:58 PM

    Damien Elmes's Avatar

    The error indicates you do not have 'convert' (a program provided by
    imagemagick) installed or in your path.

  5. 5 Posted by carldejager on 12 Mar, 2013 08:34 AM

    carldejager's Avatar

    Thanks very much for the reply, Damien.

    I used the cactus lab installer for ImageMagic (http://cactuslab.com/imagemagick/)

    After I installed ImageMagick, I ran the following command in Terminal with a sample PDF to make sure that it was actually working:
    convert -density 200x200 -trim +repage -background white -flatten tmp.pdf tmp.png
    (I first tried in my usr then Desktop folders, all good)

    So if the convert command is not available, I assume it perhaps has something to do with the specific folder that Anki is using to store temporary files in? Any ideas?

  6. 6 Posted by carldejager on 12 Mar, 2013 11:07 AM

    carldejager's Avatar

    Damien. I've done a bit more fiddling around and I'm pretty sure ImageMagick is able to run.

    If you look at the Anki error it says:

    dvips: DVI file can't be opened: /var/folders/8m/m_9c09j52fs445gbgbymlv540000gn/T/magick-JsBHNWsQ: No such file or directory

    It looks like the 'magick-JsBHNWsQ' directory does not exist. The parent directory however does exist and I was able to copy a pdf there and use ImageMagick to convert the pdf to PNG.

  7. Support Staff 7 Posted by Damien Elmes on 12 Mar, 2013 10:04 PM

    Damien Elmes's Avatar

    Sorry, I misinterpreted the previous error. The add-on you are using can not be used to do what you want, because Anki expects the commands to generate a .dvi file, not some other type of file. There is a ticket on the issue tracker about looking into this in a future release, but for now you will not be able to accomplish this without replacing chunks of Anki's code in the add-on. We can't provide support for modifying add-ons here, but you could always try asking on the add-ons forum.

  8. Damien Elmes closed this discussion on 12 Mar, 2013 10:04 PM.

  9. Soren Bjornstad re-opened this discussion on 12 Mar, 2013 11:27 PM

  10. 8 Posted by Soren Bjornstad on 12 Mar, 2013 11:27 PM

    Soren Bjornstad's Avatar

    I've been considering working on the add-on to add support for arbitrary
    commands to be executed, but I'm afraid it's not a very high priority for
    me at the moment.

  11. 9 Posted by carldejager on 13 Mar, 2013 11:29 AM

    carldejager's Avatar

    Thanks for your time on this guys. I will perhaps just create these molecule images manually for now. Also thanks for all the hard work on Anki - its a really amazing tool.

  12. Support Staff 10 Posted by Damien Elmes on 14 Mar, 2013 01:07 AM

    Damien Elmes's Avatar

    You're welcome, and sorry we couldn't help further!

  13. Damien Elmes closed this discussion on 14 Mar, 2013 01:07 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac