[texhax] enviroment/ifthen [corr'd]
Uwe Lück
uwe.lueck at web.de
Tue Feb 10 23:48:04 CET 2009
[sorry, previous example was my first try, while I commented my second,
which is 2009/02/10+,
now attached and copied below, wawansub.pdf as a proof attached as well;
same posting text as before]
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.
________________________________________________
%% 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
}
\def\substitute#1\end{%
\def\inoutstring{#1}%
\xreplacements \inoutstring \end}
\providecommand{\disguisedpar}{\par}%% fool short arguments
\begin{document}
\begin{substitute}
ABSUOZ
\disguisedpar
abSUoz
\end{substitute}
\end{document}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wawansub.pdf
Type: application/pdf
Size: 5204 bytes
Desc: not available
Url : http://tug.org/pipermail/texhax/attachments/20090210/07dd31ad/attachment.pdf
-------------- 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
}
\def\substitute#1\end{%
\def\inoutstring{#1}%
\xreplacements \inoutstring \end}
\providecommand{\disguisedpar}{\par}%% fool short arguments
\begin{document}
\begin{substitute}
ABSUOZ
\disguisedpar
abSUoz
\end{substitute}
\end{document}
More information about the texhax
mailing list