I have been creating vector graphics with the matlab2tikz tool and got the error message ! TeX capacity exceeded, sorry [main memory size=5000000]. As I found out on the matlab2tikz github page page I might be able to resolve the issue by running the lualatex command to remove the strict memory limitation. It is suggested to type into the system prompt:

lualatex main.tex

I am using a mac and therefore type this into the Terminal.

I get the following response:

enter image description here

MY QUESTION IS: What do I need to do to successfully run the command?

  • 2
    Is main.tex in your home directory? You need to navigate into the folder containing main.tex with cd. You can check if your are in the correct directory by typing ls in the command line. If main.tex is listed in the output of ls you are in the right place.
    – moewe
    May 31, 2020 at 9:08
  • Just to be clear, the main.tex should be my preamble LaTeX file, correct? If I go the the folder which contains the preamble document using cd ~/Documents/Studium/Masterstudium\ Medizintechnik/Masterarbeit/Ausarbeitung and try to use ls I get ls: .: Operation not permitted. :( Trying to use lualatex Ausarbeitung.tex, where Ausarbeitung.tex is my main.tex filename I get ! I can't find file Ausarbeitung.tex.
    – Timon
    May 31, 2020 at 11:10
  • 1
    No main.tex needs to be your main document file. Usually that is the file starting with \documentclass, but depending on your setup (if you have an externalised preamble that also externalises the document class) it may start differently. If main.tex contains only your preamble code, it is quite probably not the right file to compile. I don't know anything about Macs, but I always thought there were Unixoid and ls should work... (maybe this explains the ls thingy? apple.stackexchange.com/q/339862)
    – moewe
    May 31, 2020 at 11:14
  • 1
    Mhhh, normally you only get ? prompts when there is an error. In that case you should investigate why that error appears, fix it and re-run LuaLaTeX.
    – moewe
    Jun 1, 2020 at 12:15
  • 1
    Sorry, I don't know. I thought that LuaTeX does dynamic allocation, so I would not have expected the error. Maybe you want to think about externalising your figures. See tex.stackexchange.com/q/7953/35864
    – moewe
    Jun 2, 2020 at 9:54

1 Answer 1


LuaTeX did not work for me, even after I deleted all of my Errors, which showed up in my log-file.

However the cleanfigure command suggested under "2." on the GitHub Page did the job for me. This is a snippet of the Matlab code I use now:

matlab2tikz('/Users/timonschulz/Documents/Studium/Masterstudium Medizintechnik/Masterarbeit/Ausarbeitung/Figures/Ergebnisse/MS1_P3_standardisiert_mg_pro_mW.tikz')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .