4

I would like to create an index as it can be found in glossaries-user.pdf.

Precise goal: A glossary for acronyms and an index in which all acronyms are listed (though only for selected pages) in addition to other terms. The index should have its pagenumbers colored, right aligned in two balanced columns, with dots filling the gap between the term and the page numbers.

Current attempt: Currently glossaries is used for the glossary and I plan on using an indexing package for the index with xindy and a style file.

Problem: While I am not sure about the correct style definition, I get the error message undefined controlsequence \lettergroup as soon as I use the example style file

MWE:

\documentclass{muthesis}

\usepackage[xindy]{imakeidx}

\makeindex[options={-M indexStyle}]

\usepackage{lipsum}

\begin{document}
    ASd\index{asd}

    \lipsum

    \index{end}

    \printindex
\end{document}

Stylefile (based on makeidx.xdy from xindy, commented out lines that just caused warnings/errors):

;; $Id: makeidx.xdy,v 1.1 1997/02/07 14:17:31 kehr Exp $
;;
;; This file implements the Output Style Specifiers for plain
;; makeindex (see manpage of makeindex 2.x) in conjuction with
;; TeX/LaTeX.
;;
;; The Input Style Specifiers of makeindex cannot de defined in a
;; `xindy' style file. Use an appropriate version of the program
;; `tex2xindy' which should be included with this distribution.
;;
;; Since `xindy' uses a different specification language than
;; makeindex and some of the command-line options of makeindex are now
;; only available as style-file commands, this file can only serve as
;; a template that produces the default-markup of makeindex. However,
;; it may be used as a starting point for further modification and
;; specialization.
;;
;; The following values are taken from the source of the makeindex
;; distribution (see file scanst.h and the manpage) for further
;; details.
;;

;; Define all attributes appearing in your document. Your attributes
;; are all encapsulators you use in your \index commands following the
;; vertical bar sign `|'. For example `foo' is the attribute in the
;; command \index{...|foo}. Here you specify the set of attributes
;; that appear in your document, the order in which they appear in the
;; index and which one superdes the other.
;;
;; Example: a) (define-attibutes (("default") ("bf") ("it")))
;;          b) (define-attibutes (("bf" "default")))
;;
;; The initial command is (change it accordingly):

;; (define-attributes (("default")))

;; The description of the location-classes.
;; Add more location classes as needed.

;; (define-location-class "arabic-page-numbers" ("arabic-numbers"))
;; (define-location-class "roman-page-numbers"  ("roman-numbers-lowercase"))
;; (define-location-class "Roman-page-numbers"  ("roman-numbers-uppercase"))
;; (define-location-class "alpha-page-numbers"  ("alpha"))
;; (define-location-class "Alpha-page-numbers"  ("ALPHA"))

;; The most frequently used cross reference class "see". Add more, if
;; necessary.

;; (define-crossref-class "see")
;; (markup-crossref-list :open "\see{" :close "}{}" :class "see")

;; In makeindex: page_precedence <string>  "rnaRA"
;; List all location classes appearing in your document.

(define-location-class-order ("roman-page-numbers"
                  "arabic-page-numbers"
                  "alpha-page-numbers"
                  "Roman-page-numbers"
                  "Alpha-page-numbers"
                  "see"))


;; preamble <string>        "\\begin{theindex}\n"
;; postamble <string>       "\n\n\\end{theindex}\n"

(markup-index :open  "\begin{theindex}~n"
          :close "~n~n\end{theindex}~n"
          :tree)

;; These specifiers are not directly supported via a command-line
;; switch as in makeindex. Add the appropriate markup-commands into
;; the preamble.

;; setpage_prefix <string>  "~n  \setcounter{page}{"
;; setpage_suffix <string>  "}~n"

;; group_skip <string>      "~n~n  \indexspace~n"

(markup-letter-group-list :sep "~n~n  \indexspace~n")

;; The indexentries (item_<..> specifiers)

(markup-indexentry :open "~n  \item "           :depth 0)
(markup-indexentry :open "~n    \subitem "      :depth 1)
(markup-indexentry :open "~n      \subsubitem " :depth 2)

;; Location-references

;; delim_0 <string>         ", "
;; delim_1 <string>         ", "
;; delim_2 <string>         ", "

(markup-locclass-list :open ", " :sep ", ")

;; delim_n <string>         ", "

(markup-locref-list   :sep ", ")

;; delim_r <string>         "--"

(markup-range :sep "--")

;; Here follow all letter-groups. The short-cut notation is used here.

(define-letter-groups
    ("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m"
     "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"))

;;
;; The sort-rules map all letters to their lowercase counterpart.
;;

(sort-rule "A" "a")
(sort-rule "B" "b")
(sort-rule "C" "c")
(sort-rule "D" "d")
(sort-rule "E" "e")
(sort-rule "F" "f")
(sort-rule "G" "g")
(sort-rule "H" "h")
(sort-rule "I" "i")
(sort-rule "J" "j")
(sort-rule "K" "k")
(sort-rule "L" "l")
(sort-rule "M" "m")
(sort-rule "N" "n")
(sort-rule "O" "o")
(sort-rule "P" "p")
(sort-rule "Q" "q")
(sort-rule "R" "r")
(sort-rule "S" "s")
(sort-rule "T" "t")
(sort-rule "U" "u")
(sort-rule "V" "v")
(sort-rule "W" "w")
(sort-rule "X" "x")
(sort-rule "Y" "y")
(sort-rule "Z" "z")


;; That's all ;-)


;; End

;; Local Variables:
;; mode: lisp
;; End:

What the index should look like: What the index should look like

Rational/What I tried: Since I would like a index as in the user guide, the best solution would be to copy the method. However, when I tried to create the user guide from the sources the index did not show up. I assume I have to run texindy with specific parameters, (as is needed for the glossaries-code.pdf but could not find instructions for the generation. Furthermore, it seems to me that the index code is anchored in the nctldoc class, and I am forced to use the muthesis class. As the author of glossaries prefers the use of an external indexing package, I assumed that it would make sense to use an indexing package. Furthermore, I am unsure how I would use the term in the Acronym and the index glossary. While there is a solution to make a glossary term only add selected page numbers, using an explicit index package seems more straight forward.

I do not care which indexing package to use, currently I am trying imakeidx with xindy and a style file.

4
  • If I had to rewrite glossaries-user.tex, I'd probably use bib2gls instead. (It's too big a task and not worth the effort.) If you want to stick with makeindex or xindy, then using the glossaries-extra extension package is better for this type of thing. Commented Apr 26, 2018 at 11:03
  • You seem to be asking two questions: (1) how to have a term appear in both a glossary list (e.g. list of abbreviations) and in the index, which I've answered, and (2) how to adjust the non-glossary index style. Commented Apr 26, 2018 at 11:43
  • @NicolaTalbot: I am actually most interested in (2), I don't want every use of \gls{myAcronym} to appear in the index. While you have an excellent answer for this, I am under the expression that it is better to use an actual index package for the index, rather than glossaries. My rational for this is that you, the Queen of glossaries, seem to use makeidx over the index glossaries option. This leads to my formatting question for the index. However, I wanted to avoid the XY problem, and leave the option of using glossaries ...
    – ted
    Commented Apr 26, 2018 at 11:59
  • ... which then changes the index formating problem from a xindy problem into a formatting a glossarie problem. While, I had no issues with changing glossaries format, it seems to me that using imakeidx is the right tool
    – ted
    Commented Apr 26, 2018 at 12:01

1 Answer 1

2

The index should have its pagenumbers colored, right aligned in two balanced columns, with dots filling the gap between the term and the page numbers.

This can be achieved as follows:

\RequirePackage{filecontents}
\begin{filecontents*}{indexStyle.xdy}
(markup-locclass-list :open "\dotfill " :sep "\dotfill ")
\end{filecontents*}

\documentclass{muthesis}

\usepackage[xindy]{imakeidx}
\usepackage[colorlinks]{hyperref}

\makeindex[options={-M indexStyle}]

\usepackage{lipsum}

\begin{document}
    ASd\index{asd}

    \lipsum

    \index{end}

    \printindex
\end{document}

The index looks like:

image of index

For automatically indexing glossary entries, you could trying using the indexname and dualindex attributes. The example file sample-autoindex.tex provided with glossaries-extra uses this method:

\documentclass{report}

\usepackage[T1]{fontenc}

\usepackage{makeidx}
\usepackage[abbreviations,counter=chapter,nopostdot=false]{glossaries-extra}

\renewcommand*{\abbreviationsname}{List of Abbreviations}
\renewcommand*{\glossarypreamble}{\emph{Numbers refer to the 
\textbf{chapter} where the entry was referenced.}}

\makeindex
\makeglossaries

% Automatically index the location of entry in the glossary
% for those entries that are in the "general" category:

\glssetcategoryattribute{general}{indexname}{textbf}
\glssetcategoryattribute{general}{dualindex}{true}

% Only index first use for the glossary location lists
% (doesn't affect the indexing from "dualindex" attribute):
%\glssetcategoryattribute{general}{indexonlyfirst}{true}

% Automatically index the location of entry in the glossary
% for those entries that are in the "abbreviation" category
% and use "textbf" as the encap:

\glssetcategoryattribute{abbreviation}{indexname}{textbf}
\glssetcategoryattribute{abbreviation}{dualindex}{true}

% Only index first use for the glossary location lists
% (doesn't affect the indexing from "dualindex" attribute):
%\glssetcategoryattribute{abbreviation}{indexonlyfirst}{true}

% Convert the first letter of the name to upper case in the 
% glossary for general entries:
\glssetcategoryattribute{general}{glossname}{firstuc}

% Allow "format" key to override "dualindex" attribute.
\GlsXtrEnableIndexFormatOverride

% use first field instead of name field
\renewcommand*{\glsxtrautoindexentry}[1]{\string\glsentryfirst{#1}}

% use long form for the sort value, if provided:
\renewcommand*{\glsxtrautoindexassignsort}[2]{%
  \ifglshaslong{#2}%
  {\glsletentryfield{#1}{#2}{long}}%
  {\glsletentryfield{#1}{#2}{sort}}%
}

% Define general entries:

\newglossaryentry{duck}{name=duck,%
  description={a waterbird with webbed feet}}

\newglossaryentry{parrot}{name=parrot,%
  description={mainly tropical bird with bright plumage}}

\newglossaryentry{at}{name={@},%
  description={makeindex's default for the ``actual value''}}

\newglossaryentry{esc}{name={"},%
  description={makeindex's default for the ``escape value''}}

\newglossaryentry{level}{name={!},%
  description={makeindex's default for the ``level value''}}

\newglossaryentry{encap}{name={|},%
  description={makeindex's default for the ``encap value''}}

% Set abbreviation style:

\setabbreviationstyle{long-short-sc}

% Define abbreviations:

\newabbreviation
 {html}% identifying label
 {html}% short form
 {hypertext markup language}% long form

\newabbreviation
 {xml}% identifying label
 {xml}% short form
 {extensible markup language}% long form

\title{Sample document testing the glossaries-extra package}
\author{Nicola Talbot}

\begin{document}
\maketitle

\chapter{Introduction}

This is a sample\index{sample} document testing the
\texttt{glossaries-extra} package.

\chapter{General Entries}

Sample entries: \gls{duck} and \gls{parrot}.

Test makeindex's special characters: \gls{at} (actual)
\gls{esc} (escape) \gls{level} (level) and \gls{encap} (encap).

\chapter{Abbreviations}

First use: \gls{html} and \gls{xml}.

Next use: \gls{html} and \gls{xml}.

\newpage

Uses some entries again: \gls{duck} and \gls[format=textit]{parrot}.

\printglossaries

\printindex

\end{document}

The dualindex attribute is boolean. If true then whenever an entry is referenced with commands like \gls then it's also indexed with \index. For example \gls{duck} additionally does \index{duck}. If the indexonlyfirst attribute is set (commented out in the above) then only the first use of \gls (or variants) is accompanied by \index.

The indexname attribute, if set, indicates that the entry's place in the glossary should be indexed with \index. The value of this attribute may either be true (indexed with no encap) or the encap value. For example, the value textbf means that when the entry duck shows up in the glossary it should be indexed with \index{duck|textbf}. Since the glossary doesn't exist on the first LaTeX run, the index can't be fully created until after the glossary exists, so if indexname is used, then the build process needs to be:

pdflatex sample-autoindex
makeglossaries sample-autoindex
pdflatex sample-autoindex
makeindex sample-autoindex
pdflatex sample-autoindex

The actual part used in \index is obtained from \glsxtrautoindexentry{label}. By default this uses \glsentryname to match the way the term is displayed in the glossary. In the above, this is changed to use \glsentryfirst, which is the way the term appears on first use.

The sort part used in \index is assigned using \glsxtrautoindexassignsort{cs}{label}, where cs is the control sequence used to store the sort value. In the above, I've redefined it to use the long form if set. This means that abbreviations are sorted by their long form.

The \gls command (and its variants) allows the default encap used in the glossary to be changed with the format key. You can ensure that this encap is copied over to \index with

\GlsXtrEnableIndexFormatOverride

For example, with this set, \gls[format=textbf]{duck} does \index{duck|textbf} otherwise it would just do \index{duck}.

The complete document is sample-autoindex.pdf

The glossary looks like:

image of glossary

The list of abbreviations:

image of list of abbreviations

The index:

image of index

If you want to use hyperref, have a look at sample-autoindex-hyp instead

3
  • I think my question was poorly written, I tired to clarify: Main issue: How to get an index that looks like the one in your userguide. Sidenote: I am early enoguh in the flow to switch packages, but am currently trying to do the index with imakeidx and xindy. +1 for the excellent answer though
    – ted
    Commented Apr 26, 2018 at 12:05
  • @ted Sorry I misunderstood. I've updated my answer. Commented Apr 26, 2018 at 12:16
  • Not your fault, after all I could have just asked for the styling. Thanks for the quick reply.
    – ted
    Commented Apr 26, 2018 at 12:39

You must log in to answer this question.

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