如何将 hyperfirst 设置为仅一个词汇表?

如何将 hyperfirst 设置为仅一个词汇表?

这是一个后续问题这里

我如何将我的首字母缩略词词汇表设置为hyperfirst=false并将主词汇表设置为hyperfirst=true?我尝试将其作为选项提供,\printglossary但不起作用。在文档中,我只能找到一个包选项来完全禁用特定词汇表的超级引用。

也许最简单的方法是设置hyperfirst=true并重新定义首字母缩略词的首次使用。

答案1

在 Nicola 实现此功能之前(如果有的话glossaries),我认为唯一的方法是修补glossaries.sty所有使用该功能的命令的代码hyperfirst。据我所知,它们是,,,,,\gls。如果\Gls你知道其他人,请告诉我。\GLS\glspl\Glspl\GLSpl

\makeatletter这是我的尝试。和之间的代码\makeatother可实现默认缩写列表所需的功能。

请注意,您必须glossaries使用选项来加载acronym,但不能使用选项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}

输出

在此处输入图片描述

答案2

这已被记录为功能请求。 的新版本glossaries正在等待中(请参阅待处理清单),但由于这是一次重大更新,因此需要一段时间才能完成。与此同时,这里有一个可能的解决方案。假设主词汇表条目具有相同的第一个和文本键(这大概就是为什么您希望第一次使用像后续使用一样超链接,而不像首字母缩略词那样第一次使用提供更多详细信息。):

\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}

结果:

生成的文档的图像

相关内容