# Anki - LaTeX, Math Font Size, & DeclareMathSizes

I use the Anki flashcard program and render math equations using LaTeX within the program.

The problem is that the font sizes are generally too big, unless the equation is really long, in which case the equation automatically sizes down in order to fit the screen.

This is the default LaTeX header in Anki:

\documentclass[12pt]{article}
\special{papersize=3in,5in}
\usepackage{amssymb,amsmath}
\pagestyle{empty}
\setlength{\parindent}{0in}
\begin{document}


And this is the default footer:

\end{document}


To call LaTeX within Anki when creating a flashcard, you use $and$, which I assume refer to the header and footer respectively. (I'm neither an Anki nor a LaTeX expert.)

Anyway, I've tried inserting the following right before \begin{document}:

\DeclareMathSizes{2}{2}{2}{2}


Yes, I realize this is supposed to make the text really tiny, but more importantly, nothing changes. My equations are still too big (or too small, if the equation is really long).

• welcome to tex.sx. For those of use (most of us I'd guess) without that program could you post the generated latex document including an equation so we can see what markup it is generating and then can suggest a preamble to control the fonts. – David Carlisle Apr 12 '13 at 21:32
• Maybe a simple change to the header is enough. Something like \documentclass[10pt]{article} should change all font sizes. – Alexander Apr 12 '13 at 22:01
• @David, thanks for the welcome. Anki generates an image from the LaTeX input and attaches the image to the flashcard. Not being an Anki expert (nor a big tech expert in general), I don't know how to dig into its source code to see what "markup" it is generating. – MMS Apr 12 '13 at 22:46
• looking at github.com/dae/anki/blob/master/anki/latex.py it deosn't seem to do much with the latex other than append the preamble that you showed, you could change the 200 in the dvipng command on line 11 which will affect the image resolution so (depending on what exactly it means by that it might change the size when it is re-included) – David Carlisle Apr 12 '13 at 23:02
• @Alexander, thanks for the suggestion - it made me discover something interesting, which is that changing 12pt to 8pt did nothing to change the size of the text, even when testing something as simple as $Text$ (i.e., just plain old text). – MMS Apr 12 '13 at 23:02

Tools -> Manage Note Types... -> Options; in the last line of the Header field after \begin{document} just type

\tiny


And your LaTeX will be made smaller. Because previously rendered latex is cached as image files, you may have to delete those files before the change is apparent. On my Mac the files are in ~/Anki/User 1/collection.media/latex-*.png

For me this makes my [$$][/$$] equations the same size as the surrounding Anki font.

I hope this helps!

UPDATE: On Linux, the media directory seems to be located in ~/Documents/Anki/User 1/collection.media/

• On Windows, it's %USERPROFILE%\Documents\Anki\User 1\collection.media\ – Sydius Apr 28 '15 at 7:54
• In my case, I could not enter the \tiny on a new line. It had to immediately follow \begin{document}. – KSHMR Jan 30 '16 at 1:32
• That is, you can't press Enter and expect it to work, but it's okay for too long a line to overlap onto the next line. It seems this isn't designed for newlines. – KSHMR Jan 30 '16 at 1:37
• If you want to render the entire card in LaTeX to make it look more uniform, try changing out the \special{papersize=3in,5in} for \usepackage[paperheight=3in,paperwidth=5in]{geometry} or whatever card size you want, as well. I had to make the geometry smaller for the smaller text to make it look right for me. – Joe Anderson Jun 13 '17 at 13:39
• I settled on using 2in by 3.5in with \scriptsize instead of \tiny. – Joe Anderson Jun 13 '17 at 13:47

I have been struggling with this as well. My solution was to use the LaTeX environment for my entire question and answer. I surround my text with $ and $ and use Latex commands to format the card. This keeps my sizes consistent between text and math, and allows me to use other packages (such as making nice looking tables, compared to the Anki tables!)

For example, my Basic and Reverse cards have this in the preamble:

\documentclass[12pt]{article}
\special{papersize=3in,5in}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{libertine-type1}
\usepackage{biolinum-type1}
\usepackage{libertineMono-type1}
\usepackage[libertine]{newtxmath}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{amssymb,amsmath}
\usepackage{booktabs}
\usepackage{color}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{graphicx}
\usepackage{wasysym}
\pagestyle{empty}
\setlength{\parindent}{0in}
\newcommand{\noun}[1]{\textsc{#1}}
\definecolor{blue}{RGB}{0,130,255}
\begin{document}


This gives me nice tables, math symbols, small caps and default to sans-serif font for graphical display devices.

An example card,

Front: $What is \textbf{finiteness?}$

Back: $A set A is said to be finite \emph{if and only if} \left|A\right|=\mathbb{N} (natural number.) A set that is not finite is said to be infinite.$

Granted, if the displayed card is resized, then the longer card back will also be resized to fit a smaller window. However, I think this can be fixed by changing the papersize in the preamble. I strictly use my laptop and tablet, so I do not have any issues. It may crop up on smaller devices like a phone though.