Question has been written above.
2 Answers
TeX notation versus LaTeX notation.
\newdimen\myDim \myDim=5cm+\linewidth does not work
\newdimen\myDim \myDim=\dimexpr5cm+\linewidth\relax works with etex
\newlength\myLen \setlength\myLen{5cm+\linewidth} works with package calc
\newlength\myLen \setlength\myLen{\dimexpr5cm+\linewidth} works with etex
myDim=5cm plus 1em does not work, must be a skip instead \newskip\mySkip
\setlength\myLen{5cm plus 1em minus .2ex} works, a LaTeX length is always a skip register
-
thanks for this answer. I will revisit this tomorrow again. It is a bit confusing to read. It is time to sleep. :-) – Display Name Dec 26 '10 at 19:40
To elaborate a bit on what Herbert says, LaTeX 'lengths' are what TeX calls 'skips': lengths with a rubber component. They can therefore be set using the TeX syntax
\fboxsep=1 cm
or the LaTeX syntax
\setlength{\fboxsep}{1 cm}
There are a couple of points to watch here. First, LaTeX inserts a \relax to prevent the code accidentally picking up a 'plus' or 'minus' part. For example
\def\Oops#1{\fboxsep=#1}
\Oops{1 cm} plus some space
will lead TeX is complain that a number is missing, as the 'plus' is interpreted as a stretch component for the skip. The LaTeX solution, which inserts a \relax, is safe. The same can of course be done in TeX macros without LaTeX:
\def\Safe#1{\fboxsep=#1\relax}
\Safe{1 cm} plus some space
Here the 'plus' is not mis-interpreted.
Herbert also points out that the calc package allows calculations as part of the length setting. Personally, I tend to use e-TeX for this:
\def\Safer#1{\fboxsep\glueexpr#1\relax}
In this, the calculation is done by the engine, which is usually a better plan than using macros. (Note though that \glueexpr only does basic arithmetic using (, ), +, -, x and /. The calc package has 'max' and 'min' functions.)
- 259,911
- 34
- 706
- 1,036