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}
\def\IfTikzLibraryLoaded#1{%
\@ifl@aded\@tikzextension{tikzlibrary#1}
}
\makeatother
\listfiles
\begin{document}
\IfTikzLibraryLoaded{circuits}{is loaded}{not loaded}
\end{document}
\def\CheckTikzLibraryLoaded#1{ \ifcsname tikz@library@#1@loaded\endcsname \else \PackageWarning{tikz}{You forgot to add usetikzlibrary{#1} in the preamble!} \fi } \CheckTikzLibraryLoaded{circuits}– ferdymercury Oct 20 '21 at 12:36