Jump to content
xisto Community
Sign in to follow this  
Giniu

Problem With Nested Latex Command Definition help needed... any LaTeX master around?

Recommended Posts

Hi,

this can be considered of topic but is about typeseting, so goes there - into Business like most office apps... I hope :)

I'm trying to make a macro in LaTeX that would help to substitute strings for custom ordering in makeindex package, the idea is to have command \Mindex that would substitute defined substrings and then make inxed still look good, so for example if we define T -> x and R -> w, and call:
\Mindex{aaa} it would just call \index{aaa}, but when we would call \Mindex{TRRa} we would get equivalent of \index{xwwa@TRRa}, and more - we would do same to every separate index entry...

first step was to substitute first occurence of letter in string - it went good I thought as it was working...

\Substitute{a}{b}{aacs} -> {bacs}

now I wanted first to check and make two before I make recurency call there...

\Substitete{a}{b}{\Substitute{a}{b}{aacs}}

and it crashed... I know that this have to do with expand order, I have to expand argument first, and then expand rest command... docs about \expandafter are very short...

any LaTeX master overthere that can throw me some docs about \expandafter (in readable form) or that can just tell how to fix that?

thanks in advance,
Giniu.

-==edit==-

ok, so I managed to get second step working... now I can substitute them but still have to do some kind of substitution list and it don't work for non 8-bit characters... it's getting harder with every step, anyone hava ideas? There is what I have, it works only when defined in .sty or .cls files (as I used @-notation):

\newcommand\rl@Substitute[3]{%\def\rl@left##1#2##2\@nil{##1}%\def\rl@right##1#2##2\@nil{##2}%  \def\rl@inside##1#2##2\@nil{%\def\rl@result{##2}%\ifx\rl@result\@empty%#1%\else%\edef\rl@changed{\rl@left#1\@nil #3\rl@right#1\@nil}%\expandafter\rl@Substitute\expandafter{\rl@changed}{#2}{#3}%\fi%}%\rl@inside#1#2\@nil%}

Edited by Giniu (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.