LATEX-L Archives

Mailing list for the LaTeX3 project


Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Content-Type: text/plain; charset=windows-1252
Date: Fri, 12 Jul 2013 15:49:19 +0200
Reply-To: Mailing list for the LaTeX3 project <[log in to unmask]>
MIME-Version: 1.0
Message-ID: <[log in to unmask]>
Content-Transfer-Encoding: 8bit
Sender: Mailing list for the LaTeX3 project <[log in to unmask]>
From: Michiel Helvensteijn <[log in to unmask]>
Parts/Attachments: text/plain (75 lines)
Hello all,

I have found it useful in my recent work to have unique csnames
generated automatically.

For example, when implementing a `\something_map_inline:Nn` from an
existing `\something_map_function:NN`, there is the need to
automatically generate a function from the provided loop body. It is
not possible to keep using the same control sequence over and over,
because that would make it impossible to do any nesting.

I am thinking about argument specifiers:

:U  and  :u

Their actual parameters are a variable and variable-name respectively,
which will contain the uniquely generated csname. The formal parameter
in both cases is the uniquely generated control sequence (the cs, not
the csname; same as with :N and :c).

Here's an example of its use:

\tl_new:N \l__something_map_csname_tl
\cs_new_protected:Nn \something_map_inline:Nn {
    \cs_set:Upn \l__something_map_csname_tl ##1##2 {#2}
    \something_map_function:Nc #1 \l__something_map_csname_tl

Internally, I suspect it'll be easy enough to generate unique csnames.
In my 'with' package (not in CTAN yet) I do it simply by increasing a
counter (

Obviously any function with a :U or :u argument is protected (as with :x).

--- --- --- ---

I now go one step further. The following idea is related to the above,
but please evaluate them separately.

It's about a third argument specifier that would go a long way towards
solving the problem stated in

Briefly, there is need for a simple and generally applicable technique
to store user-supplied data and move it around —with the guarantee
that it is never expanded or modified— and then to return (pass as a
parameter; leave in the input stream) said data exactly as it was

Of course, there are already many ways to accomplish this, but they
are always dependent on the situation (i.e. ad-hoc) and error-prone.

I suggest another new argument specifier:


The actual parameter is any kind of token-list (the 'user-supplied
data'). The formal parameter is a uniquely generated csname to a macro
containing that token-list: a "pointer" or "reference".

Because of this extra level of redirection the pointer can be stored,
moved around, expanded and dragged through the mud with relative
certainty that the original data remains intact. The corresponding
"dereference" specifiers already exist:

:v  and  :c

The first yields the data exactly as it was stored. The second yields
a control sequence through which the data can be modified.

Let me know what you think.