3

I am newbie to LaTeX3 and i am trying to understand some basics.

So, suppose i want to do somthing like

\newcommand{\contentsname}{Contents}

I can achieve this by one of these ways

\tl_const:Nn \c_myclass_contentsname_tl {Contents}

\tl_set:Nn \myclass_contentsname_tl {Contents}

\cs_set:Npn \myclass_contentsname: {Contents}

What is the best way? is there any difference?

0

1 Answer 1

5

They are internally more or less the same (conceptually they are very different), but they differ, for example, with parameter tokens:

\tl_const:Nn \c_myclass_contentsname_tl { # Contents } % works
\tl_set:Nn \l_myclass_contentsname_tl { # Contents } % works
\cs_set:Npn \myclass_contentsname: { # Contents } % breaks

(\tl_new:N + \tl_set:Nn and \tl_const:Nn are more or less the same, except that you should use the latter only if the contents of the token list will not ever change.)

But other than that, your really need to evaluate what you are defining. Since you are defining a container for some text, and not a command to do something (for some definition of “do”), you want a token list, so the right way is to use a tl.

Use

\tl_const:Nn \c_myclass_contentsname_tl { Contents }

if \c_myclass_contentsname_tl should not be modified, or

\tl_new:N \l_myclass_contentsname_tl
\tl_set:Nn \l_myclass_contentsname_tl { Contents }

if the user can change the token list if needed.

4
  • So here i think it's \tl_set:Nn no? Jan 14, 2021 at 19:57
  • 1
    @studentmaths I think so, yes. Definitely not \cs_set:Npn. The choice between set and const is if the contents will change. From the looks of your example, it seems set is more appropriate, yes Jan 14, 2021 at 19:58
  • What is the meaning of tl? TeX LaTeX? I mean, the letters tl.
    – Sigur
    Jan 14, 2021 at 20:05
  • 1
    @Sigur Token List Jan 14, 2021 at 20:10

You must log in to answer this question.

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