Calculations on variables using LaTeX

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I'm trying to do some basic calculations using values stored on a command, but it doesn't do the calculation:



newcommandlenghtHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerlenghtHeatExchanger*heightHeatExchanger


Is there a simple way to do that using LaTeX ?



Thank you.










share|improve this question







New contributor




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















  • 1




    LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such as fp, xfp, or tikz. By the way, length is spelled length rather than lenght.
    – Steven B. Segletes
    4 hours ago











  • Can you please show an example of how you'd like to use such macros?
    – egreg
    4 hours ago














up vote
3
down vote

favorite












I'm trying to do some basic calculations using values stored on a command, but it doesn't do the calculation:



newcommandlenghtHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerlenghtHeatExchanger*heightHeatExchanger


Is there a simple way to do that using LaTeX ?



Thank you.










share|improve this question







New contributor




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















  • 1




    LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such as fp, xfp, or tikz. By the way, length is spelled length rather than lenght.
    – Steven B. Segletes
    4 hours ago











  • Can you please show an example of how you'd like to use such macros?
    – egreg
    4 hours ago












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I'm trying to do some basic calculations using values stored on a command, but it doesn't do the calculation:



newcommandlenghtHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerlenghtHeatExchanger*heightHeatExchanger


Is there a simple way to do that using LaTeX ?



Thank you.










share|improve this question







New contributor




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











I'm trying to do some basic calculations using values stored on a command, but it doesn't do the calculation:



newcommandlenghtHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerlenghtHeatExchanger*heightHeatExchanger


Is there a simple way to do that using LaTeX ?



Thank you.







calculations






share|improve this question







New contributor




joseldsm 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




joseldsm 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






New contributor




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









asked 4 hours ago









joseldsm

253




253




New contributor




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





New contributor





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






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







  • 1




    LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such as fp, xfp, or tikz. By the way, length is spelled length rather than lenght.
    – Steven B. Segletes
    4 hours ago











  • Can you please show an example of how you'd like to use such macros?
    – egreg
    4 hours ago












  • 1




    LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such as fp, xfp, or tikz. By the way, length is spelled length rather than lenght.
    – Steven B. Segletes
    4 hours ago











  • Can you please show an example of how you'd like to use such macros?
    – egreg
    4 hours ago







1




1




LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such as fp, xfp, or tikz. By the way, length is spelled length rather than lenght.
– Steven B. Segletes
4 hours ago





LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such as fp, xfp, or tikz. By the way, length is spelled length rather than lenght.
– Steven B. Segletes
4 hours ago













Can you please show an example of how you'd like to use such macros?
– egreg
4 hours ago




Can you please show an example of how you'd like to use such macros?
– egreg
4 hours ago










3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










I will suggest to use the calculator package and its MULTIPLY command, see documentation here.
BUT: I think that if you could switch to LuaLaTeX it would surely be the best solution!






share|improve this answer




















  • Works great and very simple to use, thanks !
    – joseldsm
    2 hours ago

















up vote
2
down vote













If you're free to employ LuaLaTeX, performing calculations involving macros doesn't require the loading of any external packages, as the following example shows. The solution method exploits the fact that the argument of directlua is expanded automatically. In the current example, docalclength*height is expanded to directluatex.sprint(2.5*4); LuaTeX performs the calculation, and the result (10) replaces docalclength*height; hence, it works out to newcommandarea10.



enter image description here



Of course, if you needn't store the value of the calculation, you could simply run $length times height = docalclength*height$.



documentclassarticle
% set up a LaTeX macro to interface with Lua:
newcommanddocalc[1]directluatex.sprint(#1)
begindocument
newcommandlength2.5
newcommandheight4
newcommandareadocalclength*height

$length times height = area$
enddocument





share|improve this answer




















  • Thank you ! I dont know why it doesnt work. I think it's because I never used LuaLaTeX and I'm not sure exaclty how to use it and what comes with it.
    – joseldsm
    2 hours ago










  • @joseldsm - I assume your TeX system and front-end ediror are set up to compile tex documents with pdfLaTeX. How to switch compilation from pdfLaTeX to LuaLaTeX depends primarily on your editor. Which editing program do you employ?
    – Mico
    2 hours ago


















up vote
1
down vote













xfp provides a number of floating point operations:



enter image description here



documentclassarticle

usepackagexfp

begindocument

newcommandlengthHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger

$verb|lengthHeatExchanger| = lengthHeatExchanger$

$verb|heightHeatExchanger| = heightHeatExchanger$

$verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$

enddocument





share|improve this answer




















    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: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    joseldsm 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%2f453454%2fcalculations-on-variables-using-latex%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    I will suggest to use the calculator package and its MULTIPLY command, see documentation here.
    BUT: I think that if you could switch to LuaLaTeX it would surely be the best solution!






    share|improve this answer




















    • Works great and very simple to use, thanks !
      – joseldsm
      2 hours ago














    up vote
    1
    down vote



    accepted










    I will suggest to use the calculator package and its MULTIPLY command, see documentation here.
    BUT: I think that if you could switch to LuaLaTeX it would surely be the best solution!






    share|improve this answer




















    • Works great and very simple to use, thanks !
      – joseldsm
      2 hours ago












    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    I will suggest to use the calculator package and its MULTIPLY command, see documentation here.
    BUT: I think that if you could switch to LuaLaTeX it would surely be the best solution!






    share|improve this answer












    I will suggest to use the calculator package and its MULTIPLY command, see documentation here.
    BUT: I think that if you could switch to LuaLaTeX it would surely be the best solution!







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 3 hours ago









    Lord Nexprex

    583




    583











    • Works great and very simple to use, thanks !
      – joseldsm
      2 hours ago
















    • Works great and very simple to use, thanks !
      – joseldsm
      2 hours ago















    Works great and very simple to use, thanks !
    – joseldsm
    2 hours ago




    Works great and very simple to use, thanks !
    – joseldsm
    2 hours ago










    up vote
    2
    down vote













    If you're free to employ LuaLaTeX, performing calculations involving macros doesn't require the loading of any external packages, as the following example shows. The solution method exploits the fact that the argument of directlua is expanded automatically. In the current example, docalclength*height is expanded to directluatex.sprint(2.5*4); LuaTeX performs the calculation, and the result (10) replaces docalclength*height; hence, it works out to newcommandarea10.



    enter image description here



    Of course, if you needn't store the value of the calculation, you could simply run $length times height = docalclength*height$.



    documentclassarticle
    % set up a LaTeX macro to interface with Lua:
    newcommanddocalc[1]directluatex.sprint(#1)
    begindocument
    newcommandlength2.5
    newcommandheight4
    newcommandareadocalclength*height

    $length times height = area$
    enddocument





    share|improve this answer




















    • Thank you ! I dont know why it doesnt work. I think it's because I never used LuaLaTeX and I'm not sure exaclty how to use it and what comes with it.
      – joseldsm
      2 hours ago










    • @joseldsm - I assume your TeX system and front-end ediror are set up to compile tex documents with pdfLaTeX. How to switch compilation from pdfLaTeX to LuaLaTeX depends primarily on your editor. Which editing program do you employ?
      – Mico
      2 hours ago















    up vote
    2
    down vote













    If you're free to employ LuaLaTeX, performing calculations involving macros doesn't require the loading of any external packages, as the following example shows. The solution method exploits the fact that the argument of directlua is expanded automatically. In the current example, docalclength*height is expanded to directluatex.sprint(2.5*4); LuaTeX performs the calculation, and the result (10) replaces docalclength*height; hence, it works out to newcommandarea10.



    enter image description here



    Of course, if you needn't store the value of the calculation, you could simply run $length times height = docalclength*height$.



    documentclassarticle
    % set up a LaTeX macro to interface with Lua:
    newcommanddocalc[1]directluatex.sprint(#1)
    begindocument
    newcommandlength2.5
    newcommandheight4
    newcommandareadocalclength*height

    $length times height = area$
    enddocument





    share|improve this answer




















    • Thank you ! I dont know why it doesnt work. I think it's because I never used LuaLaTeX and I'm not sure exaclty how to use it and what comes with it.
      – joseldsm
      2 hours ago










    • @joseldsm - I assume your TeX system and front-end ediror are set up to compile tex documents with pdfLaTeX. How to switch compilation from pdfLaTeX to LuaLaTeX depends primarily on your editor. Which editing program do you employ?
      – Mico
      2 hours ago













    up vote
    2
    down vote










    up vote
    2
    down vote









    If you're free to employ LuaLaTeX, performing calculations involving macros doesn't require the loading of any external packages, as the following example shows. The solution method exploits the fact that the argument of directlua is expanded automatically. In the current example, docalclength*height is expanded to directluatex.sprint(2.5*4); LuaTeX performs the calculation, and the result (10) replaces docalclength*height; hence, it works out to newcommandarea10.



    enter image description here



    Of course, if you needn't store the value of the calculation, you could simply run $length times height = docalclength*height$.



    documentclassarticle
    % set up a LaTeX macro to interface with Lua:
    newcommanddocalc[1]directluatex.sprint(#1)
    begindocument
    newcommandlength2.5
    newcommandheight4
    newcommandareadocalclength*height

    $length times height = area$
    enddocument





    share|improve this answer












    If you're free to employ LuaLaTeX, performing calculations involving macros doesn't require the loading of any external packages, as the following example shows. The solution method exploits the fact that the argument of directlua is expanded automatically. In the current example, docalclength*height is expanded to directluatex.sprint(2.5*4); LuaTeX performs the calculation, and the result (10) replaces docalclength*height; hence, it works out to newcommandarea10.



    enter image description here



    Of course, if you needn't store the value of the calculation, you could simply run $length times height = docalclength*height$.



    documentclassarticle
    % set up a LaTeX macro to interface with Lua:
    newcommanddocalc[1]directluatex.sprint(#1)
    begindocument
    newcommandlength2.5
    newcommandheight4
    newcommandareadocalclength*height

    $length times height = area$
    enddocument






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 3 hours ago









    Mico

    265k30355735




    265k30355735











    • Thank you ! I dont know why it doesnt work. I think it's because I never used LuaLaTeX and I'm not sure exaclty how to use it and what comes with it.
      – joseldsm
      2 hours ago










    • @joseldsm - I assume your TeX system and front-end ediror are set up to compile tex documents with pdfLaTeX. How to switch compilation from pdfLaTeX to LuaLaTeX depends primarily on your editor. Which editing program do you employ?
      – Mico
      2 hours ago

















    • Thank you ! I dont know why it doesnt work. I think it's because I never used LuaLaTeX and I'm not sure exaclty how to use it and what comes with it.
      – joseldsm
      2 hours ago










    • @joseldsm - I assume your TeX system and front-end ediror are set up to compile tex documents with pdfLaTeX. How to switch compilation from pdfLaTeX to LuaLaTeX depends primarily on your editor. Which editing program do you employ?
      – Mico
      2 hours ago
















    Thank you ! I dont know why it doesnt work. I think it's because I never used LuaLaTeX and I'm not sure exaclty how to use it and what comes with it.
    – joseldsm
    2 hours ago




    Thank you ! I dont know why it doesnt work. I think it's because I never used LuaLaTeX and I'm not sure exaclty how to use it and what comes with it.
    – joseldsm
    2 hours ago












    @joseldsm - I assume your TeX system and front-end ediror are set up to compile tex documents with pdfLaTeX. How to switch compilation from pdfLaTeX to LuaLaTeX depends primarily on your editor. Which editing program do you employ?
    – Mico
    2 hours ago





    @joseldsm - I assume your TeX system and front-end ediror are set up to compile tex documents with pdfLaTeX. How to switch compilation from pdfLaTeX to LuaLaTeX depends primarily on your editor. Which editing program do you employ?
    – Mico
    2 hours ago











    up vote
    1
    down vote













    xfp provides a number of floating point operations:



    enter image description here



    documentclassarticle

    usepackagexfp

    begindocument

    newcommandlengthHeatExchanger0.820
    newcommandheightHeatExchanger1.081
    newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger

    $verb|lengthHeatExchanger| = lengthHeatExchanger$

    $verb|heightHeatExchanger| = heightHeatExchanger$

    $verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$

    enddocument





    share|improve this answer
























      up vote
      1
      down vote













      xfp provides a number of floating point operations:



      enter image description here



      documentclassarticle

      usepackagexfp

      begindocument

      newcommandlengthHeatExchanger0.820
      newcommandheightHeatExchanger1.081
      newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger

      $verb|lengthHeatExchanger| = lengthHeatExchanger$

      $verb|heightHeatExchanger| = heightHeatExchanger$

      $verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$

      enddocument





      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        xfp provides a number of floating point operations:



        enter image description here



        documentclassarticle

        usepackagexfp

        begindocument

        newcommandlengthHeatExchanger0.820
        newcommandheightHeatExchanger1.081
        newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger

        $verb|lengthHeatExchanger| = lengthHeatExchanger$

        $verb|heightHeatExchanger| = heightHeatExchanger$

        $verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$

        enddocument





        share|improve this answer












        xfp provides a number of floating point operations:



        enter image description here



        documentclassarticle

        usepackagexfp

        begindocument

        newcommandlengthHeatExchanger0.820
        newcommandheightHeatExchanger1.081
        newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger

        $verb|lengthHeatExchanger| = lengthHeatExchanger$

        $verb|heightHeatExchanger| = heightHeatExchanger$

        $verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$

        enddocument






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        Werner

        423k589261593




        423k589261593




















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









             

            draft saved


            draft discarded


















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












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











            joseldsm 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%2f453454%2fcalculations-on-variables-using-latex%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery