How can I get LaTeX working on Anki? 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?
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:


Install MacTeX.  I installed BasicTeX-2011.pkg (MacTeX-Additions-2011.mpkg is NOT required).
Open the terminal, type "tlmgr update --self &amp;&amp; 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.