3

I'm using a few acronyms in my thesis, and I want them to appear in the alphabetical index as:

ACR, see acronym

acronym, iii, 5, 48

This is my code:

\documentclass[11pt,a4paper]{book}

\usepackage[nottoc,notlot,notlof]{tocbibind}
\usepackage{imakeidx}
\usepackage{bookmark} % includes hyperref
\usepackage[toc,acronym]{glossaries}

\makeindex[intoc]
\makeglossaries

\newacronym{fmea}{FMEA}{Fail\-ure Mode and Ef\-fect A\-nal\-y\-sis}

\begin{document}

    \frontmatter
    \tableofcontents
    
    \mainmatter
    Occurrence of the acronym \acrlong{FMEA}
    \index{FMEA}
    
    \backmatter
    \printglossary[type=\acronymtype,nonumberlist]
    \index{failure mode and effect analysis|see{FMEA}}
    \printindex
\end{document}

This code works perfectly but I have to declare each acronym twice (as newacronym and as index "see"). I introduced this command as a variant of \newacronym which also generates the corresponding \index voice:

\newcommand{\newacronymidx}[3]{
  \newacronym{#1}{#2}{#3}
  \index{\MakeLowercase{#3}|see #2}
}

\newacronym{fmea}{FMEA}{Fail\-ure Mode and Ef\-fect A\-nal\-y\-sis}

I have three problems:

  1. the "ACR, see acronym" index entry appears at the beginning of the alphabetical index instead of its correct alphabetically-sorted position
  2. now I get a page number after "ACR, see acronym", whose hyperlink refers to first page (the frontispiece, not included in this MWE)
  3. for some weird reason I can't understand, FMEA becomes FEA (which does not appear anywhere in my code)

Screenshot of the index

In this example, FMEA is defined with \newacronymidx, other acronyms with \newacronym and \index{acronym|see ACR}. The only wrong one is FMEA.

Question 1:

I think that the first two problems are related to the position of the \index command in the source (which is now in the preamble). Is there any way to create an auxiliary files, use \makeacronymidx to append a new line with the \index command to this file, and use \include{myAuxFile} right before \printindex?

Question 2:

Any idea about FMEA becoming FEA in the index? This does not happen with this MWE, but I can't post the full code here...

Thank you!

EDIT: solved by Nicola Talbot in the comments

\newcommand{\newacronymidx}[3]{
  \newacronym{#1}{#2}{#3}
  \index{#3@\MakeLowercase{#3}|see {#2}}
}
4
  • 1
    Your definition of \newacronymidx is missing braces for the see argument: \index{\MakeLowercase{#3}|see #2} should be \index{\MakeLowercase{#3}|see{#2}} (which accounts for Question 2, M is treated as the second argument which is ignored). Apr 13, 2018 at 17:17
  • 1
    Sorry, I missed the obvious solution to the main part of the question. You need to specify the actual (sort) part: \index{#3@\MakeLowercase{#3}|see{#2}}. (Pretty sure this is a dup.) Apr 13, 2018 at 21:12
  • Thank you, now everything works fine. So the first problem was due to the fact that the entry was sorted under "\" instead of "f", is that right? Apr 14, 2018 at 0:56
  • Yes, that's right. Apr 14, 2018 at 10:14

2 Answers 2

4

Summary of comments:

  • A sort value is required when the indexed term contains formatting commands (as makeindex doesn't ignore LaTeX commands but treats them as a string starting with \).
  • The see encap requires braces around the argument: |see FMEA becomes \see FMEA{1} which is effectively \see{F}{M}EA1, so the M is discarded and the page number appears.

So the definition needs to be:

\newcommand{\newacronymidx}[3]{%
  \newacronym{#1}{#2}{#3}%
  \index{#3@\MakeLowercase{#3}|see{#2}}%
}
1

If this could be helpful to anyone, here are two ways to index acronyms, with the corrections made by Nicola Talbot. This code allows to specify the sorting part as optional argument.


Method 1: acronym points to full text

\usepackage{etoolbox}

\newcommand{\newacronymidx}[4][]{ % rimanda acronimo a esteso
    \newacronym{#2}{#3}{#4}
    \ifstrempty{#1}
        { \index{#3|see{\MakeLowercase{#4}}} }
        { \index{#3|see{#1}} }
}

\newacronymidx{acr}{ACR}{Acronym}
\newacronymidx[qwerty]{abb}{ABB}{Abbreviation}

INDEX:
ABB, see qwerty
ACR, see acronym
acronym, 18
qwerty, 36, 58

A possible use could be:

\newacronymidx[control limits]{ucl}{UCL}{Upper Control Limit}

Index entry: UCL, see control limits


Method 2: full text points to acronym

\usepackage{etoolbox}

\newcommand{\newacronymidx}[4][]{ % rimanda esteso ad acronimo
    \newacronym{#2}{#3}{#4}
    \ifstrempty{#1}
    { \index{#4@\MakeLowercase{#4}|see{#3}} }
    { \index{#1|see{#3}} }
}

\newacronymidx{acr}{ACR}{Acronym}
\newacronymidx[qwerty]{abb}{ABB}{Abbreviation}

INDEX:
ABB, 36, 58
ACR, 18
acronym, see ACR
qwerty, see ABB

A possible use could be:

\newacronymidx[Western Electric rules]{wer}{WER}{Western Electric Rules}

Index entry: Western Electric rules, see WER

(I don't want Western Electric to be lowercased)

You must log in to answer this question.

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