# Tag Info

32

You can assign a default value for a key by using the .default handler. By setting qar/.style={ draw, rectangle, fill=#1 }, qar/.default=red the value red will be used whenever qar is called without an argument. The same thing works for keys that take two or more arguments: qar2/.style 2 args={ rectangle, draw=#1, thick, fill=#2 },...

32

My humble opinion is that the manual is misleadingly written here. It freely mixes two different classes of pgfkeys operators: The key-value interface, which is accessed solely through the syntax \pgfkeys{<key> = <value>}, but which has extensible capabilities through the use (and creation!) of handlers, namely, special key suffixes that ...

26

Jake is correct in his now deleted answer. The options you pass to arrow inside are not applied as they are simply grabbed and not used (i.e. “gobbled”) similar to #1 in: \newcommand*{\myCommand}[1]{Foobar Rhubarb}% no "#1" in its definition You need to add #1 in your .style definition. But instead of using the .store in handler, consider using .initial ...

24

As already pointed out by Jake, the = is detected by TikZ that parses the options based on , and =. This works: \node[label=below:{$\mathcal{L}^*(B)=\mathcal{L}(D)$}] As well as that: \node[label={below:$\mathcal{L}^*(B)=\mathcal{L}(D)$}] If you want to include a : in the label but do not specify a direction (here: below), then you will need to protect ...

23

The answer why PGF 3.1 does not support Knuth TeX is two-fold. It is the current year. By now e-TeX is over 20 years old and has simplified TeX development tremendously. I consider it a bug on your side that you are not using e-TeX. Unfortunately TeX Live ships a tex binary which does not enable e-TeX extensions. You have to use etex instead. ...

19

I suggest a different approach, not optimal (see What do the pgfkeys key handlers .get and .store in do?), but it works. Indeed, one problem in your code is that, inside arrow style the keys do not inherit the correct path /tikz/arrow inside/key-name. To make it working you can do something like: \[ \int_{ \tikz[scale=0.3]{ \path[fill=lightgray] ...

18

A possible solution: \documentclass[border=5mm]{standalone} \usepackage{tikz} \pgfkeys{/tikz/.cd,% to set the path circle height/.initial=0, % initial value circle height/.get=\circleheight, % to get the value from a macro circle height/.store in=\circleheight, % to store the value into a macro diameter/.initial=1, diameter/.get=\diameter, ...

17

When TikZ places a label (or a pin) it calculates a point that is label distance (or pin distance) away from a point on the anchor-border of its parent node. This point on the anchor-border is directly dependent on the angle/direction before the : (or the default label position/pin position). In the same direction the * distance is added. This is the new ...

16

Three answers in and much more confusion (at least on my side). The handlers .get and .store in are very different and nothing alike. The <key>/.store in=\<macro> handler sets up a key <key> so that if it is used with <key>=<value> it stores <value> in \<macro>. This is the same as if you would have written <key&...

15

Regular text formatting doesn't apply to math mode and \pgfmathprintnumber inherently uses \ensuremath behind the scenes around the number. You can turn it off via \pgfmathprintnumber[assume math mode=true]{123.567} Then it will assume that it is already in the math mode and won't modify the number printing. That means the number will be interpreted as ...

14

My personal preference is to avoid using .store in keys at all, with the following exception: A .store in key is required when using pgfkeys as an interface to an existing system that doesn't use it. For example, suppose that you wanted, in the course of your key-processing, to alter the material that would be printed by \ref if it pointed to a \label ...

14

I suspected that your question How do I use the ampersand (&) inside a foreach or conditional (or other group/environment) when building tables? was of the XY type. The usual problem in these cases is that you cannot build a table inside a \foreach statement, because table cells form groups. The strategy is to build the table body beforehand. \...

13

You can define your own style that sets the shorten for both ends at the same time: \tikzset{ shorten <>/.style={ shorten >=#1, shorten <=#1 } }

13

The .is choice handler basically does two things. In your case, it setups the size key as if you would do: size/.style={/ae/example/size/#1} However, before that style (size/#1) is executed, the argument #1 is saved in \pgfkeys@was@choice. This macro \pgfkeys@was@choice is then used in the definition of the size/.unknown code to give a proper error ...

13

The first code is an example of how to use keys, but not how to define them: that's why pgfkeys complains that it does not know the key. If you want to use keys to store values, use \pgfkeys{/my key/.initial=hallo} to initialise the key. You can then access the value of the key using \pgfkeysvalueof{/my key}. To assign the key a different value later on, ...

13

Brilliant documentation isn't it:-) In general setting keys is more or less just making macro definitions, so the ones you can't set in advance are the ones that are initialised by \includegraphics before it processes the keys. Looking at the code (strangely more revealing than the documentation) the only relevant initialisation is \@tempswafalse and ...

13

Yes it is the /.list handler. The argument to it is passed to a \foreach array and at each spin next item is passed to the original handler. \documentclass{article} \usepackage{pgfkeys,pgffor} \pgfkeys{ mykeysetter/.style={ #1/.code={#1:##1}, #1/.default=1 }, mykeysetter/.list={a,b,c} } \begin{document} \pgfkeys{a=4,b=3,c} \end{document} This gives ...

12

Edit: Via the .forward to handler (only available with the CVS version of PGF) , you can attach a boolean to your Hollow style when you want to test if it is specified: \documentclass{article} \usepackage{tikz} \usepackage{etoolbox} \newbool{Hollow} \tikzset{ Hollow is used/.code=\booltrue{Hollow}, Test Hollow/.code={\tikzset{Hollow/.forward to=/tikz/...

12

Value keys (created by the /.initial handler) save the value in a macro named \pgfk@<full path to key>. Most used examples probably include the keys minimum width, minimum height as well as the inner and outer separations that are read very often while PGF constructs a node. Besides directly using \csname pgfk@<full path to key> they can be ...

12

How does a .style handler work? It is basically a .code handler (as everything is in the end anyway), the code that is saved is \pgfkeysalso{#1}. The style A expands to \pgfkeysalso{draw} and B to \pgfkeysalso{fill=yelow}. The manual says for \pgfkeysalso: This command has execatly the same effect as \pgfkeys, only the default path is not modified ...

12

Here is an example how you can do this : \documentclass[varwidth,border=10]{standalone} \usepackage{tikz} \begin{document} \tikzset{ mykey/.code args={#1,#2,#3}{ % perform complicated calculation involving #1, #2 and #3 here % for example \pgfmathparse{(#2-#1)*#3} \pgfkeysalso{/tikz/scale=\pgfmathresult} } } \begin{tikzpicture} \...

11

Both savedanchor and anchor are aliases for internal macros. \anchor globally defines an anchor when the shape is declared (so expansion occurs in the anchor name), but only expands the code for the anchor when the anchor is called in a coordinate, for example, (A.pin 1). \savedanchor doesn't expand either of its arguments when the shape is declared but does ...

11

From the TikZ/PGF manual (emphasis added): Some of the path commands described in the following sections take optional arguments. For these commands, when you use this key inside these options, the path will be inserted after the path command is done. The key here is the "some". The append after command needs a command to be appended after. Things ...

11

I'll rename your \alph macro to \alphstore because I am a coward and fear that redefining LaTeX's \alph command, even locally, might have undesirable side effects in some cases. Background and analysis pgfkeys implements namespaces1 using its filesystem-like key hierarchy. When you use a package based on pgfkeys (e.g., tikz, pgfplots, forest, tikz-cd, ...

10

As stated in my comment, the fundamental problem is that the statement \coordinate (A) at (1,1,0); only stores the 2d representation of the point in (A). Using pgfkeys we can define a new command \tdcoord that stores the three-dimensional representation too. Then we define your origin key to be a style that sets x, y and z from the stored information. ...

10

You have two to four choices (as \pgfmathresult is already fully expanded there is no different in all four). The key handler /.expanded is like an \edef (recommended if you use it inside \pgfkeys{…}): \pgfkeys{/junk/.expanded=\pgfmathresult} The key handlers /.expand once and /.expand twice do just enough \expandafters to expand the given value once or ...

10

As has been recently discussed in one of your previous questions, it is not that straightforward to go up in the family trees of pgfkeys hence we need to be extra careful when filtering different keys that belong to different key families. If you are writing a package for TikZ please always leave a hook for power users to tweak things directly be it a node,...

10

You can check the mechanism with the example below. get assigns the current value of the key to a macro and we are done. store in is instead keeps whatever argument is passed to the key itself. \documentclass{article} \usepackage{pgfkeys} \begin{document} \pgfkeys{a/.initial=1} \pgfkeys{a/.get=\aKey}% \aKey %1 \pgfkeys{a=7}% \aKey %2 \...

10

A possible solution with LaTeX3 key-value interface: tmpsty.sty \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{tmpsty}[2013/09/24 Standard Style File For Assessments At SHJC] \RequirePackage[letterpaper,tmargin=2cm,bmargin=2cm,lmargin=2.5cm,rmargin=2.5cm,showframe]{geometry} \RequirePackage{amsmath,amssymb,amsfonts} \RequirePackage{booktabs,array} \...

9

Although this does not specifically add anything to the answer already provided, the following example helped me understand the difference more intuitively: \documentclass{article} \usepackage{pgfkeys} \setlength{\parindent}{0mm} \begin{document} %% Create the keys, default values, etc. \pgfkeys{% /mythingy/.is family, /mythingy, usecolor/.default = ...

Only top voted, non community-wiki answers of a minimum length are eligible