# how to test if tikz library is loaded

I want to write some demo code showing code with examples for tikz. However I want the resulting pdf to be automatically depended on the tikz libraries and therefore I must test which are loaded.

Is this functionality implemented in tikz already or can I test for the existence of special commands?

EDIT:

Example which shows that the code does not work outside the preamble. I however need code that works everywhere:

\documentclass[]{scrbook}

\usepackage{pgf}
\usepackage{tikz}

\usetikzlibrary{circuits}

\makeatletter
\newcommand*\@tikzextension{code.tex}
}
\makeatother

\listfiles

\begin{document}
\end{document}
-

When tikz loads the library foo, it defines the macro \tikz@library@foo@loaded. Therefore the following code will do the job:

\makeatletter
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\makeatother
-
Works, thank you. – Matthias Pospiech Mar 18 '12 at 13:39

you can create a new command based on the definition of the command \@ifpackageloaded:

In the example below I provided the new conditional \iftikzlibraryloaded with the syntax:

{True Code}%
{False Code}

Here the complete example:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc}

\makeatletter
\newcommand*\@tikzextension{code.tex}
}
\makeatother