Calculations on variables using LaTeX
Clash 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.
calculations
New contributor
add a comment |Â
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.
calculations
New contributor
1
LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such asfp
,xfp
, ortikz
. 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
add a comment |Â
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.
calculations
New contributor
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
calculations
New contributor
New contributor
New contributor
asked 4 hours ago
joseldsm
253
253
New contributor
New contributor
1
LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such asfp
,xfp
, ortikz
. 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
add a comment |Â
1
LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such asfp
,xfp
, ortikz
. 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
add a comment |Â
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!
Works great and very simple to use, thanks !
â joseldsm
2 hours ago
add a comment |Â
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
.
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
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
add a comment |Â
up vote
1
down vote
xfp
provides a number of f
loating p
oint operations:
documentclassarticle
usepackagexfp
begindocument
newcommandlengthHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger
$verb|lengthHeatExchanger| = lengthHeatExchanger$
$verb|heightHeatExchanger| = heightHeatExchanger$
$verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$
enddocument
add a comment |Â
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!
Works great and very simple to use, thanks !
â joseldsm
2 hours ago
add a comment |Â
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!
Works great and very simple to use, thanks !
â joseldsm
2 hours ago
add a comment |Â
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!
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!
answered 3 hours ago
Lord Nexprex
583
583
Works great and very simple to use, thanks !
â joseldsm
2 hours ago
add a comment |Â
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
add a comment |Â
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
.
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
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
add a comment |Â
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
.
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
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
add a comment |Â
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
.
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
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
.
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
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
add a comment |Â
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
add a comment |Â
up vote
1
down vote
xfp
provides a number of f
loating p
oint operations:
documentclassarticle
usepackagexfp
begindocument
newcommandlengthHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger
$verb|lengthHeatExchanger| = lengthHeatExchanger$
$verb|heightHeatExchanger| = heightHeatExchanger$
$verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$
enddocument
add a comment |Â
up vote
1
down vote
xfp
provides a number of f
loating p
oint operations:
documentclassarticle
usepackagexfp
begindocument
newcommandlengthHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger
$verb|lengthHeatExchanger| = lengthHeatExchanger$
$verb|heightHeatExchanger| = heightHeatExchanger$
$verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$
enddocument
add a comment |Â
up vote
1
down vote
up vote
1
down vote
xfp
provides a number of f
loating p
oint operations:
documentclassarticle
usepackagexfp
begindocument
newcommandlengthHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger
$verb|lengthHeatExchanger| = lengthHeatExchanger$
$verb|heightHeatExchanger| = heightHeatExchanger$
$verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$
enddocument
xfp
provides a number of f
loating p
oint operations:
documentclassarticle
usepackagexfp
begindocument
newcommandlengthHeatExchanger0.820
newcommandheightHeatExchanger1.081
newcommandareaHeatExchangerfpevallengthHeatExchanger * heightHeatExchanger
$verb|lengthHeatExchanger| = lengthHeatExchanger$
$verb|heightHeatExchanger| = heightHeatExchanger$
$verb|lengthHeatExchanger| times verb|heightHeatExchanger| = areaHeatExchanger$
enddocument
answered 2 hours ago
Werner
423k589261593
423k589261593
add a comment |Â
add a comment |Â
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.
joseldsm is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
LaTeX has limited ability to do math calculations. Best way is to employ a package that does floating math, such as
fp
,xfp
, ortikz
. 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