4

I often use the term range expansion in a text. Thus I'd like to abbreviate it using RE. When it first occurs in a chapter, The abbreviation should be expalained like this: Range expansion (RE). In my glossary I'd like to have an entry for both, RE and Range expansion. To make it easier for the reader to find the explanation for RE, I linked the description to the entry for Range expansion using \gls:

\newacronym{RE}{RE}{\gls{RangeExpansion}}
\newglossaryentry{RangeExpansion}{
    name        = {range expansion},
    description = {A range expansion ...}
}

Now I can use \gls{RE} in my text. The first time this happens each chapter, range expansion (RE) and afterwards it uses RE. At the beginning of a chapter I used the term at the beginning of a sentence - that made me use \Gls{RE}, since I'd like the sentence to start with an uppercase letter. But using \Gls resulted in the following error messages:

Missing \endcsname inserted \Glspl{RE}

and

glossaries: Glossary entry `\MakeUppercase {R}angeExpansion' has not been defined. \Glspl{RE}\index

When I don't link the explanation for RE, \Gls works fine:

\newacronym{RE}{RE}{range expansion}
\newglossaryentry{RangeExpansion}{
    name        = {range expansion},
    description = {A range expansion ...}
}

I also tried using \newacronym{RE}{RE}{\Gls{RangeExpansion}}, but this didn't work at all.

How do I have to call the Link to RangeExpansion within the description of the acronym, so that \gls and \Gls work?

  • Try \glsentrytext instead of \gls – karlkoeller Nov 19 '13 at 9:46
4

The first letter upper case commands, such as \Gls, use \makefirstuc which requires its argument to either be just text or in the form \\command{text} (e.g. \makefirstuc{\emph{text}} is equivalent to \emph{\MakeUppercase{t}ext}). What your code is attempting to do is \makefirstuc{\gls{RangeExpansion}} which becomes \gls{\MakeUppercase{R}angeExpansion} and the error occurs because \MakeUppercase{R}angeExpansion is an invalid label.

Another problem with your definition is that you get nested links where \gls{RE} is attempting to be a hyperlink both to the RE entry in the list of acronyms and to the RangeExpansion entry in the main glossary.

A better approach, which overcomes both the above issues is to do something like:

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage[acronym,description]{glossaries}

\makeglossaries

% Define command to create linked entries
% Syntax:
% \newlinkedacr[options]{entry-label}{acr-label}{short}{long}{description}
\newcommand*{\newlinkedacr}[6][]{%
  \newglossaryentry{#2}{name={#5},description={#6},#1}%
  \newacronym[description={\gls{#2}}]{#3}{#4}{#5}%
}

\newlinkedacr
 {RangeExpansion}% main entry label
 {RE}% acronym label
 {RE}% abbreviation
 {range expansion}% long form
 {A range expansion etc}% description

\begin{document}

First use: \gls{RE}. Subsequent use: \gls{RE}.

\glsresetall
First use: \Gls{RE}. Subsequent use: \Gls{RE}.

\printglossaries

\end{document}

Image of resulting document

Here, the description in the acronym list forms a hyperlink to the entry in the main glossary. The acronyms in the main body of the document link to the entry in the list of acronyms. If you prefer the long form in the first use to link to the main glossary rather than the list of acronyms, then this can be achieved although it's more complicated. The following example requires at least v4.0 of glossaries:

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage[acronym,hyperfirst=false]{glossaries}

\makeglossaries

% Define command to create linked entries
% Syntax:
% \newlinkedacr[options]{entry-label}{acr-label}{short}{long}{description}
\newcommand*{\newlinkedacr}[6][]{%
  \newglossaryentry{#2}{name={#5},description={#6},#1}%
  \newacronym[description={\glshyperlink{#2}},user1={#2}]{#3}{#4}{#5}%
}

\renewcommand*{\CustomAcronymFields}{name={\the\glsshorttok}}

\renewcommand*{\SetCustomDisplayStyle}[1]{%
  \defglsentryfmt[#1]{%
    \ifdefempty\glscustomtext
    {%
      \ifglsused\glslabel
      {% subsequent use
        \glsgenentryfmt
      }%
      {% First use
       % Get the label of the corresponding main entry (stored in
       % user1 field)
        \edef\mainlabel{\glsentryuseri{\glslabel}}%
        % If empty, then there's no linked entry
        \ifdefempty\mainlabel
        {% use generic format
          \glsgenentryfmt
        }%
        {%
          \glsifplural
          {% plural form
            \glscapscase
            {% no case change
               \glshyperlink[\glsentrylongpl{\glslabel}\glsinsert]{\mainlabel}%
               \space (\glsentryshortpl{\glslabel})%
            }%
            {% first letter uppercase
               \glshyperlink[\Glsentrylongpl{\glslabel}\glsinsert]{\mainlabel}%
               \space (\glsentryshortpl{\glslabel})%
            }%
            {% all caps
               \glshyperlink[\MakeTextUppercase{%
                 \glsentrylongpl{\glslabel}\glsinsert}]{\mainlabel}%
               \MakeTextUppercase{\space (\glsentryshortpl{\glslabel})}%
            }%
          }%
          {% singular form
            \glscapscase
            {% no case change
               \glshyperlink[\glsentrylong{\glslabel}\glsinsert]{\mainlabel}%
               \space (\glsentryshort{\glslabel})%
            }%
            {% first letter uppercase
               \glshyperlink[\Glsentrylong{\glslabel}\glsinsert]{\mainlabel}%
               \space (\glsentryshort{\glslabel})%
            }%
            {% all caps
               \glshyperlink[\MakeTextUppercase{%
                \glsentrylong{\glslabel}\glsinsert}]{\mainlabel}%
               \MakeTextUppercase{\space (\glsentryshort{\glslabel})}%
            }%
          }%
          % add main entry to glossary
          \glsadd{\mainlabel}%
        }%
      }%
    }%
    {% \glsdisp used
       \glscustomtext
    }%
  }%
}

\SetCustomStyle

\newlinkedacr
 {RangeExpansion}% main entry label
 {RE}% acronym label
 {RE}% abbreviation
 {range expansion}% long form
 {A range expansion etc}% description

\begin{document}

First use: \gls{RE}. Subsequent use: \gls{RE}.

\glsresetall
First use: \Gls{RE}. Subsequent use: \Gls{RE}.

\printglossaries

\end{document}

This produces:

Image of resulting document

where the first use long form hyperlinks to the entry in the main glossary, the subsequent use acronyms link to the entry in the list of acronyms, and the description in the list of acronyms links to the corresponding entry in the main glossary.

If you have entries in the main glossary that aren't link in this way to the list of acronyms, you may need to do \glsunsetall[main] to counteract the effect of hyperfirst=false option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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