2

As an alternative to the question detailed Nested conditional glossary terms using Glossaries \ifglsused in \newglossaryentry I would like to add some fields to a glossary definition. Is this possible?

Specifically I would like to add a boolean value, and string to use if if this parameter is true. Alternatively if there is a way to test for a null value in the optional string parameter I would be happy to simplify this to one new field. I plan to use renewcommand to put some conditionals to reconstruct the gls command to accommodate the more robust decision structure.

Heres a small template that could be expanded on if it's possible to add new fields.

\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 Answer 1

3

You can add fields using \glsaddkey before defining your entries (either using \newglossaryentry or \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} 

This produces:

image of document

You can wrap up the test in a command. For example:

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

And then just do

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .