# What is the difference between assignment, \setlength and \renewcommand when changing a variable?

I want to set the \extrarowheight to 0.5ex. I find the following three ways are all applicable.

\extrarowheight = 0.5ex
\setlength{\extrarowheight}{0.5ex}
\renewcommand{\extrarowheight}{0.5ex}


Just out of curiosity, which way is the canonical one?

• One is setting it the tex way, one is using the latex way, one is more or less just wrong. – Johannes_B Dec 11 '18 at 6:13
• @Johannes_B I beg to differ. \arraystretch can only be changed by \renewcommand since \arraystretch is implemented as a macro rather than a variable. – Eli4ph Dec 13 '18 at 11:04

As mentioned in the comments, the first version is the TeX version of assignments, the second version is the LaTeX version of assigning values to variables. Both usually yield the same result, as the second one is based on the first.

The second version is less error-prone, though, because it's equivalent to \extrarowheight=0.5ex\relax which prevents the parser from accidentally mistaking extra characters after the assignment to be part of the new value.

Note however, that the third version is not equivalent to the other two, and wrong in that sense. It doesn't do a variable assignment but redefines \extrarowheight to be a macro which expands to the token sequence 0.5ex. You can see the difference when you try the following:

\setlength{\extrarowheight}{0.5ex}
\show\extrarowheight


outputs

\extrarowheight=\dimen104.

while

\renewcommand{\extrarowheight}{0.5ex}
\show\extrarowheight


outputs

\extrarowheight=\long macro:
->0.5ex.

In some cases the use of that macro will still yield the same result as the use of the variable, but as soon as you try to set the variable the correct way, the problem becomes apparent:

\renewcommand{\extrarowheight}{0.5ex}
\setlength{\extrarowheight}{1.0ex}


prints 0.5ex1.0ex instead of doing an assignment.

• Good answer. Note that \setlength and others can be extended by package like calc to handle simple equations, e.g. \setlength{\somelength}{\baselineskip + .5ex}. Then it is not equivialent to the TeX assignment anymore. – Martin Scharrer Dec 11 '18 at 7:29
• Thanks for the detailed description. By the way, is \extrarowheight 0.5ex also legitimate? – Eli4ph Dec 13 '18 at 9:07
• @eli People use different things because things are implemented differently. You cannot use everyting everywhere. So the simple answer would be: use the right tool for the job. Not everything can be fixed by whacking it with a hammer. – Johannes_B Dec 13 '18 at 11:10
• @Johannes Agree! The motivation for this question is to do things right. Apparently I did not realize the difference between \arraystretch and \extrarowheight when asking this question. – Eli4ph Dec 13 '18 at 11:15