[texhax] enviroment/ifthen
Uwe Lück
uwe.lueck at web.de
Tue Feb 10 19:32:13 CET 2009
At 13:38 08.02.09, wawan wrote:
>I need help how to build sty in latex ( environment ) that can replace
>squences of chars with my symbols. For example if there input chars "SU"
>than replace with XY ( my symbols from metafont).
The macros and example in the attached wawansub.tex may be a solution. I
just found Nicola Talbot's datatool.sty (requires substr.sty and xfor.sty)
for replacement, while there may be other useful packages xstring.sty or under
http://ctan.tug.org/tex-archive/help/Catalogue/bytopic.html#parsingfiles
The substitutions must be declared in the definition of \xreplacements.
There is a number of difficulties with such operations. The present
implementation breaks when you try to embed another environment, and it
ignores the content of curly braces. I have another version which looks
inside braces but disables macros with arguments. This can hardly be
improved without considerably more work.
With the present implementation the environment `substitute' must not
contain \par.
I wonder about `my symbols from metafont' since we are just manipulating
tokens, not glyphs as metafont produces them. Maybe you are using some rich
encoding like Unicode, otherwise you may introduce certain commands to call
your glyphs.
HTH -- Uwe.
-------------- next part --------------
%% WAWANSUB.TEX 2009/02/10 uwe.lueck[at]web.de
\documentclass[12pt]{article}
\usepackage{datatool}%% requires substr + xfor
\newcommand{\xreplacements}{%% executed on having read env
\DTLsubstituteall{\inoutstring}{SU}{XY}%% add modifications
% \DTLsubstituteall{\inoutstring}{<in>}{<out>}%% template
}
\begingroup
\catcode`\{12 \catcode`\}12
\catcode`\<1 \catcode`\>2
\gdef\xsubstitute#1\end{substitute}<%
\endgroup
\def\inoutstring<#1>%
\xreplacements \inoutstring \end<substitute>>
\endgroup
\newcommand{\substitute}{%
\begingroup \catcode`\{12 \catcode`\}12 \xsubstitute}
\providecommand{\disguisedpar}{\par}%% fool short arguments
\begin{document}
\begin{substitute}
ABSUOZ
\disguisedpar
abSUoz
\end{substitute}
\end{document}
More information about the texhax
mailing list