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 5
eTeX
eTeX supports the commands \dimexpr
and \numexpr
. This simplify the example above as follows:
\@tempdima=\dimexpr (35pt+10pt)/5 \relax
LaTeX3
LaTeX3 can be compared with eTeX.
\dim_set:Nn \l_tmpa_dim { (35pt+10pt) / 5 }
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?
skip
nordimension
etc.? – Marco Daniel May 25 '13 at 8:09expl3
usingexpl3
's possibilities seems natural. For a package written in LaTeX2e syntax I'd probably useetoolbox
's wrappers for the eTeX primitives.etoolbox
has very handy 2e writing tools, anyway. – cgnieder May 25 '13 at 9:30expl3
. I think this is clear. As I wrote my packagemdframed
I useddimexpr
. At comp.text.tex a guy told me thatdimexpr
is too slow and I should use TeX commands. So I switched. Now I want to switch back but is it recommended? – Marco Daniel May 25 '13 at 9:38expl3
is really using a very thin wrapper around the e-TeX primitives here (with the exception offp
operations, where there is no e-TeX support). As such, there will be very little in it performance wise between those two methods. – Joseph Wright♦ May 25 '13 at 14:08