Received: from mail.proteosys.com ([213.139.130.197]) by nummer-3.proteosys with Microsoft SMTPSVC(6.0.3790.3959); Thu, 3 Dec 2009 18:31:46 +0100 Received: by mail.proteosys.com (8.14.3/8.14.3) with ESMTP id nB3HVmgN003294 for ; Thu, 3 Dec 2009 18:31:48 +0100 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id nB3HRa9f026766 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 3 Dec 2009 18:27:36 +0100 Received: from listserv.uni-heidelberg.de (localhost.localdomain [127.0.0.1]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id nB3G8T0O025664; Thu, 3 Dec 2009 18:27:35 +0100 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 15.5) with spool id 363983 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Thu, 3 Dec 2009 18:27:35 +0100 Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id nB3HRZ4E008886 for ; Thu, 3 Dec 2009 18:27:35 +0100 Received: from smtp.ampere.inpg.fr (smtp.ampere.inpg.fr [147.171.64.83]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id nB3HRN9A026676 for ; Thu, 3 Dec 2009 18:27:27 +0100 Received: from localhost (localhost [127.0.0.1]) by smtp.ampere.inpg.fr (Postfix) with ESMTP id 85FC0981A1 for ; Thu, 3 Dec 2009 18:27:24 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ampere.inpg.fr Received: from smtp.ampere.inpg.fr ([127.0.0.1]) by localhost (smtp.ampere.grenoble-inp.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rccpt08o8UXw for ; Thu, 3 Dec 2009 18:27:24 +0100 (CET) Received: from [192.168.0.1] (cap69-1-82-233-38-63.fbx.proxad.net [82.233.38.63]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.ampere.inpg.fr (Postfix) with ESMTPSA id 3E8D198108 for ; Thu, 3 Dec 2009 18:27:24 +0100 (CET) User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 References: Content-Type: multipart/alternative; boundary="------------040804030301010603020402" Message-ID: <4B17F4FE.6090302@free.fr> Date: Thu, 3 Dec 2009 18:27:26 +0100 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: "Julien RIVAUD (_FrnchFrgg_)" Subject: Re: Rescanning an argument with a special catcode for the colon To: LATEX-L@LISTSERV.UNI-HEIDELBERG.DE In-Reply-To: Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: X-ProteoSys-SPAM-Score: -6.598 () BAYES_00,HTML_MESSAGE,RCVD_IN_DNSWL_MED X-Scanned-By: MIMEDefang 2.65 on 213.139.130.197 Return-Path: owner-latex-l@LISTSERV.UNI-HEIDELBERG.DE X-OriginalArrivalTime: 03 Dec 2009 17:31:46.0450 (UTC) FILETIME=[7CD35720:01CA743E] Status: R X-Status: X-Keywords: X-UID: 6194 This is a multi-part message in MIME format. --------------040804030301010603020402 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Joseph Wright a écrit : > frnchfrgg@FREE.FR wrote: > >> \begingroup >> \catcode`\:=13 >> \catcode`\.=13\relax >> \gdef\chemin#1{% >> \begingroup >> \catcode`\:=13 >> \catcode`\.=13\relax >> \let.\cheminsommet >> \let:\cheminface >> \endlinechar=-1 >> \everyeof{}% >> \scantokens{#1}% >> \endgroup >> } >> \endgroup >> > > A couple of things here. First, active characters tend to be bad news. In my own siunitx package, I've moved from using an approach like yours in v1 to trying a different system in v2, based on \tl_replace_all_in:Nnn: > > \cs_set:Nn \my_int_function:n #1 { > \tl_set:Nn \l_my_tmp_tl {#1} > \tl_replace_all_in:Nnn \l_my_tmp_tl { . } { \cheminsommet } > \tl_replace_all_in:Nnn \l_my_tmp_tl { : } { \cheminface } > % Do more stuff with the input > } > > The reason for this is two-fold. First, active characters can cause a lot of problems (see what happens when two packages try to do something like this). Note that those characters would be set active only in the call of the function; outside of it the catcode is preserved (or so I think). In fact, in my first version of the \chemin macro, I did some kind of replace, but without expl3 that meant an ugly thing with a lot of ad-hoc looping code. Won't search/replace be slower than setting . and : to macros ? Anyway, the question here is more to play with expl3 than anything else, getting rid of chemin as it is now isn't a priority at all... :) > Second, the \tl_replace_all_in:Nnn approach means that there is only one level of replacement, which is often what people expect if they protect characters. I think the general feeling is that the team are aiming to avoid active characters as far as possible. > Fair enough. > If you do want to use \tl_rescan:Nnx, what is wrong with > > \group_begin: > \char_make_active:N \: > \char_make_active:N \. > \cs_gset:Npn \my_int_function:n #1 { > \tl_set_rescan:Nnx \l_my_tmp_tl > { > \char_make_active:N \: > \char_make_active:N \. > \cs_set_eq:NN . \cheminsommet > \cs_set_eq:NN : \cheminface > } > {#1} > % Stuff with \l_my_tmp_tl > } > \group_end: > > or > > \group_begin: > \char_make_active:N \: > \char_make_active:N \. > \cs_gset_eq:NN . \cheminsommet > \cs_gset_eq:NN : \cheminface > \cs_gset:Npn \my_int_function:n #1 { > \tl_set_rescan:Nnn \l_my_tmp_tl > { > \char_make_active:N \: > \char_make_active:N \. > } > {#1} > % Stuff with \l_my_tmp_tl > } > \group_end: > > (The later makes active . and : globally available, so works without x-type expansion of the tl. I'd personally go for the first of these two solutions as it again is independent of what others do.) > I think I have tried such solutions, wouldn't TeX complain about nonexistent \char_make_active because a colon cannot anymore be in the name of a macro ? Julien --------------040804030301010603020402 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Joseph Wright a écrit :
frnchfrgg@FREE.FR wrote:
  
\begingroup
\catcode`\:=13
\catcode`\.=13\relax
\gdef\chemin#1{%
\begingroup
\catcode`\:=13
\catcode`\.=13\relax
\let.\cheminsommet
\let:\cheminface
\endlinechar=-1
\everyeof{}%
\scantokens{#1}%
\endgroup
}
\endgroup
    

A couple of things here. First, active characters tend to be bad news. In my own siunitx package, I've moved from using an approach like yours in v1 to trying a different system in v2, based on \tl_replace_all_in:Nnn:

  \cs_set:Nn \my_int_function:n #1 {
    \tl_set:Nn \l_my_tmp_tl {#1}
    \tl_replace_all_in:Nnn \l_my_tmp_tl { . } { \cheminsommet }
    \tl_replace_all_in:Nnn \l_my_tmp_tl { : } { \cheminface   }
   % Do more stuff with the input
  }

The reason for this is two-fold. First, active characters can cause a lot of problems (see what happens when two packages try to do something like this).
Note that those characters would be set active only in the call of the function; outside of it the catcode is preserved (or so I think). In fact, in my first version of the \chemin macro, I did some kind of replace, but without expl3 that meant an ugly thing with a lot of ad-hoc looping code. Won't search/replace be slower than setting . and : to macros ? Anyway, the question here is more to play with expl3 than anything else, getting rid of chemin as it is now isn't a priority at all... :)
Second, the \tl_replace_all_in:Nnn approach means that there is only one level of replacement, which is often what people expect if they protect characters. I think the general feeling is that the team are aiming to avoid active characters as far as possible.
  
Fair enough.
If you do want to use \tl_rescan:Nnx, what is wrong with

\group_begin:
  \char_make_active:N \:
  \char_make_active:N \.
  \cs_gset:Npn \my_int_function:n #1 {
    \tl_set_rescan:Nnx \l_my_tmp_tl
      {
        \char_make_active:N \:
        \char_make_active:N \.
        \cs_set_eq:NN . \cheminsommet
        \cs_set_eq:NN : \cheminface 
      } 
      {#1}
    % Stuff with \l_my_tmp_tl
  }
\group_end:

or

\group_begin:
  \char_make_active:N \:
  \char_make_active:N \.
  \cs_gset_eq:NN . \cheminsommet
  \cs_gset_eq:NN : \cheminface 
  \cs_gset:Npn \my_int_function:n #1 {
    \tl_set_rescan:Nnn \l_my_tmp_tl
      {
        \char_make_active:N \:
        \char_make_active:N \.
      } 
      {#1}
    % Stuff with \l_my_tmp_tl
  }
\group_end:

(The later makes active . and : globally available, so works without x-type expansion of the tl. I'd personally go for the first of these two solutions as it again is independent of what others do.)
  
I think I have tried such solutions, wouldn't TeX complain about nonexistent \char_make_active because a colon cannot anymore be in the name of a macro ?

Julien
--------------040804030301010603020402--