Text FormattingLonger Embedded Solutions

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Longer Embedded Solutions

Post by LaTexLearner »

cgnieder wrote:
LaTexLearner wrote:

Code: Select all

\node[\PrintSolutionsTF{answercolor}{opacity=0}] at (3,-0.8) {6};
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 to \node. It obviously expands \PrintSolutionsTF but very likely after reading the options when it is too late. It doesn't see an option opacity with value 0 but sees an option opacity=0 (thinking the = and 0 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...
There is no standard way to tell TikZ/pgf to read those things as commands? Some use of brackets maybe?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Longer Embedded Solutions

Post by cgnieder »

I had an idea last night: you could define a new TikZ option:

Code: Select all

\pgfkeys{
  /tikz/.cd ,
    ifanswer/.code 2 args =
    \PrintSolutionsTF{\pgfkeysalso{#1}}{\pgfkeysalso{#2}}
}
and then use it like this:

Code: Select all

\node[ifanswer={answercolor}{opacity=0}] at (2,-0.8) {4};
Regards
site moderator & package author
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Longer Embedded Solutions

Post by LaTexLearner »

cgnieder wrote:I had an idea last night: you could define a new TikZ option:

Code: Select all

\pgfkeys{
  /tikz/.cd ,
    ifanswer/.code 2 args =
    \PrintSolutionsTF{\pgfkeysalso{#1}}{\pgfkeysalso{#2}}
}
and then use it like this:

Code: Select all

\node[ifanswer={answercolor}{opacity=0}] at (2,-0.8) {4};
Regards
Awesome! That worked perfectly!

Where might I learn about all these new types of commands: \pgfkeys, .cd, ifanswer, etc.?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Longer Embedded Solutions

Post by cgnieder »

LaTexLearner wrote:Where might I learn about all these new types of commands: \pgfkeys, .cd, ifanswer, etc.?
The ifanswer key is defined by the above code. The others are explained in the pgfmanual.
site moderator & package author
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Longer Embedded Solutions

Post by Stefan Kottwitz »

In my opinion, such things as /.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 :-) but it's great to know such code for extending styles and customizing features.

Stefan
LaTeX.org admin
Post Reply