-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"\@namedef" in xparse #179
Comments
Am 08.07.2014 08:48, schrieb Will Robertson:
do you have a few pointers on the use cases? In my opinion this looks simply like a misuse of interface layer to me However, I might be mistaken and this is why I would like to see examples
even more 'orrible :-) frank |
A Google search yielded fewer results than I expected. I agree that generally people are just using it wrong. I guess I just wanted to flag that it was happening; let's leave it along for now. |
Find use cases. |
I'm pretty sure we are taking the position 'do not do this' ... |
A “use case”, admittedly not really so explicitly useful |
If we don't provide variants of the standard commands, I think we still need to address how to create document-level macros with "constructed" names. For example, in a "newfloat" style package, maybe I have a command Packages like Any package which defines its own I can't see a way around doing this kind of thing without having the equivalent of |
I think we should have an expl3-level API for xparse that would provide
\xparse_command_new:Nnn, \xparse_command_renew:Nnn,
\xparse_command_declare:Nnn, \xparse_command_provide:Nnn and similarly
for environments. Then people can just use \exp_args:Nc.
|
One can just do \use:x
{
\NewDocumentCommand \exp_not:c { name }
} ... thought I do see that this is sub-optimal. I guess @FrankMittelbach may have thoughts on this:
and so forth for every case which is not hard-coded. |
Am 24.09.2018 um 08:31 schrieb Bruno Le Floch:
I think we should have an expl3-level API for xparse that would provide
\xparse_command_new:Nnn, \xparse_command_renew:Nnn,
\xparse_command_declare:Nnn, \xparse_command_provide:Nnn and similarly
for environments. Then people can just use \exp_args:Nc.
I'm not sure that an interface from expl3 into xparse is a good idea as
that is like a two-way street essentially blurring the distinction
between document level syntax and internal programming level, i.e. you
would afterwards not any longer be able to replace the document layer
with a different syntax.
Instead, to stick with Will's example, newfloat.sty should have a
\nfloat_declare:n #1 { ... }
andthe package would generally just provide \nfloat_list_of:n
On the document layer (ie xparse) you could then do
\DeclareNewDocumentCommand \newfloat {m ...}
{ \nfloat_declare:n {#1}
\DeclareNewNamedDocumentCommand{listof #1}{}
{ \nfloat_list_of:n{#1} }
}
Or if you want that \nfloat_declare:n automatically defines a fixed
\cs_new:cpn {nfloat_list_of_#1:}{...}
then the line would be
\DeclareNewNamedDocumentCommand{listof #1}{}
{ \cs_use:n{float_list_of_#1:}
In either case, one could swap out xparse and provide say an xml
interface without touching the lower-level code.
So all that would require is xparse to allow defining named commands
(probably with a different name as above) but that is the direction I
would take it.
|
On naming, what do you think of my tongue-in-cheek suggestion to have
be equivalent? :) We don't need these to be fast, after all. |
But how about |
On 24 Sep 2018, at 13:17, Will Robertson ***@***.***> wrote:
On naming, what do you think of my tongue-in-cheek suggestion to have
\NewDocumentCommand\foo ...
\NewDocumentCommand{foo}...
be equivalent? :) We don't need these to be fast, after all.
Oh, no! :-)
This is against any known and reasonable user interface.
Perhaps `\NewDocumentCommand*{foo}`? But this would
confuse people accustomed to `\newcommand*`.
|
precisely. Which is why I think it needs a different name for declaration. You can of course invent another type of syntax, e.g. |
Returning to this topic ... what about:
Rationale: this is lengthy but understandable.
|
@FrankMittelbach Names are good, the question was always whether this belongs at all at the document-command level. The alternative I think was always that such constructs should arise from an \cs_new_protected:Npn \module_funct:n #1
{
% Stuff
\@@_internal:c {#1}
}
\cs_new_protected:Npn \@@_internal:N #1
{
% Stuff
\NewDocumentCommand #1 ...
}
\cs_generate_variant:Nn \@@_internal:N { c } |
Names are good, > the question was always whether this belongs at all at the >
document-command level. The alternative I think was always that such >
constructs should arise from an |expl3| function in which the |c|-type >
expansion will take place internally, of the form> >
\cs_new_protected:Npn\module_funct:n #1> {> % Stuff>
\@@_internal:c {#1}> }> \cs_new_protected:Npn\@@_internal:N #1>
{> % Stuff> \NewDocumentCommand #1 ...> }>
\cs_generate_variant:Nn\@@_internal:N { c }
Mixing doc level in the middle of L3 programming layer code I think is
really a bad idea as it blurs between the levels badly
…---------
I think we had enough examples where this makes a lot of sense at
document level and "simple" package level
\NewDocumentCommand\SetupInterfaceX{m}
{
\newcounter{X-#1}
\NewConstructedDocumentCommand{X#1}{...}
\NewConstructedDocumentCommand{X#1default}{...}
...
}
as I said I don't think there is a lot of pressure here but to get aways
from \expandafter gymnastics or the mixtures as the ones you suggest at
the top I think they make sense.
|
@FrankMittelbach I was mainly worried we want to be as clear as we can about the fact that creating document commands should be explicit. There are use cases as you say for creating them on-the-fly: I'm entirely happy with the suggested names. |
The names might be
but They should come with a big warning; at least some people will read them. |
Sounds better IMHO.
I am looking forward to it, since I'm not sure to see what's wrong... |
that would match the old internal |
I think we want |
oh sure, I meant to write |
Joseph suggested to just use
This mixes expl3 and document level, as Frank objected. But I don't understand how
still needs to get On a separate note, a variant of Will's idea is to allow |
But Is “Constructed” understandable or at all meaningful here? Noting that these commands are no more or less “constructed” than any other command, not even the name is is “constructed” The only distinction is how the name is specified (no ), and of course what characters it can contain. Neither of these are implied by the word “Constructed”, especially since this qualifies the command and is apparently unrelated to the name specification. “ByName” or “Named” may work (a little) better? Possibly @blefloch 's idea of a specialised indicator that the name argument has to be preprocessed (and has a larger alphabet). Then there is no need for a new name, however long! |
Must admit
but also
or anything else where you are tempted to use |
However, David's idea of |
I also like David's idea. How should peoble than use such a command? So what would be the counterpart of @nameuse? |
Again, I don't see in what situation anyone would use Basically I'd advocate having |
|
searching tex.sx for
for example. Some things would be better done in a package or done with expl3 but there is always pressure to do a certain amount of simple programming in the document preamble and I think this could help improve the facilities available for that. |
Thanks Frank, this is a very clear and compelling use case, I'm now convinced that |
Well, all our interface (newer) command |
Since we seem recently to have got very close to this, maybe it is simplest to take the logical step of just providing a single very general interface command, thus: Maybe particular cases, such as @nameuse, will additionally need simple commands (with clear/useful names:-). |
More precisely:
|
As in |
For now I think it is better to stick with just a few commands. If we find ourselves adding more, we can revisit the idea of adding a general |
One could, when you want to add the general |
Yes, that's correct. But every interface build with |
I'm not concerned about the few case in front of |
Yes, as I at least meant to say, some commonly used special cases need to be reasonably fast.
For these a general constructor would be best: then programmers can easily define any such, speedy, command that they need (using whatever name they want!).
Yes, Maybe two such examples for now, if that is what is supported by the evidence of current common usage. |
Eight years old . . . wow! |
with respect to speed .. what's so surprising about that? and what is this line on eight years old? that looks totally out of context. |
I don't really see a good reason for reimplementing the L3 programming layer in 2e. It is all there already: if you write new code and want to make use of all that use L3 prog layer aka expl3. The suggestion to provide just the two stems from the fact that a) those two are likely to be useful in simple 2e preamble code (that neither wants |
No! Well, I am totally lost now. No reimplementation was intended. Look at the whole issue for the 8 years. |
As discussed elsewhere we provide four CamelCase commands |
Sorry to comment rather than writing a commit, but: we should document |
@blefloch isn't that the way it is is usrguide3.pdf?
|
* Creating document commands and environments (covers |\NewDocumentCommand| etc)
* Copying and showing (robust) commands (covers |\NewCommandCopy|etc)
* Preconstructing command names (covers how to use |\ExpandNc| etc together
with commands from the previous two sections)
Ok, it sounds perfect! I hadn't looked, sorry. Perhaps a note in the
documentation of \NewDocumentCommand and the like?
|
there should remain a reason to buy TLC3 :-) ... but no, you are right, one could and probably should make a forward reference from section 2 to 4. I'll take a look. |
@blefloch please take a look at latex3/latex2e@cdc831c to see if this fits the bill |
@blefloch <https://github.com/blefloch> please take a look at
***@***.***
<latex3/latex2e@cdc831c>
to see if this fits the bill
Yes, it is perfect!
|
> @blefloch <https://github.com/blefloch> please take a look at
> ***@***.*** to see if this fits the bill
Yes, it is perfect!
Ah, no! We should most likely mention hooks around this point too, to push
people towards this rather than copying commands willy-nilly?
|
Perhaps I'm late to the party, but would |
I'm seeing a few cases on tex.sx of things like
I wonder if this indicates that we should possibly provide supported variants of
\NewDocumentCommand
and friends that take csname-type input. I don't have any good suggestions on what we could call these.Alternatively, we could instead provide a prefix command such as
that's internally just
\exp_args:Nc
. (I don't like\WithCSname
though.)The text was updated successfully, but these errors were encountered: