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?
skipnordimensionetc.? – Marco Daniel May 25 '13 at 08:09expl3usingexpl3's possibilities seems natural. For a package written in LaTeX2e syntax I'd probably useetoolbox's wrappers for the eTeX primitives.etoolboxhas very handy 2e writing tools, anyway. – cgnieder May 25 '13 at 09:30expl3. I think this is clear. As I wrote my packagemdframedI useddimexpr. At comp.text.tex a guy told me thatdimexpris 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 09:38expl3also wraps around the eTeX primitives. – cgnieder May 25 '13 at 09:43expl3is really using a very thin wrapper around the e-TeX primitives here (with the exception offpoperations, 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