12

Originally I was going to ask a question about how to get LaTeX working in Anki, but as I was writing the question, I was trying to solve the problem myself. I thought others may benefit from my findings, so I decided to post them here. If you notice that any of my steps are wrong, please let me know. And I was still unable to get it to work, so if you scroll down to the end, you can see where I'm stuck and still need help.

The current issue is: How can I install libgd?


I'm trying to make Anki work with LaTeX. The only information I could find about how to do this is from this page:

  • [...] to use LaTeX, you have to install it separately - it is not bundled with Anki
  • [...] on OSX use MacTex
  • Dvipng must also be installed.
  • On OSX, if you use MacPorts or similar to install LaTeX, make sure latex and dvipng are linked in /usr/bin.

The standard installation of MacTex takes up 3GB, far more than I believe is necessary, since I am not going to use its GUI application. I just need the LaTeX library, if I understand it correctly, which should be way less than 3GB. Therefore, I'm installing the BasicTeX version instead, which only takes up about 100MB.

I'm not sure if I already have Dvipng installed or not, so I'm restarting Anki to see if it works or not. I got the following error:

Error executing dvipng. [...] Output written on tmp.dvi [...]

So I probably need to install dvipng... The Install readme has the following information:

Installing dvipng should be simple: merely ./configure',make', and `make install'.

Prerequisites:

  • The GD Graphics Draw library, libgd
  • The path-searching library kpathsea
  • libpng and libz

Again, I'm not sure which, if any, of these prerequisites I already have installed, so I'm just going ahead with the installation in hopes of error messages guiding me to the right path.

After executing ./config, it gives the error:

configure: error: cannot find/use libpng

... which I think is weird since the readme states:

 To be able to compress and write PNG files to disk, dvipng (or
 really libgd) uses libpng which in turn uses libz. These should be
 available on any modern system, if not, download them and install
 them.

I went to the libpng website, and tried finding a "current binary" that works with my OS (10.6/i386), but it seems that none of the latest 3 versions have a binary that is available to download. So I went to the "old binaries" section, which took me to this website, which has libpng v1.4.5. I installed the "Individual Installer package" for libpng.

Now that it's installed, I tried installing Dvipng again, and it now gives the following error:

cannot find/use libgd
This drawing library can be downloaded at http://www.boutell.com/gd

When I go to that website, I see it says that the page moved and that it is currently down. There is only a link to the source files and no binary distribution. I'm not sure where I should go from here... should I download the source and compile it somehow? Once it's complied what do I do with it? Do I run some file it generates? Would I move files it generates to specific folders? How would Dvipng know how to access it? I'm unfamiliar with how to do something like this, so any help would be appreciated.


Here's a summary (so far) of the dependency hierarchy which must be installed in order to get LaTeX to work with Anki:

  • MacTeX: Installed (got the BasicTeX version to save a lot of disk space).
  • Dvipng: Not installed (can't install without libgd).
    • libpng: Installed (got the Individual Installer package).
    • libgd: Not installed (not sure how to install this).
    • ???

Other questions:

  • Is there a better, reliable method to know if any of these dependencies are installed rather than running an installer which depends on them and hoping for a meaningful error message?

3 Answers 3

17

Your question was very helpful to me in getting LaTeX working with Anki, but I've found there's an easier way to get dvipng:

  1. Install MacTeX. I installed BasicTeX-2011.pkg (MacTeX-Additions-2011.mpkg is NOT required).
  2. Open the terminal, type "tlmgr update --self && tlmgr install dvipng" and press enter. It will update TeX Live Manager and install the latest dvipng.

Once you do that, you should be all set.

3
  • I agree. It is much better to install packages in MacTex via Tex Live Utility than the command line. This suggestion should work.
    – dan8394
    Commented Aug 14, 2011 at 3:46
  • 2
    Question: I am the only admin on my system but when I try and run the terminal command "tlmgr update --self && tlmgr install dvipng" I get an error saying I need to run the program as an admin. I am the admin! How do I run this program? I need it to properly configure latex on OSX10.6 (Snow Leopard) because I am having pdflatex/ dvipng errors after a new install of BasicTex. Thanks!
    – user21373
    Commented Apr 8, 2012 at 19:01
  • 2
    For posterity: the answer to @user21373's question is to use the 'sudo' command.
    – SigmaX
    Commented Mar 8, 2017 at 9:21
4

I was having this exact problem but the command "tlmgr update --self && tlmgr install dvipng" did not work and I got the error I need to run the program as an admin.

The user account I was using was an admin account. What I did instead is run each command separately as sudo: At the Mac OS X Terminal prompt:

$ sudo tlmgr update --self

(wait for this command to grab updates and compete)

$ sudo tlmgr install dvipng

This worked and installed tlmgr updates as well as dvipng, causing Anki to display LaTeX output!

1
  • 1
    You can run these commands as a one-liner with sudo tlmgr update --self && sudo tlmgr install dvipng Commented Sep 1, 2015 at 18:07
3

If you have Homebrew installed, the easiest way is:

brew install basictex && sudo tlmgr update --self && sudo tlmgr install dvipng
3
  • 1
    This works perfectly. I think it should be the accepted answer.
    – Gavin
    Commented Apr 3, 2022 at 0:27
  • 1
    This is also documented on docs.ankiweb.net/math.html#assumed-knowledge.
    – thiagowfx
    Commented Feb 14, 2023 at 15:44
  • Note 1: You might have to restart the terminal/open a new terminal after installing basictex and then run both tlmgr commands. Note 2: Latex math env in Anki i.e. [latex]$$\frac{1}{2}$$[/latex] need the $$ signs inside of it.
    – xotix
    Commented Oct 8, 2023 at 10:19

You must log in to answer this question.

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