LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

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

Print Reply
Subject:
From:
Will Robertson <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Tue, 11 Aug 2009 00:21:23 +0930
Content-Type:
multipart/signed
Parts/Attachments:
text/plain (1722 bytes) , smime.p7s (2446 bytes)
Hi Lars,

On 06/08/2009, at 10:52 PM, Lars Hellström wrote:

> The xdoc2l3 preprocessing is more about doing things to an argument  
> after you've grabbed it, than about changing the conditions under  
> which it is grabbed.

[...]

> and refer to the scratch variables \l_tmpa_tl, \l_tmpb_tl, etc.  
> where the values are needed, we can have #1, #2, etc. be these  
> cleaned-up values throughout the body.

[...]

> Just bear in mind that what seems esoteric today may be standard  
> practice for the programming technique you'll learn tomorrow.

Sorry for the slow reply; your idea finally clicked in my brain a few  
days ago and the idea has kinda stuck.

So let's say we want to define \foo that takes an argument but has to  
sanitise it in some way before processing it:

     \DeclareDocumentCommand \foo {m} {
       \my_sanitise:Nn \l_sanitised_tl {#1}
       \foo_internal:V \l_sanitised_tl
     }
     \cs_new:Nn \my_sanitise:Nn {
       % do something with #1 and save it in \l_sanitised_tl
     }
     \cs_new:Nn \foo_internal:n {
       % do whatever \foo is supposed to do with #1
     }
     \cs_generate_variant:Nn \foo_internal:n {V}

 From my not in-depth understanding of xdoc2l3, this can be  
dramatically simplified (I imagine) with something like

     \DeclareDocumentCommand \foo { ?{\my_sanitise:n} } {
       % do whatever \foo is supposed to do with #1
     }

Just to confirm -- have I got this thing sort of right? :)

With this sort of example, it seems pretty clear that this can save a  
lot of code that's just shuffling arguments around. (In the same way  
that manual optional argument processing consists of lots of  
intermediate functions that simply pass their arguments around.)

Best regards,
Will




ATOM RSS1 RSS2