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?










share|improve this question






















  • 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










  • 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















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?










share|improve this question






















  • 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










  • 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













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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 at 18:58









user11171

432147




432147












  • 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










  • 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










  • @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
















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










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}


enter image description here



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.






share|improve this answer























  • 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












  • @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











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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}


enter image description here



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.






share|improve this answer























  • 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












  • @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















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}


enter image description here



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.






share|improve this answer























  • 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












  • @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













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}


enter image description here



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.






share|improve this answer














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}


enter image description here



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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 at 19:24

























answered Nov 25 at 19:02









marmot

79.8k490169




79.8k490169












  • 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












  • @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












  • 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












  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?