3

What is the difference between \skipeval and \dimeval? They appear to produce the same result, but perhaps \dimeval removes the glue?

\rule{\dimeval{ \linewidth plus 1cm minus 1cm - 1cm}}{1pt} a\\
\rule{\skipeval{\linewidth plus 1cm minus 1cm - 1cm}}{1pt} a\\

2 Answers 2

7

They are thin wrappers around the eTeX primitives \dimexpr and \glueexpr

In a dimen context such as a rule length both may be used but compare a skip/glue context such as setting \baselineskip

\documentclass{article}

\begin{document}

\setlength\baselineskip{\skipeval{20pt plus 2pt - 3pt}}
\showthe\baselineskip

\setlength\baselineskip{\dimeval{20pt plus 2pt - 3pt}}
\showthe\baselineskip

\end{document}

shows \skipeval producing 17.0pt plus 2.0pt but \dimeval produces 20.0pt plus 2.0pt and -3pt gets typeset. Actually the \dimeval is terminated by the p of plus but \setlength then absorbs the plus 2pt as a primitive skip component, leaving -3pt as trailing tokens that are typset as text

1
3

\rule is not the best tool for comparing \dimens with \skip's, because the plus or minus specifications are ignored.

The definition of \rule is

\DeclareRobustCommand\rule{\@ifnextchar[\@rule{\@rule[\z@]}}%
 \def\@rule[#1]#2#3{%
   \leavevmode
   \hbox{%
     \setlength\@tempdima{#1}%
     \setlength\@tempdimb{#2}%
     \setlength\@tempdimc{#3}%
     \advance\@tempdimc\@tempdima
     \vrule\@width\@tempdimb\@height\@tempdimc\@depth-\@tempdima}}

The token \@width stands for width; since \vrule requires a \dimen either explicit or with a register, in the latter cases it coerces a \skip to a \dimen.

So the fact that \rule{123pt plus 12pt minus 42pt}{1pt} works without error is just a consequence of the implementation and the resulting width would be 123pt anyway.

It's better to compare the values you get. Consider

\documentclass{article}

\newlength{\mytest}

\begin{document}

\setlength{\mytest}{\dimeval{\linewidth plus 100pt minus 100pt - 100pt}}

\texttt{\the\mytest}

\setlength{\mytest}{\skipeval{\linewidth plus 100pt minus 100pt - 100pt}}

\texttt{\the\mytest}

\end{document}

where I changed 1cm into 100pt in order not to get decimals.

enter image description here

What's that “-100pt” doing at the top? That's the proof your attempts are not equivalent.

Indeed, your

\dimeval{\linewidth plus 100pt minus 100pt - 100pt}

returns 345.0pt, because p is extraneous to \dimexpr (on which \dimeval is based) so in the end LaTeX does

\setlength{\mytest}{345.0pt plus 100pt minus 100pt - 100pt}

which becomes

\mytest=345.0pt plus 100pt minus 100pt - 100pt\relax

(because of the implementation of \setlength). The part

\mytest=345.0pt plus 100pt minus 100pt

is a complete \skip specification; then TeX typesets -100pt.

To the contrary, the argument in \skipeval is valid for \glueexpr and the length is computed as expected.

Can the wrong input to \dimeval be caught? I don't think it's possible without performing assignments, which would make the command unexpandable.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .