General[glossaries] output depending on definition of a userkey

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
redted
Posts: 5
Joined: Sat Jul 17, 2010 8:32 pm

[glossaries] output depending on definition of a userkey

Post by redted »

edited:Added minimal example and desired output vs generated output

Hi,
since i have not found a more suiting subforum i'll post this in general.

I use the glossaries package and would like to have different output in the glossarie depending on wether the user1-key (key the package provides as options for the entries) has been defined or not.

I am trying to do this by putting the following into a style definition (for a tabular style thats why there are ampersands and double backslashes):

Code: Select all

\renewcommand*{\glossaryentryfield}[5]{\bfseries{\glstarget{##1}{##2}} & ##3 \\
\ifempty{\glsentryuseri{##1}}
    it & is very empty \\
\else
    & \glsentryuseri{##1} \\%
\fi}

which however results in the following error(s):

Code: Select all

! Undefined control sequence. \ifempty l.49 \setentrycounter{page}\glsnumberformat{a}}} % The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., \hobx'), typeI' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.
I assume it has something to do with the order of the expansion/evaluation.

Greetings ted

P.S.: This is a Crosspost from here (were it has not been answered for 2 days) : http://stackoverflow.com/questions/3245 ... -userkey-h

Minimal example (almost), the part with "\renewcommand*{\glossaryentryfield}" is the important one:

Code: Select all

\documentclass{scrreprt}
\usepackage[latin1]{inputenc}
\usepackage[toc,nomain]{glossaries}
\newglossarystyle{acronymAndExplanation}{%
\glossarystyle{long}
% put the glossary in a longtable environment:
\renewenvironment{theglossary}{\begin{longtable}{lp{\glsdescwidth}}}{\end{longtable}}%
\renewcommand*{\glossaryheader}{}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glossaryentryfield}[5]{\bfseries{\glstarget{##1}{##2}} & ##3 \\
\ifempty{\glsentryuseri{##1}}
	it & is very empty \\
\else
& \glsentryuseri{##1} \\%
\fi
}
\renewcommand*{\glossarysubentryfield}[6]{\glossaryentryfield{##2}{##3}{##4}{##5}{##6}}%
\renewcommand*{\glsgroupskip}{& \\}%
}

\newglossary[abkuerzungen]{abk}{abkin}{abkout}{Abkürzungsverzeichnis}
\makeglossaries

\newacronym[type=abk]{abc}{abc}{Alphabet}
\newacronym[type=abk,user1={my longer description}]{abba}{abba}{Band}

\glsaddall

\begin{document}

\printglossary[type=abk,nonumberlist,style=acronymAndExplanation]

\begin{longtable}{lp{\glsdescwidth}}
\bfseries{abba} & Band \\
 & my longer description \\
\bfseries{abc} & Alphabet \\
\end{longtable}

\end{document}
Attachments
minimalExample.pdf
Sample of output (top) and desired output (bottom)
I am aware that i have to remove the line "it & is very empty \\" in the if-branch, however this line is for debugging to show that both parts of the if seem to be evaluated
(33.46 KiB) Downloaded 366 times
Last edited by redted on Wed Jul 21, 2010 9:08 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

[glossaries] output depending on definition of a userkey

Post by nlct »

\ifempty isn't defined in standard LaTeX, which is what's causing the error message. You can use the ifmtarg package, which provides the internal command \@ifmtarg. For example:

Code: Select all

\documentclass{article}

\usepackage{ifmtarg}
\usepackage[style=long]{glossaries}

\makeglossaries

\makeatletter
\newcommand*{\ifuseriempty}[3]{%
  \protected@edef\tmp{\glsentryuseri{#1}}%
  \expandafter\@ifmtarg\expandafter{\tmp}{#2}{#3}%
}
\makeatother

\renewcommand*{\glossaryentryfield}[5]{\bfseries{\glstarget{#1}{#2}}
& #3 \\
\ifuseriempty{#1}%
  {it &is very empty}%
  { &\glsentryuseri{#1}}%
\\%
}

\newglossaryentry{sample}{name=sample,%
  description={sample without user 1 key}}

\newglossaryentry{sample2}{name=sample2,%
  description={sample with user 1 key},
  user1={User1 Value}}

\begin{document}
\gls{sample}, \gls{sample2}.

\printglossaries
\end{document}
Regards
Nicola Talbot
redted
Posts: 5
Joined: Sat Jul 17, 2010 8:32 pm

[glossaries] output depending on definition of a userkey

Post by redted »

Thank you very much Nicola, the solution works just fine. I stumbled briefly over the fact that i have to use two '#' instead of one '#' if I want too use that in the definition of a new \newglossarystyle enviornment

For my purposes the glossaryentryfield has to look like this:

Code: Select all

\renewcommand*{\glossaryentryfield}[5]{\bfseries{\glstarget{#1}{#2}}
& #3 \\
\ifuseriempty{#1}%
  {}%
  { &\glsentryuseri{#1}\\}%
}
thus only creating rows if the field has been defined.

Thanks again ted
eezacque
Posts: 7
Joined: Mon Jan 06, 2020 5:47 pm

[glossaries] output depending on definition of a userkey

Post by eezacque »

Struggling with exactly the same problem. However, the example by Nicola Talbot gives me a single line of output, with just "sample, sample2." Is this supposed to be a working example?
Post Reply