1

Short version: The tikz externalize library takes something like 2-3 seconds to compile a single very simple diagram. As a result, when there are many diagrams, the first run of pdflatex is really long. For instance, my documentation (52 pages) was taking 41 seconds to compile without externalization, now it takes 13 minutes (x20). Hopefully the second run is much smaller (3 seconds)... but because of this bug if I just add a single diagram at the beginning of the document, I need to recompile everything because the file name change... and therefore I'm back to a 13mn compilation.

Is it normal? If yes, is it possible to decrease this time somehow? For instance, I've the feeling that what takes most of the time is the action of starting LaTeX. It would be cool if it were possible to pre-load LaTeX only once and compile multiple times with the same pre-loaded LaTeX.

EDIT

I'm reading the documentation, and I see that tikz externalize actually uses the current document as the base. So it means that if I load many libraries, then the current document will likely take much more than 3 seconds to load... and therefore tikz externalize will be even slower. Maybe my question would be solved if we can find a way to provide a "template" to the externalize program.

EDIT

I guess that \tikzsetfigurename can be used to limit the effect of the bug by giving different names to parts of the file... But I still need to pay the high price to compile the first pictures. I'm particularly worried when the main document loads a lot of library.

tobiasBora
  • 8,684
  • 1
    you can just generate the tikz pdfs as separate documents with a minimal preamble and the standalone class to get a tightly cropped pdf then use \includegraphics, then they have stable filenames and you choose when to rebuild them you can also use a format with tikz preloaded to speed things up (search this site for mylatex or mylatexformat) – David Carlisle Feb 08 '22 at 19:40
  • @DavidCarlisle The thing is that the library generates many small tikz figure, sometimes in the middle of equations, so manually moving them in different standalone file would be way too long and hard to maintain. However, it would be super cool if this template could be automatically generated and compiled on file change. Maybe the external library already provides a way to choose a template different from the current file? – tobiasBora Feb 08 '22 at 20:41
  • @DavidCarlisle You say this sarcastically but in fact for many tasks like positioning an \includegraphics picture mode is preferable. Also in LuaTeX there is native Metapost which is really fast. – Henri Menke Feb 08 '22 at 21:56
  • @HenriMenke yes agreed which is why we basically folded picture mode \put into the page hook mechanism so you can position background images etc without much overhead. – David Carlisle Feb 08 '22 at 21:58
  • 2
    With tikzsetfigurename I really don't see a problem. Following workflow suggestion: Add a tikzpicture with externelization turned off for that specific picture, edit until you are satisfied, enable externelization for that picture, set a unique file name and move on to the next picture. That way, gradually building up the document is not too slow because most pictures are cache hits. A clean run takes time but when do you really need that. And as mentioned in the other comments, the no-overhead way is to use standalone graphics with minimal preamble that are compiled independently. – TeXnician Feb 08 '22 at 22:02
  • 2
    The purpose of externalizing is to speed later compilations. You concentrate the overhead on the first run after a picture has been introduced or modified. – egreg Feb 08 '22 at 22:27
  • @TeXnician Thanks, I guess I'll use this workflow. But this is not perfect since if a single of my co-author forgets to add a tikzsetfigurename, it can easily triger a full recompilation. Also, a full recompilation may happen if my users use overleaf and if overleaf decides to clean the internal cache. – tobiasBora Feb 09 '22 at 13:59
  • @egreg Sure, but if the overhead on the first run is multiplied by 20 or 200 times, it may not be very appealing. Like in my thesis, each diagram takes already 30 seconds to build. I have around 500 diagrams... so the first compilation should take 4h (and I just got an error Runaway definition?->\oddpage@label {…). On overleaf, it would have timeout, and even locally, if I just forget once to rename figures I go for another 4h compilation. If I ask to co-authors to compile the document, they also wait 4h. But using an external simple template, we should be able to decrease the time drastically – tobiasBora Feb 09 '22 at 15:26
  • Also, any idea why sometimes I get this oddpage@label error? It's strange, some .dpth files have this: $ cat file-figure9.dpth \oddpage@label{45}{24} – tobiasBora Feb 09 '22 at 15:30
  • 1
    The external library allows the option list and make which allows parallel processing. You might want to read up on that as well. – TeXnician Feb 09 '22 at 16:46
  • Oh, thanks for this option @TeXnician I will give it a try! (it seems crazy that will all these options it's not possible to define a simple template for tikz external) – tobiasBora Feb 09 '22 at 17:22

0 Answers0