LaTeX forum ⇒ General[glossaries] output depending on definition of a userkey

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

[glossaries] output depending on definition of a userkey

Postby redted » Sat Jul 17, 2010 8:48 pm

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):
  1. \renewcommand*{\glossaryentryfield}[5]{\bfseries{\glstarget{##1}{##2}} & ##3 \\
  2. \ifempty{\glsentryuseri{##1}}
  3. it & is very empty \\
  4. \else
  5. & \glsentryuseri{##1} \\%
  6. \fi}
  7.  


which however results in the following error(s):
  1. ! 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:

  1. \documentclass{scrreprt}
  2. \usepackage[latin1]{inputenc}
  3. \usepackage[toc,nomain]{glossaries}
  4. \newglossarystyle{acronymAndExplanation}{%
  5. \glossarystyle{long}
  6. % put the glossary in a longtable environment:
  7. \renewenvironment{theglossary}{\begin{longtable}{lp{\glsdescwidth}}}{\end{longtable}}%
  8. \renewcommand*{\glossaryheader}{}%
  9. \renewcommand*{\glsgroupheading}[1]{}%
  10. \renewcommand*{\glossaryentryfield}[5]{\bfseries{\glstarget{##1}{##2}} & ##3 \\
  11. \ifempty{\glsentryuseri{##1}}
  12. it & is very empty \\
  13. \else
  14. & \glsentryuseri{##1} \\%
  15. \fi
  16. }
  17. \renewcommand*{\glossarysubentryfield}[6]{\glossaryentryfield{##2}{##3}{##4}{##5}{##6}}%
  18. \renewcommand*{\glsgroupskip}{& \\}%
  19. }
  20.  
  21. \newglossary[abkuerzungen]{abk}{abkin}{abkout}{Abkürzungsverzeichnis}
  22. \makeglossaries
  23.  
  24. \newacronym[type=abk]{abc}{abc}{Alphabet}
  25. \newacronym[type=abk,user1={my longer description}]{abba}{abba}{Band}
  26.  
  27. \glsaddall
  28.  
  29. \begin{document}
  30.  
  31. \printglossary[type=abk,nonumberlist,style=acronymAndExplanation]
  32.  
  33. \begin{longtable}{lp{\glsdescwidth}}
  34. \bfseries{abba} & Band \\
  35. & my longer description \\
  36. \bfseries{abc} & Alphabet \\
  37. \end{longtable}
  38.  
  39. \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 112 times
Last edited by redted on Wed Jul 21, 2010 9:08 am, edited 1 time in total.

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
nlct
Posts: 263
Joined: Thu Nov 06, 2008 11:15 am
Contact:

Postby nlct » Tue Jul 20, 2010 5:33 pm

\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:
  1. \documentclass{article}
  2.  
  3. \usepackage{ifmtarg}
  4. \usepackage[style=long]{glossaries}
  5.  
  6. \makeglossaries
  7.  
  8. \makeatletter
  9. \newcommand*{\ifuseriempty}[3]{%
  10. \protected@edef\tmp{\glsentryuseri{#1}}%
  11. \expandafter\@ifmtarg\expandafter{\tmp}{#2}{#3}%
  12. }
  13. \makeatother
  14.  
  15. \renewcommand*{\glossaryentryfield}[5]{\bfseries{\glstarget{#1}{#2}}
  16. & #3 \\
  17. \ifuseriempty{#1}%
  18. {it &is very empty}%
  19. { &\glsentryuseri{#1}}%
  20. \\%
  21. }
  22.  
  23. \newglossaryentry{sample}{name=sample,%
  24. description={sample without user 1 key}}
  25.  
  26. \newglossaryentry{sample2}{name=sample2,%
  27. description={sample with user 1 key},
  28. user1={User1 Value}}
  29.  
  30. \begin{document}
  31. \gls{sample}, \gls{sample2}.
  32.  
  33. \printglossaries
  34. \end{document}


Regards
Nicola Talbot

Link:
BBcode:
HTML:
Hide post links
Show post links

redted
Posts: 5
Joined: Sat Jul 17, 2010 8:32 pm

Postby redted » Wed Jul 21, 2010 9:04 am

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:

  1. \renewcommand*{\glossaryentryfield}[5]{\bfseries{\glstarget{#1}{#2}}
  2. & #3 \\
  3. \ifuseriempty{#1}%
  4. {}%
  5. { &\glsentryuseri{#1}\\}%
  6. }

thus only creating rows if the field has been defined.

Thanks again ted

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “General”

Who is online

Users browsing this forum: No registered users and 8 guests