Unable calculate value of coordinate by macro constructed by newcommand in tikz












5















I construct a macro named mycal(with an optional argument) to calculate value of coordinates which will be used in tikzdraw.
I find that with this optioal arg, the code can not compile. When the optional arg become mandatory, the code works all right. But I do need this arg optional.
Why and how to solve this problem?



MWE:



documentclass{article}
usepackage{tikz,picture}

begin{document}
% The following part can not compile
% newcommand{mycal}[3][0pt]{thedimexpr #2 + #3 + #1}
% newcommandmydraw[3]{tikzdraw(0,0)--(mycal[#1]{#2}{#3},0);}
% mydraw{1pt}{2cm}{3cm}

% The following part ok!
newcommand{mycal}[3]{thedimexpr #2 + #3 + #1}
newcommandmydraw[3]{tikzdraw(0,0)--(mycal{#1}{#2}{#3},0);}
mydraw{1pt}{2cm}{3cm}
end{document}









share|improve this question

























  • Does this tip or this one help ?

    – Partha D.
    Feb 5 at 8:23











  • What confuses me is why macro with optional arg can not be used in tikz coordinate calculation and how to solve it if optional arg has to be kept in macro defination.

    – lyl
    Feb 5 at 8:36
















5















I construct a macro named mycal(with an optional argument) to calculate value of coordinates which will be used in tikzdraw.
I find that with this optioal arg, the code can not compile. When the optional arg become mandatory, the code works all right. But I do need this arg optional.
Why and how to solve this problem?



MWE:



documentclass{article}
usepackage{tikz,picture}

begin{document}
% The following part can not compile
% newcommand{mycal}[3][0pt]{thedimexpr #2 + #3 + #1}
% newcommandmydraw[3]{tikzdraw(0,0)--(mycal[#1]{#2}{#3},0);}
% mydraw{1pt}{2cm}{3cm}

% The following part ok!
newcommand{mycal}[3]{thedimexpr #2 + #3 + #1}
newcommandmydraw[3]{tikzdraw(0,0)--(mycal{#1}{#2}{#3},0);}
mydraw{1pt}{2cm}{3cm}
end{document}









share|improve this question

























  • Does this tip or this one help ?

    – Partha D.
    Feb 5 at 8:23











  • What confuses me is why macro with optional arg can not be used in tikz coordinate calculation and how to solve it if optional arg has to be kept in macro defination.

    – lyl
    Feb 5 at 8:36














5












5








5


1






I construct a macro named mycal(with an optional argument) to calculate value of coordinates which will be used in tikzdraw.
I find that with this optioal arg, the code can not compile. When the optional arg become mandatory, the code works all right. But I do need this arg optional.
Why and how to solve this problem?



MWE:



documentclass{article}
usepackage{tikz,picture}

begin{document}
% The following part can not compile
% newcommand{mycal}[3][0pt]{thedimexpr #2 + #3 + #1}
% newcommandmydraw[3]{tikzdraw(0,0)--(mycal[#1]{#2}{#3},0);}
% mydraw{1pt}{2cm}{3cm}

% The following part ok!
newcommand{mycal}[3]{thedimexpr #2 + #3 + #1}
newcommandmydraw[3]{tikzdraw(0,0)--(mycal{#1}{#2}{#3},0);}
mydraw{1pt}{2cm}{3cm}
end{document}









share|improve this question
















I construct a macro named mycal(with an optional argument) to calculate value of coordinates which will be used in tikzdraw.
I find that with this optioal arg, the code can not compile. When the optional arg become mandatory, the code works all right. But I do need this arg optional.
Why and how to solve this problem?



MWE:



documentclass{article}
usepackage{tikz,picture}

begin{document}
% The following part can not compile
% newcommand{mycal}[3][0pt]{thedimexpr #2 + #3 + #1}
% newcommandmydraw[3]{tikzdraw(0,0)--(mycal[#1]{#2}{#3},0);}
% mydraw{1pt}{2cm}{3cm}

% The following part ok!
newcommand{mycal}[3]{thedimexpr #2 + #3 + #1}
newcommandmydraw[3]{tikzdraw(0,0)--(mycal{#1}{#2}{#3},0);}
mydraw{1pt}{2cm}{3cm}
end{document}






tikz-pgf tex-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 5 at 8:34







lyl

















asked Feb 5 at 8:07









lyllyl

51728




51728













  • Does this tip or this one help ?

    – Partha D.
    Feb 5 at 8:23











  • What confuses me is why macro with optional arg can not be used in tikz coordinate calculation and how to solve it if optional arg has to be kept in macro defination.

    – lyl
    Feb 5 at 8:36



















  • Does this tip or this one help ?

    – Partha D.
    Feb 5 at 8:23











  • What confuses me is why macro with optional arg can not be used in tikz coordinate calculation and how to solve it if optional arg has to be kept in macro defination.

    – lyl
    Feb 5 at 8:36

















Does this tip or this one help ?

– Partha D.
Feb 5 at 8:23





Does this tip or this one help ?

– Partha D.
Feb 5 at 8:23













What confuses me is why macro with optional arg can not be used in tikz coordinate calculation and how to solve it if optional arg has to be kept in macro defination.

– lyl
Feb 5 at 8:36





What confuses me is why macro with optional arg can not be used in tikz coordinate calculation and how to solve it if optional arg has to be kept in macro defination.

– lyl
Feb 5 at 8:36










1 Answer
1






active

oldest

votes


















6














Your macro does not work because macros with optional arguments are not expandable and therefore cannot be used in the middle of a path construction. Tex has to perform some assignment to determine whether the optional argument is present or not. The solution may be to use pgfextra which allows you to interrupt temporarily the construction of the path and execute some code. You have to modify your code to save the result of the computation to some register and then use it.



documentclass{article}

usepackage{tikz}

newdimenmydimen
newcommandmycal[3][0cm]{mydimen=dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{tikzdraw(0cm,0cm) pgfextra{mycal[#1]{#2}{#3}} --(mydimen,0cm);}

begin{document}
mydraw[1cm]{2cm}{3cm}

mydraw{2cm}{3cm}
end{document}


By the way, in your example, mycal does not really need to take an optional argument. mydraw does.



newcommandmycal[3]{dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{begin{tikzpicture}draw(0cm,0cm)-- (mycal{#1}{#2}{#3},0cm);


EDIT:



If you really insist on using mycal with an optional argument without using pgfextra, you can use the following trick. It defines an expandable mycalc with an optional argument.



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2#3{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm}{3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm}{3cm},0cm);
end{document}


NEW EDIT:



To write mycal{2cm,3cm} or mycal[1cm]{2cm,3cm} instead of mycal{2cm}{3cm} or mycal[1cm]{2cm}{3cm} you can define mycal as follows



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2{@@mycal{#1}#2@nil}
def@@mycal#1#2,#3@nil{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm,3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm,3cm},0cm);
end{document}





share|improve this answer


























  • Thank you @Eric. Optional args is needed in mycal, because there are many calculations in the path, and for most of them ,#1 is 0cm. So I don't want to write so many "[...]" which is only 0cm and does not affect the result of calculation. Is there any other way to force expland of optional args?

    – lyl
    Feb 5 at 10:35













  • @lyl I updated my answer to define an expandable macro mycal with an optional argument.

    – Eric Domenjoud
    Feb 5 at 10:53











  • Thank you so much for your solutions. And is there a way to construct mycal when calling it like this: mycal{1cm,2cm} rather than mycal{1cm}{2cm}?

    – lyl
    Feb 6 at 0:53











  • @lyl I updated again my answer.

    – Eric Domenjoud
    Feb 6 at 6:33











  • Many many thanks!! Please forgive my greed. I think a macro like "mycal[5pt]{1pt,2pt,3em,4cm,...,5mm} "(the mandatory arg is a list dilimited by ",", the number of the list member is variable ) will be the ultimate solution. Is there such a solution?

    – lyl
    Feb 6 at 7:03











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',
autoActivateHeartbeat: false,
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%2f473441%2funable-calculate-value-of-coordinate-by-macro-constructed-by-newcommand-in-tikz%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









6














Your macro does not work because macros with optional arguments are not expandable and therefore cannot be used in the middle of a path construction. Tex has to perform some assignment to determine whether the optional argument is present or not. The solution may be to use pgfextra which allows you to interrupt temporarily the construction of the path and execute some code. You have to modify your code to save the result of the computation to some register and then use it.



documentclass{article}

usepackage{tikz}

newdimenmydimen
newcommandmycal[3][0cm]{mydimen=dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{tikzdraw(0cm,0cm) pgfextra{mycal[#1]{#2}{#3}} --(mydimen,0cm);}

begin{document}
mydraw[1cm]{2cm}{3cm}

mydraw{2cm}{3cm}
end{document}


By the way, in your example, mycal does not really need to take an optional argument. mydraw does.



newcommandmycal[3]{dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{begin{tikzpicture}draw(0cm,0cm)-- (mycal{#1}{#2}{#3},0cm);


EDIT:



If you really insist on using mycal with an optional argument without using pgfextra, you can use the following trick. It defines an expandable mycalc with an optional argument.



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2#3{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm}{3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm}{3cm},0cm);
end{document}


NEW EDIT:



To write mycal{2cm,3cm} or mycal[1cm]{2cm,3cm} instead of mycal{2cm}{3cm} or mycal[1cm]{2cm}{3cm} you can define mycal as follows



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2{@@mycal{#1}#2@nil}
def@@mycal#1#2,#3@nil{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm,3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm,3cm},0cm);
end{document}





share|improve this answer


























  • Thank you @Eric. Optional args is needed in mycal, because there are many calculations in the path, and for most of them ,#1 is 0cm. So I don't want to write so many "[...]" which is only 0cm and does not affect the result of calculation. Is there any other way to force expland of optional args?

    – lyl
    Feb 5 at 10:35













  • @lyl I updated my answer to define an expandable macro mycal with an optional argument.

    – Eric Domenjoud
    Feb 5 at 10:53











  • Thank you so much for your solutions. And is there a way to construct mycal when calling it like this: mycal{1cm,2cm} rather than mycal{1cm}{2cm}?

    – lyl
    Feb 6 at 0:53











  • @lyl I updated again my answer.

    – Eric Domenjoud
    Feb 6 at 6:33











  • Many many thanks!! Please forgive my greed. I think a macro like "mycal[5pt]{1pt,2pt,3em,4cm,...,5mm} "(the mandatory arg is a list dilimited by ",", the number of the list member is variable ) will be the ultimate solution. Is there such a solution?

    – lyl
    Feb 6 at 7:03
















6














Your macro does not work because macros with optional arguments are not expandable and therefore cannot be used in the middle of a path construction. Tex has to perform some assignment to determine whether the optional argument is present or not. The solution may be to use pgfextra which allows you to interrupt temporarily the construction of the path and execute some code. You have to modify your code to save the result of the computation to some register and then use it.



documentclass{article}

usepackage{tikz}

newdimenmydimen
newcommandmycal[3][0cm]{mydimen=dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{tikzdraw(0cm,0cm) pgfextra{mycal[#1]{#2}{#3}} --(mydimen,0cm);}

begin{document}
mydraw[1cm]{2cm}{3cm}

mydraw{2cm}{3cm}
end{document}


By the way, in your example, mycal does not really need to take an optional argument. mydraw does.



newcommandmycal[3]{dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{begin{tikzpicture}draw(0cm,0cm)-- (mycal{#1}{#2}{#3},0cm);


EDIT:



If you really insist on using mycal with an optional argument without using pgfextra, you can use the following trick. It defines an expandable mycalc with an optional argument.



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2#3{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm}{3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm}{3cm},0cm);
end{document}


NEW EDIT:



To write mycal{2cm,3cm} or mycal[1cm]{2cm,3cm} instead of mycal{2cm}{3cm} or mycal[1cm]{2cm}{3cm} you can define mycal as follows



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2{@@mycal{#1}#2@nil}
def@@mycal#1#2,#3@nil{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm,3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm,3cm},0cm);
end{document}





share|improve this answer


























  • Thank you @Eric. Optional args is needed in mycal, because there are many calculations in the path, and for most of them ,#1 is 0cm. So I don't want to write so many "[...]" which is only 0cm and does not affect the result of calculation. Is there any other way to force expland of optional args?

    – lyl
    Feb 5 at 10:35













  • @lyl I updated my answer to define an expandable macro mycal with an optional argument.

    – Eric Domenjoud
    Feb 5 at 10:53











  • Thank you so much for your solutions. And is there a way to construct mycal when calling it like this: mycal{1cm,2cm} rather than mycal{1cm}{2cm}?

    – lyl
    Feb 6 at 0:53











  • @lyl I updated again my answer.

    – Eric Domenjoud
    Feb 6 at 6:33











  • Many many thanks!! Please forgive my greed. I think a macro like "mycal[5pt]{1pt,2pt,3em,4cm,...,5mm} "(the mandatory arg is a list dilimited by ",", the number of the list member is variable ) will be the ultimate solution. Is there such a solution?

    – lyl
    Feb 6 at 7:03














6












6








6







Your macro does not work because macros with optional arguments are not expandable and therefore cannot be used in the middle of a path construction. Tex has to perform some assignment to determine whether the optional argument is present or not. The solution may be to use pgfextra which allows you to interrupt temporarily the construction of the path and execute some code. You have to modify your code to save the result of the computation to some register and then use it.



documentclass{article}

usepackage{tikz}

newdimenmydimen
newcommandmycal[3][0cm]{mydimen=dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{tikzdraw(0cm,0cm) pgfextra{mycal[#1]{#2}{#3}} --(mydimen,0cm);}

begin{document}
mydraw[1cm]{2cm}{3cm}

mydraw{2cm}{3cm}
end{document}


By the way, in your example, mycal does not really need to take an optional argument. mydraw does.



newcommandmycal[3]{dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{begin{tikzpicture}draw(0cm,0cm)-- (mycal{#1}{#2}{#3},0cm);


EDIT:



If you really insist on using mycal with an optional argument without using pgfextra, you can use the following trick. It defines an expandable mycalc with an optional argument.



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2#3{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm}{3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm}{3cm},0cm);
end{document}


NEW EDIT:



To write mycal{2cm,3cm} or mycal[1cm]{2cm,3cm} instead of mycal{2cm}{3cm} or mycal[1cm]{2cm}{3cm} you can define mycal as follows



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2{@@mycal{#1}#2@nil}
def@@mycal#1#2,#3@nil{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm,3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm,3cm},0cm);
end{document}





share|improve this answer















Your macro does not work because macros with optional arguments are not expandable and therefore cannot be used in the middle of a path construction. Tex has to perform some assignment to determine whether the optional argument is present or not. The solution may be to use pgfextra which allows you to interrupt temporarily the construction of the path and execute some code. You have to modify your code to save the result of the computation to some register and then use it.



documentclass{article}

usepackage{tikz}

newdimenmydimen
newcommandmycal[3][0cm]{mydimen=dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{tikzdraw(0cm,0cm) pgfextra{mycal[#1]{#2}{#3}} --(mydimen,0cm);}

begin{document}
mydraw[1cm]{2cm}{3cm}

mydraw{2cm}{3cm}
end{document}


By the way, in your example, mycal does not really need to take an optional argument. mydraw does.



newcommandmycal[3]{dimexpr #2 + #3 + #1relax}
newcommandmydraw[3][0cm]{begin{tikzpicture}draw(0cm,0cm)-- (mycal{#1}{#2}{#3},0cm);


EDIT:



If you really insist on using mycal with an optional argument without using pgfextra, you can use the following trick. It defines an expandable mycalc with an optional argument.



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2#3{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm}{3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm}{3cm},0cm);
end{document}


NEW EDIT:



To write mycal{2cm,3cm} or mycal[1cm]{2cm,3cm} instead of mycal{2cm}{3cm} or mycal[1cm]{2cm}{3cm} you can define mycal as follows



documentclass{article}

usepackage{tikz}

makeatletter
defmycal#1{%
ifx[#1expandafter@firstoftwoelseexpandafter@secondoftwofi
{@mycal[}{@mycal[0cm]{#1}}}
def@mycal[#1]#2{@@mycal{#1}#2@nil}
def@@mycal#1#2,#3@nil{dimexpr#1+#2+#3relax}
makeatother

begin{document}
tikzdraw(0cm,0cm)--(mycal{2cm,3cm},0cm);

tikzdraw(0cm,0cm)--(mycal[1cm]{2cm,3cm},0cm);
end{document}






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 6 at 6:32

























answered Feb 5 at 10:12









Eric DomenjoudEric Domenjoud

92828




92828













  • Thank you @Eric. Optional args is needed in mycal, because there are many calculations in the path, and for most of them ,#1 is 0cm. So I don't want to write so many "[...]" which is only 0cm and does not affect the result of calculation. Is there any other way to force expland of optional args?

    – lyl
    Feb 5 at 10:35













  • @lyl I updated my answer to define an expandable macro mycal with an optional argument.

    – Eric Domenjoud
    Feb 5 at 10:53











  • Thank you so much for your solutions. And is there a way to construct mycal when calling it like this: mycal{1cm,2cm} rather than mycal{1cm}{2cm}?

    – lyl
    Feb 6 at 0:53











  • @lyl I updated again my answer.

    – Eric Domenjoud
    Feb 6 at 6:33











  • Many many thanks!! Please forgive my greed. I think a macro like "mycal[5pt]{1pt,2pt,3em,4cm,...,5mm} "(the mandatory arg is a list dilimited by ",", the number of the list member is variable ) will be the ultimate solution. Is there such a solution?

    – lyl
    Feb 6 at 7:03



















  • Thank you @Eric. Optional args is needed in mycal, because there are many calculations in the path, and for most of them ,#1 is 0cm. So I don't want to write so many "[...]" which is only 0cm and does not affect the result of calculation. Is there any other way to force expland of optional args?

    – lyl
    Feb 5 at 10:35













  • @lyl I updated my answer to define an expandable macro mycal with an optional argument.

    – Eric Domenjoud
    Feb 5 at 10:53











  • Thank you so much for your solutions. And is there a way to construct mycal when calling it like this: mycal{1cm,2cm} rather than mycal{1cm}{2cm}?

    – lyl
    Feb 6 at 0:53











  • @lyl I updated again my answer.

    – Eric Domenjoud
    Feb 6 at 6:33











  • Many many thanks!! Please forgive my greed. I think a macro like "mycal[5pt]{1pt,2pt,3em,4cm,...,5mm} "(the mandatory arg is a list dilimited by ",", the number of the list member is variable ) will be the ultimate solution. Is there such a solution?

    – lyl
    Feb 6 at 7:03

















Thank you @Eric. Optional args is needed in mycal, because there are many calculations in the path, and for most of them ,#1 is 0cm. So I don't want to write so many "[...]" which is only 0cm and does not affect the result of calculation. Is there any other way to force expland of optional args?

– lyl
Feb 5 at 10:35







Thank you @Eric. Optional args is needed in mycal, because there are many calculations in the path, and for most of them ,#1 is 0cm. So I don't want to write so many "[...]" which is only 0cm and does not affect the result of calculation. Is there any other way to force expland of optional args?

– lyl
Feb 5 at 10:35















@lyl I updated my answer to define an expandable macro mycal with an optional argument.

– Eric Domenjoud
Feb 5 at 10:53





@lyl I updated my answer to define an expandable macro mycal with an optional argument.

– Eric Domenjoud
Feb 5 at 10:53













Thank you so much for your solutions. And is there a way to construct mycal when calling it like this: mycal{1cm,2cm} rather than mycal{1cm}{2cm}?

– lyl
Feb 6 at 0:53





Thank you so much for your solutions. And is there a way to construct mycal when calling it like this: mycal{1cm,2cm} rather than mycal{1cm}{2cm}?

– lyl
Feb 6 at 0:53













@lyl I updated again my answer.

– Eric Domenjoud
Feb 6 at 6:33





@lyl I updated again my answer.

– Eric Domenjoud
Feb 6 at 6:33













Many many thanks!! Please forgive my greed. I think a macro like "mycal[5pt]{1pt,2pt,3em,4cm,...,5mm} "(the mandatory arg is a list dilimited by ",", the number of the list member is variable ) will be the ultimate solution. Is there such a solution?

– lyl
Feb 6 at 7:03





Many many thanks!! Please forgive my greed. I think a macro like "mycal[5pt]{1pt,2pt,3em,4cm,...,5mm} "(the mandatory arg is a list dilimited by ",", the number of the list member is variable ) will be the ultimate solution. Is there such a solution?

– lyl
Feb 6 at 7:03


















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473441%2funable-calculate-value-of-coordinate-by-macro-constructed-by-newcommand-in-tikz%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?

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

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents