# Is there a listings configuration for TikZ as used in PGF/TikZ manual?

I want to create a tutorial how to use TikZ now. Is there a listings configuration for TikZ as used in PGF/TikZ manual?

For example, I want to make \ as an integral part of tikz in \tikz, relevant macros must have consistent colors, no annoying line numbers, PDF copy-paste friendly, etc.

-
Christian Feuersänger once mentioned that the code to produce the listings might become available, but I'm not sure if this is the case. He's best to answer that... –  Werner Sep 18 '12 at 5:56
Isn't it available in the CVS version build? I remember Alain Matthes had a problem compiling it with LuaLaTeX. –  percusse Sep 18 '12 at 7:59
The sources of the manual are available. But I don't think that it uses listings to format the code. To me it looks like more or less normal verbatim. –  Ulrike Fischer Sep 18 '12 at 8:23
–  percusse Sep 18 '12 at 8:25
Look for the pgfmanual-en-macros.tex file in your distribution. It contains the definition of the codexample environment... –  Paul Gaborit Sep 18 '12 at 8:28

Werner is right, I once mentioned that the code to produce listings might become available. And I still believe it would be nice if it would.

However, the TikZ manual styles are still (a) quite useful and (b) almost undocumented and (c) untidy without much progress since that comment.

I have assembled a minimum working example which demonstrates a couple of key features such that you may be able to start such a document. I believe it is a good starting point, and it allows to skip a few unavoidable usability issues.

Perhaps someone of the power-users on this site might want to create a "right" package out of the complete styles - including documentation for the documentation.

In order to get this piece of code up and running, you NEED TO COPY pgfmanual-macros.tex from doc/generic/pgf/macros/pgfmanual-en-macros.tex into your local directory.

Then, use

pdflatex file.tex
makeindex file
pdflatex file.tex


to compile it.

% to allow compression of cross references.
% both pgfmanual and pgfplots manual would be MUCH larger without it.
\pdfminorversion=5
\pdfobjcompresslevel=2
\documentclass{ltxdoc} % the pgf manual styles are based on ltxdoc

\usepackage{tikz}

% necessary for the manual styles:
\usepackage{calc}

% if you need an index.
\usepackage{makeidx}

% for cross-references:
\usepackage[pdfborder=0 0 0]{hyperref}
\hypersetup{%
colorlinks=true,    % use true to enable colors below:
filecolor=blue,%magenta,
pagecolor=blue,%red,
urlcolor=blue,%cyan,
citecolor=blue,
pdfborder=0 0 0,    % PDF link-darstellung, falls colorlinks=false. 0 0 0: nix. 0 0 1: default.
%plainpages=false,  % Das ist notwendig, wenn die Seitenzahlen z.T. in Arabischen und z.T. in römischen Ziffern gemacht werden.
%pdfsubject=,
}

% just in case you need it:
\newcommand\Tikz{Ti\textit kZ}

% this is due to some stupidity in pgfmanual-en-macros.tex:
% if this macro is not defined, the automatic cross-referencing is
% disabled:
\def\pgfautoxrefs{1}

% this here contains definitions (and the ONLY documentation for these
% definitions) like
% \begin{command}{\macro}
% \end{command}
%
% \begin{key}{/some/key=\marg{value}}
% \end{key}
\input pgfmanual-en-macros.tex

\makeatletter
% the index of PGF contains
% ----
% This index only contains automatically generated entries. A good index should
% also contain carefully selected keywords. This index is not a good index.
% ---
% use this line to reset that entry:
}
\makeatother

% this here allows automatic cross referencing:
\RequirePackage{pgfmanual}

% this here configures automatic cross referencing.
% It works for ANY package that uses pgfkeys and is independent on tikz/pgf.
\pgfkeys{
% whenever an unqualified key is found, the following key prefix
% list is tried to find a match.
%
% the link prefix written to the pdf file:
%
}

% belongs to \usepackage{makeindex}
\makeindex

\begin{document}

\begin{command}{{\tikz}\marg{macro}}
This is some command definition.
\end{command}

\begin{key}{/tikz/key=\marg{value} (initially somevalue)}
This is some key definition.
\end{key}

\begin{key}{/tikz/red}
Sets the color to red.
\end{key}

\begin{key}{/something/strange=\mchoice{choice1,choice2} (initially choice1)}
A special key.
\end{key}

We want to reference |key|.

\begin{codeexample}[]
\begin{tikzpicture}
\draw[red,->] (0,0) -- (1,1);
\end{tikzpicture}
\end{codeexample}

Note that |/something/strange| does not belong to \Tikz. Note that |\tikz| is a macro of \Tikz.

% belongs to \usepackage{makeindex}
\printindex

\end{document}


PS the manual is a customized verbatim environment. It is unrelated to listings. In fact, the auto-cross referencing is unique to the PGF verbatim environment.

-
+1 Thank you for these details. –  Paul Gaborit Sep 18 '12 at 22:09