Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Question has been written above.

share|improve this question

2 Answers 2

up vote 12 down vote accepted

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

share|improve this answer
    
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

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.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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