4

I've created a macro which highlights a word and sends it to the index

\newcommand{\indexthis}[1]{\textcolor{Maroon}{\textbf{#1}}\index{\MakeLowercase{#1}@{#1}}\xspace).

However the \MakeLowercase command does not appear to work as words which appear at the beginning of the sentence are sent to the .idx file with the capital letter in place. This then affects the sort order of the index as the capitalised words come first. Here's a minimal worked example

\documentclass{minimal}

\usepackage{makeidx}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

\newcommand{\indexthis}[1]{\textcolor{Maroon}{\textbf{#1}}\index{\MakeLowercase{#1}@{#1}}\xspace}

\makeindex
%================================================================================================
\begin{document}

\indexthis{Aardvarks} keep out of the sun \\
\indexthis{Badgers} prefer the shade \\
But \indexthis{antelopes} adore sunshine \\
And \indexthis{lions} are sun addicts \\

\printindex

\end{document}

And here is a screenshot

Screenshot

The problem is that we have two A-Z lists, one for words which begin with uppercase letters, and one for words which begin with lowercase letters. Can anyone make changes to the macro to force the argument #1 into lowercase before sending it to the .idx file? Alternatively is there a way to get makeindex to ignore capital letters during sorting? Ta.

(NB there's a thread Applying \lowercase to index entries which deals partly with this issue. However, the solution is a macro containing two arguments. I'm trying to both highlight and add to the index using only one argument, and I haven't been able to adapt this code)

5
  • 1
    to actually run, your example needs \usepackage{xspace}. if you don't care whether some of your index entries start with uppercase letters, then \newcommand{\indexthis}[1]{\textcolor{Maroon}{\textbf{#1}}\index{#1}\xspace} would have them sorted in the right alphabetical order -- ordinarily, makeindex doesn't make a distinction. Aug 20, 2013 at 16:27
  • It's working now, and I don't understand what you did except remove the \lowercase command. Is it just a case of running makeindex enough times? Aug 20, 2013 at 17:42
  • what i did was remove the \MakeLowercase{#1}@ and extra braces. so an entry with an initial caps will be sorted separately from an all-lowercase entry, and if two entries are otherwise the same (say "Aardvark" and "aardvark"), you will get two entries in the index -- but sorted next to one another. Aug 20, 2013 at 17:54
  • Brill. So it was just a case of curly brackets after all that? Aug 21, 2013 at 17:36
  • i haven't checked this, but i think it may be at least partly a case of the \MakeLowercase not being expanded at the right time. the argument of an \index command is written out verbatim (one should check to see what actually gets into the .idx file), and the whole shebang is then sorted by a "dumb" ascii sort. the extra braces may play a part, but that needs checking. i will look into this; i'm writing a tome on how to abolish stealthy glitches, and this looks like something i hadn't yet considered. Aug 21, 2013 at 18:49

2 Answers 2

5

Perhaps

\newcommand{\indexthis}[1]{\textcolor{Maroon}{\textbf{#1}}\lowercase{\index{#1}}}

(deleted xspace as it is not needed here as the macro call ends with } so does not drop spaces)

3

Are you also concerned about singular/plural use? For example, it would be more usual to have a single index entry for lion rather than separate index entries for lion and lions? Here's a possible way of adjusting for singular/plural/uppercase/lowercase:

\documentclass{article}

\usepackage[dvipsnames]{xcolor}
\usepackage[style=index]{glossaries}

\makeglossaries

\renewcommand*{\glossaryname}{\indexname}
\renewcommand*{\glsnamefont}[1]{\textmd{#1}}
\renewcommand*{\glstextformat}[1]{\textcolor{Maroon}{#1}}

\newcommand*{\newterm}[2][]{%
  \newglossaryentry{#2}{name={#2},description={\nopostdesc},#1}%
}

\newterm{lion}
\newterm{aardvark}
\newterm{badger}
\newterm{antelope}

\begin{document}

\Glspl{lion} or \gls{lion}.
\Gls{lion} or \glspl{lion}.

\Glspl{aardvark} or \gls{aardvark}.
\Gls{aardvark} or \glspl{aardvark}.

\Glspl{badger} or \gls{badger}.
\Gls{badger} or \glspl{badger}.

\Glspl{antelope} or \gls{antelope}.
\Gls{antelope} or \glspl{antelope}.

\printglossaries

\end{document}

The result looks like:

Image of resulting document

The makeindex call is now

makeindex -s "test.ist" -t "test.glg" -o "test.gls" "test.glo"

where the document is called test.tex. Alteratively, you can just do makeglossaries test.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .