There is no standard way to tell TikZ/pgf to read those things as commands? Some use of brackets maybe?cgnieder wrote:Funny: that is exactly what I tried first when writing my last answer. I am not sure why this doesn't work but my guess is that it is due to how TikZ/pgf reads the argument toLaTexLearner wrote:Code: Select all
\node[\PrintSolutionsTF{answercolor}{opacity=0}] at (3,-0.8) {6};
\node
. It obviously expands\PrintSolutionsTF
but very likely after reading the options when it is too late. It doesn't see an optionopacity
with value0
but sees an optionopacity=0
(thinking the=
and0
were part of the option name). Such an option obviously isn't defined which explains the error. This is the reason why I put\PrintSolutionsTF
outside of the path...
Text Formatting ⇒ Longer Embedded Solutions
-
- Posts: 139
- Joined: Tue Mar 10, 2015 11:06 am
Longer Embedded Solutions
NEW: TikZ book now 40% off at Amazon.com for a short time.

Longer Embedded Solutions
I had an idea last night: you could define a new TikZ option:
and then use it like this:
Regards
Code: Select all
\pgfkeys{
/tikz/.cd ,
ifanswer/.code 2 args =
\PrintSolutionsTF{\pgfkeysalso{#1}}{\pgfkeysalso{#2}}
}
Code: Select all
\node[ifanswer={answercolor}{opacity=0}] at (2,-0.8) {4};
site moderator & package author
-
- Posts: 139
- Joined: Tue Mar 10, 2015 11:06 am
Longer Embedded Solutions
Awesome! That worked perfectly!cgnieder wrote:I had an idea last night: you could define a new TikZ option:
and then use it like this:Code: Select all
\pgfkeys{ /tikz/.cd , ifanswer/.code 2 args = \PrintSolutionsTF{\pgfkeysalso{#1}}{\pgfkeysalso{#2}} }
RegardsCode: Select all
\node[ifanswer={answercolor}{opacity=0}] at (2,-0.8) {4};
Where might I learn about all these new types of commands:
\pgfkeys
, .cd
, ifanswer
, etc.?Longer Embedded Solutions
TheLaTexLearner wrote:Where might I learn about all these new types of commands:\pgfkeys
,.cd
,ifanswer
, etc.?
ifanswer
key is defined by the above code. The others are explained in the 
site moderator & package author
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Longer Embedded Solutions
In my opinion, such things as
but it's great to know such code for extending styles and customizing features.
Stefan
/.code
and commands beginning with \pgf
are advanced commands, coming from the backend below TikZ, so I would not worry too much about them at the beginning. A lot of other TikZ things are easier 
Stefan
LaTeX.org admin