TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose that one has two definitions

\seq_new:N \l_input_seq % declare a list (seq) variable

shared by 2 macros \NewDocumentCommand. Is there a way to check if \l_input_seq is already defined? Something like \seq_provide:N? So far I found only \cs_if_exist:NTF and

\cs_if_exist:NTF \l_input_seq { } { \seq_new:N \l_input_seq }

makes exactly what i need.

UPDATE: In my particular case I could just use twice \seq_new:N to define two different variables, say \l_input_seq_one and \l_input_seq_two. I was just curious when posting this question ;) To say trust, I don't like to introduce plenty of temporal variables when I need only one at once.

share|improve this question
On the update, if you look at LaTeX2e there is a lot of effort to keep down the number of scratch macros/registers as they used to be very limited. However, to do that 'safely' is tricky: it's easy to mess up. Thus the LaTeX3 approach is different: we've preferred having more macros with 'known' use patterns. Certainly for two document commands I'd expect the scratch space to be declared outside of the commands, so you can happily use a single sequence if you know a clash is not possible. – Joseph Wright Jan 8 '14 at 7:12
up vote 9 down vote accepted

Not really at the code level, although see below: we do have \ProvideDocumentCommand.

Broadly, you should almost always know when a new variable is needed: the general LaTeX3 approach is to define these 'early on' in a module/package. As such, if two commands use the same variable I'd expect

\seq_new:N \l_mypkg_seq
\cs_new_protected:Npn \mypkg_cmd_one:n #1
     \seq_put_right:Nn \l_mypkg_seq { foo }
\cs_new_protected:Npn \mypkg_cmd_two:n #1
     \seq_put_right:Nn \l_mypkg_seq { bar }
\NewDocumentCommand { \mypkgone } { m } { \mypkg_cmd_one:n {#1} }
\NewDocumentCommand { \mypkgtwo } { m } { \mypkg_cmd_two:n {#1} }

Very occasionally there are places where you can't be sure if a variable's been defined, usually ones created 'on the fly' from user input. For those, we provide functions of the form \<var>_clear_new:N, which can be used to ensure that the variable exists and is in the 'initial' state

\seq_clear_new:N \l_mypkg_seq

In a real case I'd expect these almost always to be used in the c form: almost always what is wanted for 'on the fly' input:

\cs_new_protected:Npn \mypkg_command:n #1
    \seq_clear_new:c { l_mypkg_user_data_ #1 _ seq }
    \seq_put_right:c { l_mypkg_user_data_ #1 _ seq } { First }
share|improve this answer
So, answer is No: there is neither \seq_provide:N nor \seq_clear_new:N. This might be resonable since \cs_if_exist:NTF solves the problem of overriding temporal cs whereas introducing lot of \..._clear_new:... would mess existing system of LaTeX3 control sequencies. – Igor Kotelnikov Jan 8 '14 at 3:43
@IgorKotelnikov There definitely is \seq_clear_new:N in the latest release of expl3: it's been there for some time. – Joseph Wright Jan 8 '14 at 7:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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