How to use macro inside TikZ decoration options
up vote
1
down vote
favorite
I would like to set the decoration options for an edge by using a macro, like this:
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration={curlbl}] (#2);
}
However, this does not work as I intended and I get an error I do not understand:
./minimal.tex:12: Package pgfkeys Error: I do not know the key '/pgf/decoration/pgfkeyscurrentname ' and I am going to ignore it. Perhaps you misspelled it.
Here is my tex file:
documentclass[tikz,border=10pt]{standalone}
usetikzlibrary{positioning,decorations.text}
begin{document}
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration={curlbl}] (#2);%
}
begin{tikzpicture}
node (A) {emph{A}};
node[below left=10ex and 6ex of A] (B) {emph{B}};
myedge{A}{B};
end{tikzpicture}
end{document}
Is it possible to use a macro to set the options of a TikZ decoration
?
tikz-pgf tikz-decorations
add a comment |
up vote
1
down vote
favorite
I would like to set the decoration options for an edge by using a macro, like this:
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration={curlbl}] (#2);
}
However, this does not work as I intended and I get an error I do not understand:
./minimal.tex:12: Package pgfkeys Error: I do not know the key '/pgf/decoration/pgfkeyscurrentname ' and I am going to ignore it. Perhaps you misspelled it.
Here is my tex file:
documentclass[tikz,border=10pt]{standalone}
usetikzlibrary{positioning,decorations.text}
begin{document}
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration={curlbl}] (#2);%
}
begin{tikzpicture}
node (A) {emph{A}};
node[below left=10ex and 6ex of A] (B) {emph{B}};
myedge{A}{B};
end{tikzpicture}
end{document}
Is it possible to use a macro to set the options of a TikZ decoration
?
tikz-pgf tikz-decorations
Why do you want to use aLaTeX
macro when you can do it withTikZ
without a macro?
– AndréC
Nov 25 at 19:27
@AndréC I want to conditionally set the macro with anifthenelse
.
– user11171
Nov 25 at 19:29
In my humble opinion, it would be better to pose the problem with a conditional macro. But now, since there is already an answer, it is no longer useful.
– AndréC
Nov 25 at 21:51
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I would like to set the decoration options for an edge by using a macro, like this:
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration={curlbl}] (#2);
}
However, this does not work as I intended and I get an error I do not understand:
./minimal.tex:12: Package pgfkeys Error: I do not know the key '/pgf/decoration/pgfkeyscurrentname ' and I am going to ignore it. Perhaps you misspelled it.
Here is my tex file:
documentclass[tikz,border=10pt]{standalone}
usetikzlibrary{positioning,decorations.text}
begin{document}
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration={curlbl}] (#2);%
}
begin{tikzpicture}
node (A) {emph{A}};
node[below left=10ex and 6ex of A] (B) {emph{B}};
myedge{A}{B};
end{tikzpicture}
end{document}
Is it possible to use a macro to set the options of a TikZ decoration
?
tikz-pgf tikz-decorations
I would like to set the decoration options for an edge by using a macro, like this:
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration={curlbl}] (#2);
}
However, this does not work as I intended and I get an error I do not understand:
./minimal.tex:12: Package pgfkeys Error: I do not know the key '/pgf/decoration/pgfkeyscurrentname ' and I am going to ignore it. Perhaps you misspelled it.
Here is my tex file:
documentclass[tikz,border=10pt]{standalone}
usetikzlibrary{positioning,decorations.text}
begin{document}
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration={curlbl}] (#2);%
}
begin{tikzpicture}
node (A) {emph{A}};
node[below left=10ex and 6ex of A] (B) {emph{B}};
myedge{A}{B};
end{tikzpicture}
end{document}
Is it possible to use a macro to set the options of a TikZ decoration
?
tikz-pgf tikz-decorations
tikz-pgf tikz-decorations
asked Nov 25 at 18:58
user11171
432147
432147
Why do you want to use aLaTeX
macro when you can do it withTikZ
without a macro?
– AndréC
Nov 25 at 19:27
@AndréC I want to conditionally set the macro with anifthenelse
.
– user11171
Nov 25 at 19:29
In my humble opinion, it would be better to pose the problem with a conditional macro. But now, since there is already an answer, it is no longer useful.
– AndréC
Nov 25 at 21:51
add a comment |
Why do you want to use aLaTeX
macro when you can do it withTikZ
without a macro?
– AndréC
Nov 25 at 19:27
@AndréC I want to conditionally set the macro with anifthenelse
.
– user11171
Nov 25 at 19:29
In my humble opinion, it would be better to pose the problem with a conditional macro. But now, since there is already an answer, it is no longer useful.
– AndréC
Nov 25 at 21:51
Why do you want to use a
LaTeX
macro when you can do it with TikZ
without a macro?– AndréC
Nov 25 at 19:27
Why do you want to use a
LaTeX
macro when you can do it with TikZ
without a macro?– AndréC
Nov 25 at 19:27
@AndréC I want to conditionally set the macro with an
ifthenelse
.– user11171
Nov 25 at 19:29
@AndréC I want to conditionally set the macro with an
ifthenelse
.– user11171
Nov 25 at 19:29
In my humble opinion, it would be better to pose the problem with a conditional macro. But now, since there is already an answer, it is no longer useful.
– AndréC
Nov 25 at 21:51
In my humble opinion, it would be better to pose the problem with a conditional macro. But now, since there is already an answer, it is no longer useful.
– AndréC
Nov 25 at 21:51
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
This is a so-called expansion problem: when TikZ parses the path, your macro is not yet expanded. Of course, the problem can of course be solved in various way. An arguably rather elegant way, provided you insist on the overall strategy here to use a macro in this way, is to tell TikZ to expand curlbl
. This can be accomplished by using the .expanded
key.
documentclass[tikz,border=10pt]{standalone}
usetikzlibrary{positioning,decorations.text}
begin{document}
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration/.expanded={curlbl}] (#2);%
}
begin{tikzpicture}
node (A) {emph{A}};
node[below left=10ex and 6ex of A] (B) {emph{B}};
myedge{A}{B};
end{tikzpicture}
end{document}
I strongly suspect that, if you provide us with the full picture, there will be a more TikZy way to achieve that. Without knowing the details, at this point I can only draw your attention to the keys is if
and is choice
, which are described on p. 889 of the pgfmanual.
Hm, before posting this question I tried puttingedef
infront ofcurlbl
, but that did not work. The real reason I want this is for conditionally setting some decoration options in the macro. Do you know a good place where I can read about how to I should useedef
? I am new to this latex macro business :)
– user11171
Nov 25 at 19:08
My own failed attempt was to usedecoration={edefcurlbl}
. I tried to reduce my problem down to the minimal reproducible example. Your solution seems to work for conditionally changing the decoration - I simply have an extraifthenelse{}
to conditionally definecurlbl
.
– user11171
Nov 25 at 19:16
@user11171 Meanwhile I added a slightly more TikZy way that just uses./expanded
. Cold you please add the full ifthenelse thingy to your question? Otherwise there might be miscommunication because I do not really understand yet what you want to achieve.
– marmot
Nov 25 at 19:17
Thank you so much for the answer! The second solution does seem more elegant.
– user11171
Nov 25 at 19:19
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
This is a so-called expansion problem: when TikZ parses the path, your macro is not yet expanded. Of course, the problem can of course be solved in various way. An arguably rather elegant way, provided you insist on the overall strategy here to use a macro in this way, is to tell TikZ to expand curlbl
. This can be accomplished by using the .expanded
key.
documentclass[tikz,border=10pt]{standalone}
usetikzlibrary{positioning,decorations.text}
begin{document}
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration/.expanded={curlbl}] (#2);%
}
begin{tikzpicture}
node (A) {emph{A}};
node[below left=10ex and 6ex of A] (B) {emph{B}};
myedge{A}{B};
end{tikzpicture}
end{document}
I strongly suspect that, if you provide us with the full picture, there will be a more TikZy way to achieve that. Without knowing the details, at this point I can only draw your attention to the keys is if
and is choice
, which are described on p. 889 of the pgfmanual.
Hm, before posting this question I tried puttingedef
infront ofcurlbl
, but that did not work. The real reason I want this is for conditionally setting some decoration options in the macro. Do you know a good place where I can read about how to I should useedef
? I am new to this latex macro business :)
– user11171
Nov 25 at 19:08
My own failed attempt was to usedecoration={edefcurlbl}
. I tried to reduce my problem down to the minimal reproducible example. Your solution seems to work for conditionally changing the decoration - I simply have an extraifthenelse{}
to conditionally definecurlbl
.
– user11171
Nov 25 at 19:16
@user11171 Meanwhile I added a slightly more TikZy way that just uses./expanded
. Cold you please add the full ifthenelse thingy to your question? Otherwise there might be miscommunication because I do not really understand yet what you want to achieve.
– marmot
Nov 25 at 19:17
Thank you so much for the answer! The second solution does seem more elegant.
– user11171
Nov 25 at 19:19
add a comment |
up vote
1
down vote
accepted
This is a so-called expansion problem: when TikZ parses the path, your macro is not yet expanded. Of course, the problem can of course be solved in various way. An arguably rather elegant way, provided you insist on the overall strategy here to use a macro in this way, is to tell TikZ to expand curlbl
. This can be accomplished by using the .expanded
key.
documentclass[tikz,border=10pt]{standalone}
usetikzlibrary{positioning,decorations.text}
begin{document}
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration/.expanded={curlbl}] (#2);%
}
begin{tikzpicture}
node (A) {emph{A}};
node[below left=10ex and 6ex of A] (B) {emph{B}};
myedge{A}{B};
end{tikzpicture}
end{document}
I strongly suspect that, if you provide us with the full picture, there will be a more TikZy way to achieve that. Without knowing the details, at this point I can only draw your attention to the keys is if
and is choice
, which are described on p. 889 of the pgfmanual.
Hm, before posting this question I tried puttingedef
infront ofcurlbl
, but that did not work. The real reason I want this is for conditionally setting some decoration options in the macro. Do you know a good place where I can read about how to I should useedef
? I am new to this latex macro business :)
– user11171
Nov 25 at 19:08
My own failed attempt was to usedecoration={edefcurlbl}
. I tried to reduce my problem down to the minimal reproducible example. Your solution seems to work for conditionally changing the decoration - I simply have an extraifthenelse{}
to conditionally definecurlbl
.
– user11171
Nov 25 at 19:16
@user11171 Meanwhile I added a slightly more TikZy way that just uses./expanded
. Cold you please add the full ifthenelse thingy to your question? Otherwise there might be miscommunication because I do not really understand yet what you want to achieve.
– marmot
Nov 25 at 19:17
Thank you so much for the answer! The second solution does seem more elegant.
– user11171
Nov 25 at 19:19
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
This is a so-called expansion problem: when TikZ parses the path, your macro is not yet expanded. Of course, the problem can of course be solved in various way. An arguably rather elegant way, provided you insist on the overall strategy here to use a macro in this way, is to tell TikZ to expand curlbl
. This can be accomplished by using the .expanded
key.
documentclass[tikz,border=10pt]{standalone}
usetikzlibrary{positioning,decorations.text}
begin{document}
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration/.expanded={curlbl}] (#2);%
}
begin{tikzpicture}
node (A) {emph{A}};
node[below left=10ex and 6ex of A] (B) {emph{B}};
myedge{A}{B};
end{tikzpicture}
end{document}
I strongly suspect that, if you provide us with the full picture, there will be a more TikZy way to achieve that. Without knowing the details, at this point I can only draw your attention to the keys is if
and is choice
, which are described on p. 889 of the pgfmanual.
This is a so-called expansion problem: when TikZ parses the path, your macro is not yet expanded. Of course, the problem can of course be solved in various way. An arguably rather elegant way, provided you insist on the overall strategy here to use a macro in this way, is to tell TikZ to expand curlbl
. This can be accomplished by using the .expanded
key.
documentclass[tikz,border=10pt]{standalone}
usetikzlibrary{positioning,decorations.text}
begin{document}
defcurlbl{text along path,text={hi}}
newcommand{myedge}[2]{%
path (#1) edge[decorate, decoration/.expanded={curlbl}] (#2);%
}
begin{tikzpicture}
node (A) {emph{A}};
node[below left=10ex and 6ex of A] (B) {emph{B}};
myedge{A}{B};
end{tikzpicture}
end{document}
I strongly suspect that, if you provide us with the full picture, there will be a more TikZy way to achieve that. Without knowing the details, at this point I can only draw your attention to the keys is if
and is choice
, which are described on p. 889 of the pgfmanual.
edited Nov 25 at 19:24
answered Nov 25 at 19:02
marmot
79.8k490169
79.8k490169
Hm, before posting this question I tried puttingedef
infront ofcurlbl
, but that did not work. The real reason I want this is for conditionally setting some decoration options in the macro. Do you know a good place where I can read about how to I should useedef
? I am new to this latex macro business :)
– user11171
Nov 25 at 19:08
My own failed attempt was to usedecoration={edefcurlbl}
. I tried to reduce my problem down to the minimal reproducible example. Your solution seems to work for conditionally changing the decoration - I simply have an extraifthenelse{}
to conditionally definecurlbl
.
– user11171
Nov 25 at 19:16
@user11171 Meanwhile I added a slightly more TikZy way that just uses./expanded
. Cold you please add the full ifthenelse thingy to your question? Otherwise there might be miscommunication because I do not really understand yet what you want to achieve.
– marmot
Nov 25 at 19:17
Thank you so much for the answer! The second solution does seem more elegant.
– user11171
Nov 25 at 19:19
add a comment |
Hm, before posting this question I tried puttingedef
infront ofcurlbl
, but that did not work. The real reason I want this is for conditionally setting some decoration options in the macro. Do you know a good place where I can read about how to I should useedef
? I am new to this latex macro business :)
– user11171
Nov 25 at 19:08
My own failed attempt was to usedecoration={edefcurlbl}
. I tried to reduce my problem down to the minimal reproducible example. Your solution seems to work for conditionally changing the decoration - I simply have an extraifthenelse{}
to conditionally definecurlbl
.
– user11171
Nov 25 at 19:16
@user11171 Meanwhile I added a slightly more TikZy way that just uses./expanded
. Cold you please add the full ifthenelse thingy to your question? Otherwise there might be miscommunication because I do not really understand yet what you want to achieve.
– marmot
Nov 25 at 19:17
Thank you so much for the answer! The second solution does seem more elegant.
– user11171
Nov 25 at 19:19
Hm, before posting this question I tried putting
edef
infront of curlbl
, but that did not work. The real reason I want this is for conditionally setting some decoration options in the macro. Do you know a good place where I can read about how to I should use edef
? I am new to this latex macro business :)– user11171
Nov 25 at 19:08
Hm, before posting this question I tried putting
edef
infront of curlbl
, but that did not work. The real reason I want this is for conditionally setting some decoration options in the macro. Do you know a good place where I can read about how to I should use edef
? I am new to this latex macro business :)– user11171
Nov 25 at 19:08
My own failed attempt was to use
decoration={edefcurlbl}
. I tried to reduce my problem down to the minimal reproducible example. Your solution seems to work for conditionally changing the decoration - I simply have an extra ifthenelse{}
to conditionally define curlbl
.– user11171
Nov 25 at 19:16
My own failed attempt was to use
decoration={edefcurlbl}
. I tried to reduce my problem down to the minimal reproducible example. Your solution seems to work for conditionally changing the decoration - I simply have an extra ifthenelse{}
to conditionally define curlbl
.– user11171
Nov 25 at 19:16
@user11171 Meanwhile I added a slightly more TikZy way that just uses
./expanded
. Cold you please add the full ifthenelse thingy to your question? Otherwise there might be miscommunication because I do not really understand yet what you want to achieve.– marmot
Nov 25 at 19:17
@user11171 Meanwhile I added a slightly more TikZy way that just uses
./expanded
. Cold you please add the full ifthenelse thingy to your question? Otherwise there might be miscommunication because I do not really understand yet what you want to achieve.– marmot
Nov 25 at 19:17
Thank you so much for the answer! The second solution does seem more elegant.
– user11171
Nov 25 at 19:19
Thank you so much for the answer! The second solution does seem more elegant.
– user11171
Nov 25 at 19:19
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461725%2fhow-to-use-macro-inside-tikz-decoration-options%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why do you want to use a
LaTeX
macro when you can do it withTikZ
without a macro?– AndréC
Nov 25 at 19:27
@AndréC I want to conditionally set the macro with an
ifthenelse
.– user11171
Nov 25 at 19:29
In my humble opinion, it would be better to pose the problem with a conditional macro. But now, since there is already an answer, it is no longer useful.
– AndréC
Nov 25 at 21:51