3

In my thesis there are a large number of Arabic terms. I include these (transcribed) in the index. I would like to add the corresponding English term in parenthesis after the index entry, before the pointers to pages. To do this I define the command \trans that works in a similar way to the \see and \seealso commands. I put these command at the start of the document to ensure that they come before the page pointers in the index. This works fine, but the problem is that it produces a comma between the Arabic term and the translation, like so:

arabic term, (english translation), 2, 3

Is there a way to get rid of this comma for entries for which there are a translations? The output I want is

arabic term (english translation), 2, 3

\documentclass{book}
\usepackage{imakeidx}
\makeindex[columns=1]
\usepackage{kantlipsum}

\AtBeginDocument{
\index{arabic term|trans{english translation}}
}

\newcommand\trans[2]{(#1)}

\begin{document}
\kant[1]
\clearpage\kant[2]
\index{arabic term} 
\clearpage
\kant[3]
\index{arabic term} 

\printindex
\end{document}
2

Create a file andreas.ist (or whatever name you prefer, so long as the extension is .ist) in the same directory as your main TeX file, with the following contents

delim_0 "\\addindexcomma"

Now change your document to read

\documentclass{book}
\usepackage{imakeidx}
\makeindex[columns=1,options=-s andreas.ist]
\usepackage{kantlipsum}

\AtBeginDocument{%
  \index{arabic term|trans{english translation}}%
}

\newcommand\trans[2]{(#1)}
\makeatletter
\newcommand{\addindexcomma}{%
  \@ifnextchar\trans{\space}{,\space}%
}
\makeatother

\begin{document}
\kant[1]
\clearpage\kant[2]
\index{arabic term} 
\clearpage
\kant[3]
\index{arabic term} 

\index{bar} % for testing

\printindex
\end{document}

enter image description here

  • When I run the MWE it works fine, but when I implement it on my actual thesis the \index commands with the trans produce duplicate entries in the index, with the comma. – Andreas Sep 20 '15 at 21:59
  • @Andreas My crystal ball says nothing, unfortunately. – egreg Sep 20 '15 at 22:01
  • Hmm. I'll investigate further. – Andreas Sep 20 '15 at 22:36
  • @Andreas Are you perhaps hiding \index in some macro? – egreg Sep 20 '15 at 22:36
  • No, but I am using macros in them. – Andreas Sep 20 '15 at 22:40

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.