Common programming languages (C).

// foo is global scope
int foo = 0;

int main() {
    // bar is local scope within main
    int bar = 1;

Let's consider LaTeX3


\cs_set:Nn \create_list:n
    \tl_set:Nn \l_my_tl {(#1)}

    \create_list:n {#1}
     \tl_use:N \l_my_tl




In LaTeX3 I expected the scope of \l_my_tl is a body of \create_list:n. But \l_my_tl visible also from \uselist{m} macro. Why is that? What am I misunderstanding here?


Scope in TeX, and thus in expl3, is not defined by macros: they are simply replaced by their definition when 'used'. Scope is therefore provided using explicit groups:

  • \group_begin:/\group_end: (expl3) - \begingroup/\endgroup (classical TeX names)
  • { ... } or \bgroup/\egroup

The brace-based version potentially impacts on math mode spacing, and in expl3 we always use the first type of grouping.

There are some 'hidden' scopes, such as table cells, but for the bulk of programming these are not what we use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.