MakeIndex, Nomenclature, Glossaries and Acronymsmodified "see" command adds spurious page number

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

modified "see" command adds spurious page number

Post by murraye »

My document uses a command modifying the usual indexing "see" command in order to surround the entire "see..." phrase in parentheses. When I run the document through pdflatexmk, I'm getting a spurious page number there. (The ordinary "see" command doesn't do this.) What's wrong?

In the following MWE, the "see" correctly gives index entry "zero, see zero elements". But the "seeonly" entry gives "additive identity (see zero elements), 1". The ", 1" are the spurious text.

(Some years ago, when I used just such a command, that kind of spurious text did not appear.)

Code: Select all

\documentclass{article}

\newcommand{\seeonly}[1]{(\emph{see} #1)}
\usepackage{makeidx}\makeindex

\begin{document}

This is a very short book. It's about zero.\index{zero elements}
\index{zero|see{zero elements}}
\index{additive identity \seeonly{zero elements}}

\printindex

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

modified "see" command adds spurious page number

Post by localghost »

The command needs two arguments.

Code: Select all

\documentclass{article}
\usepackage{makeidx}

\makeindex

\newcommand{\seeonly}[2]{(\emph{see} #1)}

\begin{document}
  This is a very short book. It's about zero.\index{zero elements}
  \index{zero|see{zero elements}}
  \index{additive identity \seeonly{zero elements}}

  \printindex
\end{document}
For an explanation see Section 4.2 of the makeidx manual. Consider to use the more sophisticated imakeidx package instead.


Thorsten
murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

modified "see" command adds spurious page number

Post by murraye »

localghost wrote:The command needs two arguments.

Code: Select all

\documentclass{article}
\usepackage{makeidx}

\makeindex

\newcommand{\seeonly}[2]{(\emph{see} #1)}

\begin{document}
  This is a very short book. It's about zero.\index{zero elements}
  \index{zero|see{zero elements}}
  \index{additive identity \seeonly{zero elements}}

  \printindex
\end{document}
For an explanation see Section 4.2 of the makeidx manual. Consider to use the more sophisticated imakeidx package instead.


Thorsten
That change does not change the fault I'm seeing: the spurious page number still appears in "additive identity (see zero elements) 1".

Yes, I deleted all auxiliary files before running this again with the change. (In fact, I directly copied and pasted the above code to replace what I had.)
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

modified "see" command adds spurious page number

Post by cgnieder »

You need to use it like this:

Code: Select all

\documentclass{article}
\usepackage{makeidx}

\makeindex

\newcommand{\seeonly}[2]{(\emph{see} #1)}

\begin{document}
  This is a very short book. It's about zero.\index{zero elements}
  \index{zero|see{zero elements}}
  \index{additive identity|seeonly{zero elements}}%<= watch the usage here

  \printindex
\end{document}
Regards
site moderator & package author
murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

modified "see" command adds spurious page number

Post by murraye »

cgnieder wrote:You need to use it like this:

Code: Select all

\documentclass{article}
\usepackage{makeidx}

\makeindex

\newcommand{\seeonly}[2]{(\emph{see} #1)}

\begin{document}
  This is a very short book. It's about zero.\index{zero elements}
  \index{zero|see{zero elements}}
  \index{additive identity|seeonly{zero elements}}%<= watch the usage here

  \printindex
\end{document}
That correction does suppress the unwanted page number. However, it still causes printing of an unwanted comma: "additive identity, (see zero elements)"
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

modified "see" command adds spurious page number

Post by cgnieder »

Yes, as this is set by makeindex.

When this is used

Code: Select all

\index{entry|page number formatting}
makeindex sets the code specified by

Code: Select all

delim_0
It's default definition is ", " including a space after the comma.

You can try the following (untested):

Code: Select all

\documentclass{article}
\usepackage{makeidx}

\newcommand\gobbletwo[2]{}
\newcommand*\seeonly[2]{(\emph{see} #1)}

\makeindex

\begin{document}
  This is a very short book. It's about zero.\index{zero elements}
  \index{zero|see{zero elements}}
  \index{additive identity \seeonly{zero elements}|gobbletwo}

  \printindex
\end{document}
Regards
Last edited by cgnieder on Wed Sep 19, 2012 11:31 pm, edited 1 time in total.
site moderator & package author
murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

modified "see" command adds spurious page number

Post by murraye »

The solution using macro \gobbletwo works just fine. Thank you!

The same ruse works with commands for "(see also...)" and "See also..." , as shown below.

Code: Select all

\documentclass{article}
\usepackage{makeidx}

\makeindex

\newcommand\gobbletwo[2]{}
\newcommand*{\seeonly}[2]{(\emph{see} #1)}
\newcommand*{\also}[2]{(\emph{see also} #1)}
\newcommand{\Also}[2]{\emph{See also} #1}

\begin{document}
  This is a short book. It's about zero.\index{zero elements}
  
  \index{zero|see{zero elements}}
  \index{elements}
 \index{additive identity \seeonly{zero elements}|gobbletwo}

 Therefore, it's also about nothing.\index{nothing}
 \index{nothing!\also{zero elements}|gobbletwo}
 
  That's the same as zilch.\index{zilch}
 \index{zilch!\Also{nothing}|gobbletwo}

\printindex
\end{document}
murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

modified "see" command adds spurious page number

Post by murraye »

Did the functionality of makeindex change markedly since 1997? I ask because when I last used it then while typesetting a book, I did not have to resort to ruses such as were suggested here and do work. Rather, I could use the versions of \seeonly and \also that I originally showed in my first posts.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

modified "see" command adds spurious page number

Post by cgnieder »

I honestly can't tell as I've used makeindex the first time only a few years ago. Also I only ever used the \see command… sorry.

Regards
site moderator & package author
murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

modified "see" command adds spurious page number

Post by murraye »

Alas, all is not well with the proposed solution using \gobbletwo afer all. After each use of \seeonly, \also or \Also that involve \gobbletwo, the next index entry is printed run-on to the end of that "see also" or "See also" line. Here's the source:

Code: Select all

\documentclass{article}
\usepackage{makeidx}
\makeindex

\newcommand\gobbletwo[2]{}
\newcommand*{\seeonly}[2]{(\emph{see} #1)}
\newcommand*{\also}[2]{(\emph{see also} #1)}
\newcommand{\Also}[2]{\emph{See also} #1}

\begin{document}
This is a short book. It's about zero.
\index{zero elements}
\index{zero \seeonly{zero elements}|gobbletwo}
\index{additive identity \seeonly{zero elements}|gobbletwo}
\index{additive subtraction}

Therefore, it's also about nothing.
\index{nothing}
\index{nothing!zz@\also{zero elements}|gobbletwo}
Which means null.
\index{null}\index{nothing!nil}

That's the same as zilch.
\index{zilch}
\index{zilch!zero}
\index{zilch!\Also{nothing}|gobbletwo}
 
 \newpage
 Another name for zilch is nil.\index{zilch}

\printindex
\end{document}
The printed index looks roughly like this (in the proper font, and with "see", "see also", and "See also" in italics, of course):

Code: Select all

additive identity (see zero elements) ad-
               ditive subraction, 1

nothing, 1
      nil, 1
      (see also zero elements) null, 1

zero (see zero elements) zero elements,
               1
zilch, 1, 2
        See also nothing zero, 1
Notice how the top-level entry "additive subtraction" is run-on with the preceding entry. Likewise the top-level entries "null" and "zero elements".
Last edited by murraye on Sun Sep 23, 2012 6:41 pm, edited 1 time in total.
Post Reply