3

I am working on a LaTeX file with many plots containing a lot of data points. I have a main.tex file that is including chapter files and inside these chapter files I include the files that contain the \begin{figure}\begin{tikzpicture}...\end{tikzpicture}\end{figure} and I am running into this error

! TeX capacity exceeded, sorry [main memory size=5000000]

I have read many posts about externalizing etc. but I don't know how to apply this method or to put it into other words it is too complicated for me. I simply want to increase my main memory such that I do not run into such problems.

I would be glad if someone could explain to me how I can increase my main memory. I am not looking for a solution with externalization because it is too complicated for me. I am running Texmaker 4.5 as Editor, Miktex 2.9 and Windows 7.

EDIT: What I have tried

  • Finding: texmf.cnf (could not find it using the hint by Alan Munn)
  • Typing: "initexmf --edit-config-file=pdflatex" into the cmd. The pdflatex.ini file opend and I added the following to the file and saved and recompiled without success.

main_memory=9000000

extra_mem_bot=9000000

font_mem_size=9000000

MrYouMath
  • 670
  • 3
  • 3
    Try kpsewhich texmf.cnf in a command line window. – Alan Munn Nov 24 '17 at 22:51
  • 1
    Yes a cmd window. Just type exactly that. This is a command that should show you where TeX will look for texmf.cnf. It should return a full path. – Alan Munn Nov 24 '17 at 22:54
  • 1
    Sorry, MikTeX seems to work differently from TeX Live. See http://docs.miktex.org/manual/runtimeparams.html – Alan Munn Nov 24 '17 at 23:01
  • 2
    Are you using pgfplots? If so, the best strategy might be to use \usetikzlibrary{external}. This will do away with the need to recompile every plot every time. Compilation will be faster and use less memory. To get around the current memory shortage snag, start with a smaller document: insert \end{document} halfway down or so to compile some plots first, then remove it again and compile the rest. – Michael Palmer Nov 24 '17 at 23:05
  • 1
    @MichaelPalmer: I used \usetikzlibrary{external} in my main document in the preamble. I tried to compile 4 plots separately (worked) and then together(didn't work). But the problem with the size still remains. – MrYouMath Nov 24 '17 at 23:24
  • 1
    Sorry, I'm a Mac user and don't know anything more about MikTeX. In the linked question it's also suggested to try using lualatex instead of increasing the memory. Have you tried that? – Alan Munn Nov 24 '17 at 23:35
  • @MrYouMath: Did you think of redoing the pdflatex format before recompiling? – Bernard Nov 25 '17 at 00:10
  • @Bernard: If I go into my folder with my main.tex and run pdflatex format it asks me to enter a different file name. – MrYouMath Nov 25 '17 at 08:17
  • 1
    @Zarko this is not a duplicate of the linked question. The user is asking about miktex, the other question handles only texlive. A possible duplicate would be https://tex.stackexchange.com/a/109573/2388. – Ulrike Fischer Nov 25 '17 at 12:20
  • An alternative approach would be to compile the plots as standalone tex files first and then include the resulting pdf files into the main document with \includegraphics{}. So a more explicit externalization then suggested here. See also: https://tex.stackexchange.com/questions/482557/how-to-externalize-tikz-pictures/557015#557015 – fry Jun 01 '22 at 09:38
  • I could not get around the memory limit on Linux. The only thing that worked and blended well into my document was to save it as PDF using the latex backend and import it using \includegraphics. – Suuuehgi Sep 13 '22 at 14:21

1 Answers1

4

I solved the problem by finally beeing able to use tikz externalize (Miktex 2.9, Editor: Texmaker 4.5, OS: Windows 7).

I used

\usepackage{graphicx}
\usepackage{epstopdf} % to turn my eps files into pdf

and

\usepackage{pgfplots}
\usepackage{tikz}
\usepgfplotslibrary{external}
\tikzexternalize{main}

My main.tex included my chapters and my plots are included as .tex files into the chapter files. You might have to uncomment plots such that the compilation can start.

Then I open cmd (Windows + R >> cmd) and entered my folder by using cd.. and cd Directory and then I finally used pdflatex -shell-escape main. I have not found a solution for doing this directly from Texmaker 4.5.

MrYouMath
  • 670
  • 1
    Go to Options -> Configure Texmaker in the menu. There, you will see the command template for running pdflatex. Add -shell-escape to it (and remove -synctex=1 if you don't use it). After that, it should work. – Michael Palmer Nov 26 '17 at 13:52
  • @MichaelPalmer: What does -synctex=1 do? – MrYouMath Nov 26 '17 at 13:55
  • 1
    See here https://tex.stackexchange.com/questions/118489/what-exactly-is-synctex – Michael Palmer Nov 26 '17 at 13:57
  • I tried pdflatex -shell-escape %.tex but it did not work. I also tried pdflatex -shell-escape -interaction=nonstopmode %.tex and it did not work. Also tried without the %.tex and still get an error message "package tikz Error: ... – MrYouMath Nov 26 '17 at 14:00
  • @MrYouMath - It would be truly helpful if you spelled out what exactly "it did not work" means here. E.g., do you get error messages? If so, what do the error mesages say? – Mico Nov 26 '17 at 14:19
  • 1
    Please look here - https://tex.stackexchange.com/questions/236641/shell-escape-in-texmaker. The accepted answer uses --enable-write18 instead of -shell-escape. Maybe that will do it. (I am on Linux, so things are a bit different - didn't mean to give you the run-around.) – Michael Palmer Nov 26 '17 at 14:19
  • Really appreciate your help :). I tried to use --enable-write18 but it still does not work. – MrYouMath Nov 26 '17 at 14:34
  • 1
    Have you tried again to do it stepwise? On the first run, the externalize wouldn't make a difference, so you might have to add the plots one by one. If that does not work, I'm out of ideas ... – Michael Palmer Nov 26 '17 at 14:48
  • Doing it step by step did and using --enable-wirte18 also did not solve the problem. I think I will have to remember to add plots only after I have finished most of the work. And using cmd etc. and opening the pdf file is not so comfortable but it works :D. This memory size issue is really the biggest downside of tikz. – MrYouMath Nov 26 '17 at 14:55
  • 1
    A possible workaround may be to use arara to configure your compilation. Texmaker doesn't have a preconfigured command for it, but you could abuse one of the others that you never use (for example, put arara %.tex into the configuration for latexmk). – Michael Palmer Nov 26 '17 at 15:00
  • @MichaelPalmer: I have no idea what this is doing but I tried it also by removing the plots and it still does not work. – MrYouMath Nov 26 '17 at 15:08
  • 1
    I probably didn't make myself clear. arara is an external program that allows you to configure the compilation of each document within each LaTeX file itself. See here for example: https://www.texdev.net/2012/04/24/arara-making-latex-files-your-way/ Instead of invoking pdflatex itself, you would then invoke arara, which calls pdflatex for you. The configuration trick I proposed for calling arara is probably just confusing. – Michael Palmer Nov 26 '17 at 15:31