I love LaTeX and TikZ for creating high-quality documents. The problem is that large projects require a pretty long compilation time and that complicated TikZ figures/plots quickly exceed the memory cap. I can evade his problem if I include different sections into my main.tex and consequently uncomment them if I am not working on them. An alternative approach is an externalization of my TikZ figures/plots, but that is also not optimal, because often I will have to uncomment plots in sequential order and then compile each plot in sequential order. But compiling the whole project will be quite problematic.

Question: That is why I want to know the best practice for managing large projects with a massive amount of TikZ figures/plots.

  • For this sole reason, I switched to LuaLatex which doesn't suffer from this afore-mentioned memory issues. Then I started using TikZexternalise feature to cache my figures as a pdf and re-include it whenever there are no changes made in them. – Raaja Mar 13 '19 at 11:58
  • Hi @MachineLearner, IMHO externalization is the way to go. I am not sure I fully understood the issue you had with that can you maybe elaborate on why this is not suited for you? – sheß Mar 13 '19 at 12:02
  • An alternative to externalize is to use standalone and only recompile when the images change. Basically, this is what externalize does (or attempts to do) automatically. – John Kormylo Mar 13 '19 at 16:32

If I understand you correctly, the reason why tikzexternalize is not working for you is because it gets confused and recompiles pictures when you change the order of figures by commenting out parts. The problem here seems to be that that tikzexternalize uses the relative position of a figure in the document to reference it.

One way to make tikzexternalize recognize pictures even if they change their position is to name them (then tikzexternalize will stop using the order to reference figures). Assuming you load your TikZ pictures from external files, you could do something like this:


and then use \inputtikz{name of file} wherever you want to put your figure. This will be stable when you move your figures around or comment out sections.

Of yource you can also manually name each figure with \tikzsetnextfilename{name} or define some other command/environment that does that, which is more suitable for your workflow.

  • However, could you also include your comments on the memory issue as well? – Raaja Mar 13 '19 at 12:33
  • 1
    Sorry that was poorly written. What I am trying to tell you is, please consider adding some remarks on the case when the memory is too low for compiling a tikz image. – Raaja Mar 13 '19 at 12:50
  • Concerning memory, I can't really say much without knowing a bit more about what @MachineLearner actually does (is a single picture the problem, the mass of picutures, or is it something else?). Yet, provided (s)he follows my suggestion above, (s)he'd never have to compile the whole document with all TikZ pictures at once. If some or all pictures are already pre-compiled and externalized from previous, partial runs memory should be less of an issue. – sheß Mar 13 '19 at 13:00
  • 1
    I agree with you here. Given the way the question is formulated, I think it is sufficient as you have given in your answer. – Raaja Mar 13 '19 at 13:04
  • 1
    I will check this out as soon as I feel comfortable with this solution I will accept your answer. At the moment I am struggling with Texmaker with compiling my references. As soon as this is resolved I can check out your method. – MachineLearner Mar 14 '19 at 13:15

What I would do in such a case is to redefine the environment of tikzpicture to be just a comment while working with the text or other part of my document and comment out this redefinition when the document is final or whenever I want to see it with all the figures inside.

I would also keep the old definition of it, in order to be able to work with individual tikzpictures in a environment called currenttikzpicture (this long name just for demonstration).



\foreach \i in {1,2,...,4}{\draw[-,thick,red]  (\i,0)to[in={\i*10}, out={170-\i*10}]({2*\i},{4*\i+1}) to[in={170-\i*10},out={270-\i*10}] ({2*\i-3},{\i/10})--(\i,0);}

\foreach \i in {1,2,...,4}{\draw[-,thick,red]  (\i,0)to[in={\i*10}, out={170-\i*10}]({2*\i},{4*\i+1}) to[in={170-\i*10},out={270-\i*10}] ({2*\i-3},{\i/10})--(\i,0);}

\foreach \i in {1,2,...,4}{\draw[-,thick,red]  (\i,0)to[in={\i*10}, out={170-\i*10}]({2*\i},{4*\i+1}) to[in={170-\i*10},out={270-\i*10}] ({2*\i-3},{\i/10})--(\i,0);}

\foreach \i in {1,2,...,4}{\draw[-,thick,green]  (\i,0)to[in={\i*10}, out={170-\i*10}]({2*\i},{4*\i+1}) to[in={170-\i*10},out={270-\i*10}] ({2*\i-3},{\i/10})--(\i,0);}


PS: I know that the output would not keep the figures in the place that they should be, but I don't really care while trying to work faster.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.