12

I'm new to LaTeX and this may have been answered somewhere already. But I don't understand why I have to use the command \usetikzlibrary{...}. Why doesn't \usepackage{tikz} give me all the libraries? Are there other packages beside tikz that do a similar thing?

My guess at why it does this is because tikz might be a big library so it doesn't want to load all of it at once? Basically what is the difference between the two?

  • your guess is correct - it's a matter of efficiency – cmhughes May 6 '14 at 17:29
  • Regarding "Are there other packages": yes, pgfplots also comes with a couple of optional libraries which are loaded with \usetikzlibrary or its shorthand \usepgfplotslibrary. Naturally, pgfplots itsself can be seen as a huge library on top of tikz. – Christian Feuersänger May 6 '14 at 20:59
9

When you load TikZ it loads many many macros but this is not slowing down anything per se at this time of history. It is actually not that important to load all the macros. But at the same time every library implements many TeX ifs, dimens and lengths etc. that might run out if other packages are using lots of registers. This is usually solved (or hoped to be solved) by also loading the etex package which boosts the number of registers.

Also some of the libraries change the behavior of options such as positioning switches the below of= to below= of, backgrounds switches layering which might interfere with some patterns etc.

So as a very good design decision, you turn on the rockets whenever you need them.

A nice answer by Heiko is good to keep in mind Is it possible to load a TikZ library locally?

  • It will be good if TikZ adopts "lazy loading" approach behind the scene where it loads packages that are really needed in the code and does not load the unused packages. But it needs to scan the code once before actually does the main job. – kiss my armpit May 6 '14 at 18:53
  • 1
    @IamwhoIsayIam or you just load it :) It's one liner. – percusse May 6 '14 at 18:54
  • "Lazy loading" also only works if there are no name conflicts between libraries. In that case, how would TikZ know which one you want? There are enough libraries out there that such conflicts must exist. Basically, TikZ doesn't immediately load all of its libraries for all of the same reasons that TeX doesn't immediately load all of its packages. – Emma Oct 18 '16 at 14:37
  • @Emma There are none. That's by design and also the reason of ridiculously long PGF macro names. Otherwise you can't use two libraries together. – percusse Oct 18 '16 at 14:58
  • I tried using "\usetikzlibrary" but it gives "undefined control sequence" – Reda Drissi Apr 23 at 10:06

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.