Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In my document, some glossary entries appear within the section titles. E.g.:

\documentclass{article}
    \usepackage{glossaries}
    \makeglossaries
    \begin{document}
        \tableofcontents
        \section{\newglossaryentry{1}{name=somename,description={Description.}}\gls{111}}
    \printglossaries
\end{document}

When compiling for a second time, it reports:

Package glossaries Error: Glossary entry `1' has already been defined.

I think maybe it appears in the table of contents, then in the page, then in the headings within the page, so it returns this error.

  • How can I place glossary entries inside \part's, \chapter's, and \section's while displaying a table of contents and page headings with the title of the current section?
  • The page number listed in the glossary should point to the first appearance of the entry within the title of the chapter as it appears within the page (i.e. not point to the location in the table of contents).
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

The "already defined" error comes from the fact that the \newglossaryentry makes its way into the ToC, which then executes it twice.

You should use the ToC-caption entry when performing such commands within section headings to avoid the duplication:

\section[<toc-entry>]{<heading>}

enter image description here

\documentclass{article}
\usepackage{glossaries}% http://ctan.org/pkg/glossaries
\makeglossaries
\begin{document}
\tableofcontents
\section[somename]{\newglossaryentry{1}{name=somename,description={Description.}}\gls{1}}
\printglossaries
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.