[texhax] (no subject) [xy -> x or y]
Uwe Lück
uwe.lueck at web.de
Sun Jul 9 21:16:51 CEST 2006
... due to another Windows crash I came 10 minutes later than Philip Taylor
:-)
-- As usual, dealing with curly braces would need additional efforts.
One might turn all the category codes into "other" at first
using \meaning (as exemplified by the LaTeX index package)
-- and re-input the final result via writing it to the disk
(if the original category codes are needed).
-- Uwe Lueck.
-------------- next part --------------
%% plainrpl.tex -- replace with Plain TeX
%% Uwe Lueck 2006/07/09 for Zalman Rubinstein on texhax.
%% To use it as a mere package, replace `% \endinput' by
%% `\endinput' below.
%% Macros:
\def\replaceInOutThisBy#1#2#3#4{%
%% #1 input token register, #2 output token register,
%% #3 string to replace, #4 replacing string.
%% #1 must not contain #3\RIOTBprivate!
#2{}% initiate output register
\def\RIOTBloop##1#3##2\RIOTBprivate{%
%% #3 and \RIOTBprivate are used as parameter delimiters,
%% cf. TeXbook p. 202f.
\ifx\RIOTBprivate##2\RIOTBprivate
%% this case: ##2 nothing, no more #3 in #1 -- finish
#2\expandafter{\the#2##1}%
\let\RIOTBloop\relax \let\RIOTBnext\RIOTBgobble
\else
%% #3 to be replaced by #4 has been found;
%% ##2 ends on dummy #3
#2\expandafter{\the#2##1#4}%
\fi
\RIOTBnext ##2\RIOTBprivate
}%
\let\RIOTBnext\RIOTBloop
\expandafter #1\expandafter {\expandafter }\expandafter
%% <- empty #1 immediately after reading -- or want keep it?
\RIOTBloop\the#1#3\RIOTBprivate
}
\def\RIOTBprivate{RIOTB}
\def\RIOTBgobble\RIOTBprivate{}
% \endinput
%% Examples:
\newtoks\inputtoks \newtoks \outputtoks
\def\RIOTBmessage#1#2{\immediate\write16{RIOTB #1: \the#2}}
\def\RIOTBemptyscreenline{\immediate\write16{}}
\RIOTBemptyscreenline
%% Reducing `xy' to `x':
\inputtoks{ABxyCDExyFGHI}
\RIOTBmessage{ input}\inputtoks
% \tracingmacros=1
\replaceInOutThisBy\inputtoks\outputtoks{xy}{x}
\RIOTBmessage{output}\outputtoks
\RIOTBemptyscreenline
%% Reducing `xy' to `y':
\inputtoks{ABxyCDExyFGHI}
\RIOTBmessage{ input}\inputtoks
\replaceInOutThisBy\inputtoks\outputtoks{xy}{y}
\RIOTBmessage{output}\outputtoks
\RIOTBemptyscreenline
\bye
More information about the texhax
mailing list