TransWikia.com

Package to obtain the style of the TikZ/PGF-Documentation

TeX - LaTeX Asked on December 8, 2021

The gold standard of LaTeX-documentation is – at least for me – the TikZ/PGF-documentation. It is formatted consistently, has great code highlighting and (one of the best features in my opinion) you can click on any command in code-snippets and get to the corresponding chapter with it’s explanation.

How can I obtain the same look and functionality?

I had a look at the source of the doc, but it was quite overwhelming. Most of the macros seem to be defined in pgfmanual-en-macros.tex, is this correct? Or is it also based on a special package?

The package tcolorbox has the additional library documentation, which supports the typesetting and indexing of the explanations for commands, environments, keys … and the simultaneous printing of the source code and the compiled result. But it does not seem to provide the functionality of "clickable" code snippets.

One Answer

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}{textbfmarg{text}}
  Prints its argument in bold.
end{command}

% These empty brackets are NOT optional
%                  |
%                  v
begin{codeexample}[]
textbf{This is a test}
end{codeexample}

end{document}

enter image description here

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

Answered by Henri Menke on December 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP