# TeX capacity exceeded when calling LuaLaTeX

I am using recently updated MacTex Distribution 2016 on a MacBook Pro Mid 2009 and Texmaker is my editor. I want to include a phase portrait created with matlab2tikz with a lot of lines. Reducing the samples is no option since it reduces quality and I can see kinks in the lines... So I get the well known error:

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


Since I want to avoid to change memory allocation hard bounds I use lualatex in the system call with \tikzset. See my MWE below and the phase_portrait.tex

\documentclass{article}

\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzset{external/system call={lualatex -shell-escape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}

\begin{document}
\input{phase_portrait.tex}
\end{document}


I run the file with

 "pdflatex" --shell-escape -synctex=1 -interaction=nonstopmode %.tex


and it doesn't work and I get the same error. Why do I still get it? even though I call Lualatex which has dynamic memory allocation? Any help is appreciated. Thanks!

My versions are respectively:

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex 2016.7.11)

This is LuaTeX, Version 0.95.0 (TeX Live 2016)  (format=lualatex 2016.7.11)


EDIT: For me I solved the issue now by compiling my whole document with LuaLaTeX. But this is still not the answer I was looking for since now I am forced to compile with LuaLaTeX. So there is further interest in a solution to the problem ;)

• Welcome to TeX.SE! 3Mb for a .tex is too much in my opinion, have you conside to split it, and then call files somehow, like putting data in a single file? – SAM Jul 11 '16 at 13:07
• Hey! Well not really considered that since it works fine when I compile the whole file with LuaLaTex. How do you mean exactly splitting it? In the end it must be compiled in one go, no? – Erisch889 Jul 11 '16 at 13:12
• I don't know exactly I am not used to tikz tex.stackexchange.com/q/51226/92620 but in my opinion a 3MB file containning both data and commands is too much i think there is some other ways to manage a project in a simpler way by spliting it on several files using \input \include and so on. – SAM Jul 11 '16 at 13:16
• Yeah I know the externalization option, which puts any figure into one separate (compiled) file, thats exactly the case I have here. Compiling fails on one figure in the MWE. Therefore I want to use LuaLaTex in the system call fashion since it allows for larger files and works if I call the whole file with it. – Erisch889 Jul 11 '16 at 13:26

I also deleted the row sep=crcr options and all \\ line endings and also got a picture with lualatex:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
%\tikzset{external/system call={lualatex -shell-escape -halt-on-error
%    -interaction=batchmode -jobname "\image" "\texsource"}}

\begin{document}
\end{document}


lualatex on

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
\input{phase_portrait.tex}
\end{document}


runs fine and produces

If you want to externalize, you could produce a standalone latex file, compile that, and include the pdf in your document as an image.

• Hey JPi, yeah it works also for me with LuaLaTeX, but I want to compile my document with PdfLaTeX since when I use LuaLaTeX I have problems with externalize, see the other thread I opened: link Link. So the question would still be on how to run it in system call mode. – Erisch889 Jul 11 '16 at 13:53
• I don't know the answer to your question, but you can achieve what you want as follows: Compile this standalone graph in lualatex, which produces a pdf, then include it as a pdf image in the main document, which you compile with pdflatex. – JPi Jul 11 '16 at 14:00