# How does TikZ extract the pgf-keys in LaTeX

In any TikZ command, for example \draw, how does TikZ extract the keys, as they can be in any order.

For example, the following \draw statements, give the same output (in different locations in the 2D space though):

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikz \draw[->,red,thick,dashed] (0,0) |- (2,2);
\tikz \draw[->,thick,red,dashed] (3,0) |- (0,5);
\end{document}


The first \draw command has the keys, red, thick and dashed.

The second\draw command has the keys, thick, red and dashed.

How does TikZ/LaTeX know, red means color, thick is thickness of the line.

What is the logic behind this.

• thick is a known key, and tikz tries to map unknown keys like red to colors. – Ulrike Fischer Mar 25 at 9:14
• Please have a look at p. 962 of the pgfmanual where .search also is explained. (The colors do not work precisely that way but it explains a bit how it can happen that TikZ tries to find a reasonable interpretation of a key. The color behavior is determined by \tikzoption{color}{...} in tikz.code.tex.) – marmot Mar 25 at 15:02

## 2 Answers

The pgfkeys package allows 'styles' to be defined as shortcuts to normal keyvals. Thus thick is a shortcut for line width = 0.8pt and red is (approximately) a shortcut for draw = red. Ultimately, which are defined is down to the pgf implementers.

As mentioned in Problem between pgfkeys, tikz and personal macro, some of these shortcuts are not actually normal keys but are rather found on a specifically-coded path of the pgfkeys parser. In particular, many TikZ commands attempt to treat unknown keys as colours before 'giving up'.

• Maybe thickness = 0.8pt -> line width=0.8pt. – marmot Mar 25 at 14:55

It turns out the color, shape names and arrow names are not actual keys possible because there are too numerous of them. Here @percusse explains how it is handled in the code.

Problem between pgfkeys, tikz and personal macro