[tex-eplain] sidx & optional arguments

Laszlo Hosszu l.l.hosszu at shef.ac.uk
Mon Jul 26 17:57:40 CEST 2010


Hi all.

I am fairly new to eplain, but I was wondering whether a workaround has been
found for sidx expanding optional arguments within a macro (originally raised by
Russell Lyons). I feel that this would be a really useful feature. 

I have tried the following, which have been suggested, neither of which work. (I
am using eplain 3.4 with teTeX 3.0)

-------
\catcode`@=\letter
\def\residx{\@getoptionalarg\finresidx}
\def\finresidx#1{\ifx\@optionalarg\empty
			{\sidx{#1}}
                 \else
		 	{\sidx{#1}[\@optionalarg]}
		\fi}
\catcode`\@=12

This is a test of \residx[Galapagos]{Darwin}. 

{\centerline{\bf INDEX}}

\readindexfile{i}

\bye
-------

Entry in idx file (\@optionalarg macro is not expanded):

\indexentry{Darwin!\@optionalarg }{1}

and also

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

This is a test of \finresidx{Darwin}. 

{\centerline{\bf INDEX}}

\readindexfile{i}

\bye

-------

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}
                                         .
? 

Ultimately I would like something along the lines of the following....

\def\hmsidxital#1{{\it #1}, HMS}
\def\hmsship#1{%
  \ifx\@optionalarg\empty
    {\sidxmarked\hmsidxital{#1} {\it #1}} 	% No Optional Arg
  \else
    {\sidxmarked\hmsidxital{#1} [\@optionalarg] {\it #1}}
  \fi
}

\def\beagle{\hmsship{Beagle}}

Darwin joined the \beagle. The \beagle[galapagos] mapped the Galapagos in 1835. 

The macro would do the formatting and indexing simultaneously. But would the
optional argument be recognised if the macro is within another as above?

Many thanks 

Laszlo



More information about the tex-eplain mailing list