在词汇表中创建新字段 newglossaryentry

在词汇表中创建新字段 newglossaryentry

作为问题的替代方案,详细使用 \newglossaryentry 中的词汇表 \ifglsused 嵌套条件词汇表术语我想在词汇表定义中添加一些字段。可以吗?

具体来说,我想添加一个布尔值和字符串,如果此参数为真,则使用。或者,如果有一种方法可以测试可选字符串参数中的空值,我很乐意将其简化为一个新字段。我计划使用 renewcommand 放置一些条件来重建 gls 命令以适应更强大的决策结构。

这是一个可以扩展的小模板,如果可以添加新字段的话。

\documentclass{article}
\usepackage[utf8]{inputenc}
\setlength\parindent{0pt}
%=========================================================================================================================================
% PACKAGES REQUIRED FOR GLOSSARIES
%=========================================================================================================================================

% Glossaries must be loaded before amsmath as per details in the following forum answer
% https://tex.stackexchange.com/questions/85696/what-causes-this-strange-interaction-between--and-amsmath
\usepackage[nogroupskip,toc,acronym]{glossaries} % must come after href   
\usepackage{scrwfile}%http://www.dickimaw-books.com/cgi-bin/faq.cgi?action=view&categorylabel=glossaries#glsnewwriteexceeded
\usepackage{siunitx,microtype,textcomp,textgreek}
\makeglossaries

\newglossaryentry{TNF}{ 
    type={acronym}, 
    sort={tumor necrosis factor},  
    name={TNF}, 
    short={TNF}, 
    long={tumor necrosis factor}, 
    first={tumor necrosis factor (TNF)}, 
    description={tumor necrosis factor}     
}

\begin{document}
    \begin{itemize}
        \item \gls{TNF}
    \end{itemize}
\end{document} 

答案1

您可以使用以下方式添加字段\glsaddkey在定义您的条目之前(使用\newglossaryentry\newacronym)。

\documentclass{article}

\usepackage[nogroupskip,toc,acronym]{glossaries}
\makeglossaries

\glsaddkey
 {foo}% new key
 {\relax}% default value if "foo" isn't used in \newglossaryentry
 {\glsentryfoo}% analogous to \glsentrytext
 {\Glsentryfoo}% analogous to \Glsentrytext
 {\glsfoo}% analogous to \glstext
 {\Glsfoo}% analogous to \Glstext
 {\GLSfoo}% analogous to \GLStext

\newglossaryentry{TNF}{ 
    type={acronym}, 
    sort={tumor necrosis factor},  
    name={TNF}, 
    short={TNF}, 
    long={tumor necrosis factor}, 
    first={tumor necrosis factor (TNF)}, 
    description={tumor necrosis factor},
    foo={something to do with TNF}     
}

% Or just:
\setacronymstyle{long-short}
%\newacronym[foo=something to do with TNF]{TNF}{TNF}{tumor necrosis factor}

% Now for an example without the new field:
\newacronym{TNF2}{TNF2}{tumor necrosis factor2}

\begin{document}
 \begin{itemize}
   \item \gls{TNF} \glsfoo{TNF}
 \end{itemize}

 Is \texttt{foo} field defined?

 TNF:
 \glsletentryfield{\tmp}{TNF}{foo}%
 \if\tmp\relax
  No
 \else
  Yes
 \fi

 TNF2:
 \glsletentryfield{\tmp}{TNF2}{foo}%
 \if\tmp\relax
  No
 \else
  Yes
 \fi

 Alternatively:

 TNF:
 \expandafter\if\glsentryfoo{TNF}\relax
  not defined
 \else
  defined
 \fi

 TNF2:
 \expandafter\if\glsentryfoo{TNF2}\relax
  not defined
 \else
  defined
 \fi
\end{document} 

得出的结果为:

文件图像

您可以在命令中完成测试。例如:

\newcommand{\isfoodefined}[3]{%
  \expandafter\if\glsentryfoo{#1}\relax
   #3%
  \else
   #2%
  \fi
}

然后就做

\isfoodefined{TNF}{true part}{false part}

相关内容