LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced Font
Show HTML 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:
Bruno Le Floch <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Wed, 16 Feb 2011 08:28:33 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (73 lines)
The code for reversing tl follows. I will send the code for full
expansion in a nice form soon.

As I now understand, the key point in all of this is that we can
detect spaces and braces expandably using delimited arguments, and we
can then be sure to act on one token at a time.

The current implementation ( http://users.aims.ac.za/~bruno/LaTeX/ULcase/ )

- brace group: applies   \UL_table_<table-name>_braces   to the brace group

- token: if   \UL_table_<table-name>_<token>   exists, use it,
else   \UL_table_<table-name>_default{<token>}

For e.g., \Lowercase and \Uppercase, we use many macros (one per
letter that has a different capitalization than itself), but for other
applications I mentionned, there are only a few special tokens. If we
want to limit the number of tokens, nothing prevents us from making
the  \UL_..._default  test its argument against a given list to know
what to do, closer to what Joseph was doing. It will be ~15 times
slower (back to the previous speed) for \Uppercase and \Lowercase, but
for the rest, nothing will change.

By adding an argument to (almost) every macro, we can manipulate
tables of case change with an argument. With some work, this can allow
us some pretty crazy things, e.g.

\expandwithdefs{\def\foo{FOO}\def\bar#1{Arg=(#1)}}{%
    \foo\bar{\baz}%
}
->
FOOArg=(\baz)

Tell me if it is useful.

% ======== Code for \UL_reverse:n =========
% To reverse, we just need to set the correct output.
\input ULcase.sty\relax
\long\gdef\UL_reverse:n{\UL_to_case:nn{ULreverse}}

% To output one token, place it after the end of what we are reading
(this is from
% Joseph's implementation). Namely, at the /start/ of  the argument of
% |\UL_to_case_end:n|.

\long\gdef\UL_reverse_output:n#1#2\UL_to_case_end:n#3{%
   #2\UL_to_case_end:n{#1#3}}

\long\gdef\UL_table_ULreverse_default{\UL_reverse_output:n}

% The default action is to output the given token.
% Spaces don't need a special treatment.
%
% Braces are treated in the same way as for the ULnil table, except that the
% output is done using |\UL_reverse_output:n|.

\long\gdef\UL_table_ULreverse_braces#1#2{%
    \expandafter\expandafter\expandafter\UL_reverse_output:n%
    \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter{\UL_to_case:nn{#1}{#2}}%
    }%
}

% ========= Tests
\long\def\a{\UL_reverse:n{\a{ b \} cd\{e}f}}
\long\def\b{f{e\{dc \} b }\a}
\expandonce\a\expandonce\a\expandonce\a
\ifx\a\b\show\CORRECT\else\show\WRONG

%--
%Regards,
%Bruno

ATOM RSS1 RSS2