LaTeX forum ⇒ Text FormattingLonger 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

Postby LaTexLearner » Thu Sep 17, 2015 10:01 am

cgnieder wrote:
LaTexLearner wrote:
  1. \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:

User avatar
cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Thu Sep 17, 2015 10:32 am

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

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

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

Postby LaTexLearner » Fri Sep 18, 2015 8:23 pm

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

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

and then use it like this:
  1. \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: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Fri Sep 18, 2015 8:27 pm

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

User avatar
Stefan Kottwitz
Site Admin
Posts: 8529
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sat Sep 19, 2015 12:58 pm

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
Site admin


Return to “Text Formatting”

Who is online

Users browsing this forum: Bing [Bot] and 6 guests