6

Yet another Tex Capacity exceeded error.

I am generating a matlab scatter plot which without modification resulted in a 64.5 MB printed eps file. Using that plot directly in matlab2tikz resulted in a large tikz file (34.5 MB) which gives me the Tex capacity error.

I already researched and found a number of possible solutions:

  1. Externalize tikz figures.

    • Described in externalize-tikz This ensures that every tikz figure has it's own tex job. I applied this one but it still gives me the capacity error
    • Lualatex in stead of pdflatex which does not have a tex capacity error due to dynamical memmory allocation.
    • Increase texs main memory as in Increasing TeX's main memory

The last two solutions are in my opinion not the best since it result in large pdfs. The graph that want to plot should not require that amount of memmory. Also luatex does not work with my university provided tex style.

  1. Decrease tikz size in matlab

    • dsplot dsplot did not work with standard color, linewidth and other graphical controls.
    • reduce_plot reduce_plot wrapper around LinePlotReducer -> Manages the information in a standard MATLAB plot so that only the necessary number of data points are shown. For instance, if the width of the axis in the plot is only 500 pixels, there's no reason to have more than 1000 data points along the width. This tool selects which data points to show so that, for each pixel, all of the data mapping to that pixel is crushed down to just two points, a minimum and a maximum. Since all of the data is between the minimum and maximum, the user will not see any difference in the reduced plot compared to the full plot.

    • cleanfigure('minimumPointsDistance', X) cleanfigure removes the unnecessary objects from your MATLAB plot

Of the last three methods, I used clean_figure and by playing with its value X I can drastically reduce the size of the exported tikz file. However even with a tikz file size of 500kB the tex capacity error shows up. If I use an extremely large minimumPointsDistance and reduce the figure to 30kB it gives no error but then my figure is quite different as well.

Also reduceplot worked well and it reduced the tikz file to 700 kB. But again the tex capacity error.

My question therefore is, how can I avoid this capacity error while still ensuring a decent quality figure. And shouldn't a 500kb or 700kb tikz file be externally compilable or are these sizes still large?

Also I wonder what the memory size=5000000 exactly means. Is that 5M bytes? does that mean that I should be able to compile a 5M bytes = 4.76 Mb tikz file?

  • Hello. I just have a question. Do you really need to generate the plot in mat lab? It seems like a lot of intermediate step to have a plot. I'd never seen that Tikz error. I rarely use Tikz. I normally generate my data with MATLAB, and I know it looks good, I put it in a data file, plot it with gnuplot, using epslatex terminal. That gives me a .TeX file with all the text (labels, legend, etc), and an EPS file with the actual graph. If I'm using pdflatex, I convert this EPS in PDF with eps2pdf (easily available in Linux). – phollox Jan 15 '15 at 15:11
  • Continued from my previous comment. I have no idea about the complexity or nature of your data. Probably in your case my method will fail. I'm just giving it as an alternative that mostly use native formats and so far, at least for me, has always generated high quality output – phollox Jan 15 '15 at 15:20
  • Actually you have more steps than my approach. Altough mine is not yet working :) The number of steps were all possible solutions that I tried. For clarity: my final approach is to make the plot with reduce_plot, convert to tikz with matlab2tikz and the resulting file can directly be loaded in latex. Thus once this works A single mfile will genarate neat tikz figures. – MaxBaeten Jan 15 '15 at 15:48
  • Fair enough. Hope you find answers. I never used tikz to plot numerical data. Good luck! – phollox Jan 15 '15 at 17:07
  • 1
    I think you'd be better served just including the .eps file in your TeX document, after using reduce_plot or clean_figure. You can then draw axes and labels on top of the included graphics file. – Kundor Jan 15 '15 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.