5

LaTeX/Glossary suggets the following command for combining a glossary entry and an acryonym:

\usepackage{xparse}
\DeclareDocumentCommand{\newdualentry}{ O{} O{} m m m m } {
  \newglossaryentry{gls-#3}{name={#5},text={#5\glsadd{#3}},
    description={#6},#1
  }
  \newacronym[see={[Glossary:]{gls-#3}},#2]{#3}{#4}{#5\glsadd{gls-#3}}
}

How can I add the plural to this command, so I can use \glspl{LED} showing LEDs? I know that appending a 's' is the default plural form, but I need a way to customize the plural. I tried the following with no luck

 \usepackage{xparse}
 \DeclareDocumentCommand{\newdualentry}{ O{} O{} m m m m m } {
     \newglossaryentry{gls-#3}{name={#5},text={#5\glsadd{#3}},
        description={#6},plural={#7},#1
      }
      \newacronym[see={[Glossary:]{gls-#3}},#2]{#3}{#4}{#5\glsadd{gls-#3}}
 }

Thanks!

3
  • Welcome to TeX.SX! Can you provide a compilable document instead of some fragments only?
    – user31729
    Sep 10, 2015 at 19:48
  • Sorry, my document is just too big and there are so many configurations in it that I can't figure out how to shorten it. Sep 10, 2015 at 19:59
  • Please add some more details. I am not sure what you really want to achieve here. I am not sure about the two optional arguments in a row at the beginning.
    – user31729
    Sep 10, 2015 at 20:00

3 Answers 3

4

This works for me (However, a 7-arg command is difficult to remember!):

\documentclass{article}


\usepackage{xparse}

\usepackage[acronym]{glossaries}


\DeclareDocumentCommand{\newdualentry}{O{}D<>{}m m m m m } {
  \newglossaryentry{gls-#3}{
    name={#5},
    text={#5\glsadd{gls-#3}},
    description={#6},
    plural={#7},
    #1
  }
  \newacronym[see={[Glossary:]{gls-#3}},#2]{#3}{#4}{#5\glsadd{gls-#3}}
}

\makeglossaries




\newdualentry{LED}{LED}{LED}{Light emitting diode}{LEDiodes}

\newdualentry{Ox}{Ox}{Ox}{male cow}{Oxen}


\begin{document}

Here is an entry: \gls{gls-LED} \glspl{gls-LED}

An some biology here: \gls{gls-Ox} \glspl{gls-Ox}

\printglossary[type=main]
\printglossary[type=acronym]

\end{document}

enter image description here

Edit Some notes on the design of the command about the optional arguments:

Say,you've got a small document like this

\documentclass{article}

\usepackage{xparse}

\DeclareDocumentCommand{\somecmd}{O{}O{}m}{%
Optional 1: #1

Optional 2: #2

mandatory: #3
}

\begin{document}

\somecmd[A][B]{C}

\somecmd[A]{C}

\somecmd[][B]{C}



\end{document}
  1. The first call will assign A, B and C correctly to the relevant slots
  2. The second call will use A for the 1st, C for the 3rd one --> the 2nd one is empty --> Is this correct? Yes and no, since it's not clear that A is meant for the 1st or the 2nd optional argument.
  3. This call will explicitly leave the 1st one empty, the others are 'correct'

It's better to replace the 2nd optional argument style with D<>{} or similar tokens to make some difference. Or append the 2nd optional argument to the end of the list, being the 3rd argument here.

2
  • Hi Christian, thanks for your reply. This works regarding the printing of the plural form. The problem now is, that I combine the acronym and glossary list: If I add the LED entry as you suggested, I would expect an acronym entry "LED Light emitting diode" AND a glossary entry with a description: "Light emitting diode - A small bulb that emits light." With your suggestion, the description is lost in my glossary, only the long form of the abbreviation is shown. I hope you understand what I mean. Sep 11, 2015 at 8:03
  • Got it! \newdualentry{LED}{LED}{Light emitting diode}{Description}{LEDiodes} works as expected; I just had to clean the TexStudio cache (help files etc.) Thanks! Sep 11, 2015 at 8:12
1

Thats an MWE of how I use it. (mostly in german)

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref} % optional
\usepackage[acronym,toc,shortcuts,xindy,section=section]{glossaries}
\makenoidxglossaries

\usepackage{xparse}


% #1 = optional newglossaryentry value
% #2 = optional newacronym parameter
% #3 = label
% #4 = short form
% #5 = short form plural
% #6 = long form
% #7 = long form plural
% #8 = description
\DeclareDocumentCommand{\newdualentry}{ O{} D<>{} m m m m m m } {
  \newglossaryentry{gls-#3}{
    name={#4},
    shortplural={#5},
    text={#4\glsadd{gls-#3}},
    longplural={#7},
    description={#8},
    sort={#4},
    #1
  }
  \newacronym[see={[Glossar:]{gls-#3}},#2,shortplural=#5,longplural=#7]{#3}{#4}{#6\glsadd{gls-#3}}
}

\newdualentry{abb} % label
{\textbf{abbreviation}} % abbreviation
{\textbf{abbreviation plural}} % abbreviation plural
{\textbf{long form}} % long form
{\textbf{long form plural}} % long form plural
{\textbf{The description is a very long text.
It explains everything you need to know}} % description


\begin{document}

\printnoidxglossary[title=List of Abbreviations, type=\acronymtype, style=altlist]

\clearpage
\section{Chapter One}

This is what the first use of a glossary entry looks like: \glsfirst{abb} by default.\\
This is what the first use of a glossary entry plural looks like: \glsfirstplural{abb} by default.\\


First gls call in my text: \gls{abb}.\\
Next gls call: \gls{abb}.\\
First glspl call in my text: \glspl{abb}.\\
Next glspl call: \glspl{abb}.\\

\clearpage
\printnoidxglossary[title=Glossary,style=altlist]

\end{document}
1
  • Raphael's code above (with 8 parameters) works perfectly for me as a standalone MWE. However, when I incorporate Raphael's \newdualentry code within my larger LaTeX project, I'm seeing the following error: ! LaTeX cmd Error: Bad argument specification ' O{} D' for command (cmd) '\newdualentry'. Before I attempt to understand what is happening (apologies for not providing a MWE) I'm curious if anyone else has experienced the same error, and possibly what I need to look for in my own code to correct the error. Thanks. Jan 22 at 19:40
0

Without any modifications, use the optional parameters:

\newdualentry
[    plural={Light Emitting Diodes}]  % Glossary
[longplural={Light Emitting Diodes}   % Acronym
,shortplural={LEDs}]
{led}{LED}{Light Emitting Diode}{...}

You must log in to answer this question.

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