\documentstyle{article} % modify index file with control sequences and special characters \begin{document} \def \filename {arabdoc} {\catcode `\|=0 \catcode `\\=12 |gdef |B{\}} \def \do #1{\catcode`#1=12} \def \indexentry {% build new index entry \begingroup \dospecials \catcode`\{=1 \catcode`\}=2 \idxentry } \def \idxentry #1#2{% build new index entry \immediate \write \newfile {\string \indexentry {\process #1!?}{#2}}\endgroup } \def \process #1#2!#3?{% control sequences verbatim \if #1\B.#2@\string \verb/#1#2/\else \ifx #1-#2@\string \verb/#1#2/\else \if #1_#2@#1#2\else \ifx #1'#2@#1#2\else \ifx #1`#2@#1#2\else \ifx #1,#2@#1#2\else \if #1\noexpand ~#2@#1#2\else \ifx #1.\processcs #2!#3?\else #1#2% \fi\fi\fi\fi\fi\fi\fi\fi \ifx \relax #3\relax \else !\process #3?\fi } \def \processcs #1#2!#3?{% control sequence after dot \if #1\B#2@#1#2\else .#1#2\fi } \newwrite \newfile \immediate \openout \newfile =\filename.idn\relax \typeout {Writing new indexfile \filename.idn} \input \filename.idx\relax \end{document}