LaTeX forum ⇒ MakeIndex, Nomenclature, Glossaries and Acronymsmodified "see" command adds spurious page number Topic is solved

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
User avatar
cgnieder
Site Moderator
Posts: 2001
Joined: Sat Apr 16, 2011 7:27 pm

modified "see" command adds spurious page number

Postby cgnieder » Sun Sep 23, 2012 6:02 pm

Indeed… But I said I hadn't tested it. But the solution is simple: instead of gobbling two tokens we only need to gobble one! So instead define
\newcommand\gobble[1]{}

and replace each occurrence of gobbletwo with gobble.

Regards
Last edited by cgnieder on Mon Sep 24, 2012 12:32 pm, edited 1 time in total.
site moderator & package author

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook
murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

modified "see" command adds spurious page number

Postby murraye » Sun Sep 23, 2012 6:56 pm

I think I finally figured out, but would welcome suggestions for improvement or additional test cases. I changed the \gobbletwo command to a command \gobbleonethat eats only the first argument but spits out the second.

Here's my test document:
\documentclass{article}
\usepackage{makeidx}
\makeindex

\newcommand\gobbleone[2]{#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}|gobbleone}
\index{additive identity \seeonly{zero elements}|gobbleone}
\index{additive subtraction}

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

That's the same as zilch.
\index{zilch}
\index{zilch!zero}
\index{zilch!zz@\Also{nothing}|gobbleone}
 
 \newpage
 Another name for zilch is nil.\index{zilch}Good grief!\index{zounds}

\printindex
\end{document}

User avatar
cgnieder
Site Moderator
Posts: 2001
Joined: Sat Apr 16, 2011 7:27 pm

modified "see" command adds spurious page number

Postby cgnieder » Sun Sep 23, 2012 7:04 pm

murraye wrote:I think I finally figured out, but would welcome suggestions for improvement or additional test cases. I changed the \gobbletwo command to a command \gobbleonethat eats only the first argument but spits out the second.


This is essentially the same as my suggestion. I'd favor mine as it doesn't read in the next token first just to reuse it. One remark regarding semantics:

My definitions of \gobble and \gobbletwo are the the same as the LaTeX kernel commands \@gobble and \@gobbletwo. That's why I chose the names. \gobbleone reflects its purpose even more, I think. I could have used
\makeatletter
\let\gobble\@gobble% or
\let\gobbletwo\@gobbletwo% respectively
\makeatother


Your definition of \gobbleone, however, is exactly the same as the LaTeX kernel command \@secondoftwo. In order to use a semantically meaningful command you should use the definition

\newcommand\gobbleone[1]{}


(same as my \gobble) or

\newcommand\secondoftwo[2]{#2}


Best regards
Last edited by cgnieder on Mon Sep 24, 2012 12:34 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

Postby murraye » Sun Sep 23, 2012 10:37 pm

cgnieder wrote:
murraye wrote:I think I finally figured out, but would welcome suggestions for improvement or additional test cases. I changed the \gobbletwo command to a command \gobbleonethat eats only the first argument but spits out the second.


This is essentially the same as my suggestion. I'd favor mine as it doesn't read in the next token first just to reuse it.....


Yes, your solution is better. Again, since your post was so short and to-the-point compared with mine, I had just missed it when posting that longer solution of mine. Thanks for the follow-up!

extal
Posts: 8
Joined: Tue Sep 06, 2011 3:01 pm

modified "see" command adds spurious page number

Postby extal » Thu Dec 20, 2012 4:30 pm

I have just seen your query today while investigating MakeIndex myself.
Is not your error to use \seeonly rather than |seeonlyinside the \index parameter?
The following works well for me.
    \documentclass{article}

    \newcommand{\seeonly}[2]{(\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}
Last edited by cgnieder on Fri Dec 21, 2012 5:00 pm, edited 1 time in total.

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

modified "see" command adds spurious page number

Postby murraye » Thu Dec 20, 2012 5:31 pm

extal wrote:I have just seen your query today while investigating MakeIndex myself.
Is not your error to use \seeonly rather than |seeonly inside the \index parameter?
The following works well for me.
    \documentclass{article}

    \newcommand{\seeonly}[2]{(\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}

No, your code produces an unwanted comma in the index entry for "additive identity", between "additive identity" and the parenthesized reference "(see zero elements)".

extal
Posts: 8
Joined: Tue Sep 06, 2011 3:01 pm

modified "see" command adds spurious page number

Postby extal » Thu Dec 20, 2012 9:20 pm

Murraye wrote
No, your code produces an unwanted comma in the index entry for "additive identity", between "additive identity" and the parenthesized reference "(see zero elements)".


Murraye you are quite correct. The original post did not mention an unwanted comma (,) after the index entry merely an unwanted page number. I should have read the thread further and more carefully to see that you had made my suggestion already and that that had been rejected on the grounds of the superfluous comma.

Here is my solution which gets rid of the offending comma.

    \documentclass{article}

    \usepackage{makeidx}
    
    \newcommand{\seeonly}[2]{(\emph{see} #1)}
    \newcommand{\adjtext}[2]{#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@\adjtext{additive identity}|seeonly{zero elements}}
    \pagebreak\\
    zero\index{zero elements}
    \printindex

    \end{document}

It was suggested to me by something similar I had been working on. Just why it works I am at a loss to understand. To find out would require me, I imagine, to look into the bowels of Makeindex more carefully that I wish or have the time or skill to. The .idx file is

  \begin{theindex}

  \item \adjtext{additive identity}, \seeonly{zero elements}{1}

  \indexspace

  \item zero, \see{zero elements}{1}
  \item zero elements, 1, 2

\end{theindex}

This does have a comma after the index entry which the \adjtext seems to kill. I have not been able to translate

\index{additive identity@\adjtext{additive identity}%
              |seeonly{zero elements}}

into a working command with the two input data as parameters, as I had hoped to. That is a serious drawback unless there are only a few \seeonlys in the index. Perhaps someone else can succeed with that.
Last edited by cgnieder on Fri Dec 21, 2012 5:02 pm, edited 1 time in total.

extal
Posts: 8
Joined: Tue Sep 06, 2011 3:01 pm

modified "see" command adds spurious page number

Postby extal » Fri Dec 21, 2012 4:53 pm

As a postscript to my previous post

\newcommand{\SeeOnly}[2]{\index{#1@\protect\adjtext{#1}|seeonly{#2}}}

where \seeonly and \adjtext are as previously, does all that is aked of it.

The other way to get rid of the offending text-following comma is to use an index style (.ist) file containing (and only containing, since all other keys are set to default values)

delim_0 ""
delim_1 ""
delim_2 "" 

and feed it as a parameter to \makeindex as explained in the usual LaTeX documentation. This, however, will get rid of text-following commas for all index entries at all levels.
Last edited by cgnieder on Fri Dec 21, 2012 5:03 pm, edited 1 time in total.


Return to “MakeIndex, Nomenclature, Glossaries and Acronyms”

Who is online

Users browsing this forum: No registered users and 3 guests