What is the best practice for arithmetic operations specially for package/class writing?
There are some possibilities to execute arithmetic operations inside a package or class.
TeX
TeX supports \advance, \multiply or \divide to execute arithmetic operations. However the syntax is more or less "needs getting used to". Example:
\@tempdima=35pt
\advance\@tempdima by 10pt
\divide\@tempdima by 5pt
eTeX
eTeX supports the commands \dimexpr and \numexpr. This simplify the example above as follows:
\@tempdima=\dimexpr (35pt+10pt)/5pt \relax
LaTeX3
LaTeX3 can be compared with eTeX.
\dim_set:Nn \l_tmpa_dim { (35pt+10pt) / 5pt }
Packages
I know there are some packages which allow arithmetic operations, too. E.g. calc or pgf. Those packages can be compared with eTeX, too.
However what is the recommended way of doing arithmetic operations inside a package/class? What are the benefits/drawbacks of the different approaches?
There are some possibilities to execute arithmetic operations inside a package or class.
TeX
TeX supports \advance, \multiply or \divide to execute arithmetic operations. However the syntax is more or less "needs getting used to". Example:
\@tempdima=35pt
\advance\@tempdima by 10pt
\divide\@tempdima by 5pt
eTeX
eTeX supports the commands \dimexpr and \numexpr. This simplify the example above as follows:
\@tempdima=\dimexpr (35pt+10pt)/5pt \relax
LaTeX3
LaTeX3 can be compared with eTeX.
\dim_set:Nn \l_tmpa_dim { (35pt+10pt) / 5pt }
Packages
I know there are some packages which allow arithmetic operations, too. E.g. calc or pgf. Those packages can be compared with eTeX, too.
However what is the recommended way of doing arithmetic operations inside a package/class? What are the benefits/drawbacks of the different approaches?
No comments:
Post a Comment