\glsentryuseri在 glossaries.sty 中的定义

\glsentryuseri在 glossaries.sty 中的定义

转到输出部分直接跳到问题。

该包的手册(在某种程度上)清楚地说明了如何使用样式定义中的glossaries预定义键创建自定义样式:user1, user2, user3, user4, user5, and user6

对于\glossentryp.215的重新定义

\glsentryuseri{##1}
\glsentryuserii{##1}
\glsentryuseriii{##1}
\glsentryuseriv{##1}
\glsentryuserv{##1}
\glsentryuservi{##1}

对于\subglossentryp.215的重新定义

\glsentryuseri{##2}
\glsentryuserii{##2}
\glsentryuseriii{##2}
\glsentryuseriv{##2}
\glsentryuserv{##2}
\glsentryuservi{##2}

\glsentryuseri在 glossaries.sty 中的定义

 \newcommand*{\glsentryuseri}[1]{%
   \@gls@entry@field{#1}{useri}%
 }

\glsaddstoragekeyglossaries.sty 中自定义存储键的定义

\newcommand*{\glsaddstoragekey}{\@ifstar\@sglsaddstoragekey\@glsaddstoragekey}
\newcommand*{\@sglsaddstoragekey}[1]{%
  \key@ifundefined{glossentry}{#1}%
  {%
    \expandafter\newcommand\expandafter*\expandafter
     {\csname gls@assign@#1@field\endcsname}[2]{%
       \@@gls@expand@field{##1}{#1}{##2}%
     }%
  }%
  {}%
  \@glsaddstoragekey{#1}%
}
\newcommand*{\@glsaddstoragekey}[3]{%
  \key@ifundefined{glossentry}{#1}%
  {%
    \define@key{glossentry}{#1}{\csdef{@glo@#1}{##1}}%
    \appto\@gls@keymap{,{#1}{#1}}%
    \appto\@newglossaryentryprehook{\csdef{@glo@#1}{#2}}%
    \appto\@newglossaryentryposthook{%
      \letcs{\@glo@tmp}{@glo@#1}%
      \gls@assign@field{#2}{\@glo@label}{#1}{\@glo@tmp}%
    }%
    \newcommand*{#3}[1]{\@gls@entry@field{##1}{#1}}%
  }%
  {%
    \PackageError{glossaries}{Key `#1' already exists}{}%
  }%
}

自定义按键

我已尝试以两种方式添加自定义键。

自定义存储键定义

% Add Storage Key (Store info)
\glsaddstoragekey
  {elementname}% key/value name
  {}% default value if not explicitly set
  {\macelementname}% custom command to access the value if required

自定义常规键定义

% Add Regular Key
%\glsaddkey
%  {elementname}% key/value name
%  {}% default value
%  {\glsmacelementnameentrytext}% no link cs (like \glsentrytext)
%  {\Glsmacelementnameentrytext}% no link ucfirst cs (like \Glsentrytext)
%  {\glsmacelementnametext}% link cs (like \glstext)
%  {\GLsmacelementnametext}% link ucfirst cs (like \GLstext)
%  {\GLSmacelementnametext}% link allcaps cs (like \GLStext)

如何在样式定义中引用自定义键(元素名称)?

在文档本身中,我将其称为\macelementname {<glossID>}

我尝试过使用:

\glsfieldfetch{##1}{elementname}{\test}
\test

工作示例

修改了 的定义tree。查看代码中的注入点。顺便说一句,\macelementname{##1}如果缺少密钥,使用不会崩溃,它只是忽略它。另外,我不确定为什么这个最小示例没有显示“testglossary:pickle”的描述,而我的实际文档却显示。也许我忘记了什么。更新:glsaddkey 和 glsaddstroragekey 的顺序很重要。现在显示描述。

\documentclass{article}
 \usepackage{fontspec}
 \usepackage[nopostdot,nogroupskip]{glossaries}


% Add new style
 \newglossarystyle{customtree}{%
   \renewenvironment{theglossary}%
     % setup environment theglossary
     {\setlength{\parindent}{0pt}%
      \setlength{\parskip}{0pt plus 0.3pt}}%
     {}%
   % have nothing after \begin{theglossary}:
   \renewcommand*{\glossaryheader}{}%
   % have nothing between glossary groups:
   \renewcommand*{\glsgroupheading}[1]{}%
   % set how each entry should appear:
   \renewcommand{\glossentry}[2]{%
     \hangindent0pt\relax
     \parindent0pt\relax
     \glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}} (INJECTION \macelementname{##1})}% Reason for glstreenamefmt
     \ifglshassymbol{##1}{\space(\glossentrysymbol{##1})}{}% if symbol, put it in parenthesis
     \space\glossentrydesc{##1}% the description
     \glspostdescription% the post description
     \space##2\par% the page refs list
   }%
   \renewcommand{\subglossentry}[3]{%\subglossentry{level}{label}{number list}
     \hangindent##1\glstreeindent\relax
     \parindent##1\glstreeindent\relax
     \ifnum##1=1\relax
       \glssubentryitem{##2}%
     \fi
     \glstreenamefmt{\glstarget{##2}{\glossentryname{##2}}}%
     \ifglshassymbol{##2}{\space(\glossentrysymbol{##2})}{}%
     \space\glossentrydesc{##2}\glspostdescription\space ##3\par
   }%
   \renewcommand*{\glsgroupskip}{\ifglsnogroupskip\else\indexspace\fi}
 }

% Add Storage Key (Store info)
\glsaddstoragekey
  {elementname}% key/value name
  {}% default value if not explicitly set
  {\macelementname}% custom command to access the value if required

% Add Regular Key
%\glsaddkey
%  {elementname}% key/value name
%  {}% default value
%  {\glsmacelementnameentrytext}% no link cs (like \glsentrytext)
%  {\Glsmacelementnameentrytext}% no link ucfirst cs (like \Glsentrytext)
%  {\glsmacelementnametext}% link cs (like \glstext)
%  {\GLsmacelementnametext}% link ucfirst cs (like \GLstext)
%  {\GLSmacelementnametext}% link allcaps cs (like \GLStext)



 % Define Glossaries and Associated File Extensions
 \newglossary[tlg]{testglossary}{testglossaryd}{testglossaryn}{Test Glossary}
 \provideglossaryentry{testglossary:pickle}{%
  type={testglossary},
  name={pickle},
  description={
  A delicious cucumber.
  },
}


 \makenoidxglossaries % Required
 \begin{document}
 \glsaddall % add all keys
 \printnoidxglossary[type=testglossary, sort=letter,style=customtree]
 \end{document}

输出

请注意,在“INJECTION”之后,我们应该看到“elementname”键的值(\macelementname{##1}在此处输入图片描述

相关内容