7

In the description of the /tikz/shape node option on p. 216 of the TikZ & PGF manual for version 3.0.1a states:

no default, initially rectangle

It goes on to explain that this option selects

the shape either of the current node or, when this option is not given inside a node but somewhere outside, the shape of all nodes in the current scope.

What is the difference between an option that has a default value and one that has initially a certain value? If instead of initially being rectangle the /tikz/shape would be rectangle by default, what would change in its behavior and the way it can be used?

Can someone please explain and demonstrate the differences with a minimal example?


The present question is similar to this one. However that question deals with PGF (which I am unfamiliar with), whereas the current question deals with TikZ.

PGF and TikZ are two separate levels. Consider the following quote from the manual (p. 221):

Both PGF and TikZ support such multipart nodes. On the lower level, PGF provides a system for specifying that a shape consists of several parts. On the TikZ level, you specify the different node parts by using the following command:

\nodepart[<options>]{<part name>}

The point of this quote is to show that the same feature can have different manifestations in PGF vs. in TikZ and it is reasonable to ask how a certain feature manifests in one level and how it manifests in another level, and this would constitute two different questions, just as a question about TikZ's \nodepart command can coexist with a question about PGF's system for specifying that a shape consists of several parts without any of these questions being a duplicate of the other.

My question is: Is it possible to explain the difference and to give a minimal example using only TikZ concepts and syntax without resorting to low level PGF? Is the difference perceptible from a high-level user's perspective who only knows TikZ? (I am such a user.)

  • 1
    Both tikz and pgf use the same key management system, so I think that the question you marked (tex.stackexchange.com/questions/50856/…) is really a duplicate. – Rmano Jul 11 '17 at 7:46
  • 1
    This is a duplicate of the previous one as tikz is layered over pgf (they have the same manual) and uses pgfkeys. – David Carlisle Jul 11 '17 at 7:50
  • @Rmano: The question is: Is it possible to explain the difference and to give a minimal example using only TikZ concepts and syntax without resorting to low level PGF tinkering? Is the difference perceptible in code that uses only TikZ? It's like asking whether a certain Java bytecode concept or construct can be expressed or distinguished using the Java language. – Evan Aad Jul 11 '17 at 7:50
  • As the shape key has not default value, you can't write \node[shape]{...}. You must provide a value (like \node[shape=circle]{...}). As shape has an initial value (rectangle), with \node{...} you get a rectangular node. – Paul Gaborit Jul 11 '17 at 7:54
  • @Evan, tried it. – Rmano Jul 11 '17 at 7:54
10

This answer is for explaining what the TikZ/PGF manual means for default/initial values of a keyword. It may or may not have any relation with the usage of .default and .initial keys depending on the specific implementation.

For example for shape:

  • no default means you can't say

     \node[shape, red]{...}
    

    because there is no default (in this case the key is defined so that it must have an argument, so it will error out if you do; thanks, @percusse). If, for example, it had circle as default, that means that you could have used the aforementioned command to have a circle-shaped node;

  • initial means that if you say

    \node[color=red] {...}
    

    without mentioning shape you'll have a rectangle.

Another example could be (straight from the manual):

/pgf/tips=value (default true, initially on draw) alias /tikz/tips

This key governs in what situations arrow tips are added to a path. The following values are permissible:

  • true (the value used when no value is specified)
  • proper
  • on draw (the initial value, if the key has not yet been used at all)
  • on proper draw
  • never or false (same effect)

[...]

(although I don't understand what the comment on the last item means --- just that never and false are the same?)

| improve this answer | |
  • Thanks. Just to make sure I understand: if a certain option x doesn't have an initial value, it means that given an object a that this option applies to, there isn't necessarily an answer to the question: "What is the value of a's option x?", because a may not have this option at all. And on the contrary, if an option has an initial value, then it is meaningful to ask the above question for every object a that this option applies to, because a will always have this option, the only unknown is the value this option has. Correct? – Evan Aad Jul 11 '17 at 8:05
  • Another question: can an option have both an initial and a default values? If so, which one "wins"? For instance, suppose a node had an option my_opt with initial value a and default b. What would be the value of the option in the following cases: (1) node [] (the option is not specified)? (2) node [my_opt] (the option is specified without an explicit value)? – Evan Aad Jul 11 '17 at 8:18
6

This is the case where it sounds like the problem is related to keys but shape is a pretty legacy keyword and the way it is defined is pretty straightforward.

\tikzoption{shape}{\edef\tikz@shape{#1}} 

(\tikzoption later became \tikzset. So don't use it)

Then at the initialization of TikZ package we see

\def\tikz@shape{rectangle}%

Note that this is the global scope so if you don't fiddle with it every TikZ picture will inherit this default value. This is not related to /.initial and /.default problem. It's the manual's classification that makes it looks like key issue.


In the manual if you see no default this means you need to supply a value. If you see no value then,... well... you don't need to provide a value. If you insist on providing a value sometimes you get an error, sometimes not.

Example,

\node[matrix of math nodes={4}{5}] {\tan \\ \sin};

will not error. Because every style/code handler intrinsically accepts arguments. If not explicitly set by /.value forbidden handler then nothing happens.

Initially <...> means if you don't provide anything else I'm going to use <...>.

As usual, exceptions apply...

One final note about TikZ/PGF difference. All TikZ is converted to PGF code so there are no separate functionalities. It's a matter of syntax.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.