## LaTeX forum ⇒ Text Formatting ⇒ Longer Embedded Solutions

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

### Re: Longer Embedded Solutions

cgnieder wrote:
LaTexLearner wrote:
`\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?

Tags:

cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
I had an idea last night: you could define a new TikZ option:

`\pgfkeys{   /tikz/.cd ,     ifanswer/.code 2 args =     \PrintSolutionsTF{\pgfkeysalso{#1}}{\pgfkeysalso{#2}}}`

and then use it like this:
`\node[ifanswer={answercolor}{opacity=0}] at (2,-0.8) {4};`

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

LaTexLearner
Posts: 138
Joined: Tue Mar 10, 2015 11:06 am
cgnieder wrote:I had an idea last night: you could define a new TikZ option:

`\pgfkeys{   /tikz/.cd ,     ifanswer/.code 2 args =     \PrintSolutionsTF{\pgfkeysalso{#1}}{\pgfkeysalso{#2}}}`

and then use it like this:
`\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.?

cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
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.
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

Stefan Kottwitz
Posts: 8529
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
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