[tex-eplain] sidx & optional arguments

Laszlo Hosszu l.l.hosszu at shef.ac.uk
Fri Aug 6 14:33:13 CEST 2010


Hi Oleg,

sorry for the delay, but I have been away from my linux box. Anyway 
following your suggestion I have tried the following;

Enclosing with \makeatletter...\makeatother works, but the The macro 
does not seem to recognise the presence of the optional argument, and 
goes to the "else" statement regardless.

%%%%%%%%%%%%%%%%%%%%%%%

\makeatletter
\def\finresidx#1{%
   \ifx\@optionalarg\empty
     \sidx{#1}%
   \else
     \toks0={#1}%
     \toks2=\expandafter{\@optionalarg}%
     \edef\temp{\noexpand\sidx{\the\toks0}[\the\toks2]}%
     \temp
   \fi
}
\makeatother
\def\pagebreak{\vfil\eject}

This is a test of \finresidx{Darwin}.
\pagebreak

This is a test of \finresidx{Darwin}[optional argument]. This is a test 
of \finresidx{Darwin}[This is a test].
\pagebreak

This is a test of \finresidx{Hosszu}.
\pagebreak

{\centerline{\bf INDEX}}
\readindexfile{i}
\bye

%%%%%%%%%%%%%%%%%%%%%%%

Results in the following .idx file:

\indexentry{Darwin!definexref,xrdef,li,eq,bib,foot,footback,idx}{1}
\indexentry{Darwin!definexref,xrdef,li,eq,bib,foot,footback,idx}{2}
\indexentry{Darwin!definexref,xrdef,li,eq,bib,foot,footback,idx}{2}
\indexentry{Hosszu!definexref,xrdef,li,eq,bib,foot,footback,idx}{3}

The following version recognises the presence of the optional argument, 
but fails to expand it.

%%%%%%%%%%%%%%%%%%%%%%%

\makeatletter
\def\residx{\@getoptionalarg\finresidx}
\def\finresidx#1{\ifx\@optionalarg\empty
			\message {NO arguments!}
			{\sidx{#1}}
                  \else
		 	\message {Arguments!!}
		 	{\sidx{#1}[\@optionalarg]}
		 \fi}
\makeatother

\def\pagebreak{\vfil\eject}

This is a test of \residx{Darwin}.
\pagebreak

This is a test of \residx[optional argument]{Darwin}.
This is a test of \residx[This is a test]{Darwin}.
\pagebreak

This is a test of \residx{Hosszu}.
\pagebreak

This is a test of \residx[optional argument]{Hosszu}.
\pagebreak

{\centerline{\bf INDEX}}
\readindexfile{i}
\bye

%%%%%%%%%%%%%%%%%%%%%%%

Results in the following .idx file:

\indexentry{Darwin}{1}
\indexentry{Darwin!\@optionalarg }{2}
\indexentry{Darwin!\@optionalarg }{2}
\indexentry{Hosszu}{3}
\indexentry{Hosszu!\@optionalarg }{4}

(The @optionalarg entry has an extra space)

Again I am using I eplain 3.4 with teTeX 3.0

Thanks for he help

Laszlo
-

Oleg Katsitadze wrote:
 > Hi Laszlo,
 >
 > On Mon, 26 Jul 2010 15:57:40 +0000 (UTC), Laszlo 
Hosszu<l.l.hosszu at shef.ac.uk>  said:
 >> Which results in following error.
 >>
 >> ! Undefined control sequence.
 >> \finresidx ...\toks 0={#1}\toks 2=\expandafter {\@
 >>                                                    optionalarg}\edef 
\temp {\...
 >> l.12 This is a test of \finresidx{Darwin}
 >>                                           .
 >> ?
 >
 > Try wrapping your definitions of \residx and \finresidx in a
 > \makeatletter ... \makeatother block.
 >
 > HTH,
 > Oleg
 >


Oleg Katsitadze wrote:
> Hi Laszlo,
>
> On Mon, 26 Jul 2010 15:57:40 +0000 (UTC), Laszlo Hosszu<l.l.hosszu at shef.ac.uk>  said:
>> Which results in following error.
>>
>> ! Undefined control sequence.
>> \finresidx ...\toks 0={#1}\toks 2=\expandafter {\@
>>                                                    optionalarg}\edef \temp {\...
>> l.12 This is a test of \finresidx{Darwin}
>>                                           .
>> ?
>
> Try wrapping your definitions of \residx and \finresidx in a
> \makeatletter ... \makeatother block.
>
> HTH,
> Oleg
>




More information about the tex-eplain mailing list