How to properly capture return value of a command?












2















I have a problem with capturing returned value of my command.



Here is my preamble with command definition:



documentclass[convert={density=300,size=800x600,outext=.png}]{standalone}
usepackage[utf8]{inputenc}
usepackage{tikz}

% Font used for writing commands.
defcmdFont{fontsize{10}{12}selectfont}

% Commands.
defcmdOne {cmdFont aaa}
defcmdTwo {cmdFont bbbbb}
defcmdThree{cmdFont cccc}

% Function which returns maximum width needed to write any of provided arguments.
makeatletter

newlength{textLength@getMaximumWidthHelper}
newlength{textLength@getMaximumWidth}

newcommand{getMaximumWidthHelper}[2]
{%
settowidth{textLength@getMaximumWidthHelper}{pgfinterruptpicture #2endpgfinterruptpicture}%

pgfmathparse{max(#1,textLength@getMaximumWidthHelper)}%
@ifnextcharbgroup{getMaximumWidthHelper{pgfmathresult pt}}{pgfmathresult pt}%
}%

newcommand{getMaximumWidth}[1]
{%
settowidth{textLength@getMaximumWidth}{pgfinterruptpicture #1endpgfinterruptpicture}%
@ifnextcharbgroup{getMaximumWidthHelper{thetextLength@getMaximumWidth}}{thetextLength@getMaximumWidth}%
}%

makeatother


Working example used to test the above command:



begin{document}

getMaximumWidth{cmdOne}
getMaximumWidth{cmdOne}{cmdTwo}
getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}

end{document}


However, when I try to capture the output of getMaximumWidth, it doesn't work as expected.



begin{document}

newlength{maximumWidth}
setlength{maximumWidth}{getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}}
themaximumWidth

end{document}


On the second line, the return value of getMaximumWidth is not captured but instantly printed.

Afterwards I get an error:




! Missing number, treated as
zero.




After that, the third line just prints default value 0.0pt.



What is the proper way to capture the output of getMaximumWidth?



P.S. This is my first time writing Latex document, feel free to point out anything i could've done better.










share|improve this question









New contributor




Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    while @ifnextcharbgroup works you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments using {} delimiters and a variable number of optional arguments which use delimiters. You have defined a command with optional {} arguments which is wrong.

    – David Carlisle
    10 hours ago













  • macros do not have return values, your getMaximumWidth expands to a series of assignments so is not a length that can be used in setlength, you need to define it to leave a length in some command, say tempresult then use getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}setlength{maximumWidth}{tempresult} or using a latex-conforming syntax, getMaximumWidth{cmdOne,cmdTwo,cmdThree}setlength{maximumWidth}{tempresult}

    – David Carlisle
    9 hours ago













  • That is exactly why pgfmathparse leaves its answer in pgfmathresult

    – David Carlisle
    8 hours ago











  • Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.

    – Iskustvo
    8 hours ago
















2















I have a problem with capturing returned value of my command.



Here is my preamble with command definition:



documentclass[convert={density=300,size=800x600,outext=.png}]{standalone}
usepackage[utf8]{inputenc}
usepackage{tikz}

% Font used for writing commands.
defcmdFont{fontsize{10}{12}selectfont}

% Commands.
defcmdOne {cmdFont aaa}
defcmdTwo {cmdFont bbbbb}
defcmdThree{cmdFont cccc}

% Function which returns maximum width needed to write any of provided arguments.
makeatletter

newlength{textLength@getMaximumWidthHelper}
newlength{textLength@getMaximumWidth}

newcommand{getMaximumWidthHelper}[2]
{%
settowidth{textLength@getMaximumWidthHelper}{pgfinterruptpicture #2endpgfinterruptpicture}%

pgfmathparse{max(#1,textLength@getMaximumWidthHelper)}%
@ifnextcharbgroup{getMaximumWidthHelper{pgfmathresult pt}}{pgfmathresult pt}%
}%

newcommand{getMaximumWidth}[1]
{%
settowidth{textLength@getMaximumWidth}{pgfinterruptpicture #1endpgfinterruptpicture}%
@ifnextcharbgroup{getMaximumWidthHelper{thetextLength@getMaximumWidth}}{thetextLength@getMaximumWidth}%
}%

makeatother


Working example used to test the above command:



begin{document}

getMaximumWidth{cmdOne}
getMaximumWidth{cmdOne}{cmdTwo}
getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}

end{document}


However, when I try to capture the output of getMaximumWidth, it doesn't work as expected.



begin{document}

newlength{maximumWidth}
setlength{maximumWidth}{getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}}
themaximumWidth

end{document}


On the second line, the return value of getMaximumWidth is not captured but instantly printed.

Afterwards I get an error:




! Missing number, treated as
zero.




After that, the third line just prints default value 0.0pt.



What is the proper way to capture the output of getMaximumWidth?



P.S. This is my first time writing Latex document, feel free to point out anything i could've done better.










share|improve this question









New contributor




Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1





    while @ifnextcharbgroup works you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments using {} delimiters and a variable number of optional arguments which use delimiters. You have defined a command with optional {} arguments which is wrong.

    – David Carlisle
    10 hours ago













  • macros do not have return values, your getMaximumWidth expands to a series of assignments so is not a length that can be used in setlength, you need to define it to leave a length in some command, say tempresult then use getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}setlength{maximumWidth}{tempresult} or using a latex-conforming syntax, getMaximumWidth{cmdOne,cmdTwo,cmdThree}setlength{maximumWidth}{tempresult}

    – David Carlisle
    9 hours ago













  • That is exactly why pgfmathparse leaves its answer in pgfmathresult

    – David Carlisle
    8 hours ago











  • Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.

    – Iskustvo
    8 hours ago














2












2








2








I have a problem with capturing returned value of my command.



Here is my preamble with command definition:



documentclass[convert={density=300,size=800x600,outext=.png}]{standalone}
usepackage[utf8]{inputenc}
usepackage{tikz}

% Font used for writing commands.
defcmdFont{fontsize{10}{12}selectfont}

% Commands.
defcmdOne {cmdFont aaa}
defcmdTwo {cmdFont bbbbb}
defcmdThree{cmdFont cccc}

% Function which returns maximum width needed to write any of provided arguments.
makeatletter

newlength{textLength@getMaximumWidthHelper}
newlength{textLength@getMaximumWidth}

newcommand{getMaximumWidthHelper}[2]
{%
settowidth{textLength@getMaximumWidthHelper}{pgfinterruptpicture #2endpgfinterruptpicture}%

pgfmathparse{max(#1,textLength@getMaximumWidthHelper)}%
@ifnextcharbgroup{getMaximumWidthHelper{pgfmathresult pt}}{pgfmathresult pt}%
}%

newcommand{getMaximumWidth}[1]
{%
settowidth{textLength@getMaximumWidth}{pgfinterruptpicture #1endpgfinterruptpicture}%
@ifnextcharbgroup{getMaximumWidthHelper{thetextLength@getMaximumWidth}}{thetextLength@getMaximumWidth}%
}%

makeatother


Working example used to test the above command:



begin{document}

getMaximumWidth{cmdOne}
getMaximumWidth{cmdOne}{cmdTwo}
getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}

end{document}


However, when I try to capture the output of getMaximumWidth, it doesn't work as expected.



begin{document}

newlength{maximumWidth}
setlength{maximumWidth}{getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}}
themaximumWidth

end{document}


On the second line, the return value of getMaximumWidth is not captured but instantly printed.

Afterwards I get an error:




! Missing number, treated as
zero.




After that, the third line just prints default value 0.0pt.



What is the proper way to capture the output of getMaximumWidth?



P.S. This is my first time writing Latex document, feel free to point out anything i could've done better.










share|improve this question









New contributor




Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have a problem with capturing returned value of my command.



Here is my preamble with command definition:



documentclass[convert={density=300,size=800x600,outext=.png}]{standalone}
usepackage[utf8]{inputenc}
usepackage{tikz}

% Font used for writing commands.
defcmdFont{fontsize{10}{12}selectfont}

% Commands.
defcmdOne {cmdFont aaa}
defcmdTwo {cmdFont bbbbb}
defcmdThree{cmdFont cccc}

% Function which returns maximum width needed to write any of provided arguments.
makeatletter

newlength{textLength@getMaximumWidthHelper}
newlength{textLength@getMaximumWidth}

newcommand{getMaximumWidthHelper}[2]
{%
settowidth{textLength@getMaximumWidthHelper}{pgfinterruptpicture #2endpgfinterruptpicture}%

pgfmathparse{max(#1,textLength@getMaximumWidthHelper)}%
@ifnextcharbgroup{getMaximumWidthHelper{pgfmathresult pt}}{pgfmathresult pt}%
}%

newcommand{getMaximumWidth}[1]
{%
settowidth{textLength@getMaximumWidth}{pgfinterruptpicture #1endpgfinterruptpicture}%
@ifnextcharbgroup{getMaximumWidthHelper{thetextLength@getMaximumWidth}}{thetextLength@getMaximumWidth}%
}%

makeatother


Working example used to test the above command:



begin{document}

getMaximumWidth{cmdOne}
getMaximumWidth{cmdOne}{cmdTwo}
getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}

end{document}


However, when I try to capture the output of getMaximumWidth, it doesn't work as expected.



begin{document}

newlength{maximumWidth}
setlength{maximumWidth}{getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}}
themaximumWidth

end{document}


On the second line, the return value of getMaximumWidth is not captured but instantly printed.

Afterwards I get an error:




! Missing number, treated as
zero.




After that, the third line just prints default value 0.0pt.



What is the proper way to capture the output of getMaximumWidth?



P.S. This is my first time writing Latex document, feel free to point out anything i could've done better.







tikz-pgf lengths






share|improve this question









New contributor




Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 8 hours ago









David Carlisle

501k4211471897




501k4211471897






New contributor




Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 11 hours ago









IskustvoIskustvo

1133




1133




New contributor




Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Iskustvo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1





    while @ifnextcharbgroup works you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments using {} delimiters and a variable number of optional arguments which use delimiters. You have defined a command with optional {} arguments which is wrong.

    – David Carlisle
    10 hours ago













  • macros do not have return values, your getMaximumWidth expands to a series of assignments so is not a length that can be used in setlength, you need to define it to leave a length in some command, say tempresult then use getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}setlength{maximumWidth}{tempresult} or using a latex-conforming syntax, getMaximumWidth{cmdOne,cmdTwo,cmdThree}setlength{maximumWidth}{tempresult}

    – David Carlisle
    9 hours ago













  • That is exactly why pgfmathparse leaves its answer in pgfmathresult

    – David Carlisle
    8 hours ago











  • Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.

    – Iskustvo
    8 hours ago














  • 1





    while @ifnextcharbgroup works you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments using {} delimiters and a variable number of optional arguments which use delimiters. You have defined a command with optional {} arguments which is wrong.

    – David Carlisle
    10 hours ago













  • macros do not have return values, your getMaximumWidth expands to a series of assignments so is not a length that can be used in setlength, you need to define it to leave a length in some command, say tempresult then use getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}setlength{maximumWidth}{tempresult} or using a latex-conforming syntax, getMaximumWidth{cmdOne,cmdTwo,cmdThree}setlength{maximumWidth}{tempresult}

    – David Carlisle
    9 hours ago













  • That is exactly why pgfmathparse leaves its answer in pgfmathresult

    – David Carlisle
    8 hours ago











  • Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.

    – Iskustvo
    8 hours ago








1




1





while @ifnextcharbgroup works you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments using {} delimiters and a variable number of optional arguments which use delimiters. You have defined a command with optional {} arguments which is wrong.

– David Carlisle
10 hours ago







while @ifnextcharbgroup works you should almost never do it as it results in commands that fail to obey latex syntax conventions. All latex commands have a fixed number of arguments using {} delimiters and a variable number of optional arguments which use delimiters. You have defined a command with optional {} arguments which is wrong.

– David Carlisle
10 hours ago















macros do not have return values, your getMaximumWidth expands to a series of assignments so is not a length that can be used in setlength, you need to define it to leave a length in some command, say tempresult then use getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}setlength{maximumWidth}{tempresult} or using a latex-conforming syntax, getMaximumWidth{cmdOne,cmdTwo,cmdThree}setlength{maximumWidth}{tempresult}

– David Carlisle
9 hours ago







macros do not have return values, your getMaximumWidth expands to a series of assignments so is not a length that can be used in setlength, you need to define it to leave a length in some command, say tempresult then use getMaximumWidth{cmdOne}{cmdTwo}{cmdThree}setlength{maximumWidth}{tempresult} or using a latex-conforming syntax, getMaximumWidth{cmdOne,cmdTwo,cmdThree}setlength{maximumWidth}{tempresult}

– David Carlisle
9 hours ago















That is exactly why pgfmathparse leaves its answer in pgfmathresult

– David Carlisle
8 hours ago





That is exactly why pgfmathparse leaves its answer in pgfmathresult

– David Carlisle
8 hours ago













Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.

– Iskustvo
8 hours ago





Thanks a lot! I am not able to test everything at the moment, but your solution seems a lot easier and can be used as I intended.

– Iskustvo
8 hours ago










2 Answers
2






active

oldest

votes


















4














I would write this something like



enter image description here



documentclass{article}

newcommandcmdFont{fontsize{10}{12}selectfont}% this is the default anyway

% Commands.
newcommandcmdOne {cmdFont aaa}
newcommandcmdTwo {cmdFont bbbbb}
newcommandcmdThree{cmdFont cccc}


newlength{maximumWidth}

newcommand{getMaximumWidth}[1]{%
settowidthmaximumWidth{begin{tabular}{@{}l@{}}#1end{tabular}}}

begin{document}

getMaximumWidth{cmdOne\ cmdTwo\ cmdThree}

themaximumWidth

end{document}





share|improve this answer































    3














    I'd generalize settowidth and, by the way, get also height and depth for free.



    documentclass{article}
    usepackage{xparse}

    ExplSyntaxOn
    NewDocumentCommand{settomaximumwidth}{mm}
    {% #1 = length, #2 = comma separated list of objects
    iskustvo_settomaxdim:Nnn settowidth { #1 } { #2 }
    }
    NewDocumentCommand{settomaximumheight}{mm}
    {% #1 = length, #2 = comma separated list of objects
    iskustvo_settomaxdim:Nnn settoheight { #1 } { #2 }
    }
    NewDocumentCommand{settomaximumdepth}{mm}
    {% #1 = length, #2 = comma separated list of objects
    iskustvo_settomaxdim:Nnn settodepth { #1 } { #2 }
    }

    dim_new:N l__iskustvo_tempa_dim
    dim_new:N l__iskustvo_tempb_dim
    tl_new:N l__iskustvo_temp_tl

    cs_new_protected:Nn iskustvo_settomaxdim:Nnn
    {
    dim_zero:N l__iskustvo_tempa_dim
    clist_map_variable:nNn { #3 } l__iskustvo_temp_tl
    { __iskustvo_measure:N #1 }
    dim_set_eq:NN #2 l__iskustvo_tempa_dim
    }
    cs_new_protected:Nn __iskustvo_measure:N
    {
    #1{l__iskustvo_tempb_dim}{l__iskustvo_temp_tl}
    dim_set:Nn l__iskustvo_tempa_dim
    {
    dim_max:nn { l__iskustvo_tempa_dim } { l__iskustvo_tempb_dim }
    }
    }
    ExplSyntaxOff

    % Font used for writing commands.
    defcmdFont{fontsize{10}{12}selectfont}

    % Commands.
    defcmdOne {cmdFont aaa}
    defcmdTwo {cmdFont bbbbb}
    defcmdThree{cmdFont cccc}

    begin{document}

    newlength{test}

    settomaximumwidth{test}{cmdOne,cmdTwo,cmdThree}
    thetest

    settomaximumheight{test}{cmdOne,cmdTwo,cmdThree}
    thetest

    settomaximumdepth{test}{cmdOne,cmdTwo,cmdThree}
    thetest

    end{document}


    enter image description here






    share|improve this answer



















    • 1





      Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.

      – Iskustvo
      7 hours ago












    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
    });


    }
    });






    Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f487375%2fhow-to-properly-capture-return-value-of-a-command%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    I would write this something like



    enter image description here



    documentclass{article}

    newcommandcmdFont{fontsize{10}{12}selectfont}% this is the default anyway

    % Commands.
    newcommandcmdOne {cmdFont aaa}
    newcommandcmdTwo {cmdFont bbbbb}
    newcommandcmdThree{cmdFont cccc}


    newlength{maximumWidth}

    newcommand{getMaximumWidth}[1]{%
    settowidthmaximumWidth{begin{tabular}{@{}l@{}}#1end{tabular}}}

    begin{document}

    getMaximumWidth{cmdOne\ cmdTwo\ cmdThree}

    themaximumWidth

    end{document}





    share|improve this answer




























      4














      I would write this something like



      enter image description here



      documentclass{article}

      newcommandcmdFont{fontsize{10}{12}selectfont}% this is the default anyway

      % Commands.
      newcommandcmdOne {cmdFont aaa}
      newcommandcmdTwo {cmdFont bbbbb}
      newcommandcmdThree{cmdFont cccc}


      newlength{maximumWidth}

      newcommand{getMaximumWidth}[1]{%
      settowidthmaximumWidth{begin{tabular}{@{}l@{}}#1end{tabular}}}

      begin{document}

      getMaximumWidth{cmdOne\ cmdTwo\ cmdThree}

      themaximumWidth

      end{document}





      share|improve this answer


























        4












        4








        4







        I would write this something like



        enter image description here



        documentclass{article}

        newcommandcmdFont{fontsize{10}{12}selectfont}% this is the default anyway

        % Commands.
        newcommandcmdOne {cmdFont aaa}
        newcommandcmdTwo {cmdFont bbbbb}
        newcommandcmdThree{cmdFont cccc}


        newlength{maximumWidth}

        newcommand{getMaximumWidth}[1]{%
        settowidthmaximumWidth{begin{tabular}{@{}l@{}}#1end{tabular}}}

        begin{document}

        getMaximumWidth{cmdOne\ cmdTwo\ cmdThree}

        themaximumWidth

        end{document}





        share|improve this answer













        I would write this something like



        enter image description here



        documentclass{article}

        newcommandcmdFont{fontsize{10}{12}selectfont}% this is the default anyway

        % Commands.
        newcommandcmdOne {cmdFont aaa}
        newcommandcmdTwo {cmdFont bbbbb}
        newcommandcmdThree{cmdFont cccc}


        newlength{maximumWidth}

        newcommand{getMaximumWidth}[1]{%
        settowidthmaximumWidth{begin{tabular}{@{}l@{}}#1end{tabular}}}

        begin{document}

        getMaximumWidth{cmdOne\ cmdTwo\ cmdThree}

        themaximumWidth

        end{document}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 8 hours ago









        David CarlisleDavid Carlisle

        501k4211471897




        501k4211471897























            3














            I'd generalize settowidth and, by the way, get also height and depth for free.



            documentclass{article}
            usepackage{xparse}

            ExplSyntaxOn
            NewDocumentCommand{settomaximumwidth}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settowidth { #1 } { #2 }
            }
            NewDocumentCommand{settomaximumheight}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settoheight { #1 } { #2 }
            }
            NewDocumentCommand{settomaximumdepth}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settodepth { #1 } { #2 }
            }

            dim_new:N l__iskustvo_tempa_dim
            dim_new:N l__iskustvo_tempb_dim
            tl_new:N l__iskustvo_temp_tl

            cs_new_protected:Nn iskustvo_settomaxdim:Nnn
            {
            dim_zero:N l__iskustvo_tempa_dim
            clist_map_variable:nNn { #3 } l__iskustvo_temp_tl
            { __iskustvo_measure:N #1 }
            dim_set_eq:NN #2 l__iskustvo_tempa_dim
            }
            cs_new_protected:Nn __iskustvo_measure:N
            {
            #1{l__iskustvo_tempb_dim}{l__iskustvo_temp_tl}
            dim_set:Nn l__iskustvo_tempa_dim
            {
            dim_max:nn { l__iskustvo_tempa_dim } { l__iskustvo_tempb_dim }
            }
            }
            ExplSyntaxOff

            % Font used for writing commands.
            defcmdFont{fontsize{10}{12}selectfont}

            % Commands.
            defcmdOne {cmdFont aaa}
            defcmdTwo {cmdFont bbbbb}
            defcmdThree{cmdFont cccc}

            begin{document}

            newlength{test}

            settomaximumwidth{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            settomaximumheight{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            settomaximumdepth{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            end{document}


            enter image description here






            share|improve this answer



















            • 1





              Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.

              – Iskustvo
              7 hours ago
















            3














            I'd generalize settowidth and, by the way, get also height and depth for free.



            documentclass{article}
            usepackage{xparse}

            ExplSyntaxOn
            NewDocumentCommand{settomaximumwidth}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settowidth { #1 } { #2 }
            }
            NewDocumentCommand{settomaximumheight}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settoheight { #1 } { #2 }
            }
            NewDocumentCommand{settomaximumdepth}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settodepth { #1 } { #2 }
            }

            dim_new:N l__iskustvo_tempa_dim
            dim_new:N l__iskustvo_tempb_dim
            tl_new:N l__iskustvo_temp_tl

            cs_new_protected:Nn iskustvo_settomaxdim:Nnn
            {
            dim_zero:N l__iskustvo_tempa_dim
            clist_map_variable:nNn { #3 } l__iskustvo_temp_tl
            { __iskustvo_measure:N #1 }
            dim_set_eq:NN #2 l__iskustvo_tempa_dim
            }
            cs_new_protected:Nn __iskustvo_measure:N
            {
            #1{l__iskustvo_tempb_dim}{l__iskustvo_temp_tl}
            dim_set:Nn l__iskustvo_tempa_dim
            {
            dim_max:nn { l__iskustvo_tempa_dim } { l__iskustvo_tempb_dim }
            }
            }
            ExplSyntaxOff

            % Font used for writing commands.
            defcmdFont{fontsize{10}{12}selectfont}

            % Commands.
            defcmdOne {cmdFont aaa}
            defcmdTwo {cmdFont bbbbb}
            defcmdThree{cmdFont cccc}

            begin{document}

            newlength{test}

            settomaximumwidth{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            settomaximumheight{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            settomaximumdepth{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            end{document}


            enter image description here






            share|improve this answer



















            • 1





              Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.

              – Iskustvo
              7 hours ago














            3












            3








            3







            I'd generalize settowidth and, by the way, get also height and depth for free.



            documentclass{article}
            usepackage{xparse}

            ExplSyntaxOn
            NewDocumentCommand{settomaximumwidth}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settowidth { #1 } { #2 }
            }
            NewDocumentCommand{settomaximumheight}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settoheight { #1 } { #2 }
            }
            NewDocumentCommand{settomaximumdepth}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settodepth { #1 } { #2 }
            }

            dim_new:N l__iskustvo_tempa_dim
            dim_new:N l__iskustvo_tempb_dim
            tl_new:N l__iskustvo_temp_tl

            cs_new_protected:Nn iskustvo_settomaxdim:Nnn
            {
            dim_zero:N l__iskustvo_tempa_dim
            clist_map_variable:nNn { #3 } l__iskustvo_temp_tl
            { __iskustvo_measure:N #1 }
            dim_set_eq:NN #2 l__iskustvo_tempa_dim
            }
            cs_new_protected:Nn __iskustvo_measure:N
            {
            #1{l__iskustvo_tempb_dim}{l__iskustvo_temp_tl}
            dim_set:Nn l__iskustvo_tempa_dim
            {
            dim_max:nn { l__iskustvo_tempa_dim } { l__iskustvo_tempb_dim }
            }
            }
            ExplSyntaxOff

            % Font used for writing commands.
            defcmdFont{fontsize{10}{12}selectfont}

            % Commands.
            defcmdOne {cmdFont aaa}
            defcmdTwo {cmdFont bbbbb}
            defcmdThree{cmdFont cccc}

            begin{document}

            newlength{test}

            settomaximumwidth{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            settomaximumheight{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            settomaximumdepth{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            end{document}


            enter image description here






            share|improve this answer













            I'd generalize settowidth and, by the way, get also height and depth for free.



            documentclass{article}
            usepackage{xparse}

            ExplSyntaxOn
            NewDocumentCommand{settomaximumwidth}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settowidth { #1 } { #2 }
            }
            NewDocumentCommand{settomaximumheight}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settoheight { #1 } { #2 }
            }
            NewDocumentCommand{settomaximumdepth}{mm}
            {% #1 = length, #2 = comma separated list of objects
            iskustvo_settomaxdim:Nnn settodepth { #1 } { #2 }
            }

            dim_new:N l__iskustvo_tempa_dim
            dim_new:N l__iskustvo_tempb_dim
            tl_new:N l__iskustvo_temp_tl

            cs_new_protected:Nn iskustvo_settomaxdim:Nnn
            {
            dim_zero:N l__iskustvo_tempa_dim
            clist_map_variable:nNn { #3 } l__iskustvo_temp_tl
            { __iskustvo_measure:N #1 }
            dim_set_eq:NN #2 l__iskustvo_tempa_dim
            }
            cs_new_protected:Nn __iskustvo_measure:N
            {
            #1{l__iskustvo_tempb_dim}{l__iskustvo_temp_tl}
            dim_set:Nn l__iskustvo_tempa_dim
            {
            dim_max:nn { l__iskustvo_tempa_dim } { l__iskustvo_tempb_dim }
            }
            }
            ExplSyntaxOff

            % Font used for writing commands.
            defcmdFont{fontsize{10}{12}selectfont}

            % Commands.
            defcmdOne {cmdFont aaa}
            defcmdTwo {cmdFont bbbbb}
            defcmdThree{cmdFont cccc}

            begin{document}

            newlength{test}

            settomaximumwidth{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            settomaximumheight{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            settomaximumdepth{test}{cmdOne,cmdTwo,cmdThree}
            thetest

            end{document}


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 7 hours ago









            egregegreg

            736k8919353261




            736k8919353261








            • 1





              Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.

              – Iskustvo
              7 hours ago














            • 1





              Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.

              – Iskustvo
              7 hours ago








            1




            1





            Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.

            – Iskustvo
            7 hours ago





            Thank you! I won't lie, I have absolutely no idea what you did, but the usage at the end is pretty neat.

            – Iskustvo
            7 hours ago










            Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.













            Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.












            Iskustvo is a new contributor. Be nice, and check out our Code of Conduct.
















            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%2f487375%2fhow-to-properly-capture-return-value-of-a-command%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

            數位音樂下載

            When can things happen in Etherscan, such as the picture below?

            格利澤436b