Increasing the "main memory" of LaTeX

If you are trying to compile a particularly large LaTeX document (or one containing hugely complex Tikz diagrams / charts) you may find you run out of memory. After externalising all the Tikz figures, if you still run into the limit you can increase it!

Running kpsewhich texmf.cnf should tell you which file you need to edit, but for some reason in my Xubuntu 14.04 installations it points to the wrong file! So the correct file for these systems is actually /usr/share/texlive/texmf-dist/web2c/texmf.cnf

Find the line that starts main_memory = and simply increase the number! Unfortunately (due to reasons I haven't looked into properly) there's a limit - the highest value you can use without it giving the error "Ouch---my internal constants have been clobbered!---case 1" is 12435455.

After changing the number, save the file and run fmtutil-sys --all to make the change take effect.

If you still can't compile the document, don't despair! Although you cannot increase the main_memory any higher, you can allocate "extra memory". Edit the same file, and find the lines beginning extra_mem_top = and extra_mem_bot =. I haven't found whether there is a maximum for either of these, but using 15000000 for each allowed my massive scatter plot to compile!

After changing either of these values, you don't need to re-run the fmtutil-sys command above.