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.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
Longer Embedded Solutions
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};
-
- 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 
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Longer Embedded Solutions
/.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