14

Question has been written above.

14

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. :-) – xport Dec 26 '10 at 19:40
13

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{\fboxset\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.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.