4

I have nearly the same problem as this guy but the solution doesn't work for me, I think because the string I am indexing is in a macro argument.

From the other question:

The characters !, @, and | need to be escaped in an indexing context. For makeindex to understand you mean to mention them rather than use them, you must 'quote' them with a ". The following should do the trick:

\index{"!} % or, in this case: \fun{"!}

Applying this to my code I get

\newcommand{\coper}[1]%
{%
    \texttt{#1}%
    \ifthenelse%
        {\equal{#1}{!} \OR \equal{#1}{@}}%
        {%
            \index{"#1@\texttt{"#1} (C operator)}%
            \index{operators!\texttt{"#1} (C)}%
        }%
        {%
            \index{#1@\texttt{#1} (C operator)}%
            \index{operators!\texttt{#1} (C)}%
        }%
}

Invoking \coper{!} adds an entry to the index, but the exclamation point does not appear in the index (it's just blank, but the surrounding text is there).

How do I add the exclamation point to the index when it is given through a macro argument?

  • as always it would be better to put a complete documument showing the probkem – David Carlisle Feb 2 '17 at 23:09
4

It's unrelated to " just as the error message indicates you have more { than }

i assume

 \index{"#1@\texttt{"#1} (C operator)%

was intended to be

 \index{"#1@\texttt{"#1} (C operator)}%

and

           \index{#1@\texttt{#1} (C operator)%

intended to be

           \index{#1@\texttt{#1} (C operator)}%

enter image description here

\documentclass{article}

\usepackage{makeidx,ifthen}
\makeindex
\begin{document}

\newcommand{\coper}[1]%
{%
    \texttt{#1}%
    \ifthenelse%
        {\equal{#1}{!} \OR \equal{#1}{@}}%
        {%
            \index{"#1@\texttt{"#1} (C operator)}%
            \index{operators!\texttt{"#1} (C)}%
        }%
        {%
            \index{#1@\texttt{#1} (C operator)}%
            \index{operators!\texttt{#1} (C)}%
        }%
}

aaa\coper{!}

\printindex

\end{document}
  • Ah, that fixes the compile error, although I still don't have the desired result. I updated my question. – spraff Feb 2 '17 at 23:06
  • @spraff works for me, I added the output – David Carlisle Feb 2 '17 at 23:16
  • I did a clean build and that fixed it. I've been getting a lot of n00b help from you, David, thanks a lot, much appreciated :-) – spraff Feb 2 '17 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.