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












3















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?










share|improve this question

























  • 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


















3















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?










share|improve this question

























  • 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
















3












3








3








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?










share|improve this question
















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?







macros lengths






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 11 '18 at 14:18









Martin Scharrer

200k45635818




200k45635818










asked Dec 11 '18 at 6:03









Eli4phEli4ph

657




657













  • 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





















  • 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



















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





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







@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












1 Answer
1






active

oldest

votes


















7














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.5exrelax 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}
showextrarowheight


outputs




extrarowheight=dimen104.




while



renewcommand{extrarowheight}{0.5ex}
showextrarowheight


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.






share|improve this answer





















  • 1





    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











  • Note that standard LaTeX arraystretch is implemented as a macro. Thus it is not a variable and the "conceptual" assignment to it can only be achieved by renewcommand. Actually, this is the origin for my question – people use renewcommand for arraystretch while setlength for extrarowheight.

    – Eli4ph
    Dec 13 '18 at 11:00








  • 1





    @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













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464258%2fwhat-is-the-difference-between-assignment-setlength-and-renewcommand-when-cha%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














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.5exrelax 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}
showextrarowheight


outputs




extrarowheight=dimen104.




while



renewcommand{extrarowheight}{0.5ex}
showextrarowheight


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.






share|improve this answer





















  • 1





    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











  • Note that standard LaTeX arraystretch is implemented as a macro. Thus it is not a variable and the "conceptual" assignment to it can only be achieved by renewcommand. Actually, this is the origin for my question – people use renewcommand for arraystretch while setlength for extrarowheight.

    – Eli4ph
    Dec 13 '18 at 11:00








  • 1





    @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


















7














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.5exrelax 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}
showextrarowheight


outputs




extrarowheight=dimen104.




while



renewcommand{extrarowheight}{0.5ex}
showextrarowheight


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.






share|improve this answer





















  • 1





    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











  • Note that standard LaTeX arraystretch is implemented as a macro. Thus it is not a variable and the "conceptual" assignment to it can only be achieved by renewcommand. Actually, this is the origin for my question – people use renewcommand for arraystretch while setlength for extrarowheight.

    – Eli4ph
    Dec 13 '18 at 11:00








  • 1





    @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
















7












7








7







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.5exrelax 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}
showextrarowheight


outputs




extrarowheight=dimen104.




while



renewcommand{extrarowheight}{0.5ex}
showextrarowheight


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.






share|improve this answer















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.5exrelax 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}
showextrarowheight


outputs




extrarowheight=dimen104.




while



renewcommand{extrarowheight}{0.5ex}
showextrarowheight


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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 11 '18 at 14:12

























answered Dec 11 '18 at 7:22









siracusasiracusa

4,97511428




4,97511428








  • 1





    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











  • Note that standard LaTeX arraystretch is implemented as a macro. Thus it is not a variable and the "conceptual" assignment to it can only be achieved by renewcommand. Actually, this is the origin for my question – people use renewcommand for arraystretch while setlength for extrarowheight.

    – Eli4ph
    Dec 13 '18 at 11:00








  • 1





    @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
















  • 1





    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











  • Note that standard LaTeX arraystretch is implemented as a macro. Thus it is not a variable and the "conceptual" assignment to it can only be achieved by renewcommand. Actually, this is the origin for my question – people use renewcommand for arraystretch while setlength for extrarowheight.

    – Eli4ph
    Dec 13 '18 at 11:00








  • 1





    @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










1




1





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







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





Thanks for the detailed description. By the way, is extrarowheight 0.5ex also legitimate?

– Eli4ph
Dec 13 '18 at 9:07













Note that standard LaTeX arraystretch is implemented as a macro. Thus it is not a variable and the "conceptual" assignment to it can only be achieved by renewcommand. Actually, this is the origin for my question – people use renewcommand for arraystretch while setlength for extrarowheight.

– Eli4ph
Dec 13 '18 at 11:00







Note that standard LaTeX arraystretch is implemented as a macro. Thus it is not a variable and the "conceptual" assignment to it can only be achieved by renewcommand. Actually, this is the origin for my question – people use renewcommand for arraystretch while setlength for extrarowheight.

– Eli4ph
Dec 13 '18 at 11:00






1




1





@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





@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







@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




















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464258%2fwhat-is-the-difference-between-assignment-setlength-and-renewcommand-when-cha%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?