7

Is there a difference between using the package tikz-cd and using the cd tikz library and loading tikz directly?

I can't find the answer in the documentation of either package.

2
  • 3
    It's one of the first things written in the tikz-cd manual actually. Chapter 1 starts with "To invoke this package in Latex, type \usepackage{tikz-cd} or load TikZ and then type \usetikzlibrary{cd}". In other words, they're equivalent. May 26, 2020 at 22:11
  • 3
    @TorbjørnT. That doesn't necessarily mean they do the exact same thing though. May 26, 2020 at 22:18

3 Answers 3

12

No (practical) difference. The code (excluding copyright comment lines) in tikz-cd.sty is:

\ProvidesPackage{tikz-cd}[2014/10/30 v0.9e Commutative diagrams with tikz]
\RequirePackage{tikz}[2013/12/13] % pgf version 3.0.0 required
\usetikzlibrary{cd}

\endinput

so it just loads TikZ and then does \usetikzlibrary{cd}.

1
  • 1
    Great, thanks for the help! May 26, 2020 at 22:11
4

This is just a pedantic comment: there can be differences.

This is an admittedly nasty example.

This code works1:

\documentclass{article}
\usepackage{tikz-cd}
\pgfmathdeclarefunction*{axis_height}{0}{\edef\pgfmathresult{1}}
\begin{document}
Hello
\end{document}

This code does not work:

\documentclass{article}
\usepackage{tikz}
\pgfmathdeclarefunction*{axis_height}{0}{\edef\pgfmathresult{1}}
\usetikzlibrary{cd}
\begin{document}
Hello
\end{document}

However, this works1 again:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{cd}
\pgfmathdeclarefunction*{axis_height}{0}{\edef\pgfmathresult{1}}
\begin{document}
Hello
\end{document}

It is absolutely true that this is not a very useful code, and I have just designed the second code to crash. It does, however, show that there is a technical difference between loading tikz and then the cd library among other libraries (which could in principle do something along the lines of \pgfmathdeclarefunction*{axis_height}{0}{\edef\pgfmathresult{1}}), or later, and loading tikz-cd, which forces a certain ordering of loading of the libraries.

Of course, the cd library is, even though it is not part of pgf, a standard library and the authors of other libraries will most likely look at the cd code to make sure that they do not do harm to it, though it is not inconceivable that someone else may want to define function with the name axis_height. Nevertheless, if one is very strict, one has to say that it can, at least in principle, make a difference whether one load the tikz-cd package or the cd library. As I said, this is just an extended comment, but it does show that one cannot be absolutely sure that there is no difference.

1 "Works" means you do not get an error when you compile the snippet. You should definitely not overwrite the function axis_height if you actually want to use the cd library.

4

Additionally, in ConTeXt the tikz-cd module is not available, you need to do:

\usemodule[tikz]
\usetikzlibrary[cd]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .