Sender: |
|
Date: |
Sat, 18 Sep 2010 01:33:51 +0200 |
Content-Disposition: |
inline |
Reply-To: |
|
Subject: |
|
MIME-Version: |
1.0 |
Message-ID: |
|
In-Reply-To: |
<1816801436.1740507.1284759290533.JavaMail.fmail@mwmweb010> |
Content-Type: |
text/plain; charset=us-ascii |
From: |
|
Parts/Attachments: |
|
|
On Fri, Sep 17, 2010 at 11:34:50PM +0200, Uwe Lueck wrote:
> > \define_active_char:Nn <character> {<code>}
> >
> > which makes the <character> active and assigns the given code to it,
> > internally using the code that Will wrote.
>
> \begingroup
> \catcode`\~=13
> \gdef\define_active_char:Nn#1#2{%
> \catcode`#113%
> \begingroup
> \lccode`\~`#1%
> \lowercase{\endgroup \def ~{#2}}%
> }
> \endgroup
>
> Not tested exactly this way, sorry, but in a so far private package of mine, I have
>
> \providecommand*{\MakeActiveDef}[2]{%
> \catcode`#1\active
> \begingroup
> \lccode`\~`#1%
> \lowercase{\endgroup \def ~{#2}}%
> }
But then the contents of #2 is converted to lowercase, too.
The trick is to move the (parameter text and) definition text
outside of \lowercase:
\providecommand*{\MakeActiveDef}[2]{%
\catcode`#1\active
\begingroup
\lccode`\~`#1%
\lowercase{\endgroup \def ~}{#2}%
}
or even
\providecommand*{\MakeActiveDef}[1]{%
\catcode`#1\active
\begingroup
\lccode`\~`#1%
\lowercase{\endgroup \def ~}%
}
The latter allows definition of active chars with parameters:
\MakeActiveDef{\+}#1{Do something with #1}
> The \endgroup trick here is from doc.sty's \[log in to unmask]
doc.sty contains:
\def\verbatim@nolig@list{\do\`\do\<\do\>\do\,\do\'\do\-}
\def\do@noligs#1{%
\catcode`#1\active
\begingroup
\lccode`\~=`#1\relax
\lowercase{\endgroup\def~{\leavevmode\kern\z@\char`#1}}}
\do@noligs is lucky, if used with \verbatim@nolig@list, because
#1 always contains a command token that is not affected by \lowercase.
However '`' could have an unexpected \lccode value.
Therefore I suggest
\def\do@noligs#1{%
\catcode`#1\active
\begingroup
\lccode`\~=`#1\relax
\lowercase{\endgroup\def~}{\leavevmode\kern\z@\char`#1}%
}
Yours sincerely
Heiko <[log in to unmask]>
|
|
|