TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some TikZ code in my LaTeX document. Whenever I edit other parts in the LaTeX document, I recompile it. But repeating recompiling unmodified TikZ code can be time-consuming.

I was wondering if there is some way to avoid re-compilation of unmodified part of LaTeX document? If such methods exist, do they apply not just to unchanged TikZ code but also unchanged non-TikZ code?

Thanks and regards!

share|improve this question
Do answers to this question help? – Seamus May 12 '11 at 13:05
For the TikZ part, you can use the external library. This works nicely in TikZ/PGF 2.10 (not sure about earlier versions). For more, read the relevant section in the manual or browse the questions on this site starting with: tex.stackexchange.com/q/45/86 – Loop Space May 12 '11 at 13:06
I updated my answer, check it! – pmav99 May 16 '11 at 23:29

You could create your figures with Ktikz, save them as pdf (export to pdf) and then include them as figures.

Each time you make a change at your figures, you just overwrite the previous pdf. Also you get the "real time" preview that can be a huge boost in productivity.


The problem with this approach is that, in order to be consistent, if at some point you decide to change the font size or something similar, you have to change the preamble that Ktikz uses, and recompile all your figures. It is not huge work, but keep it in mind. Better do it only once, just before the final compilation of your document.

Ultimately the best solution would be to have a package that would check if the tikz source file has been modified since last compilation and if there were changes, recompile the source automatically (using the main's file preamble) and include the pdf as a figure.

This way compilation is going to be both fast (as only few files are going to be recompiled each time) and consistent (as the same preamble is going to be used everywhere).

Perhaps, a final/draft option would be useful too.

ps. If anyone knows of anything that allows such a workflow, I am more than intrested :)


I wrote a Python (ver. 2) script that automates the process.

It must be placed in the same folder as the TeX main file. It checks for files with tikz extension and checks their modification time.

The first time it runs, it stores the names of the tikz source files and their modification time in a pickled dictionary and, after reading the preamble of the main TeX file, compiles them. The produced pdfs are named after the tikz source code filenames and they are moved in the same (sub)folder as the tikz source file.

On subsequent runs, it checks for new tikz files and changes in the modification time of the old tikz files and recompiles as necessary.

It needs more testing, but as far as I can tell it works ok.

You may find it at BitBucket

share|improve this answer
TikZ already has something near to the capability that you ask for, at least in the 2.10 version. Look at the documentation for the external library. – Loop Space May 12 '11 at 18:30
@ Andrew Thank you! I'll check it – pmav99 May 12 '11 at 18:33

You could use \include and \includeonly to compile only the "active" parts of the document. See this answer for my best attempt to explain how this works. Do note that the use of \include will cause page breaks; if that's not what you want, you could work this way, replacing \includes with \inputs at a late stage of editing.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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