1

I love the way tikz's (and tizk-cd's) documentation is formatted with clickable links to go to the definition of a style/command, colors, examples with image and code next to each others etc… As mentionned here Package to obtain the style of the TikZ/PGF-Documentation pgfmanual seems to provide such functionalities but has not been documented.

Would it be possible to have quick introduction to how to use pgfmanual, together with pointers to explore more advanced options?

3
  • See 1.5 Authors and Acknowledgements in the packages documentation. Manual use (as well all other similar LaTeX documents with hyper text facility) hyperref package for this.
    – Zarko
    Oct 10, 2021 at 7:41
  • @Zarko : thanks, but I don't see how this acknowledgement is helping, it is just a list of people. And I huess hyperref is used internally, but I guess other mechanisms are involved to automatically add links to code… It would be way too tedious to do it manually.
    – tobiasBora
    Oct 10, 2021 at 10:31
  • 1
    In Acknowledgement is clearly stated who add hypertext to manual. Yes, this is demanding manual task. you need to insert ˙hyperref anchoes. In this can be of help editor. Ho to do this, see documentation for hyperref package.
    – Zarko
    Oct 10, 2021 at 10:41

1 Answer 1

3

Here is a minimal example for how to use the PGF manual style. Note the following requirements

  1. You must use the ltxdoc documentclass.
  2. The packages calc, tikz and hyperref are required.
  3. The “optional” argument of codeexample is not really optional. Even if it is empty, there have to be empty brackets [].

I recommend using the hidelinks option for hyperref to hide the red boxes around links in the PDF. In general the hyperref package should be loaded as late as possible (see also Which packages should be loaded after hyperref instead of before?).

Since PGF 3.1.6 the file pgfmanual-en-macros.tex is installed into the TeX search path. Before that version you have to go to the PGF documentation directory and copy the file into your working directory.

\documentclass{ltxdoc}
\usepackage{calc}
\usepackage{tikz}
\input{pgfmanual-en-macros.tex}
\usepackage[hidelinks]{hyperref}
\begin{document}

\begin{command}{\textbf\marg{text}}
  Prints its argument in bold.
  % These empty brackets are NOT optional
  %                |
  %                v
\begin{codeexample}[]
\textbf{This is a test}
\end{codeexample}
  %
\end{command}

\begin{environment}{{center}}
  Center text horizontally on the page.
  %
\begin{codeexample}[vbox]
  \begin{center}
    \textbf{This is a test}
  \end{center}
\end{codeexample}
  %
\end{environment}

\end{document}

enter image description here

If for some reason you want to document starred commands separately with the command environment, see this workaround.

8
  • Thanks a lot! I tried to compile this example but it gives ERROR: Package pgfkeys Error: I do not know the key '/codeexample/prettyprint/comment font', to which you passed '\itshape ', and I am going to ignore it. Perhaps you misspelled it.. Any idea what's wrong? Also, I'm curious, what's the link between pgfmanual-en-macros.tex and pgfmanual?
    – tobiasBora
    Oct 10, 2021 at 18:27
  • So I managed to make this code work by copying this folder github.com/pgf-tikz/pgf/tree/… onto the working directory. I'm not sure why because I'm on a quite recent TeX distribution (TexLive 2021, Tikz/pgf version 3.1.8b). Thanks a lot!
    – tobiasBora
    Oct 11, 2021 at 4:35
  • Also, for example on how to add environments with optional arguments, see github.com/astoff/tikz-cd/blob/…
    – tobiasBora
    Oct 11, 2021 at 4:43
  • Also a question: how can I use environments like \begin{center} \end{center} or itemize inside a codeexample? They all fail.
    – tobiasBora
    Oct 11, 2021 at 5:02
  • 1
    @tobiasBora To typeset examples that need a paragraph, use the vbox option (see updated answer). To break all codeexamples use \pgfkeys{/codeexample/every codeexample/.append style={width=0pt}}. As you can see the options get more and more obscure. That's because there is absolutely no support! Oct 11, 2021 at 17:01

You must log in to answer this question.

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