latex3 expl3 add tag
nsajko
Looking at the interface3.pdf LaTeX documentation, I see, for a start, these two functions for defining functions: `\cs_new:Npn` and `\cs_new:Nn`.

However, I'm having trouble understanding the purpose behind `\cs_new:Npn`, as the difference between the two function seems to be that `\cs_new:Npn` allows specifying parameter names, as opposed to `\cs_new:Nn` which just uses *default* names for parameters. The weird thing seems to be that `\cs_new:Npn` only ever seems to accept parameter names in the form `#1 #2 #3 ...`, so the same thing that would be  achieved by using `\cs_new:Nn`.

Doesn't that make `\cs_new:Npn` redundant, and `\cs_new:Nn` the better function to use? Why does `\cs_new:Npn` exist, then?
Top Answer
Skillmon
You got the `\cs_new:Npn` one wrong. TeX only ever has consecutive numeric parameters for macros, `\cs_new:Npn` doesn't change that. Keep in mind that under the hood the "functions" of `expl3` are macros (plus a few primitives), the differentiation between "function" and "variable" is just for the reader to have a better idea of when to use what (well, I don't know the initial intention of the differentiation, but it boils down to that, imho).

However there are two differences between `\cs_new:Nn` and `\cs_new:Npn` (at least two come to my mind instantly):

1. `\cs_new:Nn` has to parse the macro name to count the number of `n` and `N` arguments, then build the argument pattern as a consecutive list (like `#1#2#3` for 3 arguments). For this reason `\cs_new:Nn` imposes the naming conventions of `expl3`, but it is also a tad slower than `\cs_new:Npn`.

2. `\cs_new:Npn` allows to not only specify parameters but also explicit delimiters. `\cs_new:Npn \use_none_until_q_stop:w #1 \q_stop {}` will gobble everything up to and including the next `\q_stop` (or will throw a low level error if it doesn't find any).

So `\cs_new:Npn` is both faster (slightly), and more versatile. It is however more low level than `\cs_new:Nn` and hence more prone to user error.

There is stuff you'll only be able to code efficiently in TeX when using delimited arguments, for instance a naive (and super fast) argument splitter to separate some input at the first hyphen looks like this:

```
\cs_new:Npn \my_function:n #1
  {
    \__my_function_aux:w #1 \q_stop
  }
\cs_new:Npn \__my_function_aux:w #1 - #2 \q_stop
  {
    \my_do_stuff_with_args:nn {#1} {#2}
  }
```

(it will however result in undefined behaviour if no hyphen or a `\q_stop` is part of the argument).

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.