TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In an answer to Flushing PGF commands and local variable Matthew had suggested using \IfNoValueTF within a TikZ \node specification to determine the text. This solution works great for me.

However, I would also like to able to have these type of conditions within the style without having to define a temporary style. So, in the following, I would like use LabelPointZ to be to determine the style to be used, just as the working LabelPointY determines the text without having an intermediate variable.



\NewDocumentCommand{\LabelPointY}{o o m m g}{
  \addplot [#1] coordinates{(#3,#4)} 
    node [#2]

\NewDocumentCommand{\LabelPointZ}{o g m m g}{
  \addplot [#1] coordinates{(#3,#4)} 
    node [\IfNoValueTF{#2}{color=red,right}{right, #2}]

    \LabelPointY[mark=*,color=red][color=blue, below right]{0.5}{0.5} % default label
    \LabelPointY[mark=*,color=red][color=blue, below]{1  }{1  }{top}  % given label
share|improve this question
Please don't use the minimal class for minimal working examples. It is not intended for this even when the name might suggest it. There is no reason to use it and it might cause issues because it only defines a minimal set of macros and has some common lengths set to zero. – Martin Scharrer May 9 '11 at 13:01
@Martin: The first document linked to in the FAQ answer to meta.tex.stackexchange.com/questions/228/… uses this class, which might make people think it's the appropriate thing to use. Maybe you could incorporate your comment into the FAQ? – Jake May 9 '11 at 13:33
@Jake: Thanks for pointing this out to me. That document also states quite at the beginning: "You may need to substitute the minimal class with another commonly available class, such as article, report or book." I better add some note to the FAQ. – Martin Scharrer May 9 '11 at 13:43
up vote 2 down vote accepted

Having some code in the styles, even expandable ones, doesn't work well. Just move the \IfNoValueTF out from the TikZ style:

\NewDocumentCommand{\LabelPointZ}{o o m m g}{%
    \addplot [#1] coordinates{(#3,#4)} 
        node [color=red,right]
    \addplot [#1] coordinates{(#3,#4)} 
        node [right, #2]

This has however the drawback that you have to write some code twice.

Alternatively use the /utils/exec key to execute the \IfNoValueIF switch and use then \tikzset to set the styles. It looks quite funny but works stable.

\NewDocumentCommand{\LabelPointZ}{o o m m g}{
  \addplot [#1] coordinates{(#3,#4)} 
    node [/utils/exec={\IfNoValueTF{#2}{\tikzset{color=red,right}}{\tikzset{right, #2}}}]
share|improve this answer
I have been using a solution similar to your first example. But, can't find out exactly what /utils/exec is, so have posted a follow up question as it might be useful to others as well. – Peter Grill May 9 '11 at 23:24
@Peter: It is a PGF/TikZ key so it is documented in the PGF/TikZ manual. It can be found by a simple search in the PDF. Like I wrote it simply executes the given code. – Martin Scharrer May 10 '11 at 7:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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