6

This is a follow up question to here.

How can I set my acronyms glossary to hyperfirst=false and the main glossary to hyperfirst=true? I tried to give that as an option to \printglossary but that doesn't work. In the documentation I can just find a package option to disable hyper references for a particular glossary in total.

Maybe the easiest way would be to set hyperfirst=true and just to redefine the first use of an acronym.

5
+100

Until Nicola implements this feature in glossaries (if ever), I think the only way is to patch the glossaries.sty code for all the commands that use the hyperfirst feature. As far as I know, they are \gls, \Gls, \GLS, \glspl, \Glspl, \GLSpl. If you know anyone else let me know.

This is my attempt. The code between \makeatletter and \makeatother does what you want for the default acronym list.

Note that you have to load glossaries with the option acronym but without the option hyperfirst=false.

% arara: pdflatex: {synctex: yes}
% arara: makeglossaries
% arara: pdflatex: {synctex: yes}
% arara: pdflatex: {synctex: yes}

\documentclass{report}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[colorlinks]{hyperref}
\usepackage[acronym]{glossaries}

\makeatletter
\def\@gls@#1#2[#3]{%
  \glsdoifexists{#2}%
  {%
    \edef\@glo@type{\glsentrytype{#2}}%
    \def\@gls@link@opts{#1}%
    \def\@gls@link@label{#2}%
    \ifglsused{#2}%
    {%
      \def\@glo@text{%
        \csname gls@\@glo@type @display\endcsname
          {\glsentrytext{#2}}{\glsentrydesc{#2}}{\glsentrysymbol{#2}}{#3}}%
    }%
    {%
      \def\@glo@text{%
        \csname gls@\@glo@type @displayfirst\endcsname
          {\glsentryfirst{#2}}{\glsentrydesc{#2}}{\glsentrysymbol{#2}}{#3}}%
    }%
    \ifglsused{#2}%
    {%
      \@gls@link[#1]{#2}{\@glo@text}%
    }%
    {%
      \gls@checkisacronymlist\@glo@type
      \ifthenelse
      {\(\boolean{@glsisacronymlist}\AND \boolean{glsacrfootnote}\)
       \OR \NOT\boolean{glshyperfirst}
      }%
      {%
        \@gls@link[#1,hyper=false]{#2}{\@glo@text}%
      }%
      {%
        \ifx\@glo@type\acronymtype%
          \@gls@link[hyper=false,#1]{#2}{\@glo@text}%
        \else%
          \@gls@link[#1]{#2}{\@glo@text}%
        \fi %
      }%
    }%
    \ifKV@glslink@local
      \glslocalunset{#2}%
    \else
      \glsunset{#2}%
    \fi
  }%
}
\def\@Gls@#1#2[#3]{%
  \glsdoifexists{#2}%
  {%
    \edef\@glo@type{\glsentrytype{#2}}%
    \def\@gls@link@opts{#1}%
    \def\@gls@link@label{#2}%
    \def\glslabel{#2}%
    \ifglsused{#2}%
    {%
      \protected@edef\@glo@text{%
        \csname gls@\@glo@type @display\endcsname
          {\glsentrytext{#2}}{\glsentrydesc{#2}}%
          {\glsentrysymbol{#2}}{#3}}%
    }%
    {%
      \protected@edef\@glo@text{%
        \csname gls@\@glo@type @displayfirst\endcsname
          {\glsentryfirst{#2}}{\glsentrydesc{#2}}%
          {\glsentrysymbol{#2}}{#3}}%
    }%
    \ifglsused{#2}%
    {%
      \@gls@link[#1]{#2}{%
      \expandafter\makefirstuc\expandafter{\@glo@text}}%
    }%
    {%
      \gls@checkisacronymlist\@glo@type
      \ifthenelse
      {%
        \(\boolean{@glsisacronymlist}\AND \boolean{glsacrfootnote}\)
        \OR \NOT\boolean{glshyperfirst}%
      }%
      {%
        \@gls@link[#1,hyper=false]{#2}{%
          \expandafter\makefirstuc\expandafter{\@glo@text}}%
      }%
      {%
        \ifx\@glo@type\acronymtype%
          \@gls@link[#1,hyper=false]{#2}{%
            \expandafter\makefirstuc\expandafter{\@glo@text}}%
        \else%
          \@gls@link[#1]{#2}{%
            \expandafter\makefirstuc\expandafter{\@glo@text}}%
        \fi %
      }%
    }%
    \ifKV@glslink@local
      \glslocalunset{#2}%
    \else
      \glsunset{#2}%
    \fi
  }%
}
\def\@GLS@#1#2[#3]{%
  \glsdoifexists{#2}%
  {%
    \edef\@glo@type{\glsentrytype{#2}}%
    \def\@gls@link@opts{#1}%
    \def\@gls@link@label{#2}%
    \ifglsused{#2}%
    {%
      \def\@glo@text{%
        \csname gls@\@glo@type @display\endcsname
        {\glsentrytext{#2}}{\glsentrydesc{#2}}{\glsentrysymbol{#2}}{#3}%
      }%
    }%
    {%
      \def\@glo@text{%
        \csname gls@\@glo@type @displayfirst\endcsname
        {\glsentryfirst{#2}}{\glsentrydesc{#2}}{\glsentrysymbol{#2}}{#3}%
      }%
    }%
    \ifglsused{#2}%
    {%
      \@gls@link[#1]{#2}{\MakeUppercase{\@glo@text}}%
    }%
    {%
      \gls@checkisacronymlist\@glo@type
      \ifthenelse
      {%
        \(\boolean{@glsisacronymlist}\AND \boolean{glsacrfootnote}\)
        \OR \NOT\boolean{glshyperfirst}}{%
        \@gls@link[#1,hyper=false]{#2}{\MakeUppercase{\@glo@text}}%
      }%
      {%
        \ifx\@glo@type\acronymtype%
          \@gls@link[#1,hyper=false]{#2}{\MakeUppercase{\@glo@text}}%
        \else%
          \@gls@link[#1]{#2}{\MakeUppercase{\@glo@text}}%
        \fi %
      }%
    }%
    \ifKV@glslink@local
      \glslocalunset{#2}%
    \else
      \glsunset{#2}%
    \fi
  }%
}
\def\@glspl@#1#2[#3]{%
  \glsdoifexists{#2}%
  {%
    \edef\@glo@type{\glsentrytype{#2}}%
    \def\@gls@link@opts{#1}%
    \def\@gls@link@label{#2}%
    \ifglsused{#2}%
    {%
      \def\@glo@text{%
        \csname gls@\@glo@type @display\endcsname
          {\glsentryplural{#2}}{\glsentrydescplural{#2}}%
          {\glsentrysymbolplural{#2}}{#3}}%
    }%
    {%
      \def\@glo@text{%
        \csname gls@\@glo@type @displayfirst\endcsname
          {\glsentryfirstplural{#2}}{\glsentrydescplural{#2}}%
          {\glsentrysymbolplural{#2}}{#3}}%
    }%
    \ifglsused{#2}%
    {%
      \@gls@link[#1]{#2}{\@glo@text}%
    }%
    {%
      \gls@checkisacronymlist\@glo@type
      \ifthenelse
      {%
        \(\boolean{@glsisacronymlist}\AND \boolean{glsacrfootnote}\)
         \OR \NOT\boolean{glshyperfirst}%
      }%
      {%
        \@gls@link[#1,hyper=false]{#2}{\@glo@text}%
      }%
      {%
        \ifx\@glo@type\acronymtype%
          \@gls@link[hyper=false,#1]{#2}{\@glo@text}%
        \else%
          \@gls@link[#1]{#2}{\@glo@text}%
        \fi %
      }%
    }%
    \ifKV@glslink@local
      \glslocalunset{#2}%
    \else
      \glsunset{#2}%
    \fi
  }%
}
\def\@Glspl@#1#2[#3]{%
  \glsdoifexists{#2}%
  {%
    \edef\@glo@type{\glsentrytype{#2}}%
    \def\@gls@link@opts{#1}%
    \def\@gls@link@label{#2}%
    \def\glslabel{#2}%
    \ifglsused{#2}%
    {%
      \protected@edef\@glo@text{%
        \csname gls@\@glo@type @display\endcsname
          {\glsentryplural{#2}}{\glsentrydescplural{#2}}%
          {\glsentrysymbolplural{#2}}{#3}}%
    }%
    {%
      \protected@edef\@glo@text{%
        \csname gls@\@glo@type @displayfirst\endcsname
          {\glsentryfirstplural{#2}}{\glsentrydescplural{#2}}%
          {\glsentrysymbolplural{#2}}{#3}}%
    }%
    \ifglsused{#2}%
    {%
      \@gls@link[#1]{#2}{%
        \expandafter\makefirstuc\expandafter{\@glo@text}}%
    }%
    {%
      \gls@checkisacronymlist\@glo@type
      \ifthenelse
      {%
        \(\boolean{@glsisacronymlist}\AND \boolean{glsacrfootnote}\)
        \OR \NOT\boolean{glshyperfirst}%
      }%
      {%
        \@gls@link[#1,hyper=false]{#2}{%
          \expandafter\makefirstuc\expandafter{\@glo@text}}%
      }%
      {%
        \ifx\@glo@type\acronymtype%
          \@gls@link[#1,hyper=false]{#2}{%
            \expandafter\makefirstuc\expandafter{\@glo@text}}%
        \else%
          \@gls@link[#1]{#2}{%
            \expandafter\makefirstuc\expandafter{\@glo@text}}%
        \fi %
      }%
    }%
    \ifKV@glslink@local
      \glslocalunset{#2}%
    \else
      \glsunset{#2}%
    \fi
  }%
}
\def\@GLSpl@#1#2[#3]{%
  \glsdoifexists{#2}%
  {%
    \edef\@glo@type{\glsentrytype{#2}}%
    \def\@gls@link@opts{#1}%
    \def\@gls@link@label{#2}%
    \ifglsused{#2}%
    {%
      \def\@glo@text{%
        \csname gls@\@glo@type @display\endcsname
        {\glsentryplural{#2}}{\glsentrydescplural{#2}}%
        {\glsentrysymbolplural{#2}}{#3}%
      }%
    }%
    {%
      \def\@glo@text{%
        \csname gls@\@glo@type @displayfirst\endcsname
        {\glsentryfirstplural{#2}}{\glsentrydescplural{#2}}%
        {\glsentrysymbolplural{#2}}{#3}%
      }%
    }%
    \ifglsused{#2}%
    {%
      \@gls@link[#1]{#2}{\MakeUppercase{\@glo@text}}%
    }%
    {%
      \gls@checkisacronymlist\@glo@type
      \ifthenelse
      {%
        \(\boolean{@glsisacronymlist}\AND \boolean{glsacrfootnote}\)
        \OR \NOT\boolean{glshyperfirst}%
      }%
      {%
        \@gls@link[#1,hyper=false]{#2}{\MakeUppercase{\@glo@text}}%
      }%
      {%
        \ifx\@glo@type\acronymtype%
          \@gls@link[#1,hyper=false]{#2}{\MakeUppercase{\@glo@text}}%
        \else%
          \@gls@link[#1]{#2}{\MakeUppercase{\@glo@text}}%
        \fi %
      }%
    }%
    \ifKV@glslink@local
      \glslocalunset{#2}%
    \else
      \glsunset{#2}%
    \fi
  }%
}
\makeatother

\newacronym{acro}{acro}{Test Acronym}

\newglossaryentry{gloss}{name={gloss},description={Test Glossary}}

\makeglossaries

\begin{document}

\gls{acro}

\gls{gloss}

\gls{acro}

\gls{gloss}

\clearpage

\printglossary[type=\acronymtype]
\printglossary

\end{document}

Output

enter image description here

3

This has been logged as a feature request. A new version of glossaries is pending (see pending list) but as it's a major update it will take a while to complete. In the meantime, here's a possible solution. The assumption is that the main glossary entries have identical first and text keys (which is presumably why you want the first use to be hyperlinked like the subsequent uses, unlike acronyms where the first use gives more detail.):

\documentclass{article}

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

\makeglossaries

\newglossaryentry{sample}{name={sample},description={an example}}
\newglossaryentry{sample2}{name={sample 2},description={another
example}}

\newacronym{ex1}{short 1}{long 1}
\newacronym{ex2}{short 2}{long 2}

\glsunsetall[main]

\begin{document}

First use: \gls{sample}, \gls{sample2}, \gls{ex1}, \gls{ex2}.

Next use: \gls{sample}, \gls{sample2}, \gls{ex1}, \gls{ex2}.

\printglossaries

\end{document}

Result:

Image of resulting document

  • Thank you. You understood me right. Text and first keys are identical. Thanks for accepting my feature request. But when it is as simple as in your above solution, you could just add this line to your documentation instead of changing something. – LaRiFaRi Sep 17 '13 at 8:32

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.