Increase Latex Resolution in Anki


If you have a display with a high pixel density, such as a "retina" MacBook Pro, the default LaTeX images generated by Anki look blurry. This is possible to change. The information on how to do so is a bit scattered on the web, so I decided to put together this short guide.

We will go through the following steps.

  1. Install an add-on that lets us modify the LaTeX configuration.
  2. Modify the LaTeX configuration in order to increase the resolution.
  3. Regenerate the images.
  4. Reduce the dimensions in the displayed images.

Update: Since writing this guide, I discovered that Anki 2.1 supports MathJax. In my experience, it works better than using MacTex in the sense that inline formulas have the right height and position together with other text. However, "AnkiDroid does not yet have built in support for [MathJax]." So if you're using AnkiDroid, this guide is for you.

The instructions below are tested on macOS 10.13.6 (High Sierra) with Anki 2.1.3 and MacTeX 2018.0417. Your mileage may vary.

1 The Edit LaTex build process add-on

Source: Any way to get better latex image resolution? (r/Anki)

Visit the add-on's page on Ankiweb and copy the code.

In Anki on your computer, click Tools -> Add-ons:

Then, click Get Add-ons:

Paste the code and click OK:

For the changes to take effect, restart Anki.

2 Modify LaTeX configuration

Source: Anki Latex image quality? (r/Anki)

Now, we're going to tell LaTeX to increase the image size. In the add-on dialog box, make sure that "Edit LaTeX build process" is selected and click Config:

Anki uses dvipng to create the images. The -D option sets the output resolution. In the config window, increase the -D value. I'm using 1000:

When you're finished, click OK.

3 Regenerate images

Source: Safe way to recreate LaTeX cards (Anki Support)

Now, we need to find out where your images are stored and delete them. First, click View Files in the Add-ons dialog:

By navigating up one level (e.g. by using Command + Up Arrow), you'll find one or more user folders. (Mine is called User 1.) In the appropriate user folder, find collection.media. In there, you should find a bunch of latex-[some numbers and letters].png:

Delete all these files starting with latex-.

To speed this up, you can use the terminal. (I won't provide detailed guidance here, because I don't think you should be deleting files from the terminal unless you really know what you're doing.)

In the Tools menu, click Check Media…:

5 Reduce the dimensions of the displayed images

Source: Anki Latex image quality? (r/Anki)

Because the images are now much larger, we need to update our styles. First, find a card that you need to update. Then, click Cards in the edit view:

Then, add

.latex {
  zoom: 20%;
}

to the Styling section.

Conclusion

In this guide, we increased the LaTeX image resolution to work better with displays with high pixel densities. As I mentioned above, it would be helpful to other users if you commented with your system details and what your experiences were.