6

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!

Caramdir
  • 89,023
  • 26
  • 255
  • 291
Tim
  • 5,763

2 Answers2

3

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.

Edit

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 :)

Update

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

pmav99
  • 6,060
  • 1
    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. – Andrew Stacey May 12 '11 at 18:30
2

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.

vanden
  • 30,891
  • 23
  • 67
  • 87