Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm compiling one pretty simple LaTeX file with few dozen of pgfplots. Now, I can compile part by part, but am unable to compile it all at once. I really need good precision for all those plots (noise plots) and would like to avoid decimating graphs more. When I run compile, I get this error message:

[...] TeX capacity exceeded, sorry [main memory size=3000000].

Is there a way to avoid this message somehow? How am I supposed to use pgfplots if I can't plot couple dozen of figures with it without having TeX overloaded? How to expand TeX memory size, please?

share|improve this question

3 Answers

up vote 26 down vote accepted

The pgfplots package can be particularly heavy on TeX's memory, especially if you are creating plots with lots of data points. Indeed, there is a section in the pgfplots manual about expanding TeX's memory. However, that does not mean that expanding TeX's memory is the best solution. Instead, I would recommend using the 'externalization' approach (section 7.1 of the pgfplots manual).

The idea of externalization is to compile each plot as a separate TeX job. This leads to a graphic which can be used in the main job. Thus each plot has its own memory requirement, separate from all of the other plots. This usually avoids needing to make TeX's memory bigger. At the same time, the resulting files can be kept between TeX runs, which will speed up compilation for the second and subsequent runs. The latest version of the externalization system needs you to do two things. First, you put

\usepgfplotslibrary{external} 
\tikzexternalize

in your preamble, to turn the system on. Secondly, you will need to enable 'shell escape'. This is done at the command line by adding the -shell-escape switch:

pdflatex -shell-escape <filename>

The same can be done in LaTeX editors: there is usually a place in the settings for this type of thing. I'll just add that shell escape does has some security implications: use only with documents that you trust!

share|improve this answer
I should probably say that I saw it coming. I had the feeling that "expanding the memory size" is not the answer, and externalization works flawlessly - plus, every following pdflatex run is ridiculously faster! Thanks! ...I should only find a way now to forward -shell-escape from rubber --pdf command that I'm using to pdflatex... – user1996 Dec 30 '10 at 9:59
6  
Also, try the lualatex compiler which appears to dynamically allocate more memory if it needs it. – Sharpie Apr 20 '11 at 4:44
Is there a more general solution that is not limited to pgf? – Brandon Kuczenski Nov 16 '11 at 7:29
@joseph-wright, this is great, but now I change some of my pgfplots and they don't get updated automatically when compiling? It seems it's still using some old compiled figure. How do I force it to re-compile? – perr0 Jan 16 at 4:17

after trying all the options (changing texmf.cnf file, etc.) I found on the web, the only one that worked for me was to use lualatex. This is the simplest and more elegant way to do it. Lualatex is available in the Texlive distribution by default.

share|improve this answer
see macosx-tex.576846.n2.nabble.com/Lua-td6030741.html for instructions on using lualatex on a mac ::: note: in pdfLuaLatex.engine you may need to change pdflualatex -synctex=1 "$1" to lualatex -synctex=1 "$1" – C. Reed Jan 4 at 13:19

In TeX Live, you can modify texmf.cnf (the one in /some/path/to/texlive/2010/texmf.cnf):

main_memory = 3000000

See comments in /some/path/to/texlive/2010/texmf/web2c/texmf.cnf for details.

share|improve this answer
@Edin: your correction is wrong. The file mentioned by Leo Liu is the one to modify, as it's not touched by any TeX Live update. – egreg May 4 '11 at 8:41
Thanks @egrep. In general things like that should not be modified directly but pointed out in a comment. – Martin Scharrer May 4 '11 at 10:20
2  
The /some/path/to/texlive/2010/texmf/web2c/texmf.cnf is the official config file which will be overwritten in an update. It should not be modified. Instead the /some/path/to/texlive/2010/texmf.cnf should be used to change all settings which are different from the default. This is pointed out in the comments of the main web2c/texmf.cnf config file, which maybe is what Leo Lio meant in his last sentence. – Martin Scharrer May 4 '11 at 10:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.