I have a question about naming variables. In expl3, the variable naming convention is the following: \<scope>_<module>_<description>_<type>. The <scope> can be l, g, or c, which indicates whether the variable is a local, global, or constant variable (although this is technically not enforced; it is just a convention).

I am currently writing a package where I set up variables using l3keys. These variables have an initial value set by the .initial: key. In this situation, I am unsure whether I should use g or c as the variable scope. One could argue c would be appropriate since I would like the variable's value never to change after it is loaded via the package option. Or perhaps g would be best since, if my understanding is correct, the variable can change from the initial value set by .initial:n to the value set by the user when loading the package options.

EDIT: I've updated my MWE.

Here is the main file.

Some text.

%I am aware that using \ExplSyntax is bad practice inside the document body.
%This is solely for demonstration.
\dim_use:N \c_mymodule_testdimen_dim
\skip_use:N \c_mymodule_testskip_skip

Here is the package file named mypackage.sty.

    {Test package}
\keys_define:nn { mymodule }
    testdimen .dim_gset:N = \c_mymodule_testdimen_dim
    ,testdimen .initial:n = { 12pt }
    ,textskip .skip_gset:N = \c_mymodule_testskip_skip
    ,textskip .initial:n = { 12pt plus 6pt minus 3pt }
  • 1
    No, I am not using the package l3keys2e because it is obsolete. ctan.org/pkg/l3keys2e Jul 2, 2023 at 3:48
  • l3keys is documented in the l3kernel. See the file interface3.pdf. ctan.org/pkg/l3kernel Also I should clarify that my question is about variable naming conventions and not about "how to do x." Jul 2, 2023 at 6:09
  • 1
    Because the user can change the values, and the values are usable anywhere in the package, I would use a global variable.
    – projetmbc
    Jul 2, 2023 at 7:39

1 Answer 1


User-defined values are never constants, as you are setting an existing variable not creating them in one go. As you are setting globally, you should use \g_... not \l_.... (You can't really have a constant set from a key, as the variable has to be created when the key is, so has one value, then is being altered when you set the key.)

Of course, TeX doesn't have formal constants, but the expl3 convention for these are they are programmer-specified global values that do no change. Thus \c_... is for things like pre-defined sizes of data structures that never change, locations of csnames that are fixed. (E.g. l3keys itself for example uses a set of constant tl to set where keys are stored.) They are in that sense not just 'set once for this TeX run' but 'set for all uses of this code on the same setup (engine, platform, etc.)'.

  • 1
    So font size would be a global variable in a standard class but a constant in a class which specified it with no other option? Also, where is the new \ProcessKeyOptions documented? I tried searching interface3.pdf and expl3.pdf, but haven't had any luck.
    – cfr
    Jul 2, 2023 at 19:37
  • 2
    @cfr I;d say it's a value judgement but I'd stick with g: it's not something that's hard-fixed in the same way an array size is.
    – Joseph Wright
    Jul 2, 2023 at 20:39
  • 2
    @cfr Documentation is in clsguide as it's a 2e feature
    – Joseph Wright
    Jul 2, 2023 at 20:39
  • 1
    Thanks. I was looking in the wrong places.
    – cfr
    Jul 2, 2023 at 23:39

You must log in to answer this question.

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