What are the differences between \newdimen, \newskip, and\newlength?
When should I use each of them? Please give me a non-trivial example for each case.
What are the differences between \newdimen, \newskip, and\newlength?
When should I use each of them? Please give me a non-trivial example for each case.
\newlength is the LaTeX2e version of \newskip. It has extra check to avoid redefinition or illegal name. In LaTeX2e, it is defined
\def\newlength#1{\@ifdefinable#1{\newskip#1}}
For example,
\newlength\foo % OK
\newlength\foo % redefinition ERROR!
\newlength\endbar % ERROR: \endbar is illegal command name in LaTeX2e.
% It is reserved by LaTeX kernel to define bar environment together with \bar
\newskip only allocates a new skip (glue, or rubber space) register. If you use low-level TeX command \newskip instead, no error message will be shown.
You should always use \newlength rather than \newskip in LaTeX.
\newdimen is another low-level TeX macro that allocates a new dimension register, it is different with \newskip. They have different meaning. For example,
\newdimen\rigidlength
\rigidlength=2pt % or \setlength{\rigidlength}{2pt}
\newlength\rubberlength % you cannot use \newdimen here
\setlength{\rubberlength}{2pt plus 2pt minus 1pt}
\newlength is LaTeX syntax and always a skip register:
\documentclass{article}
\newskip\foo
\foo=1cm plus 1mm minus 3mm
\newdimen\bar
\bar=1cm %plus 1mm minus 3mm % not possible
\newlength\baz
\setlength\baz{1cm plus 1mm minus 3mm}
\begin{document}
\the\foo \par
\the\bar \par
\the\baz
\end{document}
\newdimen,\newlengthand\newskip? – Display Name Jul 12 '11 at 12:41\newlength. Use\newdimenfor lower-level code if you are sure that you only need a rigid dimension.\newskipalso allows you to add stretch-amounts so the value can be a little higher or lower if required, which is useful for inter-word and inter-paragraph skips to fill the given size better. – Martin Scharrer Jul 12 '11 at 12:54\newlengthtests if the command (length) already exists,\newdimenandnewskipoverwrite an already existing definition – Jul 12 '11 at 12:59